Help Needed: Automating STL to BIN Conversion!
Posted: Sun Oct 15, 2023 11:38 pm
Hello experts and other community members,
I'm seeking guidance on automating the conversion of STL format files to BIN. I'm aware of how to perform this conversion manually in tools like Cloud Compare or similar software. However, I've encountered a few issues when attempting to automate the process using Python code.
The Python code I have does indeed convert the STL file to BIN successfully. However, the problem arises when I attempt to open the converted BIN format. It doesn't seem to work with any of the 3D software, including Cloud Compare.
Also, I have noticed a difference in file size when I manually convert STL to BIN instead of using the Python code. The manually converted BIN file tends to be larger, while the BIN file created with the code keeps the same size or even gets smaller.
I would be very grateful for any help, insight, or suggestions on how to properly do this conversion using the code or alternatively. If you have any experience with this or can offer any advice, I'm all ears. Your expertise would be invaluable. Thank you in advance for your help!
Mustafi
......................................................................................................................................................................................
from stl import mesh
import numpy as np
def stl_to_large_bin_point_cloud(stl_filename, bin_filename):
try:
# Load STL file using numpy-stl
mesh_data = mesh.Mesh.from_file(stl_filename)
# Extract vertices from the mesh
vertices = mesh_data.points
if len(vertices) == 0:
print("No valid vertices found in the STL file.")
return
# Convert vertices to a larger binary point cloud
# This example assumes the vertices are single-precision float32 values
vertices = vertices.astype(np.float32).tobytes()
# Write the binary point cloud data to the BIN file
with open(bin_filename, 'wb') as bin_file:
bin_file.write(vertices)
print(f'{stl_filename} has been converted to a larger {bin_filename} in binary point cloud format.')
except Exception as e:
print(f'Error: {e}')
if __name__ == "__main__":
stl_filename = "input.stl" # Replace with the path to your STL file
bin_filename = "output_point_cloud.bin" # Specify the desired name for the larger BIN file
stl_to_large_bin_point_cloud(stl_filename, bin_filename)
.......................................................................................................................................................................................
I'm seeking guidance on automating the conversion of STL format files to BIN. I'm aware of how to perform this conversion manually in tools like Cloud Compare or similar software. However, I've encountered a few issues when attempting to automate the process using Python code.
The Python code I have does indeed convert the STL file to BIN successfully. However, the problem arises when I attempt to open the converted BIN format. It doesn't seem to work with any of the 3D software, including Cloud Compare.
Also, I have noticed a difference in file size when I manually convert STL to BIN instead of using the Python code. The manually converted BIN file tends to be larger, while the BIN file created with the code keeps the same size or even gets smaller.
I would be very grateful for any help, insight, or suggestions on how to properly do this conversion using the code or alternatively. If you have any experience with this or can offer any advice, I'm all ears. Your expertise would be invaluable. Thank you in advance for your help!
Mustafi
......................................................................................................................................................................................
from stl import mesh
import numpy as np
def stl_to_large_bin_point_cloud(stl_filename, bin_filename):
try:
# Load STL file using numpy-stl
mesh_data = mesh.Mesh.from_file(stl_filename)
# Extract vertices from the mesh
vertices = mesh_data.points
if len(vertices) == 0:
print("No valid vertices found in the STL file.")
return
# Convert vertices to a larger binary point cloud
# This example assumes the vertices are single-precision float32 values
vertices = vertices.astype(np.float32).tobytes()
# Write the binary point cloud data to the BIN file
with open(bin_filename, 'wb') as bin_file:
bin_file.write(vertices)
print(f'{stl_filename} has been converted to a larger {bin_filename} in binary point cloud format.')
except Exception as e:
print(f'Error: {e}')
if __name__ == "__main__":
stl_filename = "input.stl" # Replace with the path to your STL file
bin_filename = "output_point_cloud.bin" # Specify the desired name for the larger BIN file
stl_to_large_bin_point_cloud(stl_filename, bin_filename)
.......................................................................................................................................................................................