zyq87

第 484 位会员

会员
个人信息
  • 加入于 2019-12-25 17:25:02
  • 最后登录时间 4年前
个人成就
  • 发表文章次数 0
  • 发布回复次数 1
  • 个人主页浏览次数 0
点击让模型高亮显示并显示其信息4年前

你的小棍棍 单体化gltf方式加载吧,当然3dtiles也是可以的,下面的代码是gltf方式的,高亮,与属性获取,弹窗自备:

picFeature(viewer) {
            var fragmentShaderSource =
                "uniform sampler2D colorTexture;\n" +
                "varying vec2 v_textureCoordinates;\n" +
                "uniform vec4 highlight;\n" +
                "void main() {\n" +
                "    vec4 color = texture2D(colorTexture, v_textureCoordinates);\n" +
                "    if (czm_selected()) {\n" +
                "        vec3 highlighted = highlight.a * highlight.rgb + (1.0 - highlight.a) * color.rgb;\n" +
                "        gl_FragColor = vec4(highlighted, 1.0);\n" +
                "    } else { \n" +
                "        gl_FragColor = color;\n" +
                "    }\n" +
                "}\n";
            var stage = viewer.scene.postProcessStages.add(
                new Cesium.PostProcessStage({
                    fragmentShader: fragmentShaderSource,
                    uniforms: {
                        highlight: function() {
                            return new Cesium.Color(1.0, 0.0, 0.0, 0.5);
                        }
                    }
                })
            );
            stage.selected = [];

            viewer.screenSpaceEventHandler.setInputAction(movement => {
                var pickedFeature = viewer.scene.drillPick(
                    movement.position,
                    10,
                    10,
                    10
                );

                if (!Cesium.defined(pickedFeature)) {
                    stage.selected = [];
                    return;
                }
                if (pickedFeature.length == 0) {
                    stage.selected = [];
                    return;
                }

                let pickedObject = pickedFeature[0];
				//f12看下你选中对象的相关属性吧
                if (Cesium.defined(pickedObject) && pickedObject.id != null) {
                    let properties = pickedObject.id.properties.sign.getValue();

                    this.tname = properties.name;
                    this.tid = properties.id;
                    this.type = properties.type;
                }

                if (Cesium.defined(pickedObject)) {
                    stage.selected = [pickedObject.primitive];
                } else {
                    stage.selected = [];
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        }

Your Site Analytics