Open smeybi opened 5 years ago
When using AmmoDriver, removing objects with removeChild will prevent "collidestart" and "collideend" of the remaining objects. Is there any other way to delete the object with Ammo-body added?
(edit) post new issue https://github.com/donmccurdy/aframe-physics-system/issues/141
Try after a long time, I found out, it has a problem with deleting the ammo body on remove the entity (with ammo physics). I recreated and combined it with three.js. It work until remove the entity. For example it works, remove the ammo body and the object3D separate, not problem document.querySelector('a-scene').systems.physics.driver.removeBody(e.target.body) e.target.object3D.parent.remove(e.target.object3D)
But remove the entity there were the dropouts again. e.target.parentNode.removeChild(e.target)
I figured out, if this Ammo.destroy(this.body) is exchanged with the this.system.driver.removeBody(this.body) in the script for the Ammo remove function, it works. I don't know if this causes problems anywhere else! I hope the information helps more to find the problem!
aframe-physics-system.js Line 14912:
remove: function() { if (this.triMesh) Ammo.destroy(this.triMesh); if (this.localScaling) Ammo.destroy(this.localScaling); if (this.compoundShape) Ammo.destroy(this.compoundShape); if (this.body) { this.system.driver.removeBody(this.body) //Ammo.destroy(this.body); delete this.body; } Ammo.destroy(this.rbInfo); Ammo.destroy(this.msTransform); Ammo.destroy(this.motionState); Ammo.destroy(this.localInertia); Ammo.destroy(this.rotation); },
Try after a long time, I found out, it has a problem with deleting the ammo body on remove the entity (with ammo physics). I recreated and combined it with three.js. It work until remove the entity. For example it works, remove the ammo body and the object3D separate, not problem document.querySelector('a-scene').systems.physics.driver.removeBody(e.target.body) e.target.object3D.parent.remove(e.target.object3D)
But remove the entity there were the dropouts again. e.target.parentNode.removeChild(e.target)
I figured out, if this Ammo.destroy(this.body) is exchanged with the this.system.driver.removeBody(this.body) in the script for the Ammo remove function, it works. I don't know if this causes problems anywhere else! I hope the information helps more to find the problem!
aframe-physics-system.js Line 14912:
remove: function() { if (this.triMesh) Ammo.destroy(this.triMesh); if (this.localScaling) Ammo.destroy(this.localScaling); if (this.compoundShape) Ammo.destroy(this.compoundShape); if (this.body) { this.system.driver.removeBody(this.body) //Ammo.destroy(this.body); delete this.body; } Ammo.destroy(this.rbInfo); Ammo.destroy(this.msTransform); Ammo.destroy(this.motionState); Ammo.destroy(this.localInertia); Ammo.destroy(this.rotation); },
Legend figuring that out and posting it! Was banging my head for days trying to figure out why that was happening :)
Is there any progress pls?
Hi, I noticed something, I'm not sure if it's a issue, maybe I'll remove entities the wrong way.
I would like to remove entities at collision. The collide events work, but if i use this for removeChild, not all entities are removed. It's look like a rhythm, a few are skipped.
This is the collision event code: this.el.addEventListener('collidestart', function(e) { if (remove_e) { e.target.parentNode.removeChild(e.target); } else { e.target.setAttribute('color', "blue"); }
Here is a example (only collisions with static bodies) on glitch, when a button is pressed, it will change to remove entity or color change: https://glitch.com/edit/#!/aframe-physics-ammo2
The same example with dynamic bodies it works, but I think it works, because there are many collisions events, that finally remove the entity. https://glitch.com/edit/#!/aframe-physics-ammo1
Edit: The same issue is when removing entities direct, not on the collision event. The collisions events skip some entities.