10
« on: May 05, 2023, 03:58:58 PM »
Hello.
With the aid of GPT did setup a simple script.
I whant to import a folder that is full of point clouds in .ply format. I whant to process them one by one, so import 1 .ply mesh it and save it as .fbx. No colors, just a mesh with normals.
I've two errors, one from license other specific to the script. I've activated a 30 day demo.
"(base) E:\LIDAR_JAPAN\MMS8_Prototype_3\zz_Batch_commands\MMS>python 04_e_NormalTexture_Mesh_Metashape.py
No response from license server
2.0.1
Traceback (most recent call last):
File "E:\LIDAR_JAPAN\MMS8_Prototype_3\zz_Batch_commands\MMS\04_e_NormalTexture_Mesh_Metashape.py", line 24, in <module>
import_task = doc.chunk.importPoints()
AttributeError: 'Metashape.Metashape.Chunk' object has no attribute 'importPoints'
"
According to the documentation importPoints is part of the Chunk namespace so not sure why that raises, is it because of license?
importPoints(path=’‘, format=PointsFormatNone, calculate_normals=True[, crs][, shift][,
progress])
Import point cloud from file.
Parameters
• path (string) – Path to point cloud.
• format (PointsFormat) – Point cloud format.
• calculate_normals (bool) – Calculate point normals.
• crs (CoordinateSystem) – Point cloud coordinate system.
• shift (Vector) – Optional shift to be applied to point coordinates.
• progress (Callable[[float], None]) – Progress callback.
Finally, my script:
import Metashape
print(Metashape.app.version)
import os
# Set the folder path containing the point clouds
point_cloud_folder_path = "E:/LIDAR_JAPAN/MMS8_Prototype_3/MMS/03_RoadMesh/04_Texturing/01_DATA_SOURCE_POINT_CLOUDS/00_color"
# Create a new Metashape document
doc = Metashape.Document()
# Loop over each file in the folder
for file_name in os.listdir(point_cloud_folder_path):
# Check if the file is a .ply file
if file_name.endswith(".ply"):
# Create a new chunk for the current file
chunk = doc.addChunk()
# import all point clouds in the folder
import_points = doc.chunk.importPoints()
import_points.path = point_cloud_folder_path + "/*.ply" # or replace with appropriate file extension
# Get the first chunk in the document
chunk = doc.chunk[0]
# Create a new mesh for the chunk
mesh = chunk.model
# Set the source data for the mesh generation
mesh.source_data = Metashape.DataSource.PointCloudData
# Set the surface type
mesh.surface_type = Metashape.SurfaceType.Arbitrary
# Set the face count of the mesh
mesh.face_count = Metashape.FaceCount.MediumFaceCount
# Disable vertex color calculation
mesh.enableColors(False)
# Set the interpolation
mesh.interpolation = Metashape.Interpolation.EnabledInterpolation
# Generate the mesh
chunk.buildModel()
# Export the mesh as a .ply file
mesh_file_name = os.path.splitext(file_name)[0] + ".fbx"
chunk.exportModel(os.path.join(point_cloud_folder_path, mesh_file_name))
# Clear the point cloud and remove the chunk to free up memory
point_cloud.clear()
doc.remove(chunk)
hopefully is a silly thing :\