summaryrefslogtreecommitdiff
path: root/scenegen.py
blob: 86f40066d96bfe3cded4ce60f72638e1421fd9c0 (plain)
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
import struct

from collections import OrderedDict

from gameobjects.matrix44 import *
from gameobjects.vector3 import *


class Node:
	pass

nodes = OrderedDict()

BaseNode = Node()
BaseNode.mtx = Matrix44()
#BaseNode.mtx *= Matrix44.rotation_about_axis((0,1,0), radians(180))
BaseNode.brres_key = '3D00'
BaseNode.model_name = 'GoldwoodBase'
BaseNode.lm_type = 0
nodes['Base'] = BaseNode

trees = []
trees.append([(-432.6419,491.4498,36.07888)])
trees.append([(-528.9393,465.0258,54.24921),(0,0,1,-205),(1.5,1.5,1.5)])
trees.append([(-620.4692,390.3275,67.48116),(0,0,-1,-84.99999),(2,2,2)])
trees.append([(-560.6774,261.2726,36.07889),(0,0,-1,-115)])
trees.append([(-335.7342,473.2928,58.58809),(0,0,1,-195),(2,2,2)])
trees.append([(-600.3536,168.692,54.24921),(0,0,-1,-30),(1.5,1.5,1.5)])
trees.append([(-504.1465,157.0091,34.27255),(0,0,-1,-15)])
trees.append([(-473.3172,-230.0073,-47.6824),(0,0,-1,-30),(1.5,1.5,1.5)])
trees.append([(-309.3281,-345.4817,-66.51208),(0,0,-1,-105)])
trees.append([(-200.273,417.9867,58.58809),(0,0,1,-160),(2,2,2)])
trees.append([(-428.3652,220.8884,53.48188),(0,0,1,-144.3318),(1.5,1.5,1.5)])
trees.append([(202.4636,423.0312,58.58809),(0,0,1,-190),(1.5,1.5,1.5)])
trees.append([(104.0971,448.0217,37.58566),(0,0,1,-90.00001)])
trees.append([(558.988,200.4099,134.7052),(0,0,1,-195),(2,2,2)])
trees.append([(-496.7122,52.15556,65.01857),(0,0,-1,-114.4882),(2,2,2)])
trees.append([(-625.6561,-14.46614,69.94374),(0,0,1,-160),(2,2,2)])
trees.append([(-451.8466,374.4697,54.24921),(0,0,1,-205),(1.5,1.5,1.5)])
trees.append([(-498.7201,302.163,36.07889),(0,0,1,-228.8284)])
trees.append([(-502.41,-357.0221,-66.51208),(0,0,1,-57.69051)])
trees.append([(-563.8763,-117.5426,32.63081),(0,0,-1,-15)])
trees.append([(-164.7518,28.56541,37.55599),(0,0,-1,-15)])
trees.append([(69.34688,-370.9233,54.24921),(0,0,1,-23.78404),(1.5,1.5,1.5)])
trees.append([(-381.2546,-27.60487,54.24921),(0,0,1,-143.3339),(1.5,1.5,1.5)])
trees.append([(517.5121,-118.4075,54.24921),(0,0,1,-143.3339),(1.5,1.5,1.5)])
trees.append([(636.0891,-20.87392,65.01857),(0,0,-1,-114.4882),(2,2,2)])
trees.append([(595.799,-261.0563,65.01857),(0,0,-1,-2.230904),(2,2,2)])
trees.append([(442.6156,-445.4103,35.47948),(0,0,1,-33.01907)])
trees.append([(601.3714,-369.1882,33.41096),(0,0,-1,-101.3162)])
trees.append([(135.2478,-410.5703,30.18969),(0,0,-1,-101.3162)])
trees.append([(375.7895,-410.6814,33.71223),(0,0,1,-122.8022)])
trees.append([(381.3143,312.5172,132.5149),(0,0,-1,-2.230904),(2,2,2)])
trees.append([(492.7756,314.4396,113.5759),(0,0,1,-143.3339),(1.5,1.5,1.5)])
trees.append([(123.7032,317.5327,65.01857),(0,0,-1,-76.25513),(2,2,2)])
trees.append([(224.8819,-211.3689,54.24921),(0,0,-1,-85.55461),(1.5,1.5,1.5)])
trees.append([(322.8776,-90.80885,65.01857),(0,0,1,-62.79728),(2,2,2)])
trees.append([(38.92174,-16.14143,37.55599),(0,0,1,-140.1519)])
trees.append([(123.4013,-39.51448,54.24921),(0,0,1,-226.3537),(1.5,1.5,1.5)])
trees.append([(-257.9183,-36.27791,46.23754),(0,0,1,-226.3537),(1.367996,1.367996,1.367996)])
trees.append([(-129.6952,-311.2891,30.18969),(0,0,-1,-92.79686)])
trees.append([(-212.5955,250.4542,60.27821),(0,0,1,-205),(1.645125,1.645125,1.645125)])
trees.append([(46.9944,279.5399,37.58566),(0,0,1,-216.0257)])
trees.append([(292.9048,-450.7896,54.24921),(0,0,1,-69.19887),(1.5,1.5,1.5)])
trees.append([(518.238,-452.9915,54.24921),(0,0,-1,-22.77429),(1.5,1.5,1.5)])
trees.append([(78.49855,-208.7774,30.18969),(0,0,1,-59.14187)])
trees.append([(-438.4393,-129.7501,34.27255),(0,0,1,-123.4304)])
trees.append([(-220.1394,-355.7235,65.01857),(0,0,-1,-114.4882),(2,2,2)])
trees.append([(4.708786,-273.2903,30.18969),(0,0,-1,-96.09806)])
trees.append([(-52.38176,-376.2185,54.24921),(0,0,1,-23.78404),(1.5,1.5,1.5)])
trees.append([(-233.0447,-430.365,-61.64869),(0,0,1,-195),(1.125775,1.125775,1.125775)])
trees.append([(-433.6412,-411.0383,-66.51208),(0,0,-1,-80)])
trees.append([(203.4264,-84.41426,37.55599),(0,0,1,-140.1519)])
trees.append([(78.68404,42.78148,37.55599),(0,0,1,-140.1519)])
trees.append([(-518.1977,-62.53108,54.24921),(0,0,1,-143.3339),(1.5,1.5,1.5)])
trees.append([(566.8211,-142.5897,35.47948),(0,0,1,-33.01907)])
trees.append([(-19.99593,36.96886,37.55599),(0,0,1,-20.15192)])

tree_idx = 0
for tree in trees:
	TreeNode = Node()
	TreeNode.mtx = Matrix44()
	# todo: matrix creation
	# todo: specifying which type each transformation is
	tf_idx = 0
	for tf in tree:
		if tf_idx == 0:
			#translate -- swap Y,Z! also, Z is negative for some reason...
			TreeNode.mtx *= Matrix44.translation(tf[0]+7.44,tf[2]-37,-tf[1])
		elif tf_idx == 1:
			#rotate
			TreeNode.mtx *= Matrix44.rotation_about_axis((tf[0],tf[2],tf[1]), radians(tf[3]))
		elif tf_idx == 2:
			#scale
			TreeNode.mtx *= Matrix44.scale(tf[0]*0.5, tf[1]*0.5, tf[2]*0.5)
		tf_idx += 1

	TreeNode.brres_key = '3D00'
	TreeNode.model_name = 'BrownTree' if tree_idx == 24 else 'RedTree'
	TreeNode.lm_type = 1
	nodes['Tr%02d' % tree_idx] = TreeNode
	tree_idx += 1



# todo: string table optimisation

header = struct.pack('>4sI', b'MScn', len(nodes))
entrydata = b''
stringtable = b''
stringoffsets = {}
currentoffset = 8 + (0x40 * len(nodes))

for key,node in nodes.items():
	#nodekey, brreskey, lmtype, nameoffset, matrix
	enc_name = node.model_name.encode('Shift-JIS')
	if enc_name not in stringoffsets:
		stringoffsets[enc_name] = currentoffset
		stringtable += enc_name + b'\0'
		currentoffset += len(enc_name) + 1

	nameoffs = stringoffsets[enc_name]


	entrydata += struct.pack('>4s4sII', key.encode('Shift-JIS'), node.brres_key.encode('Shift-JIS'), node.lm_type, stringoffsets[enc_name])
	for f in list(node.mtx.transposed_components())[0:12]:
		entrydata += struct.pack('>f', f)


open('scenedata.bin', 'wb').write(header + entrydata + stringtable)