Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

open3d.io.write_triangle_mesh(write_triangle_uvs) not creating mtl file for colorized 3D model. Only creates a .obj file.

Open cecolson opened this issue 3 years ago • 0 comments
trafficstars

Checklist

My Question

I am trying to create a .obj file with color using open3d. I know the write_triangle_uvs parameter allows for mtl file to be saved, however I cannot get it to work no matter what I try. This was an issue that was previously closed but I would like to reopen it with my code included below. I do not have the parameter listed here because I know its default value = True. Please help me understand what I am missing. I cannot attach the .las file I used since github does not support it, but if you try any colorized .las file I am sure you will run into the same issue.

import numpy as np
import open3d as o3d
import laspy as lp

def OutputObject(voxelGrid, voxelSize, outputPath):
    print("Generating voxel object.")
    voxels=voxelGrid.get_voxels()
    voxelMesh = o3d.geometry.TriangleMesh()
    for voxel in voxels:
        block = o3d.geometry.TriangleMesh.create_box(width=1, height=1, depth=1, create_uv_map=True)#, map_texture_to_each_face=True)
        block.paint_uniform_color(voxel.color)
        block.translate(voxel.grid_index, relative=False)
        voxelMesh+=block

    voxelMesh.translate([0.5, 0.5, 0.5], relative=True)
    voxelMesh.scale(voxelSize, [0, 0, 0])
    voxelMesh.translate(voxelGrid.origin, relative=True)
    voxelMesh.merge_close_vertices(0.0000001)
    #o3d.visualization.draw_geometries([voxelMesh])
    meshTransformed = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, -1, 0, 0], [0, 0, 0, 1]])
    o3d.io.write_triangle_mesh(outputPath, voxelMesh.transform(meshTransformed), write_ascii=True)

if __name__ == '__main__':
    pointCloud = lp.read('GreenhouseLas.las')
    pointCloudData = o3d.geometry.PointCloud()
    pointCloudData.points = o3d.utility.Vector3dVector(
        np.vstack((pointCloud.x, pointCloud.y, pointCloud.z)).transpose())
    pointCloudData.colors = o3d.utility.Vector3dVector(
        np.vstack((pointCloud.red, pointCloud.green, pointCloud.blue)).transpose()/65535)
    voxelSize = round(
        max(pointCloudData.get_max_bound() - pointCloudData.get_min_bound())*0.005, 4)
    voxelGrid = o3d.geometry.VoxelGrid.create_from_point_cloud(pointCloudData, voxel_size=voxelSize)
    #o3d.visualization.draw_geometries([voxelGrid])
    
    outputPath = 'GreenhouseVMesh.obj'
    OutputObject(voxelGrid, voxelSize, outputPath)

cecolson avatar Jul 18 '22 16:07 cecolson