Hi, what is the correct way to resize/scale a physical entity in the space simulation?
For example, if an object's (render) model is scaled/mutated as a result of some user input, what is the proper way to reflect those changes in the physics space? (i.e. update it's bounding box, orientation, position, etc)
Resizing/scaling physical entities
Re: Resizing/scaling physical entities
Various shapes have settable properties for radius, length, or other shape-specific dimensions. Setting the relevant properties will do the trick for those types of shapes. Changing a dimension on one of those shapes should call an event which forces an inertia recomputation on the entity so that its physical properties will still match its collision shape. If you want to avoid the recomputation, you can set the entity's IgnoreShapeChanges property to true.
Some shapes, like the MinkowskiSumShape, do not have settable dimensions due to the complexity of the shape type.
If you want to apply general linear transforms to a shape, it would probably be best to wrap the desired base shape in a TransformableShape. Then, as needed, set the shape's Transform property. Note that the TransformableShape is forced to use the catch-all collision system due to its transformability. This is usually no problem at all, but for example, a true BoxShape-BoxShape collision pair will have slightly better numerical behavior than a TransformableShape wrapping a BoxShape colliding with another BoxShape.
All supporting data, like bounding boxes, will be updated automatically.
Note that any modification of a shape is a form of discontinuous motion. It is not based on velocities, so the collision response will not behave rigidly. The penetration correction component of collision response will push the objects out of any penetration created due to the deformation over time, resulting in a slightly squishy response. This will only be an issue if you intend to constantly deform the shape while in complicated collisions.
Some shapes, like the MinkowskiSumShape, do not have settable dimensions due to the complexity of the shape type.
If you want to apply general linear transforms to a shape, it would probably be best to wrap the desired base shape in a TransformableShape. Then, as needed, set the shape's Transform property. Note that the TransformableShape is forced to use the catch-all collision system due to its transformability. This is usually no problem at all, but for example, a true BoxShape-BoxShape collision pair will have slightly better numerical behavior than a TransformableShape wrapping a BoxShape colliding with another BoxShape.
All supporting data, like bounding boxes, will be updated automatically.
Note that any modification of a shape is a form of discontinuous motion. It is not based on velocities, so the collision response will not behave rigidly. The penetration correction component of collision response will push the objects out of any penetration created due to the deformation over time, resulting in a slightly squishy response. This will only be an issue if you intend to constantly deform the shape while in complicated collisions.
Re: Resizing/scaling physical entities
In this specific scenario, I'm looking to construct a physical entity from a 3D model, and then later be able to scale both the model and its physical entity. From looking at some of your example code, my first thought is to create a custom content processor to extract the vertices from the model and create a MobileMesh entity from that. However how best to get that into a TransformableShape (since MobileMesh does not extend ConvexShape)?
In other words... what is the best approach to convert a 3d model into a physical entity so that it can later be scaled/resized?
In other words... what is the best approach to convert a 3d model into a physical entity so that it can later be scaled/resized?
Re: Resizing/scaling physical entities
MobileMesh is a last resort for when you really, really need mobile concave triangle mesh behavior instead of a faster (and generally more robust) approximation.
If you do need to use a mobile mesh, you could recreate the MobileMeshShape or make some modifications to the MobileMeshShape class to permit the changing of its Transform. It's immutable by default for simplicity's sake.
Ideally, you could use a primitive like a Box, Cylinder, Sphere, etc. to approximate the model. This is much faster, much more robust, and allows you to use the TransformableShape easily.
The next step towards complexity is to use a ConvexHull. You can create a convex hull from point cloud data you extract from a model. It will be the tightest fitting convex primitive for a model, though it's still a single convex object. You can use a ConvexHullShape within a TransformableShape.
Beyond that, you can use a CompoundBody and the CompoundShapes. The compound body can be constructed from simple boxes and other implicit shapes or from convex hulls created from submesh point data. However, you cannot put a CompoundShape into a Transformable shape, and CompoundShapes are immutable. To transform a compound shape, you'd need to transform every child shape with a TransformableShape and the local positions of each child shape in the compound shape. This would require reconstruction of the object.
If you do need to use a mobile mesh, you could recreate the MobileMeshShape or make some modifications to the MobileMeshShape class to permit the changing of its Transform. It's immutable by default for simplicity's sake.
Ideally, you could use a primitive like a Box, Cylinder, Sphere, etc. to approximate the model. This is much faster, much more robust, and allows you to use the TransformableShape easily.
The next step towards complexity is to use a ConvexHull. You can create a convex hull from point cloud data you extract from a model. It will be the tightest fitting convex primitive for a model, though it's still a single convex object. You can use a ConvexHullShape within a TransformableShape.
Beyond that, you can use a CompoundBody and the CompoundShapes. The compound body can be constructed from simple boxes and other implicit shapes or from convex hulls created from submesh point data. However, you cannot put a CompoundShape into a Transformable shape, and CompoundShapes are immutable. To transform a compound shape, you'd need to transform every child shape with a TransformableShape and the local positions of each child shape in the compound shape. This would require reconstruction of the object.
Re: Resizing/scaling physical entities
Thanks for your explanation. At first I was thinking to use an algorithm to find the n best-fitting primitives to approximate a model, but hearing now that compound shapes can be tricky to transform, it sounds like the best thing to use would be ConvexHull (since we can get point cloud data from the model, it would seem even easier than finding the best approximating primitive).