A-frame:如何将对象附加到模型(和/或其骨骼)上的点 [英] A-frame: How to attach an object to a point on a model (and/or it's bones)
问题描述
我想将一个对象*附加到一个特定的骨骼上,以便它与该骨骼一起移动(比如在角色的头上戴一顶帽子).在three.js中,我可以这样做:
I want to attach an object* to a particular bone, so it moves along with that bone (think putting a hat on a character's head, say). In three.js, I could do something like:
mesh.skeleton.bones[someindex].add(mesh2)
在框架中执行此操作的最佳方法是什么?
What's the best way to do this in a-frame?
另一种方法可能是将对象作为模型上特定顶点的父对象,但我也不知道该怎么做.
An alternative might be to parent an object to a specific vertex on the model, but I'm not sure how to do that either.
*:对象",我想我的意思是 A 框架术语中的具有位置和旋转的实体"
*: By "object", I think I mean "entity with position and rotation" in A-frame terms
推荐答案
据我所知,a-frame 只有一个小的 API 来处理构建在 Three.js
加载器上的模型.(+ Don McCurdys 动画混音器).
As far as i know, a-frame has only a small API for working with models build on Three.js
loaders. (+ Don McCurdys animation mixer).
我在这里能想到的唯一A-Frame"触摸是创建和访问基本模型.有:
The only "A-Frame" touch i can think of here is creating, and accessing the base model. Having:
<a-entity gltf-model="url(model.gltf)" foo>
您可以创建一个框架组件来抓取模型,并将新网格附加到骨骼上:
You can create an a-frame component which will grab the model, and attach the new mesh to the bone:
AFRAME.registerComponent("foo", {
init:function() {
let mesh = this.el.getObject3D("mesh")
// or this.el.components["gltf-model"].model
let mesh2; // get create the model using any THREE loader
mesh.skeleton.bones[someindex].add(mesh2)
}
})
<小时>如果您通过 <a-element gltf-model="url(hat.gltf)">
创建帽子并尝试使用 setAttribute()
在每个渲染循环中(在 tick()
函数中).
I can't think of any major benefit if you create the hat via
<a-element gltf-model="url(hat.gltf)">
and try to position and rotate it using setAttribute()
on each render loop (in the tick()
function).
这篇关于A-frame:如何将对象附加到模型(和/或其骨骼)上的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!