Code Monkey home page Code Monkey logo

Comments (6)

rlidwka avatar rlidwka commented on July 20, 2024 1

I'm creating it the following way, here's TriangleMesh (physics is PhysicsFoundation):

https://github.com/rlidwka/bevy_physx/blob/c5f13c495627db1272f1cce5f0b694e942ec0eaa/src/assets.rs#L187-L210

And here's TriangleMeshGeometry (mesh is TriangleMesh from previous step):

https://github.com/rlidwka/bevy_physx/blob/c5f13c495627db1272f1cce5f0b694e942ec0eaa/src/components.rs#L146-L152

The snippets above are a pretty straightforward port of the physx documentation (I like PhysX 3 docs better, and nothing has really changed since then):

https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/Geometry.html#triangle-meshes

from physx-rs.

iddm avatar iddm commented on July 20, 2024

I'm creating it the following way, here's TriangleMesh (physics is PhysicsFoundation):

https://github.com/rlidwka/bevy_physx/blob/c5f13c495627db1272f1cce5f0b694e942ec0eaa/src/assets.rs#L187-L210

And here's TriangleMeshGeometry (mesh is TriangleMesh from previous step):

https://github.com/rlidwka/bevy_physx/blob/c5f13c495627db1272f1cce5f0b694e942ec0eaa/src/components.rs#L146-L152

The snippets above are a pretty straightforward port of the physx documentation (I like PhysX 3 docs better, and nothing has really changed since then):

https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/Geometry.html#triangle-meshes

Thanks a lot! I wish there were a little more Rusty way to do this, just like the sphere example.

from physx-rs.

iddm avatar iddm commented on July 20, 2024

Can you please help me once again? I can't build the rigid dynamic:

                let indices = o.get_indices(scene.get_data());
                let vertices = o.get_vertices_physx(scene.get_data());
                let mut mesh_desc = PxTriangleMeshDesc::new();
                mesh_desc.obj.points.count = vertices.len() as u32;
                mesh_desc.obj.points.stride = std::mem::size_of::<PxVec3>() as u32;
                mesh_desc.obj.points.data = vertices.as_ptr() as *const _;

                mesh_desc.obj.triangles.count = indices.len() as u32;
                mesh_desc.obj.triangles.stride = std::mem::size_of::<[u32; 3]>() as u32;
                mesh_desc.obj.triangles.data = indices.as_ptr() as *const _;

                let physics = &mut self.foundation;
                let params = physx::cooking::PxCookingParams::new(physics).unwrap();
                let mut geometry =
                    match physx::cooking::create_triangle_mesh(physics, &params, &mesh_desc) {
                        physx::cooking::TriangleMeshCookingResult::Success(geometry) => geometry,
                        _ => panic!("Oops."),
                    };
                let (_, rotation, translation) =
                    o.get_transform_matrix().to_scale_rotation_translation();
                let translation = PxVec3::new(translation.x, translation.y, translation.z);
                let rotation = PxQuat::new(rotation.x, rotation.y, rotation.z, rotation.w);
                let scale = PxMeshScale {
                    scale: PxVec3::new(1.0f32, 1.0f32, 1.0f32).into(),
                    rotation: PxQuat::new(1.0f32, 1.0f32, 1.0f32, 1.0f32).into(),
                };
                let geometry = PxTriangleMeshGeometry::new(
                    geometry.as_mut(),
                    // &unsafe { PxMeshScale_new() },
                    &scale,
                    // PxMeshGeometryFlags::TightBounds,
                    PxMeshGeometryFlags::empty(),
                );
                self.foundation
                    .create_rigid_dynamic(
                        PxTransform::from_translation_rotation(&translation, &rotation),
                        &geometry,
                        material.as_mut(),
                        1.0f32,
                        PxTransform::default(),
                        (),
                    )
                    .expect("Couldn't build rigid dynamic actor.")

The Option returned is always None. There is nothing I can see in the error callback and the assertion handler. Everything before that was created just fine.

from physx-rs.

rlidwka avatar rlidwka commented on July 20, 2024

Can you please help me once again?

Can you link to a full repository with the code, or simplify it down, or preferably both?

Errors can happen for a lot of reasons (invalid geometry, non-unit quaternion as rotation, etc.). Typically they are shown in the error callback, but I can't verify it from the snippet above.

Do simple shapes (e.g. tetrahedron) with zero transforms work?

from physx-rs.

iddm avatar iddm commented on July 20, 2024

I found the problem. It was my thinking that we could use the TriangleMesh with dynamic actors, but we don't. Thanks for taking the time to help me!

from physx-rs.

rlidwka avatar rlidwka commented on July 20, 2024

I found the problem. It was my thinking that we could use the TriangleMesh with dynamic actors, but we don't.

Yeah physx doesn't support those. You may want to look into convex decomposition (with something like V-HACD) to break down triangle mesh into multiple convex ones.

from physx-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.