Adding gravity and physics to runtime imported CAD files.

I am using datasmith runtime to import CAD models during runtime. What I ultimately want is to give them physics, most important gravity. I have chosen the default environment “Collab Viewer” which has pre-built in datasmith runtime. You use the datasmith runtime in the collab viewer while during runtime by holding space, choosing datasmith, pressing new and choosing source. When this is done a model is imported. The problem for me here is that this model stays floating in the sky. What I want is to give it gravity which I have understood is possible by checking Simulate Physics. So I have been looking through the blueprint for the importation during runtime scripts and from root of the project it is located in Content/CollaborativeViewer/Blueprints/Commands/DataSmith/BP_DataSmith_Component.uasset. What I found which I think is relevant is this part:

I assume that here it is possible to enable the physics after import but I have no idea how since I have never used blueprint before. I would super much appreciate help here.

Thanks very much in advance.

First, it depends on what actor class the model is imported as. I’m going to assume it’s a “static mesh” actor. (If it’s an instanced static mesh, or hierarchical static mesh, this won’t work.)

Now, for physics to work, two things need to be true:

  1. The physics simulation needs to be turned on (this gives the object “mass” and lets it simulate forces and torques.)
  2. There needs to be some kind of collision geometry, which lets the physics engine stop things that move into other things.

You can easily turn on “simulate physics” on a static mesh actor, by rolling out the actor properties and checking a checkbox.

Collision is a little harder. Physics simulation works best when the bits that can actually bump into each other aren’t too complex – an intricate surface with lots of holes and concave areas, will be extremely inefficient to simulate.

Thus, you will want to open up your static mesh, and add “simplified collision” – some set of collider boxes, spheres, and convex hulls that, when taken together, approximate the shape of the object. (If you play games, this is the “hitboxes” that you’ll find on characters.)

So, open up your static mesh Asset (not the actor) and add some collision – simplified DOP or Automatic Convex Collision might work as a first iteration.

image

Then make the mobility of your Static Mesh Actor “Movable”

Then turn on physics simulation:

image

I find that you’ll want a little bit of angular momentum dampening, to make simulation be robust and not explode into infinity. The default is 0 which is not enough.

If your object is big and complex, then you might want to separate it into several less complex objects, or at least be a little more deliberate in placing collision boxes to align with the various internal/external surfaces of the object.
(There’s also a way to build proxy shapes in DCC tools like Blender or Maya that will be imported as simplified collision shapes; I don’t know of the CAD import can do the same thing – chancer are, probably not.)

Thank you for the answer @jwatte. The thing is that I want the physics to be set and the gravity to work by default while importing during runtime. I’ll upload 2 videos to show what “collab viewer” is and what I mean by importing during runtime.


It seems to be possible as shown in the second video to manually enable the “simulate physics” during runtime, tough nothing happens. And I didn’t record it but I also opened so I could edit the imported CAD file that was converted to a “StaticMeshActor” , but when I add any collision, for example “Add Sphere Simplified Collision” Unreal Engine just crashes. Either way, as I said, I want those physics to be enabled by default when importing during runtime and not having to be enabled manually in the editor. That is why I think that the blueprint that enables this importation has to be modified. More specifically the blueprint that I uploaded an image of in my first post. I am still stuck here and would still appreciate help very much.

You need to both enable “simulate physics” and make the movement mode “Movable,” at a minimum.
That needs to be done on the Datasmith Destination actor you spawn.

That being said – I don’t know whether Datasmith Destination Actor supports physics simulation. It might – only one way to find out!