Cesium的单体化就我接触过的来说分两种:
1、通过数据内部属性进行单体化:
例如:官网案例(https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=3D%20Tiles%20Feature%20Styling.html&label=All)
通过对3dtiles的某个属性进行分段达到分类的目的;
2、矢量面叠加单体化:通过classificationType属性来进行单体化;
步骤:
a:首先添加3dtiles模型
b:绘制矢量面,其中矢量面的坐标可手动绘制,保存;
c:矢量面叠加到3dtiles模型上
d:添加一个移动的面及样式,绑定移动事件,移动时获取当前选中的面的坐标,设定移动面的坐标为当前选中的面;
3、promitive添加模型,通过classificationType属性来进行单体化
参考案例(https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Classification.html&label=All)
步骤:
a:先添加primitve模型
var treeHighlight3 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(2.45, 2.45, 3.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#004FFF').withAlpha(0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume 3'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
b:加入鼠标移入事件设定样式
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var pickedObject = scene.pick(movement.endPosition);
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id)) {
if (pickedObject.id === currentObjectId) {
return;
}
if (Cesium.defined(currentObjectId)) {
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
currentShow = undefined;
}
}
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.primitive) && Cesium.defined(pickedObject.id) && Cesium.defined(pickedObject.primitive.getGeometryInstanceAttributes)) {
currentObjectId = pickedObject.id;
currentPrimitive = pickedObject.primitive;
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
currentColor = attributes.color;
currentShow = attributes.show;
if (!scene.invertClassification) {
attributes.color = [255, 0, 255, 128];
}
attributes.show = [1];
} else if (Cesium.defined(currentObjectId)) {
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
目前分层和分栋包括分户的单体化已完成。