Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vtxf committed Nov 9, 2019
2 parents bad6484 + 4b2bfd7 commit e0a9a4b
Show file tree
Hide file tree
Showing 37 changed files with 2,418 additions and 191 deletions.
63 changes: 45 additions & 18 deletions Apps/Examples/cesium-primitive-customMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
.defultbtn:hover {
background-color: #b3daf8;
}

.btnon {
background-color: #1E9FFF;
color: #fff;
border: 1px solid #1E9FFF;
}
</style>
</head>

Expand All @@ -52,24 +58,29 @@
</div>

<script>
var myBox = {}, colorMaterial = {}, imageMaterial = {}, compositeMaterial = {}, customMaterial = {};
// 1 创建Earth的vue组件
var EarthComp = {
template: `
<div style="width: 100%; height: 100%">
<div ref="earthContainer" style="width: 100%; height: 100%">
</div>
<div class="box" style="position: absolute; left: 18px; top: 18px; color: white; background: rgba(0, 0, 0, 0.6); padding: 20px; border-radius: 25px;min-width:200px; font-size:24px; font-family: 宋体;">
<div class="defultbtn" @click="colorMaterialClick">纯色材质</div>
<div class="defultbtn" @click="imageMaterialClick">图像材质</div>
<div class="defultbtn" @click="compositeMaterialClick">组合材质</div>
<div class="defultbtn" @click="customMaterialClick">自定义Shader材质</div><br/>
<div class="defultbtn" :class="{'btnon':colorMaterialShow}" @click="colorMaterialClick">纯色材质</div>
<div class="defultbtn" :class="{'btnon':imageMaterialShow}" @click="imageMaterialClick">图像材质</div>
<div class="defultbtn" :class="{'btnon':compositeMaterialShow}" @click="compositeMaterialClick">组合材质</div>
<div class="defultbtn" :class="{'btnon':customMaterialShow}" @click="customMaterialClick">自定义Shader材质</div><br/>
</div>
</div>
`,
data() {
return {
_earth: undefined, // 注意:Earth和Cesium的相关变量放在vue中,必须使用下划线作为前缀!
_tileset: undefined
_tileset: undefined,
colorMaterialShow: false,
imageMaterialShow: false,
compositeMaterialShow: false,
customMaterialShow: false
};
},
// 1.1 资源加载
Expand Down Expand Up @@ -181,7 +192,7 @@
20, 21, 22, 20, 22, 23,
]);
// 5 创建Primitive
this.myBox = viewer.scene.primitives.add(new Cesium.Primitive({
myBox = viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.Geometry({
attributes: {
Expand Down Expand Up @@ -228,7 +239,7 @@

// 6 创建material
// 6.1 创建纯色material
this.colorMaterial = new Cesium.Material({
colorMaterial = new Cesium.Material({
fabric: {
type: 'Color',
uniforms: {
Expand All @@ -242,7 +253,7 @@
translucent: false
});
// 6.2 创建图像material
this.imageMaterial = new Cesium.Material({
imageMaterial = new Cesium.Material({
fabric: {
type: 'Image',
uniforms: {
Expand All @@ -259,7 +270,7 @@
});
// 6.3 创建组合material
// Material创建几个material来组合使用,以下其写法
this.compositeMaterial = new Cesium.Material({
compositeMaterial = new Cesium.Material({
fabric: {
type: 'OurMappedPlastic',
materials: {
Expand Down Expand Up @@ -291,7 +302,7 @@
});
// 6.4 创建自定义shader的material
// 模拟纯色到图像的过渡过程
this.customMaterial = new Cesium.Material({
customMaterial = new Cesium.Material({
fabric: {
type: 'MyCustomShader1',
uniforms: {
Expand Down Expand Up @@ -321,29 +332,45 @@
});

// 使用纯色材质
// this.myBox.appearance.material = colorMaterial;
// myBox.appearance.material = colorMaterial;
// 使用图像材质
// this.myBox.appearance.material = imageMaterial;
// myBox.appearance.material = imageMaterial;
// 使用组合材质
// this.myBox.appearance.material = compositeMaterial;
// myBox.appearance.material = compositeMaterial;
// 自定义Shader材质
// this.myBox.appearance.material = customMaterial;
// myBox.appearance.material = customMaterial;

// only for Debug
window.earth = earth;
},
methods: {
colorMaterialClick() {
this.myBox.appearance.material = this.colorMaterial;
myBox.appearance.material = colorMaterial;
this.colorMaterialShow = true;
this.imageMaterialShow = false;
this.compositeMaterialShow = false;
this.customMaterialShow = false;
},
imageMaterialClick() {
this.myBox.appearance.material = this.imageMaterial;
myBox.appearance.material = imageMaterial;
this.colorMaterialShow = false;
this.imageMaterialShow = true;
this.compositeMaterialShow = false;
this.customMaterialShow = false;
},
compositeMaterialClick() {
this.myBox.appearance.material = this.compositeMaterial;
myBox.appearance.material = compositeMaterial;
this.colorMaterialShow = false;
this.imageMaterialShow = false;
this.compositeMaterialShow = true;
this.customMaterialShow = false;
},
customMaterialClick() {
this.myBox.appearance.material = this.customMaterial;
myBox.appearance.material = customMaterial;
this.colorMaterialShow = false;
this.imageMaterialShow = false;
this.compositeMaterialShow = false;
this.customMaterialShow = true;
}
},
// 1.2 资源销毁
Expand Down
4 changes: 2 additions & 2 deletions Apps/Examples/earth-analyzation-clipping.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@
this._disposers = [];
this._disposers.push(XE.MVVM.bind(this, 'positionEditing', clippingPlane, 'positionEditing'));
this._disposers.push(XE.MVVM.bind(this, 'rotationEditing', clippingPlane, 'rotationEditing'));
this._disposers.push(XE.MVVM.bind(this, 'position', clippingPlane, 'position'));
this._disposers.push(XE.MVVM.bind(this, 'rotation', clippingPlane, 'rotation'));
this._disposers.push(XE.MVVM.bindPosition(this, 'position', clippingPlane, 'position'));
this._disposers.push(XE.MVVM.bindRotation(this, 'rotation', clippingPlane, 'rotation'));
}

this.positionEditing = true; // 默认状态开启位置编辑
Expand Down
4 changes: 2 additions & 2 deletions Apps/Examples/earth-analyzation-video.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
'twoPostionsEditing'));
this._disposers.push(XE.MVVM.bind(this, 'positionEditing', cameravideo, 'positionEditing'));
this._disposers.push(XE.MVVM.bind(this, 'rotationEditing', cameravideo, 'rotationEditing'));
this._disposers.push(XE.MVVM.bind(this, 'position', cameravideo, 'position'));
this._disposers.push(XE.MVVM.bind(this, 'rotation', cameravideo, 'rotation'));
this._disposers.push(XE.MVVM.bindPosition(this, 'position', cameravideo, 'position'));
this._disposers.push(XE.MVVM.bindRotation(this, 'rotation', cameravideo, 'rotation'));
this._disposers.push(XE.MVVM.bind(this, 'near', cameravideo, 'near'));
this._disposers.push(XE.MVVM.bind(this, 'far', cameravideo, 'far'));
this._disposers.push(XE.MVVM.bind(this, 'showHelper', cameravideo, 'showHelper'));
Expand Down
6 changes: 2 additions & 4 deletions Apps/Examples/earth-analyzation-viewshed.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,15 @@
this._disposers.push(XE.MVVM.bind(this, 'twoPostionsEditing', viewshed, 'twoPostionsEditing'));
this._disposers.push(XE.MVVM.bind(this, 'positionEditing', viewshed, 'positionEditing'));
this._disposers.push(XE.MVVM.bind(this, 'rotationEditing', viewshed, 'rotationEditing'));
this._disposers.push(XE.MVVM.bind(this, 'position', viewshed, 'position'));
this._disposers.push(XE.MVVM.bind(this, 'rotation', viewshed, 'rotation'));
this._disposers.push(XE.MVVM.bindPosition(this, 'position', viewshed, 'position'));
this._disposers.push(XE.MVVM.bindRotation(this, 'rotation', viewshed, 'rotation'));
this._disposers.push(XE.MVVM.bind(this, 'near', viewshed, 'near'));
this._disposers.push(XE.MVVM.bind(this, 'far', viewshed, 'far'));
this._disposers.push(XE.MVVM.bindDegreeRadian(this, 'fovH', viewshed, 'fovH'));
this._disposers.push(XE.MVVM.bindDegreeRadian(this, 'fovV', viewshed, 'fovV'));
tileset1.flyTo();
}



this._earth = earth;
},
filters: {
Expand Down
132 changes: 132 additions & 0 deletions Apps/Examples/earth-customGroundRectangle-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="xbsj-labels" content="Earth示例"></meta>
<title>自定义贴地矩形-image</title>
<!-- 0 引入js文件 -->
<script src="../../XbsjEarth/XbsjEarth.js"></script>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}

#canvas-container {
width: 600px;
height: 600px;
position: absolute;
right: 0px;
top: 0px;
}
</style>
</head>

<body>
<div id="earthContainer" style="width: 100%; height: 100%; background: grey">
</div>
<script>
var earth;
var bgImagery;

function startup() {
earth = new XE.Earth('earthContainer');

earth.sceneTree.root = {
"children": [
{
"czmObject": {
"name": "谷歌影像",
"xbsjType": "Imagery",
"xbsjImageryProvider": {
"XbsjImageryProvider": {
"url": "//www.google.cn/maps/vt?lyrs=s,h&gl=CN&x={x}&y={y}&z={z}",
"srcCoordType": "GCJ02",
"dstCoordType": "WGS84",
"maximumLevel": 21,
},
}
},
}, {
"czmObject": {
"xbsjType": "Terrain",
"name": "中国14级(测试)",
"xbsjTerrainProvider": {
"type": "XbsjCesiumTerrainProvider",
"XbsjCesiumTerrainProvider": {
"url": "//lab.earthsdk.com/terrain/577fd5b0ac1f11e99dbd8fd044883638",
"requestVertexNormals": true,
"requestWaterMask": true
}
}
}
}
]
};

var p = createGroundCircle(earth);

p.flyTo();

window.p = p; // 方便调试
}

// 1 XE.ready()会加载Cesium.js等其他资源,注意ready()返回一个Promise对象。
XE.ready().then(startup);

function createGroundCircle(earth) {
var p = new XE.Obj.CustomGroundRectangle(earth)
p.position = [2.02729390339372, 0.6980810742548738, 755.036813823199];
p.width = 3000;
p.height= 3000;
p.canvasWidth = 512;
p.canvasHeight = 512;
// p.color = [0.5, 0.8, 1, 2];

let ctx_image = undefined;
Cesium.Resource.createIfNeeded('./images/circle.png').fetchImage().then(function(image) {
console.log('image loaded!');
ctx_image = image;
});

let angle = 0.0;
earth.czm.scene.preUpdate.addEventListener(() => {
angle -= 1.0;
if (angle > 360.0) {
angle = 0.0;
}
const rotation = angle / 180.0 * Math.PI;

p.drawCanvas(ctx => {
ctx.clearRect(0, 0, 512, 512);

ctx.beginPath();
ctx.strokeStyle = "rgb(128, 128, 128)";
// ctx.setLineDash([8, 8]);
ctx.lineWidth = 1;
ctx.arc(256, 256, 250, 0, Math.PI*2, true);
ctx.stroke();

if (ctx_image) {
ctx.save();
ctx.translate(256, 256);
ctx.rotate(rotation);
ctx.translate(-256, -256);
ctx.drawImage(ctx_image, 0, 0);
ctx.restore();
}
});
});

return p;
}
</script>
</body>

</html>
13 changes: 7 additions & 6 deletions Apps/Examples/earth-customPrimitive-character.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@
};

var p = new XE.Obj.CustomPrimitive(earth)
p.positions = [0,0,0,10,0,0,10,10,0,0,10,0,];
// p.normals = [0,0,1,0,0,1,0,0,1,0,0,1];
p.sts = [0,0, 1,0, 1,1, 0,1, ];
// p.colors = [1,1,0,1, 1,1,1,1, 1,1,1,1, 1,1,1,1];
p.indices = [0, 1, 2, 0, 2, 3];
// p.rotation = [0, 1.57, 0];

p.position = [116.39, 39.9, 10.0].xeptr;
p.positions = XE.Obj.CustomPrimitive.Geometry.unitSquare.positions;
p.sts = XE.Obj.CustomPrimitive.Geometry.unitSquare.sts;
p.indices = XE.Obj.CustomPrimitive.Geometry.unitSquare.indices;
p.scale = [100, 100, 1];

p.renderState = XE.Obj.CustomPrimitive.getRenderState(true, true);

p.vertexShaderSource = '#define FLAT\n' + p.vertexShaderSource;
Expand Down
16 changes: 9 additions & 7 deletions Apps/Examples/earth-customPrimitive-circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
};

var p = new XE.Obj.CustomPrimitive(earth)
window.p = p; // 方便调试
p.positions = [0,0,0,10,0,0,10,10,0,0,10,0,];
// p.normals = [0,0,1,0,0,1,0,0,1,0,0,1];
p.sts = [0,0, 1,0, 1,1, 0,1, ];
// p.colors = [1,1,0,1, 1,1,1,1, 1,1,1,1, 1,1,1,1];
p.indices = [0, 1, 2, 0, 2, 3];
// p.rotation = [0, 1.57, 0];

p.position = [116.39, 39.9, 10.0].xeptr;
p.positions = XE.Obj.CustomPrimitive.Geometry.unitSquare.positions;
p.sts = XE.Obj.CustomPrimitive.Geometry.unitSquare.sts;
p.indices = XE.Obj.CustomPrimitive.Geometry.unitSquare.indices;
p.scale = [100, 100, 1];

p.renderState = XE.Obj.CustomPrimitive.getRenderState(true, true);

// var imageUri = './images/earth.png';
Expand Down Expand Up @@ -145,6 +145,8 @@
});

p.flyTo();

window.p = p; // 方便调试
}

// 1 XE.ready()会加载Cesium.js等其他资源,注意ready()返回一个Promise对象。
Expand Down
Loading

0 comments on commit e0a9a4b

Please sign in to comment.