annotate io_scene_touhou/import_std.py @ 0:8265ef6db380

Hello Gensokyo _o/
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 Mar 2013 20:10:10 +0100
parents
children ba73c663a227
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # ##### BEGIN GPL LICENSE BLOCK #####
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 #
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 # This program is free software; you can redistribute it and/or
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 # modify it under the terms of the GNU General Public License
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 # as published by the Free Software Foundation; either version 2
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 # of the License, or (at your option) any later version.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 #
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 # This program is distributed in the hope that it will be useful,
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 # GNU General Public License for more details.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 #
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 # along with this program; if not, write to the Free Software Foundation,
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 #
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 # ##### END GPL LICENSE BLOCK #####
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 # <pep8-80 compliant>
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 """
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 This script imports Touhou EoSD stages files to Blender.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 Usage:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 Execute this script from the "File->Import" menu and choose a Touhou
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 stage file to open.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 """
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 from pytouhou.formats.std import Stage
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 from pytouhou.formats.anm0 import ANM0
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 from pytouhou.resource.anmwrapper import AnmWrapper
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 from pytouhou.vm.anmrunner import ANMRunner
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 from pytouhou.game.sprite import Sprite
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 from pytouhou.ui.sprite import get_sprite_rendering_data
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 import bpy
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 import os.path
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 def build_models(stage, anm_wrapper):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 """Taken from pytouhou.game.background."""
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 models = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 for obj in stage.models:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 quads = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 for script_index, ox, oy, oz, width_override, height_override in obj.quads:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 sprite = Sprite(width_override, height_override)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 anm_runner = ANMRunner(anm_wrapper, script_index, sprite)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 anm_runner.run_frame()
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 quads.append((ox, oy, oz, sprite))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 models.append(quads)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 return models
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 def read_mesh(obj_name, stage, model, image):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 verts = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 texcoords = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 cols = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 nb_vertices = 0
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 faces_indices = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 for ox, oy, oz, sprite in model:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) = vertices
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 left, right, bottom, top = uvs
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 r, g, b, a = colors
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 #verts.extend(((x1 + ox, y1 + oy, z1 + oz),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 # (x2 + ox, y2 + oy, z2 + oz),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 # (x3 + ox, y3 + oy, z3 + oz),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 # (x4 + ox, y4 + oy, z4 + oz)))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 # Blender coordinates are z-inverted.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 verts.extend(((x1 + ox, y1 + oy, -(z1 + oz)),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 (x2 + ox, y2 + oy, -(z2 + oz)),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 (x3 + ox, y3 + oy, -(z3 + oz)),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 (x4 + ox, y4 + oy, -(z4 + oz))))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 texcoords.extend(((left, bottom),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 (right, bottom),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 (right, top),
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 (left, top)))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 #TODO: use them.
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 cols.append((r, g, b, a))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 faces_indices.append((nb_vertices, nb_vertices + 1, nb_vertices + 2, nb_vertices + 3))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 nb_vertices += 4
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 mesh = bpy.data.meshes.new(obj_name)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 mesh.from_pydata(verts, [], faces_indices)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 texture = mesh.uv_textures.new('Texture')
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 for tex in texture.data:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 tex.image = image
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 uvs = mesh.uv_layers[0]
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 for i, uv_loop in enumerate(uvs.data):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 uv_loop.uv = texcoords[i]
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 return mesh
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 def add_object(name, mesh, position):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 scene = bpy.context.scene
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 for obj in scene.objects:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 obj.select = False
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 mesh.update()
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 mesh.validate()
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 obj = bpy.data.objects.new(name, mesh)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 obj.location = position
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 scene.objects.link(obj)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 obj.select = True
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 if scene.objects.active is None or scene.objects.active.mode == 'OBJECT':
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 scene.objects.active = obj
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 def read(stage_path):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 dirname = os.path.dirname(stage_path)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 obj_name = bpy.path.display_name_from_filepath(stage_path)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 assert obj_name[:5] == 'stage'
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 stage_number = int(obj_name[5])
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 with open(stage_path, "rb") as filehandle:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 stage = Stage.read(filehandle)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 anm_path = os.path.join(dirname, 'stg{}bg.anm'.format(stage_number))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 with open(anm_path, "rb") as filehandle:
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 anm = ANM0.read(filehandle)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 anm_wrapper = AnmWrapper((anm,), (0,))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 models = build_models(stage, anm_wrapper)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 texture_path = os.path.join(dirname, 'stg{}bg.png'.format(stage_number))
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 image = bpy.data.images.load(texture_path)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 meshes = []
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 for i, model in enumerate(models):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 name = '{}-mesh{}'.format(obj_name, i)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 mesh = read_mesh(name, stage, model, image)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 meshes.append(mesh)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 for i, (model_id, ox, oy, oz) in enumerate(stage.object_instances):
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 name = '{}-object{}'.format(obj_name, i)
8265ef6db380 Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 add_object(name, meshes[model_id], (ox, oy, -oz))