How to mirror a mopp shape?

How to mirror a mopp shape?

Hi, I'm working on a game that hassome axial symmetry stages. Each model instancing in these scenes has an mirror instancing at the another end of its scene. It looks like I put a mirror at the middle of the scene.In the renderer, I use a float3 scale = {1, 1, -1} and revert the face_cull state to render the mirror intancing by using the same mesh data of the "normal" instancing. My question is: How can I implement a mirror mopp instancing in Havok by using the same shape data of the "normal" mopp instancing?I have tried used the hkpTransformShape to wrap the "normal" mopp shape, by set its transform's scale to {1, 1, -1}, but it doesn't work.Anybody can help? Thanks!

9 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di havok_josh

Hey yaol-Can you explain what you mean by "it doesn't work"? It seems like that (or something similar) should be possible. Let me know what you are seeing and I'll try to figure it out.-Josh

Josh Developer Support Engineer Havok www.havok.com

Hi Josh, thanks for your reply.
"it doesn't work" means, the result is:The rigidbody character cannot be blocked by the mirrored version shape/rigidbody.In the hkVisualDebugger, I can only see the the mirrored shape's mesh wireframe without the solid shading. It may caused by reverted triangle winding.
What I have done is:1. Create ahkpTransformShape to wrap the normal mopp shape( constructed from hkpExtendedShape and TriangleSubpart).2. Set the hkpTransformShape's transform scale to {1, 1, -1}.3. Construct a rigid body by using this hkpTransformShape.4. Add this rigid body to my hkpWorld.
In the game, I used the rigidbody character controller to control characters in the game. Everything works fine with normal mopp shapes. For the mirrored model, my current solution is: duplicated the normal model's vertices and indices data, mirror vertices position, then create a new mopp shape from these mirrored vertices and indices.
Is it possible to create a mirrored mopp shape without duplicating vertices data?

Ritratto di havok_josh

yaol-The hkpTransformShape you are using takes an hkTransform as its second parameter in its constructor. An hkTransform can only represent a translation and rotation, so it does not seem possible to do an mirrored MOPP using a transformShape. How are you setting the {1,1,-1} scale?I think you are right about the rendering. I opened a demo and tried to fly "inside" an object and it does not render from the inside out, so it's likely we need correct normals to render.-Josh

Josh Developer Support Engineer Havok www.havok.com

Josh, thanks for your quick reply.
I construct a 4x4 float matrix from a mirrored model's translation, rotation and a scale = {1, 1, -1}, and set this float matrix to a hkTransform through hkTransform::set4x4ColumnMajor(const hkFloat32* p). Then use this hkTransform to construct a hkpTransformShape.I know the hkTransform::set4x4ColumnMajor wasn't supposed to be used in this way. I just want to try if a scale = {1, 1, -1} will be treat as a unnormal rotation, and can be handle corrected.There are some mistakes about my current solution in my last post.Actually my current solution is:1. Used the normal model shape's vertices data to construct a new TrianglesSubpart by set its scale to {1, 1, -1} through its setScaling interface.2. Add this TrianglesSubpart to a new hkpExtendedMeshShape.3. Build a new hkpMoppCode for this hkpExtendedMeshShape.4. Construct a new mopp shape by using the new hkpExtendedMeshShape and the new hkpMoppCode.It works. I can avoid duplicate vertices in this way, but cannot reuse the normal model shape's hkpMoppCode.Is it possible to reuse the mopp code just like what the MoppInstancingDemo does?And this solution can only works at TrianglesSubpart (use a hkQsTransform member to represent its tranform), it cannot works at ShapesSubpart (use a hkQuaternion and a hkVector4 to represent its tranfrom).But I think duplicate sub convex shapes is acceptable, since convexshapes may cost much less memory space than vertices data.

Ritratto di havok_josh

yaol-Ah, ok. Yup, as you have discovered you aren't supposed to use hkTransform::set4x4ColumnMajor that way. I think this is described in the header for that class, but kudos for experimentation!The MOPP doesn't support the nonuniform scaling you are trying to do, so I think your approach is probably best.The new meshShape will resuse the original vertices data (as described in the MoppInstancingDemo).-Josh

Josh Developer Support Engineer Havok www.havok.com

Josh, thank you for your reply. Since you said you "think" its the best approach, could you please "confirm" it for me? That's important for me and the game. I have thought 1.) it is highly probably havok development team have consider this requirement, because mirroring a model is not an unnormal requirement during game development, and 2.)havok looks like always pay great attention on memory cost at every aspect. So I feel there is no reason havok team decided to cost memory to store a "copy" of mopp code data for each mirror version (X,Y,Z axis), if they had consider this requirement. And I believe finding a way to reuse the mopp code data is not difficult for the havok team. After all, if it's exactly the best approach now, will havok team consider support a better approach in the feature?
-Yao

Ritratto di havok_josh
Best Reply

Hey yaol-I went through our internal records to figure out what the status of "mirrored mopps" was and I can confirm that we do not currently supported mirrored mopps :( I think you will need to build the MOPP twice as you are currently doing. From a physics perspective, it requires a fair bit of code modification to accommodatea mirrored shape and, perhaps suprisingly, there is not enough demand at present. The problem is not mirroring the MOPP shape itself but rather handling mirroring with code that interacts with the MOPPs (like raycasting and linearcasting).-Josh

Josh Developer Support Engineer Havok www.havok.com

Josh, many thanks for your detail answer! It's helpful.And I can imagine this requirement will cause a big modification on the raycasting and linearcasting implement. But I still want suggest the havok team don't totally overlooked this requirement, at least don't make the havok more difficult to implement it in the future. Some day havok may need implement it.
Maybe the mirror trick has not got enough attention at present, and it usually be used at simple games for mirrored levels. I think the situation may will change in the future. This trick can be used at morden big games in variant styles (not only for mirrored levels) to bring some new game play styles and experience for player.
-Yao

Accedere per lasciare un commento.