Mercurial > touhou-blender
annotate io_scene_touhou/import_std.py @ 1:ba73c663a227 default tip
Make it work with the latest PyTouhou.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 20 Dec 2013 17:11:29 +0100 |
parents | 8265ef6db380 |
children |
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 |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
31 from pytouhou.formats.anm0 import ANM |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 from pytouhou.vm.anmrunner import ANMRunner |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 from pytouhou.game.sprite import Sprite |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
34 from pytouhou.ui.opengl.sprite import get_sprite_rendering_data |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 import bpy |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 import os.path |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
39 def build_models(stage, anm): |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 """Taken from pytouhou.game.background.""" |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 models = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 for obj in stage.models: |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 quads = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 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
|
45 sprite = Sprite(width_override, height_override) |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
46 anm_runner = ANMRunner(anm, script_index, sprite) |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 quads.append((ox, oy, oz, sprite)) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 models.append(quads) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 return models |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 def read_mesh(obj_name, stage, model, image): |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 verts = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 texcoords = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 cols = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 nb_vertices = 0 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 faces_indices = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 for ox, oy, oz, sprite in model: |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite) |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
61 x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = vertices |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 left, right, bottom, top = uvs |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 r, g, b, a = colors |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 #verts.extend(((x1 + ox, y1 + oy, z1 + oz), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 # (x2 + ox, y2 + oy, z2 + oz), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 # (x3 + ox, y3 + oy, z3 + oz), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 # (x4 + ox, y4 + oy, z4 + oz))) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 # Blender coordinates are z-inverted. |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 verts.extend(((x1 + ox, y1 + oy, -(z1 + oz)), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 (x2 + ox, y2 + oy, -(z2 + oz)), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 (x3 + ox, y3 + oy, -(z3 + oz)), |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 (x4 + ox, y4 + oy, -(z4 + oz)))) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
76 texcoords.extend(((left, 1.-bottom), |
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
77 (right, 1.-bottom), |
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
78 (right, 1.-top), |
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
79 (left, 1.-top))) |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 #TODO: use them. |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 cols.append((r, g, b, a)) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 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
|
85 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 nb_vertices += 4 |
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 mesh = bpy.data.meshes.new(obj_name) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 mesh.from_pydata(verts, [], faces_indices) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 texture = mesh.uv_textures.new('Texture') |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 for tex in texture.data: |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 tex.image = image |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 uvs = mesh.uv_layers[0] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 for i, uv_loop in enumerate(uvs.data): |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 uv_loop.uv = texcoords[i] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 return mesh |
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 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 def add_object(name, mesh, position): |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 scene = bpy.context.scene |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 for obj in scene.objects: |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 obj.select = False |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 mesh.update() |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 mesh.validate() |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 obj = bpy.data.objects.new(name, mesh) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 obj.location = position |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 scene.objects.link(obj) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 obj.select = True |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 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
|
117 scene.objects.active = obj |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 def read(stage_path): |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 dirname = os.path.dirname(stage_path) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 obj_name = bpy.path.display_name_from_filepath(stage_path) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 assert obj_name[:5] == 'stage' |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 stage_number = int(obj_name[5]) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 with open(stage_path, "rb") as filehandle: |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 stage = Stage.read(filehandle) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 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
|
131 with open(anm_path, "rb") as filehandle: |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
132 anm = ANM.read(filehandle) |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
134 entry = anm[0] #XXX |
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
135 models = build_models(stage, entry) |
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 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
|
138 image = bpy.data.images.load(texture_path) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 meshes = [] |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 for i, model in enumerate(models): |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 name = '{}-mesh{}'.format(obj_name, i) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 mesh = read_mesh(name, stage, model, image) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 meshes.append(mesh) |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 |
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 for i, (model_id, ox, oy, oz) in enumerate(stage.object_instances): |
1
ba73c663a227
Make it work with the latest PyTouhou.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
147 name = '{}-object{:02}'.format(obj_name, i) |
0
8265ef6db380
Hello Gensokyo _o/
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 add_object(name, meshes[model_id], (ox, oy, -oz)) |