princeton-vl / infinigen

Infinite Photorealistic Worlds using Procedural Generation
https://infinigen.org
BSD 3-Clause "New" or "Revised" License
5.35k stars 462 forks source link

Adding rotation in create_assets makes objects floating above the floor #346

Open GCChen97 opened 1 week ago

GCChen97 commented 1 week ago

Describe the bug

I tried to add some rotation to objects in create_assets and create_pholder before returning the objects but it makes the objects floating above the floor.

Steps to Reproduce

I added some rotation, but it seems not to work and makes the objects float above the floor instead. Here is the code clip:

    def create_asset(self, **kwargs) -> bpy.types.Object:
        obj = self.populate_func(scale=(self.dim_x, self.dim_y, self.dim_z))
        obj.rotation_mode = self.rotation_mode
        obj.rotation_euler = self.rotation_euler
        return obj

    def create_placeholder(self, **kwargs) -> bpy.types.Object:
        pholder = self.pholder_func(scale=(self.dim_x, self.dim_y, self.dim_z))
        pholder.rotation_mode = self.rotation_mode
        pholder.rotation_euler = self.rotation_euler
        return holder

What version of the code were you using?

commit 88fb49cde0bbca401601d05d672b31d28e9b45cb

araistrick commented 1 week ago

Rotations are generally controlled by the piece of code which invokes the asset, not the asset itself.

If you want to apply a rotation inside an asset implementation, you may need to "apply" the rotation so that it is baked into the mesh and isnt overwritten when later parts of the code assign the rotation. You can do this by calling butil.apply_transform(obj, rot=True) on the obj & placeholder before returning them.

But this is just my best guess for what could be going on, for more specific advice id need to know what object this is and what command you are running (indoors or nature ?)

GCChen97 commented 1 week ago

@araistrick Hi, Alex. Thanks for the reply. The reason I want to add rotation is to make the scene more casual and more diverse rather than everything being regularly placed and axis-aligned.

I implemented a few simple primitive factories including cube, sphere and cylinder for indoor scenes, and managed to add materials of canfactory for them. I did this for exploring the way infinigen works and will add more complex objects when I know how it works. Is butil.apply_transform a better choice for adding rotation?

araistrick commented 1 week ago

Assuming this is for indoor scenes, the easier way to achieve this would be to edit here and add some translation / rotation.

IE right before this line you could do something like:

placeholder.rotation_euler.z += np.rad2deg(np.random.uniform(-10, 10))
GCChen97 commented 1 week ago

Thanks! I'll try both the methods.