Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import csv
- from mathutils import Vector
- def import_delta_vertices(filepath):
- # Retrieve the vertex positions from the CSV file
- vertices = []
- with open(filepath, newline='') as csvfile:
- reader = csv.reader(csvfile)
- next(reader) # Skip the header line
- for row in reader:
- vertex_index = int(row[0])
- delta_x = float(row[1])
- delta_y = float(row[2])
- delta_z = float(row[3])
- # Convert the delta values to a Vector
- delta_vector = Vector((delta_x, delta_y, delta_z))
- # Store the delta vertex position
- vertices.append(delta_vector)
- # Create a new mesh object for the point cloud
- mesh = bpy.data.meshes.new("VertexPositions")
- obj = bpy.data.objects.new("VertexPositions", mesh)
- # Get the active scene
- scene = bpy.context.scene
- # Link the object to the scene
- scene.objects.link(obj)
- # Select and make the object active
- obj.select = True
- scene.objects.active = obj
- # Enter Edit Mode to add vertices
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.mesh.select_all(action='SELECT')
- bpy.ops.mesh.delete(type='VERT')
- # Exit Edit Mode to avoid potential issues
- bpy.ops.object.mode_set(mode='OBJECT')
- # Add the vertices to the mesh
- mesh.from_pydata(vertices, [], [])
- mesh.update()
- print("Vertex positions imported successfully.")
- csv_file_path = 'D:/test.csv'
- import_delta_vertices(csv_file_path)
Advertisement
Advertisement