OK how do we use it

#2
by kinginblack - opened

Let's say now we need to be able to use the 3d file in our apps as a mesh, how do we do that?

i mean we can load it in blender but we are devs we probably want to use a command line tool to turn it from this to a mesh

Screenshot 2025-04-17 at 14.36.53.png
tried this came out bad here is my code

import trimesh
import open3d as o3d
import numpy as np

# Load the GLB file as a scene
scene = trimesh.load("mesh_car_2.glb")

# Access the geometry dictionary
if isinstance(scene, trimesh.Scene):
    geometries = list(scene.geometry.values())
    if len(geometries) > 0:
        mesh = geometries[0]  # assume first object is your point cloud
        points = np.asarray(mesh.vertices)
        
        # Optional: get vertex colors
        if mesh.visual.kind == 'vertex':
            colors = mesh.visual.vertex_colors[:, :3] / 255.0
        else:
            colors = None

        # Build Open3D point cloud
        pcd_1 = o3d.geometry.PointCloud()
        pcd_1.points = o3d.utility.Vector3dVector(points)
        
        # Extract normals from the trimesh mesh
        if hasattr(mesh, 'face_normals') and mesh.face_normals is not None:
            if not hasattr(mesh, 'vertex_normals') or mesh.vertex_normals is None:
                mesh.vertex_normals = trimesh.geometry.mean_vertex_normals(
                    len(mesh.vertices), 
                    mesh.faces, 
                    mesh.face_normals, 
                    mesh.face_angles)
        
        # Add normals to the point cloud if they exist
        if hasattr(mesh, 'vertex_normals') and mesh.vertex_normals is not None:
            normals = np.asarray(mesh.vertex_normals)
            pcd_1.normals = o3d.utility.Vector3dVector(normals)
        else:
            print("No normals found in the mesh. Estimating normals...")
            pcd_1.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.05, max_nn=50)) # Tune the search radius!
            pcd_1.orient_normals_towards_camera_location() # or another consistent approach to orient normals


        
        if colors is not None:
            pcd_1.colors = o3d.utility.Vector3dVector(colors)

        # Visualize
        # o3d.visualization.draw(pcd)
        o3d.io.write_point_cloud("output.ply", pcd_1) # Corrected variable name here


        with o3d.utility.VerbosityContextManager(  o3d.utility.VerbosityLevel.Debug) as cm:
              mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd_1, depth=9)
            
        vertices_to_remove = densities < np.quantile(densities, 0.02)
        mesh.remove_vertices_by_mask(vertices_to_remove)
        print("Bad Vertices Removed")
    
        tri_mesh = trimesh.Trimesh(np.asarray(mesh.vertices), np.asarray(mesh.triangles), vertex_colors=colors)
        print("Returning TriMesh")

        o3d.io.write_triangle_mesh("output_mesh1.ply", mesh)
         
               
    else:
        print("No geometries found in scene.")
else:
    print("File is not a scene.")
# o3d.visualization.draw(scene)

ok my issue is with the point cloud reconstruction into a solid mesh I have a feeling this is mainly with places where the point cloud isn't efficient , while dreaming last night (no jokes ) I thought it might be smarter to remove point clouds with less density and then save those vectors somewhere else and try and reconstruct those parts or cluster insdidually then add them back to the mesh , I think this is a dumb idea so means it most likely may work

Screenshot 2025-04-18 at 13.47.30.png
A you can see the mesh reconstruction doesn't work where their are no camera's so yeah this might be a good start

alright still not working ......... switched to ball pivoting from poison but still not working, I think I can make a new algorithm to turn this to a solid mesh, the way am looking at is when u use ball pivoting it doesn't do well and generate solid object but they are a lot of floating mesh points from all the examples I've made so far
image.png

image.png
as you can see it does have some sparsed points I feel if you can use like a sheet (visually image wrapping a car with car wrap) and use that to wrap the distorted mesh or better yet the actual point cloud (I don't think you would have the most ideal shape but that's okay) Ive seen some large algotirms for filling holes but they are wrappers for c++ libraries meaning I cant run them on cuda (I know I can simply just reduce the amount of vertices for the mesh shape then run that on the algorithms so they would be faster but where is the fun in that)

Screenshot 2025-04-20 at 22.34.50.png. and done was just needed to change parameters oh wow

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment