0
\$\begingroup\$

I created a scene with two primitive geometries (Sphere and Box). Now I want to recreate what I see in the scene (PhysX Visual Debugger) in my game engine window, but I can't find any functions that could help me create a vertex buffer.

How do I render PhysX items using DirectX 12? How can I get vertices from geometries in PhysX?

Code used to create a sphere using PhysX:

auto geometry = physx::PxSphereGeometry(1);
auto transform = physx::PxTransform(physx::PxVec3(0, 0, 0));
physx::PxRigidDynamic* dynamic = physx::PxCreateDynamic(*mPhysics, transform, geometry, *mMaterial, 10.0f);
mScene->addActor(*dynamic);
\$\endgroup\$
  • \$\begingroup\$ A physics engine should have no functions for rendering, this should be something your game engine connects. \$\endgroup\$ – mid Dec 17 '18 at 19:20
  • \$\begingroup\$ @Midnightas, that's what I want to achieve. Calculating physics using PhysX, rendering using DirectX. \$\endgroup\$ – Veasst Dec 17 '18 at 19:40
  • 1
    \$\begingroup\$ You probably need to give more information here about what Physx Class you have instantiated for the geometry. Are you using the physx PxShape or PxTriangleMesh, as both have functions to get the vertices that make up the mesh. Others, will not if they are defined as say a Heightfield. Referenced the physx documentation here -> docs.nvidia.com/gameworks/content/gameworkslibrary/physx/… \$\endgroup\$ – ErnieDingo Dec 17 '18 at 19:59
  • \$\begingroup\$ @ErnieDingo, Currently I'm creating PxRigidDynamic with PxSphereGeometry. Added the code used to the question. \$\endgroup\$ – Veasst Dec 17 '18 at 20:15
  • \$\begingroup\$ It's very likely that PhysX does not use vertices for representing a sphere - that would be extremely inefficient for physics purposes, since radius checks are both more precise and vastly cheaper than testing against a mesh surface. So, you probably don't want to ask PhysX for vertices for a sphere. That'd be like asking your pet pig to lay an egg for you - it's not the right kind of animal for that. ;) Are you just looking for how to generate a spherical mesh? \$\endgroup\$ – DMGregory Dec 17 '18 at 20:26
0
\$\begingroup\$

In most games, the geometry used for collision is distinct from the geometry used for rendering.

  • Rendering geometric complexity is driven by the art style and needs, along with performance considerations
  • Collision geometry is usually much simpler because collision performance scales with vertex count, and the collision geometry needs to meet mathematical correctness requirements that don't apply to art. In fact, many collision shapes are actually implicit surfaces which can be very difficult to render directly (unless you are doing raytracing).

In short, you should use the normal methods for rendering a box and sphere with DirectX and stick to using PhyX only to create the collision geometry. You make sure they are both in the same position and reference frame, and it will all work out to appear they are the same in many cases.

For code for creating boxes and sphere vertex/index buffer for rendering, see DirectX Tool Kit's GeometricPrimitive class for DX11 / DX12.

\$\endgroup\$
  • \$\begingroup\$ Didn't think about it like that. Using PhysX only for collisions makes so much more sense and would solve many of my problems. Thanks! \$\endgroup\$ – Veasst Dec 22 '18 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.