You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I enhanced the api to use btCollisionObject, this works fine for the moment.
But I need to give a new scene each time I am calling collide detection.
This imply cleanly deallocating .
I used this code to create the scene and the next one to deallocate.
unfortunately , memory is filling and this is very boring. I don't manage to find what remains allocated
allocation
const geometry = mesh.geometry.clone();
const vertices = geometry.getAttribute("position");
const indices = geometry.index;
const trimesh = new BulletObject.ammoInjection.btTriangleMesh();
const bta = new BulletObject.ammoInjection.btVector3()
const btb = new BulletObject.ammoInjection.btVector3()
const btc = new BulletObject.ammoInjection.btVector3()
let va = new THREE.Vector3()
let vb = new THREE.Vector3()
let vc = new THREE.Vector3()
// --------------------------------------------------------
for (let j = 0; j < indices.itemSize * indices.count; j += 3) {
const ai = indices.array[j] * 3
const bi = indices.array[j + 1] * 3
const ci = indices.array[j + 2] * 3
va.set(vertices.array[ai], vertices.array[ai + 1], vertices.array[ai + 2])
vb.set(vertices.array[bi], vertices.array[bi + 1], vertices.array[bi + 2])
vc.set(vertices.array[ci], vertices.array[ci + 1], vertices.array[ci + 2])
va = mesh.localToWorld(va)
vb = mesh.localToWorld(vb)
vc = mesh.localToWorld(vc)
}
bta.setValue(va.x, va.y, va.z)
btb.setValue(vb.x, vb.y, vb.z)
btc.setValue(vc.x, vc.y, vc.z)
trimesh.addTriangle(bta, btb, btc, false)
}
//----------------------------------------------------------------------------------------
const shape = new BulletObject.ammoInjection.btConvexTriangleMeshShape(trimesh);
let m = new BulletObject.ammoInjection.btCollisionObject();
m.setCollisionShape(shape);
m.threeObject = mesh
BulletObject._physicsWorld.addCollisionObject(m);
this.shapes.push(shape)
this.collide_object.push(m)
geometry.dispose()
deallocation
for (let i = 0; i < this.collide_object.length; i++) {
//this.collide_object[i].threeObject = null
BulletObject._physicsWorld.removeCollisionObject(this.collide_object[i]);
BulletObject.ammoInjection.destroy(this.collide_object[i])
}
for (let i = 0; i < this.shapes.length; i++) {
BulletObject.ammoInjection.destroy(this.shapes[i])
}
this.collide_object = [];
this.shapes = [];
}
The text was updated successfully, but these errors were encountered:
for (let i = 0, l = faces.length; i < l; i++) {
let a = faces[i].a;
let b = faces[i].b;
let c = faces[i].c;
let v1 = new Ammo.btVector3(vertices[a].x, vertices[a].y, vertices[a].z);
let v2 = new Ammo.btVector3(vertices[b].x, vertices[b].y, vertices[b].z);
let v3 = new Ammo.btVector3(vertices[c].x, vertices[c].y, vertices[c].z);
someShape.addTriangle(v1, v2, v3, true);
Ammo.destroy(v1);
Ammo.destroy(v2);
Ammo.destroy(v3);
}
I enhanced the api to use btCollisionObject, this works fine for the moment.
But I need to give a new scene each time I am calling collide detection.
This imply cleanly deallocating .
I used this code to create the scene and the next one to deallocate.
unfortunately , memory is filling and this is very boring. I don't manage to find what remains allocated
allocation
deallocation
The text was updated successfully, but these errors were encountered: