区块链技术博客
www.b2bchain.cn

Babylon.js 构建 地球,支持切片地图 (四)求职学习资料

本文介绍了Babylon.js 构建 地球,支持切片地图 (四)求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

对于切片管理类

Babylon.js 构建 地球,支持切片地图 (四)

针对切片shader 获取

TileTexture类 , 调整PROVIDER 可以支持不同的切片地图
“`javascript
const BABYLON = require(‘babylonjs’);

export class TileTexture {
constructor(scene, callback, level, k, j, quadkey) {
this.scene = scene,
this.callback = callback,
this.level = level,
this.k = k,
this.j = j,
this.quadkey = quadkey,
this.maptilerKey = “ebmPcf5wTgRus4imoGrg”,
this.build(level, k, j)
}
build(level, k, j) {
BABYLON.Effect.ShadersStore.sg0VertexShader = “precision highp float;rnrnattribute vec3 position;rnattribute vec2 uv;rnuniform mat4 worldViewProjection;rnuniform float earthRadius;rnuniform float zDepth;rnvarying vec2 vUV; rnvec3 spherify(float y, float x) {rn float phi = radians(90. – x);rn float theta = radians(y);rn vec3 pos = vec3((earthRadius) * sin(phi) * cos(theta), (earthRadius) * cos(phi), (earthRadius) * sin(phi) * sin(theta));rn return pos ;rn}rnvoid main(void) {;rn vec3 position2d = spherify(position.x,position.z);rn gl_Position = worldViewProjection * vec4(position2d, 1.0);rn vUV = uv;rn}rn”,
BABYLON.Effect.ShadersStore.sg0FragmentShader = “precision highp float;rnuniform sampler2D textureSampler;rnvarying vec2 vUV; rnfloat maxX = 1.0; rnfloat minX = 0.0;rnvoid main(void) {rnif (vUV.x <= maxX && vUV.x >= minX && rnvUV.y <= maxX && vUV.y >= minX) { rngl_FragColor = texture2D(textureSampler, vUV); rn} else { rngl_FragColor = vec4(.15,.15,.15,0); rn} rn}rn”,
this.shaderMaterial = new BABYLON.ShaderMaterial(“sg0Shader”,this.scene,{
vertexElement: “sg0”,
fragmentElement: “sg0”
},{
attributes: [“position”, “normal”, “uv”],
uniforms: [“world”, “worldView”, “worldViewProjection”, “view”, “projection”],
needAlphaBlending: true
}),
this.shaderMaterial.setFloat(“earthRadius”, 50),

对于切片管理类

Babylon.js 构建 地球,支持切片地图 (四)

针对切片shader 获取

TileTexture类 , 调整PROVIDER 可以支持不同的切片地图
“`javascript
const BABYLON = require(‘babylonjs’);

export class TileTexture {
constructor(scene, callback, level, k, j, quadkey) {
this.scene = scene,
this.callback = callback,
this.level = level,
this.k = k,
this.j = j,
this.quadkey = quadkey,
this.maptilerKey = “ebmPcf5wTgRus4imoGrg”,
this.build(level, k, j)
}
build(level, k, j) {
BABYLON.Effect.ShadersStore.sg0VertexShader = “precision highp float;rnrnattribute vec3 position;rnattribute vec2 uv;rnuniform mat4 worldViewProjection;rnuniform float earthRadius;rnuniform float zDepth;rnvarying vec2 vUV; rnvec3 spherify(float y, float x) {rn float phi = radians(90. – x);rn float theta = radians(y);rn vec3 pos = vec3((earthRadius) * sin(phi) * cos(theta), (earthRadius) * cos(phi), (earthRadius) * sin(phi) * sin(theta));rn return pos ;rn}rnvoid main(void) {;rn vec3 position2d = spherify(position.x,position.z);rn gl_Position = worldViewProjection * vec4(position2d, 1.0);rn vUV = uv;rn}rn”,
BABYLON.Effect.ShadersStore.sg0FragmentShader = “precision highp float;rnuniform sampler2D textureSampler;rnvarying vec2 vUV; rnfloat maxX = 1.0; rnfloat minX = 0.0;rnvoid main(void) {rnif (vUV.x <= maxX && vUV.x >= minX && rnvUV.y <= maxX && vUV.y >= minX) { rngl_FragColor = texture2D(textureSampler, vUV); rn} else { rngl_FragColor = vec4(.15,.15,.15,0); rn} rn}rn”,
this.shaderMaterial = new BABYLON.ShaderMaterial(“sg0Shader”,this.scene,{
vertexElement: “sg0”,
fragmentElement: “sg0”
},{
attributes: [“position”, “normal”, “uv”],
uniforms: [“world”, “worldView”, “worldViewProjection”, “view”, “projection”],
needAlphaBlending: true
}),
this.shaderMaterial.setFloat(“earthRadius”, 50),

对于切片管理类

Babylon.js 构建 地球,支持切片地图 (四)

针对切片shader 获取

TileTexture类 , 调整PROVIDER 可以支持不同的切片地图
“`javascript
const BABYLON = require(‘babylonjs’);

export class TileTexture {
constructor(scene, callback, level, k, j, quadkey) {
this.scene = scene,
this.callback = callback,
this.level = level,
this.k = k,
this.j = j,
this.quadkey = quadkey,
this.maptilerKey = “ebmPcf5wTgRus4imoGrg”,
this.build(level, k, j)
}
build(level, k, j) {
BABYLON.Effect.ShadersStore.sg0VertexShader = “precision highp float;rnrnattribute vec3 position;rnattribute vec2 uv;rnuniform mat4 worldViewProjection;rnuniform float earthRadius;rnuniform float zDepth;rnvarying vec2 vUV; rnvec3 spherify(float y, float x) {rn float phi = radians(90. – x);rn float theta = radians(y);rn vec3 pos = vec3((earthRadius) * sin(phi) * cos(theta), (earthRadius) * cos(phi), (earthRadius) * sin(phi) * sin(theta));rn return pos ;rn}rnvoid main(void) {;rn vec3 position2d = spherify(position.x,position.z);rn gl_Position = worldViewProjection * vec4(position2d, 1.0);rn vUV = uv;rn}rn”,
BABYLON.Effect.ShadersStore.sg0FragmentShader = “precision highp float;rnuniform sampler2D textureSampler;rnvarying vec2 vUV; rnfloat maxX = 1.0; rnfloat minX = 0.0;rnvoid main(void) {rnif (vUV.x <= maxX && vUV.x >= minX && rnvUV.y <= maxX && vUV.y >= minX) { rngl_FragColor = texture2D(textureSampler, vUV); rn} else { rngl_FragColor = vec4(.15,.15,.15,0); rn} rn}rn”,
this.shaderMaterial = new BABYLON.ShaderMaterial(“sg0Shader”,this.scene,{
vertexElement: “sg0”,
fragmentElement: “sg0”
},{
attributes: [“position”, “normal”, “uv”],
uniforms: [“world”, “worldView”, “worldViewProjection”, “view”, “projection”],
needAlphaBlending: true
}),
this.shaderMaterial.setFloat(“earthRadius”, 50),

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Babylon.js 构建 地球,支持切片地图 (四)求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们