首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >帧影的动画不透明度

帧影的动画不透明度
EN

Stack Overflow用户
提问于 2022-11-05 12:00:15
回答 1查看 33关注 0票数 1

因此,我一直在处理glTF模型的不透明性淡入/淡出,并使用皮奥特·亚当·米列夫斯基的模型-不透明脚本(从这里开始)取得了良好的效果,并使用疲倦的眼睛的动画管理器脚本(从这里开始)循环了我的菊花链接动画序列。

然而,我有困难,试图想出如何也动画模型的阴影的不透明度,因为目前它的阴影仍然可以看到后,模型是不可见的。

演示链接

我已经混合了一个小故障( Ada的AR初学者工具包),您可以找到这里来展示我的意思(在模型淡入/退出的故障中,请参见第204行)。

我真的很感激任何人能说明是否有可能动画的Aframe阴影,以匹配模型的不透明度。事先非常感谢您的任何建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-10 21:30:17

恐怕内置的解决方案还没有准备好(问题 / 按下)

对于单个对象,只需使用具有ShadowMaterial属性的opacity,该属性可以与对象的不透明度一起动画化:

代码语言:javascript
复制
<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>

对于多个目标,一个简单而有效的解决方案是伪造阴影--在像在三个基本原理示例中这样的物体下面有透明的径向梯度图像。你可以控制它们每一个的不透明度:

代码语言:javascript
复制
<iframe width="100%" height="100%" src="https://r105.threejsfundamentals.org/threejs/threejs-shadows-fake.html"></iframe>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74327504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档