0
$\begingroup$

I want to drop an element on a plane. Here you can see what happens:

enter image description here

This is my blender file: https://easyupload.io/bh6k7d

I load the object in my python script and set it as a rigid body:

scene = bpy.context.scene
cam = bpy.data.objects['Camera']
obj = bpy.data.objects['Cube']
plane = bpy.data.objects['Plane']

bpy.ops.import_mesh.stl(filepath=path)
obj.data = bpy.context.object.data
bpy.data.objects.remove(bpy.context.object)
scene.rigidbody_world.group.objects.link(obj)

The plane is set to rigid body passive.

I want the object to really fall onto the plane. Anyone knows what I am doing wrong?

$\endgroup$
4
  • $\begingroup$ @batFINGER yes. I let it drop and render images. But the object never really falls onto the plane. $\endgroup$ Feb 20, 2020 at 13:35
  • $\begingroup$ Have you checked the rigid bodies' margins and collide/interaction type? It looks like it is being calculated as a low poly object. $\endgroup$ Feb 22, 2020 at 0:55
  • $\begingroup$ What is going here? The script in blend is about rendering PNG? Written lines of script here are part of something? Anyway for physics you need to have origin at centre of object and as Nate_Sycro27 wrote -care about Collision Shape, should be minimal a Convex_Hull if not a Mesh type to act properly. $\endgroup$
    – vklidu
    Feb 22, 2020 at 7:24
  • 1
    $\begingroup$ you might want to try setting the origin of the object to the center of volume. I am pretty sure blender's physics applies forces to the origin and that can lead to some unexpected behavior if it is outside the object. $\endgroup$
    – Michael
    Feb 25, 2020 at 22:20

1 Answer 1

2
+50
$\begingroup$

You need to set the origin of the object to its center of mass else the simulation will become wonky. Select your object.

obj = bpy.data.objects['Cube']

obj.select_set(True)

While the object is selected in object mode, right click > Set Origin > To center of mass.

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME', center='MEDIAN')

Also, Apply scale with CTRL + A so that it is uniform at 1,1,1.

bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)

Check the difference here between one cube with its origin to its center of mass and one which is off-center. (the two origins of each cube are the yellow dots) :

enter image description here

$\endgroup$
7
  • 1
    $\begingroup$ Thank you! Do you know how I can set this with the python api as I am loading the object there? $\endgroup$ Feb 26, 2020 at 9:44
  • $\begingroup$ I just added that ! If you ever want to know what operator gets called, when you perform an action in blender, open an "Info" workspace somewhere and do your thing using the blender UI. The operators you called will appear in the bottom lines of this workspace $\endgroup$
    – Gorgious
    Feb 26, 2020 at 9:46
  • $\begingroup$ Thank you for this information! I couldn't find the info-worspace. I am using blender 2.79 and it says bpy.ops.apply.transformlocrotscale couldn't be found. $\endgroup$ Feb 26, 2020 at 11:08
  • $\begingroup$ Actually you don't need this line. Just the other one is sufficient. You can access the info workspace from any window in your blender interface. There is an icon on each of these windows on the top left corner with a downward facing arrow. You can click on it and change the workspace. The "info" is under the "scripting" workspaces $\endgroup$
    – Gorgious
    Feb 26, 2020 at 11:44
  • 1
    $\begingroup$ Perfect! I did obj.select = True because of my old blender version. Thank you again! $\endgroup$ Feb 26, 2020 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .