The thing about me and EarthSDK Cesium (1) Model data singulation

words written in front

The effect achieved in this article is to display the 3dTileset model, and change the color when clicking on a single model, which is the so-called model singulation. This function is of great significance and is the basis of many needs.

Effect

Model Unitization Demonstration

Implementation ideas

  • Click the left mouse button to get the position
  • Obtain the model object or 3DTile object under the position according to the mouse position through the corresponding Api
  • Modify the corresponding model or a single 3dTile attribute value

problems encountered

The 3DTile object obtained through Cesium's Api viewer.scene.drillPick may not be a whole. For example, a building may be divided into many parts. This requires communication with colleagues who make model data to make the required model. A whole, and mark the specific model with the corresponding id number to facilitate the display and processing of subsequent front-end data.

specific code

    viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
    
    
        const {
    
    position} = movement//屏幕坐标
        let picks = viewer.scene.drillPick(movement.position, 1);
        let type = "";
        for (let i = 0; i < picks.length; i++) {
    
    
            if (picks[i] instanceof Cesium.Cesium3DTileFeature) {
    
    
                type = "3dtiles";
            } else if (picks[i] && picks[i].primitive && picks[i].node && picks[i].mesh) {
    
    
                type = 'model';
            }
        }
        console.log(type, "type")
        if (type === "3dtiles") {
    
    
            let pick = picks[0];
            if (pick instanceof Cesium.Cesium3DTileFeature) {
    
    
                //修改颜色
                pick.color = Cesium.Color.fromAlpha(Cesium.Color.BLUE, 1);
            }
        } else if (type === 'model') {
    
    
            modelBack(movement)
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK)

scan me for details
insert image description here

Guess you like

Origin blog.csdn.net/zw21544182/article/details/126866655