xr-frame里的GLTF
<view class="container" id="xr-scene" >
<xr-scene id="xr-scene" bind:ready="handleReady" style="width: 70%; height: 70vh; margin: 0 auto;">
<xr-assets >
<xr-asset-load type="gltf" asset-id="damage-helmet" src="/images/B420-06071342.glb"
options="preserveRaw: true" material="simple"/>
</xr-assets>
<xr-gltf id="myGLTF" model="damage-helmet" bind:gltf-loaded="handleGLTFLoaded" ></xr-gltf>
<xr-light type="ambient" color="1 1 1" intensity="0.5" />
<xr-light type="point" position="1 1 1" color="1 1 1" range="60" intensity="3" />
<xr-light type="point" position="0 0 0" color="1 1 1" range="60" intensity="3" />
<xr-light type="point" position="1.5 1.5 1.5" color="1 1 1" range="60" intensity="3" />
<xr-gltf node-id="damage-helmet" model="damage-helmet" />
<xr-camera
position="0 -5 5" target="damage-helmet" background="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)
}
}
}