-
Notifications
You must be signed in to change notification settings - Fork 0
/
prism3d.py
164 lines (131 loc) · 5.55 KB
/
prism3d.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# TODO: Checkout GDT format: num_models is fixed to 13 for some reason?
import os
import bpy
from .kaitai.prism3d_gdt import Prism3dGdt
from .kaitai.prism3d_pmd import Prism3dPmd
from .kaitai.prism3d_pmg import Prism3dPmg
from .kaitai.prism3d_psm import Prism3dPsm
# V003: Shark: Hunting the great white
# V005: 911FireRescue,
# V006: DukeNukem: Manhattan Project, 18woS: Hard Truck, Hunting Unlimited 1, Hunting Unlimited 2,
# V007: OceanDive 1.4, Hunting Unlimited 3
#
# https://www.moddb.com/games/duke-nukem-manhattan-project/downloads <= Tools for V006
def import_gdt(context, filepath, mat):
name, _ = os.path.splitext(os.path.basename(filepath))
#filedir = os.path.dirname(filepath)
parsed = Prism3dGdt.from_file(filepath)
print(parsed)
view_layer = bpy.context.view_layer
collection = view_layer.active_layer_collection.collection
#root = bpy.data.objects.new(name)
#collection.objects.link(root)
for m in parsed.models:
mverts = list(map(lambda v: [v.x, v.y, v.z], m.vertices))
mfaces = []
muvs = []
for i in range(0, len(m.indices), 3):
a = m.indices[i]
b = m.indices[i+1]
c = m.indices[i+2]
mfaces.append([ a,b,c ])
muvs.append([ m.uvs[a].u, m.uvs[a].v ])
muvs.append([ m.uvs[b].u, m.uvs[b].v ])
muvs.append([ m.uvs[c].u, m.uvs[c].v ])
mesh_data = bpy.data.meshes.new(name + '_Mesh')
mesh_data.from_pydata(mverts, [], mfaces) # [] = no edges defined
mesh_data.update()
obj = bpy.data.objects.new(name, mesh_data)
collection.objects.link(obj)
# Configure uv layer
uv = obj.data.uv_layers.new(name=name + "_UV")
for loop in obj.data.loops:
uv.data[loop.index].uv = muvs[loop.index]
return {'FINISHED'}
# 4: 18WoS: Convoy, Bus Driver, Deer Drive, Hunting Unlimited 4, Hunting Unlimited 2008, Hunting Unlimited 2009, Hunting Unlimited 2010,
# 5: 911 Fire Rescue
# 7,8: Shark: Hunting the great white,
# 9: Hunting Unlimited 1,
# 10: 18WoS: Across America, 18WoS: Hard Truck
def import_pmd(context, filepath, mat):
name, _ = os.path.splitext(os.path.basename(filepath))
#filedir = os.path.dirname(filepath)
parsed = Prism3dPmd.from_file(filepath)
view_layer = bpy.context.view_layer
collection = view_layer.active_layer_collection.collection
for idx in range(parsed.num_objects):
h = parsed.object_headers[idx]
o = parsed.objects[idx]
mverts = list(map(lambda v: [v.x, v.y, v.z], o.vertices))
mfaces = []
muvs = []
for i in range(0, o.num_indices, 3):
a = o.indices[i]
b = o.indices[i+1]
c = o.indices[i+2]
mfaces.append([ a,b,c ])
muvs.append([ o.uvs[a].x, o.uvs[a].y ])
muvs.append([ o.uvs[b].x, o.uvs[b].y ])
muvs.append([ o.uvs[c].x, o.uvs[c].y ])
mesh_data = bpy.data.meshes.new(h.name + '_Mesh')
mesh_data.from_pydata(mverts, [], mfaces) # [] = no edges defined
mesh_data.update()
obj = bpy.data.objects.new(h.name, mesh_data)
collection.objects.link(obj)
# TODO: uv + animation
return {'FINISHED'}
# 0x10: 18WoS: Convoy, Hunter Unlimited 4
# 0x11: Bus Driver, Deer Drive, Hunting Unlimited 2008, Hunting Unlimited 2009, Hunting Unlimited 2010,
def import_pmg(context, filepath, mat):
name, _ = os.path.splitext(os.path.basename(filepath))
#filedir = os.path.dirname(filepath)
parsed = Prism3dPmg.from_file(filepath)
view_layer = bpy.context.view_layer
collection = view_layer.active_layer_collection.collection
for o in parsed.objects:
mverts = list(map(lambda v: [v.x, v.y, v.z], o.vertices))
mfaces = []
muvs = []
for i in range(0, len(o.indices), 3):
a = o.indices[i]
b = o.indices[i+1]
c = o.indices[i+2]
mfaces.append([ a,b,c ])
muvs.append([ o.uvs[a].x, o.uvs[a].y ])
muvs.append([ o.uvs[b].x, o.uvs[b].y ])
muvs.append([ o.uvs[c].x, o.uvs[c].y ])
mesh_data = bpy.data.meshes.new(name + '_Mesh')
mesh_data.from_pydata(mverts, [], mfaces) # [] = no edges defined
mesh_data.update()
obj = bpy.data.objects.new(name, mesh_data)
collection.objects.link(obj)
return {'FINISHED'}
# 3: Hunting Unlimited 1,
# 4: 10WoS: Hard Truck,
# 6: 18WoS: Across America, Hunting Unlimited 2, Hunting Unlimited 3,
# 7: 18WoS: Pedal to the Metal, Hunting Unlimited 3,
# 9: OceanDive 1.4,
def import_psm(context, filepath, mat):
name, _ = os.path.splitext(os.path.basename(filepath))
#filedir = os.path.dirname(filepath)
parsed = Prism3dPsm.from_file(filepath)
view_layer = bpy.context.view_layer
collection = view_layer.active_layer_collection.collection
for o in parsed.objects:
mverts = list(map(lambda v: [v.x, v.y, v.z], o.vertices))
mfaces = []
muvs = []
for i in range(0, o.num_triangles * 3, 3):
a = o.indices[i]
b = o.indices[i+1]
c = o.indices[i+2]
mfaces.append([ a,b,c ])
muvs.append([ o.uvs[a].x, o.uvs[a].y ])
muvs.append([ o.uvs[b].x, o.uvs[b].y ])
muvs.append([ o.uvs[c].x, o.uvs[c].y ])
mesh_data = bpy.data.meshes.new(o.name + '_Mesh')
mesh_data.from_pydata(mverts, [], mfaces) # [] = no edges defined
mesh_data.update()
obj = bpy.data.objects.new(o.name, mesh_data)
collection.objects.link(obj)
return {'FINISHED'}