MCPcopy Create free account
hub / github.com/Netflix/void-model / extract_object_model_data

Function extract_object_model_data

data_generation/scripts/extract_pk_data.py:79–116  ·  view source on GitHub ↗

Extract mesh vertices and faces from objects. Works in both object mode and edit mode.

()

Source from the content-addressed store, hash-verified

77 return object_data
78
79def extract_object_model_data():
80 """
81 Extract mesh vertices and faces from objects.
82 Works in both object mode and edit mode.
83 """
84 object_data = {}
85 objects = get_all_objects()
86 scene = bpy.context.scene
87
88 for obj in objects:
89 scene.frame_set(scene.frame_start)
90
91 # Only process mesh objects
92 if obj.type != 'MESH':
93 continue
94
95 # Select the object and make it active
96 bpy.context.view_layer.objects.active = obj
97 obj.select_set(True)
98
99 # If in object mode, access mesh data directly
100 mesh = obj.data
101
102 # Extract vertices (in local coordinates)
103 vertices = np.array([v.co[:] for v in mesh.vertices], dtype=np.float32)
104
105 # Extract faces (vertex indices)
106 faces = []
107 for p in mesh.polygons:
108 for iters in range(len(p.vertices) - 2):
109 faces.append([p.vertices[0], p.vertices[iters + 1], p.vertices[iters + 2]])
110 faces = np.array(faces, dtype=np.int64)
111
112 object_data[obj.name] = {
113 'mesh': (vertices, faces),
114 }
115
116 return object_data
117
118fbx_path = os.path.join(fbx_folder_path, f'{folder}.fbx')
119assert os.path.exists(fbx_path), f"FBX file not found: {fbx_path}"

Callers 1

extract_pk_data.pyFile · 0.85

Calls 1

get_all_objectsFunction · 0.85

Tested by

no test coverage detected