Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does the imported gltf model modify the material to display the vertex color in geometry? #12350

Open
mlt131220 opened this issue Dec 2, 2024 · 0 comments

Comments

@mlt131220
Copy link

What happened?

const modelPrimitive = await Cesium.Model.fromGltfAsync({
                    id: generateUUID(),
                    url: url,
                    modelMatrix: modelMatrix,
                    ...Object.assign({
                        show: true,
                        scale: 1,
                        shadows: Cesium.ShadowMode.ENABLED,
                        minimumPixelSize: 128,
                        maximumScale: 20000,
                        allowPicking: true,
                        customShader: undefined,
                        // 确定模型相对于地形的绘制方式
                        heightReference: Cesium.HeightReference.NONE,
                        // 指定该模型将在距相机多远处显示的条件
                        distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 300.0),
                        // 一种与模型渲染颜色混合的颜色
                        color: Cesium.Color.fromCssColorString("rgba(255,255,255,1)"),
                        // colorBlendMode:  Cesium.ColorBlendMode.HIGHLIGHT, // 使用MIX模式以混合顶点颜色
                        colorBlendMode: Cesium.ColorBlendMode.MIX, // 使用MIX模式以混合顶点颜色
                        // 当colorBlendMode为MIX时,用于确定颜色强度的值
                        colorBlendAmount: 0.0,
                        // 模型阴影时的浅色。如果未定义,则使用场景的光照颜色代替
                        lightColor: undefined,
                    }, options),
                    gltfCallback: gltf => {
                        animations = gltf.animations;

                        gltf.nodes.forEach(node => {
                            extras.set(node.name, node.extras);
                        })
                    }
                });

                this.viewer.scene.primitives.add(modelPrimitive);

                modelPrimitive.name = options.name || "Model";
                modelPrimitive.type = options.modelType || "Model";
                modelPrimitive.readyEvent.addEventListener(() => {
                    // extras数据添加至对应node中
                    extras.forEach((value, key) => {
                        const _node = modelPrimitive.getNode(key)._runtimeNode.node;
                        if (!_node) return;
                        _node.extras = value;
                    })

                    resolve({ model: modelPrimitive, animations, extras });
                });

I use this method to import a gltf model whose geometry contains position, normal, color, and I need to replace the displayed material with a vertex color after loading, and then switch from the vertex color to the original pbr material.
Problem: The vertex color cannot be displayed by replacing the material.

Something like this in threejs:

image
image

Reproduction steps

...

Sandcastle example

No response

Environment

Browser: Edge
CesiumJS Version: 1.123
Operating System: windows11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant