首页 > 解决方案 > 实体上的 A-Frame 静态主体

问题描述

我正在尝试框架物理

我可以在形状对象上应用静态体属性:

<a-sphere color="red" width="2" height="2" depth="2" position="2 1 -5" rotation="45 0 0" static-body></a-sphere>

但不是在一个实体对象上,我仍然能够穿过该对象:

<a-entity static-body obj-model="obj:models/lamp_mesh.obj;mtl:images/lamp_mesh.mtl" rotation="0 90 0" position="5.46 0 0" animation></a-entity>

是否只能在形状对象上应用静态/动态属性?

或者我在某处做错了什么

我看过很多关于形状对象的物理教程,但没有看到关于实体对象的教程。

请指教。提前致谢。

标签: htmlaframe

解决方案


static-body与任何<a-entity>元素 一起使用应该没有问题。在这里你有一个链接,我将它与<a-entity>gltf 模型一起使用。


debug: true该组件有一个有用的标志physics

<a-scene physics="debug: true">

如果您在对象周围没有看到线框,则可能没有物理实体连接到它。


确保你的模型加载正确,检查它周围的线框,如果没有,你可以:

1)将您的.obj模型转换为网络标准(此处.gltf为官方转换器) 2)手动创建主体。从文档
physics

<a-entity gltf-model="src: mug.glb"
      body="type: dynamic; mass: 5; shape: none;"
      shape__main="shape: cylinder;
                   height: 0.36;
                   radiusTop: 0.24;
                   radiusBottom: 0.24;"
      shape__handle="shape: box;
                     halfExtents: 0.15 0.18 0.04;
                     offset: 0.4 0 0;">
</a-entity>

推荐阅读