Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't we use buffergeometry directly when converting to geometry #223

Open
zh-pan opened this issue Dec 5, 2018 · 2 comments
Open

Comments

@zh-pan
Copy link

zh-pan commented Dec 5, 2018

`var positions=item.geometry.attributes.position.array;
var i,triangles=[];
for(i=0;i<positions.length;i+=3){
triangles.push( new THREE.Vector3().fromArray( positions, i ) );
}

                        if (!triangles.length) return false;
                        for ( i = 0; i < triangles.length; i++ ) {
                            triangle = triangles[i];

                            vec3_1.setX(triangle.x);
                            vec3_1.setY(triangle.y);
                            vec3_1.setZ(triangle.z);
                            vec3_2.setX(triangle.x);
                            vec3_2.setY(triangle.y);
                            vec3_2.setZ(triangle.z);
                            vec3_3.setX(triangle.x);
                            vec3_3.setY(triangle.y);
                            vec3_3.setZ(triangle.z);

                            triangle_mesh.addTriangle(vec3_1, vec3_2, vec3_3, true);
                        }

                        var meshShape = new Ammo.btBvhTriangleMeshShape(triangle_mesh, true, true);`
@InfiniteLee
Copy link
Contributor

InfiniteLee commented Dec 21, 2018

btBvhTriangleMeshShape requires a btStridingMeshInterface for its constructor. btTriangleMesh is the only class implemented in Ammo.js of that type but has no constructor or method for creating a btTriangleMesh from an array of vertices. It only has the addTriangle method, which requires you to specify each vertex of a triangle, like in your example.

There are other classes that implement btStridingMeshInterface like btTriangleIndexVertexArray whose constructor takes a pointer (so you could pass a pointer to the start of an array of vertices), but you would need to figure out how to define it in ammo.idl and how to use it, as it is currently not implemented in Ammo.js.

@suddenly4
Copy link

suddenly4 commented Dec 18, 2024

If you want concave shape, as an option, atfirst make some triangles form buffergeometry for example - btConvexTriangleMeshShape by set .addTriangle(Ammo.btVector3) then you can build different shape by using btConvexTriangleMeshShape, if dinamic shape - btCompoundShape. if static
btBvhTriangleMeshShape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants