收藏
回答

怎么设置GLTF模型渲染完毕后,修改其中某个mesh 材质的颜色?

xr-frame里的GLTF

<view class="containerid="xr-scene" >

    <xr-scene id="xr-scenebind:ready="handleReadystyle="width: 70%; height: 70vh; margin: 0 auto;">

            <xr-assets >

                <xr-asset-load type="gltfasset-id="damage-helmetsrc="/images/B420-06071342.glb

                options="preserveRaw: truematerial="simple"/>


            </xr-assets>

            <xr-gltf id="myGLTFmodel="damage-helmetbind:gltf-loaded="handleGLTFLoaded" ></xr-gltf>

        <xr-light type="ambientcolor="1 1 1intensity="0.5" />

        <xr-light type="pointposition="1 1 1color="1 1 1range="60intensity="3" />

        <xr-light type="pointposition="0 0 0color="1 1 1range="60intensity="3" />

        <xr-light type="pointposition="1.5 1.5 1.5color="1 1 1range="60intensity="3" />


        <xr-gltf node-id="damage-helmetmodel="damage-helmet" />

        <xr-camera

        position="0 -5 5target="damage-helmetbackground="skybox"

        clear-color="1 1 1 1 camera-orbit-control

        />

    </xr-scene>

</view>

js:

handleGLTFLoaded({ detail }) {

        const el = detail.value.target;

        const gltf = el.getComponent("gltf");

        const newMat = this.scene.assets.getAsset("texture", "MTL0");

        for (const mesh of gltf.meshes{

            console.log('mesh:' + mesh)

            mesh.material.setTexture("u_baseColorMap", newMat);

            if (mesh.id == 16{

                mesh.material.baseColorFactor = [255, 0, 0, 1];

                // mesh.material.setUniforms()

                console.log('mesh16:' + mesh)

            }

        }

    }


回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    06-09
    有用
登录 后发表内容