manim icon indicating copy to clipboard operation
manim copied to clipboard

Custom 3D .obj files

Open mattdeitke opened this issue 5 years ago • 3 comments

Is there any way to add custom 3D .obj files to a scene? I know that 3D plots and a few primitive shapes can be added, but have not seen any way to add custom 3D objects.

Thanks!

mattdeitke avatar Dec 31 '19 04:12 mattdeitke

No, that's unfortunately not possible, and I guess that manim is not the right platform for that. Probably you should have a look on Blender to do that. My idea for a workaround is to somehow convert your .obj data in a 3d- numpy array grid, and then with this code you can display all the Points where the grid has a "one":

class ImageScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=-60 * DEGREES)  # 2.5D
        self.begin_ambient_camera_rotation()
        Disp_array= VMobject()
        for x in range(-3, 3):
            for y in range(-3, 3):
                for z in range(-3, 3):
                    dot = Dot(point=(x, y, z))
                    Disp_array.add(dot)
        [Disp_array.submobjects[i].set_color(RED) for i in range(0,100)]
        self.add(Disp_array)
        self.wait(2)

output

kolibril13 avatar Jan 06 '20 17:01 kolibril13

I tried to customise classes for loading and rendering.obj 3D model. Please find it here. open3d package is needed because I use it as the .obj parser.

Currently, the Mesh class can't load very complex meshes (say more than 1000 faces) due to the efficiency issue. In this case, please use the Point_Cloud class which resamples them as a point cloud, lowering the computational stress to a handleable level.

Below is a sample: the complex human mesh was rendered with Point_Cloud and the simple polyhedron was rendered with Mesh. Hoping that it can serve your need:

https://user-images.githubusercontent.com/77708899/195068482-cca3dd6a-c4f3-4098-9e39-7e95cf280276.mp4

from manim import *
from concept import obj_model

class Test(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=60 * DEGREES)

        pcd = obj_model.Point_Cloud("gallery/material/body.obj")
        pcd.lightup()
        pcd.rotate(90*DEGREES, RIGHT)
        
        mesh = obj_model.Mesh("gallery/material/cube.obj")
        mesh.lightup()
        mesh.rotate(90*DEGREES, RIGHT).next_to(pcd, RIGHT)

        self.add(pcd)
        self.add(mesh)
        self.begin_ambient_camera_rotation(rate=4)
        self.wait()

liu-qilong avatar Oct 11 '22 10:10 liu-qilong

I would also be interested by this feature, ideally I’d love to be able to play animation (e.g. in blender I record an animation to raise the hand, or walk, and this should be actionable in manim).

tobiasBora avatar May 14 '23 14:05 tobiasBora