眼镜试戴 , 我想隐藏 镜腿
我用了人头模型 ,我想让人头模型隐藏,但是可以遮挡镜腿,让镜腿不显示。
我尝试了,但是无效
// 1. 覆盖渲染状态:这是最关键的一步,告诉材质我们要自定义渲染状态
newMaterial.useMaterialRenderStates = true;
// 2. 设置 colorWrite 掩码为 0,关闭所有颜色通道写入,实现完全透明
newMaterial.setRenderState('colorWrite', 0);
// 3. 确保深度写入开启,使其能够遮挡后方物体
newMaterial.setRenderState('depthWrite', true);
// 4. 开启双面渲染,避免因模型法线问题导致某些角度遮挡失效
newMaterial.setRenderState('side', xrFrameSystem.SIDE_DOUBLE);
// 5. 设置渲染队列,确保它在不透明物体(默认2000)之后渲染,保证深度写入正确
newMaterial.renderQueue = 3000;
<xr-scene ar-system="modes:Face;camera:Front;pose3d: true" bind:ready="handleReady" bind:tick="handleTick">
<xr-assets bind:progress="handleAssetsProgress"
bind:loaded="handleAssetsLoaded">
<xr-asset-load type="gltf" asset-id="mask" src="https://eye.yfglasses.com/eye/2_compressed.glb" />
<!-- 标准头模,外部可以直接使用,并且可以根据该模型大小,制作挂载模型 -->
<xr-asset-load type="gltf" asset-id="gltf-face" src="https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/face.glb" />
</xr-assets>
<xr-env env-data="xr-frame-team-workspace-day" />
<xr-light type="ambient" color="1 1 1" intensity="1" />
<xr-light type="directional" rotation="40 70 0" color="1 1 1" intensity="3" />
<xr-ar-tracker mode="Face" id="tracker" >
<xr-gltf model="mask" id="trackerGltf" rotation="0 0 0" scale="2.1 2.1 2.1" cull="back"/>
<!-- 不需要同步的绘制在后面 -->
<xr-gltf
id="face"
position="0 0 -0.1" rotation="0 0 0" scale="1.06 1.06 1.06" model="gltf-face"
></xr-gltf>
<!-- 坐标系提示,单位1 的坐标轴 -->
<xr-mesh node-id="mesh-x" position="1 0 0" scale="3 0.02 0.02" geometry="cube" uniforms="u_baseColorFactor:0.7 0.3 0.3 1" ></xr-mesh>
<xr-mesh node-id="mesh-y" position="0 1 0" scale="0.02 3 0.02" geometry="cube" uniforms="u_baseColorFactor:0.3 0.7 0.3 1"></xr-mesh>
<xr-mesh node-id="mesh-z" position="0 0 1" scale="0.02 0.02 3" geometry="cube" uniforms="u_baseColorFactor:0.3 0.3 0.7 1"></xr-mesh>
</xr-ar-tracker>
<xr-camera clear-color="0.4 0.8 0.6 1" background="ar" is-ar-camera/>
</xr-scene>

该功能暂不维护,如有 AR 需求,可使用 VisionKit 视觉能力