Aframe A帧网格旋转和动画
我尝试在aframe gltf模型中旋转网格,但它似乎不起作用。是否可以旋转场景中运行时添加的gltf模型的网格?我得到的网格设置了轴,但无法对其应用旋转 问题:我有一个带有两个网格的门模型。左门和右门。我想在用户单击门网格时将门旋转180度。我得到了整个3d对象上的点击事件,现在检查哪个网格被点击;检查其父级并尝试旋转左门,但不工作。你知道我错过了什么吗。 所以 object.parent 返回我尝试旋转的父对象类型。这条路对吗 这是我到目前为止得到的Aframe A帧网格旋转和动画,aframe,8thwall-web,Aframe,8thwall Web,我尝试在aframe gltf模型中旋转网格,但它似乎不起作用。是否可以旋转场景中运行时添加的gltf模型的网格?我得到的网格设置了轴,但无法对其应用旋转 问题:我有一个带有两个网格的门模型。左门和右门。我想在用户单击门网格时将门旋转180度。我得到了整个3d对象上的点击事件,现在检查哪个网格被点击;检查其父级并尝试旋转左门,但不工作。你知道我错过了什么吗。 所以 object.parent 返回我尝试旋转的父对象类型。这条路对吗 这是我到目前为止得到的 const newElement =
const newElement = document.createElement('a-entity')
// The raycaster gives a location of the touch in the scene
const touchPoint = event.detail.intersection.point
newElement.setAttribute('position', touchPoint)
//const randomYRotation = Math.random() * 360
//newElement.setAttribute('rotation', '0 ' + randomYRotation + ' 0')
newElement.setAttribute('visible', 'false')
newElement.setAttribute('scale', '4 4 4')
newElement.setAttribute('gltf-model', '#animatedModel')
this.el.sceneEl.appendChild(newElement)
newElement.addEventListener('model-loaded', () => {
// Once the model is loaded, we are ready to show it popping in using an animation
newElement.setAttribute('visible', 'true')
newElement.setAttribute('id','model')
newElement.setAttribute('class','cantap')
newElement.setAttribute('hold-drag','')
newElement.setAttribute('two-finger-spin','')
newElement.setAttribute('pinch-scale','');
/* newElement.setAttribute('animation', {
property: 'scale',
to: '4 4 4',
easing: 'easeOutElastic',
dur: 800,
}) */
newElement.addEventListener('click', event => {
const animationList = ["Action", "Action.001"];
/* newElement.setAttribute('animation-mixer', {
clip: animationList[0],
loop: 'once',
})
newElement.addEventListener('animation-loop',function() {
newElement.setAttribute('animation-mixer', {
timeScale : 0
})
}); */
var object = event.detail.intersection.object;
document.getElementById("btn").innerHTML = object.parent;
/* object.setAttribute('animation', {
property: 'rotation',
to: '0 180 0',
loop: true,
dur: 6000,
dir: 'once'
});*/
object.parent.setAttribute('rotation', {x: 0, y: 180, z: 0});
/* object.traverse((node) =>{
console.log(node.name);
document.getElementById("btn").innerHTML = ;
}); */
console.log(this.el.getObject3D('mesh').name);
// name of object directly clicked
console.log(object.name);
// name of object's parent
console.log(object.parent.name);
// name of object and its children
});
})
对gltf模型的部分执行任何操作的技巧是遍历gltf并隔离内部要操纵的对象。 您可以通过编写一个附加到gltf实体的组件来实现这一点,该组件获取底层threejs对象,并遍历gltf组中的所有对象,然后您可以根据其名称选择一个对象。 您可以在模型加载的事件侦听器中执行此操作,如下所示
el.addEventListener("model-loaded", e =>{
let tree3D = el.getObject3D('mesh');
if (!tree3D){return;}
console.log('tree3D', tree3D);
tree3D.traverse(function(node){
if (node.isMesh){
console.log(node);
self.tree = node;
}
});
这将选择其中一个模型,将其指定给一个变量,该变量可在以后用于旋转模型或执行任何您喜欢的操作
tick: function(){
if(this.tree){
this.tree.rotateY(0.01);
}
}
这是你的电话号码