-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_itm.py
40 lines (29 loc) · 1.14 KB
/
import_itm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import bpy
from struct import unpack
from . import shared
def load(context, filepath):
with open(filepath, 'rb') as f:
(version,) = unpack('<i', f.read(4))
assert version == 1, 'Unknown file version.'
vertices = []
faces = []
vertex_uvs = []
f.read(4 * 6)
(node_count,) = unpack('<i', f.read(4))
f.read(4 * 4 * node_count)
(vertex_count,) = unpack('<i', f.read(4))
for _ in range(vertex_count):
vertices.append(unpack('<fff', f.read(4 * 3)))
vertex_uvs.append(unpack('<ff', f.read(4 * 2)))
(face_count,) = unpack('<i', f.read(4))
for _ in range(face_count):
(num_vertices,) = unpack('<i', f.read(4))
vertex_indices = []
for _ in range(num_vertices):
(vertex_id,) = unpack('<i', f.read(4))
vertex_indices.append(vertex_id)
vertex_indices.reverse()
faces.append(tuple(vertex_indices))
name = bpy.path.display_name_from_filepath(filepath)
shared.load_mesh(context, name, vertices, faces, vertex_uvs)
return {'FINISHED'}