因此,我一直在处理glTF模型的不透明性淡入/淡出,并使用皮奥特·亚当·米列夫斯基的模型-不透明脚本(从这里开始)取得了良好的效果,并使用疲倦的眼睛的动画管理器脚本(从这里开始)循环了我的菊花链接动画序列。
然而,我有困难,试图想出如何也动画模型的阴影的不透明度,因为目前它的阴影仍然可以看到后,模型是不可见的。
演示链接
我已经混合了一个小故障( Ada的AR初学者工具包),您可以找到这里来展示我的意思(在模型淡入/退出的故障中,请参见第204行)。
我真的很感激任何人能说明是否有可能动画的Aframe阴影,以匹配模型的不透明度。事先非常感谢您的任何建议。
发布于 2022-11-10 21:30:17
对于单个对象,只需使用具有ShadowMaterial属性的opacity,该属性可以与对象的不透明度一起动画化:
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="https://gftruj.github.io/webzamples/aframe/models/components/model-opacity.js"></script>
<script>
AFRAME.registerComponent("relative-shadow", {
schema: {
target: { type: "selector" }
},
init: function() {
const mesh = this.el.getObject3D("mesh"); // grab the mesh
const oldMaterial = mesh.material; // store the old material
mesh.material = this.material = new THREE.ShadowMaterial(); // apply a shadow material
oldMaterial.dispose(); // dispose the old material
},
update: function() {
this.opacitySource = this.data.target.components["model-opacity"]; // react to the target being set
},
tick: function() {
if (!this.opacitySource) return; // wait until we can access the opacity value
// update the opacity using the t-rex material opacity from the component
this.material.opacity = this.opacitySource.data.opacity;
}
})
</script>
<a-scene>
<a-asset-item id="spino" src="https://rawcdn.githack.com/krlosflip22/aframe-ar-sample/c91a7a9dd8b1428bc8e68bc1b5d8641d7241fd1b/spinosaurus.glb"></a-asset-item>
<a-gltf-model id="trex" position="0 1 -4" shadow="cast: true" scale="0.5 0.5 0.5" src="#spino" model-opacity
animation="property: model-opacity.opacity; to: 0; dur: 1000; dir: alternate; loop: true;"></a-gltf-model>
<a-plane rotation="-90 0 0" scale="40 40 40"
relative-shadow="target: #trex" shadow="receive: true"></a-plane>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
对于多个目标,一个简单而有效的解决方案是伪造阴影--在像在三个基本原理示例中这样的物体下面有透明的径向梯度图像。你可以控制它们每一个的不透明度:
<iframe width="100%" height="100%" src="https://r105.threejsfundamentals.org/threejs/threejs-shadows-fake.html"></iframe>
https://stackoverflow.com/questions/74327504
复制相似问题