我有一个包含三个二十面体的 aframe 场景、一个复杂的粒子系统和一个与场景中物体融合的光标。由于粒子可见,场景运行速度太慢,因为光标试图融合在每个粒子上。我只需要它融合在三个二十面体上。
所以,我正在尝试做两件事之一:
我目前不知道如何做这两件事。这是我的场景:
<a-scene xrweb xrextras-tap-recenter xrextras-almost-there xrextras-loading xrextras-runtime-error>
<a-camera position="0 8 2">
<a-entity position="0 0 -3" geometry="primitive: ring; radiusInner: 0.25; radiusOuter: 0.3;" color="#CCCCCC"
material="shader: flat; opacity: 0.7" cursor="maxDistance: 10; fuse: true" events-cursor>
<a-animation begin="fusing" easing="ease-in" attribute="scale" fill="forwards" from="1 1 1" to="0.5 0.5 0.5"
dur="1500"></a-animation>
<a-animation begin="mouseleave" easing="ease-in" attribute="scale" fill="forwards" from="0.8 0.8 0.8" to="1 1 1"
dur="500"></a-animation>
</a-animation>
</a-entity>
</a-camera>
<!-- should only render this particle system after icosahedrons have been clicked -->
<a-entity position="0 2.25 -15"
particle-system="preset: dust; particleCount: 500; type: 2; rotationAngleSpread: .05; texture: ./images/debris.png; velocityValue: .5 0.15 .5;"
>
<a-entity rotation="0 0 0" animation="property: rotation; to: 360 0 0; loop: true; dur: 10000; easing: linear">
<a-icosahedron position="0 1 -4" radius="1.25" material="roughness: 0.8; metalness: 0.2; color: #D65C66;"
animation="property: rotation; to: 0 360 0; loop: true; dur: 10000; easing: linear" id="redOrb" events-red>
</a-icosahedron>
</a-entity>
<!--- 3 of these, hiding code for brevity-->
</a-scene>
这是处理二十面体是否已融合/点击的javascript:
AFRAME.registerComponent('events-red', {
init: function () {
el.addEventListener('click', function(){
redClicked = true;
//when all 3 have been clicked, hide them, and show the particle system.
})
}
});
我试过这个,但它不起作用(函数在正确的条件下触发,但屏幕上没有显示任何内容):
addParticleSystem = function(){
let particleSystem = document.createElement('a-entity');
particleSystem.setAttrbute('position','0 2.25 -15');
particleSystem.setAttribute('particle-system',"preset: dust; particleCount: 500; type: 2; rotationAngleSpread: .05; texture: ./images/debris.png; velocityValue: .5 0.15 .5;");
document.querySelector('a-scene').appendChild(particleSystem);
}
当您想要选择一些要融合(或单击)的对象并排除其他对象时,您可以使用 raycaster 组件来执行此操作,该组件可与光标一起使用(或可以在没有它的情况下工作,但要进行融合,请与光标组件一起使用)。
<a-entity cursor raycaster="far: 20; interval: 1000; objects: .clickable"></a-entity>
然后在要包含在光线投射中的每个实体上,添加属性 class="clickable"
<a-box id="redBox" class="clickable" color="red"></a-box>
这是关于光线投射和游标的文档:
https://aframe.io/docs/0.9.0/components/cursor.html#fuse-based-cursor
我很惊讶粒子会参与光线投射,因为它们只是 gpu 实例。它们实际上不是场景中的 3D 实体,而是作为图形卡上的几何着色器生成和渲染的。光线投射发生在所有几何图形被发送到图形卡之前。您是否测试过在粒子可见时打开和关闭光线投射以查看是否会导致速度变慢?
您的代码未显示光标或光线投射,因此我不知道您是否正在过滤实体,但您似乎并未在实体上使用类过滤器,因此您似乎没有过滤光线投射器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句