@@ -159,157 +159,6 @@ def readMZD_to_meshio(filepath):
159
159
pass
160
160
return meshio .Mesh (out_vertPositions .reshape ((out_numVertices , 3 )), cells , point_data )
161
161
162
-
163
- def readMZD_to_meshio_with_split_norm (filepath ):
164
- out_numVertices = None
165
- out_numPolygons = None
166
- out_vertPositions = None
167
- out_numNodes = None # number of loops
168
- out_polyVIndicesNum = None # faces_loop_total
169
- out_polyVIndices = None #loops_vert_idx
170
- cells = {}
171
- point_data = {}
172
-
173
- with open (filepath , 'rb' ) as file :
174
- byte = file .read (24 )
175
- if byte != head :
176
- return - 4
177
- while 1 :
178
- # check if it reach the end
179
- byte = file .read (24 )
180
- if byte == end :
181
- break
182
- else :
183
- # if not reach the end, rewind the pointer back 24 bytes
184
- file .seek (- 24 , 1 )
185
-
186
- byte = file .read (4 )
187
- chunkID = int .from_bytes (byte , byteorder = 'little' )
188
-
189
- byte = file .read (24 )
190
- name = byte
191
-
192
- byte = file .read (4 )
193
- size = int .from_bytes (byte , byteorder = 'little' )
194
-
195
- if chunkID == 0x0ABC0001 : # vertices and polygons.
196
-
197
- byte = file .read (4 )
198
- out_numVertices = int .from_bytes (byte , byteorder = 'little' )
199
- if out_numVertices < 0 :
200
- return - 127
201
- if out_numVertices == 0 :
202
- break
203
-
204
- byte = file .read (12 * out_numVertices )
205
- out_vertPositions = np .frombuffer (byte , dtype = np .float32 )
206
-
207
- byte = file .read (4 )
208
- out_numPolygons = int .from_bytes (byte , byteorder = 'little' )
209
-
210
- byte = file .read (out_numPolygons )
211
- out_polyVIndicesNum = np .frombuffer (byte , dtype = np .uint8 )
212
- out_numNodes = out_polyVIndicesNum .sum (dtype = np .int32 )
213
-
214
- byte = file .read (4 )
215
- numBytesPerPolyVInd = int .from_bytes (byte , byteorder = 'little' )
216
-
217
- if numBytesPerPolyVInd == 4 :
218
- # int
219
- byte = file .read (out_numNodes * numBytesPerPolyVInd )
220
- out_polyVIndices = np .frombuffer (byte , dtype = np .int32 )
221
- elif numBytesPerPolyVInd == 2 :
222
- # unsigned short
223
- byte = file .read (out_numNodes * numBytesPerPolyVInd )
224
- # WARNING: not sure if it's correct
225
- # uncovered branch from test data
226
- out_polyVIndices = np .frombuffer (byte , dtype = np .uint16 )
227
- else :
228
- return - 127
229
- start_polyVIndicesNum = 0
230
- start_polyVIndices = 0
231
- breaks = np .where (out_polyVIndicesNum [:- 1 ] != out_polyVIndicesNum [1 :])[0 ] + 1
232
- breaks = np .append (breaks , len (out_polyVIndicesNum ))
233
- for b in breaks :
234
- poly_nodes_num = out_polyVIndicesNum [start_polyVIndicesNum ] # 3(triangle) or 4 (quad)
235
- end_polyVIndices = start_polyVIndices + poly_nodes_num * (b - start_polyVIndicesNum )
236
- cells [num_nodes_to_name [poly_nodes_num ]] = out_polyVIndices [start_polyVIndices :end_polyVIndices ].reshape (
237
- ((b - start_polyVIndicesNum ), poly_nodes_num ))
238
- start_polyVIndices = end_polyVIndices
239
- start_polyVIndicesNum = b
240
-
241
- faces_copy = np .copy (cells ['triangle' ])
242
- faces_copy .sort (axis = 1 )
243
- _ , indxs = np .unique (faces_copy , axis = 0 , return_index = True )
244
- faces = cells ['triangle' ][indxs ]
245
- cells ['triangle' ] = faces
246
-
247
- faces_copy = np .copy (cells ['quad' ])
248
- faces_copy .sort (axis = 1 )
249
- _ , indxs = np .unique (faces_copy , axis = 0 , return_index = True )
250
- faces = cells ['quad' ][indxs ]
251
- cells ['quad' ] = faces
252
-
253
- elif chunkID == 0xDA7A0001 : # vertex normals.
254
- byte = file .read (4 )
255
- out_numVerticeAttributes = int .from_bytes (byte , byteorder = 'little' )
256
- if out_numVerticeAttributes != out_numVertices :
257
- return - 127
258
-
259
- byte = file .read (out_numVerticeAttributes * 6 )
260
- out_vertAttribute = np .frombuffer (byte , dtype = np .uint16 )
261
- out_vertAttribute = table [out_vertAttribute ]
262
- point_data ['normal' ] = out_vertAttribute .reshape ((out_numVerticeAttributes , 3 ))
263
-
264
- elif chunkID == 0xDA7A0002 : # vertex motions
265
- byte = file .read (4 )
266
- out_numVerticeAttributes = int .from_bytes (byte , byteorder = 'little' )
267
- if out_numVerticeAttributes != out_numVertices :
268
- return - 127
269
-
270
- byte = file .read (out_numVerticeAttributes * 6 )
271
- out_vertAttribute = np .frombuffer (byte , dtype = np .uint16 )
272
- out_vertAttribute = table [out_vertAttribute ]
273
- point_data ['velocity' ] = out_vertAttribute .reshape ((out_numVerticeAttributes , 3 ))
274
-
275
- elif chunkID == 0xDA7A0003 : # vertex colors
276
- byte = file .read (4 )
277
- out_numVerticeAttributes = int .from_bytes (byte , byteorder = 'little' )
278
- if out_numVerticeAttributes != out_numVertices :
279
- return - 127
280
-
281
- byte = file .read (out_numVerticeAttributes * 8 )
282
- out_vertAttribute = np .frombuffer (byte , dtype = np .uint16 )
283
- out_vertAttribute = table [out_vertAttribute ]
284
- point_data ['color' ] = out_vertAttribute .reshape ((out_numVerticeAttributes , 3 ))
285
-
286
- elif chunkID == 0xDA7A0004 : # vertex UVWs.
287
- byte = file .read (4 )
288
- out_numVerticeAttributes = int .from_bytes (byte , byteorder = 'little' )
289
- if out_numVerticeAttributes != out_numVertices :
290
- return - 127
291
-
292
- byte = file .read (out_numVerticeAttributes * 12 )
293
- out_vertAttribute = np .frombuffer (byte , dtype = np .float32 )
294
- point_data ['uvw_map' ] = out_vertAttribute .reshape ((out_numVerticeAttributes , 3 ))
295
-
296
- # For the rest of attributes, because meshio doest not support attributes on nodes, (equivalent to face cornder in blender)
297
- # So the attributes data will be skipped
298
- elif chunkID == 0xDA7A0011 : # node normals.
299
- file .seek (size , 1 )
300
- pass
301
- elif chunkID == 0xDA7A0013 : # node colors.
302
- file .seek (size , 1 )
303
- pass
304
- elif chunkID == 0xDA7A0014 : # node UVWs.
305
- file .seek (size , 1 )
306
- pass
307
- else :
308
- file .seek (size , 1 )
309
- pass
310
- return meshio .Mesh (out_vertPositions .reshape ((out_numVertices , 3 )), cells , point_data )
311
-
312
-
313
162
def readMZD_to_bpymesh (filepath , mesh ):
314
163
shade_scheme = False
315
164
if mesh .polygons :
0 commit comments