我正在使用Will Murphy的A-Frame Physics Extras和Don McCurdy的A-Frame Physics System w / Hand Control来制作交互式物理对象。我创建了一个“ spawner”组件,以便每当用户通过对撞机拉紧一只手时创建一个新副本,以便他们退出对撞机,“握住”已生成的物理副本。
只要对“ spawner”使用基本的对撞机,一切似乎都可以正常工作,但是当我向我的“ spawned”对象的mixin中添加sleepy
组件时,spawners在生成一个实体。我希望有使用这些软件包的经验的人可以帮助我解决问题-尽管如果不能在生成的对象上使用sleepy
,这还不是世界末日,它可以帮助防止以后的速度变慢该项目。
这是生成器的碰撞事件处理程序以及后续“生成”事件的代码;这些在我的里面:
“ onHit”
onHit: function(evt) {
var hitEl = evt.detail.body.el;
if(!hitEl.components.grab) {
console.log("Spawned!");
return;
}
if(!hitEl.components.grab.hitEl) {
console.log("Not holding anything!")
if(hitEl.components.grab.grabbing) {
this.el.emit("spawn");
console.log("Spawned!");
}
return;
}
if(hitEl.components.grab.grabbing) {
console.log("Holding something!")
}
},
“生成”
spawn: function() {
var el = this.el;
var entity = document.createElement('a-entity');
var matrixWorld = el.object3D.matrixWorld;
var position = new THREE.Vector3();
var rotation = el.getAttribute('rotation');
var entityRotation;
position.setFromMatrixPosition(matrixWorld);
entity.setAttribute('position', position);
entity.setAttribute('mixin', this.data.mixin);
entity.setAttribute('class', "seed")
entity.addEventListener('loaded', function() {
entityRotation = entity.getAttribute('rotation');
entity.setAttribute('rotation', {
x: entityRotation.x + rotation.x,
y: entityRotation.y + rotation.y,
z: entityRotation.z + rotation.z
});
});
el.sceneEl.appendChild(entity);
},