cesium model 自定义属性
时间: 2024-01-16 20:18:01 浏览: 277
在Cesium中,可以使用三种方式来修改模型节点组件的属性,包括比例、旋转、移动等。这三种方式分别是CZML、nodeTransformations和自定义属性。
1. 使用CZML:CZML是一种用于描述Cesium场景的JSON格式。通过使用CZML,可以在模型节点组件中定义自定义属性。以下是一个示例代码:
```javascript
var czml = [{
"id": "model",
"model": {
"gltf": "path/to/model.gltf",
"nodeTransformations": [{
"node": "nodeName",
"scale": {
"cartesian": [2.0, 2.0, 2.0]
},
"rotation": {
"unitQuaternion": [0.0, 0.0, 0.0, 1.0]
},
"translation": {
"cartesian": [10.0, 10.0, 10.0]
}
}]
}
}];
viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));
```
2. 使用nodeTransformations:nodeTransformations是Cesium模型节点组件的属性之一,可以通过它来修改模型节点的比例、旋转和移动等属性。以下是一个示例代码:
```javascript
var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
url: 'path/to/model.gltf',
modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(0.0, 0.0, 0.0)),
nodeTransformations: {
'nodeName': {
scale: new Cesium.Cartesian3(2.0, 2.0, 2.0),
rotation: Cesium.Quaternion.fromAxisAngle(Cesium.Cartesian3.UNIT_Z, Cesium.Math.toRadians(45)),
translation: new Cesium.Cartesian3(10.0, 10.0, 10.0)
}
}
}));
```
3. 使用自定义属性:除了CZML和nodeTransformations,还可以通过自定义属性来修改模型节点组件的属性。以下是一个示例代码:
```javascript
var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
url: 'path/to/model.gltf',
modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(0.0, 0.0, 0.0)),
customProperties: {
'nodeName': {
scale: new Cesium.Cartesian3(2.0, 2.0, 2.0),
rotation: Cesium.Quaternion.fromAxisAngle(Cesium.Cartesian3.UNIT_Z, Cesium.Math.toRadians(45)),
translation: new Cesium.Cartesian3(10.0, 10.0, 10.0)
}
}
}));
```
阅读全文
相关推荐


















