Mercurial > touhou-blender
diff 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 |
line wrap: on
line diff
--- a/io_scene_touhou/import_std.py +++ b/io_scene_touhou/import_std.py @@ -28,24 +28,22 @@ stage file to open. from pytouhou.formats.std import Stage -from pytouhou.formats.anm0 import ANM0 -from pytouhou.resource.anmwrapper import AnmWrapper +from pytouhou.formats.anm0 import ANM from pytouhou.vm.anmrunner import ANMRunner from pytouhou.game.sprite import Sprite -from pytouhou.ui.sprite import get_sprite_rendering_data +from pytouhou.ui.opengl.sprite import get_sprite_rendering_data import bpy import os.path -def build_models(stage, anm_wrapper): +def build_models(stage, anm): """Taken from pytouhou.game.background.""" models = [] for obj in stage.models: quads = [] for script_index, ox, oy, oz, width_override, height_override in obj.quads: sprite = Sprite(width_override, height_override) - anm_runner = ANMRunner(anm_wrapper, script_index, sprite) - anm_runner.run_frame() + anm_runner = ANMRunner(anm, script_index, sprite) quads.append((ox, oy, oz, sprite)) models.append(quads) return models @@ -60,7 +58,7 @@ def read_mesh(obj_name, stage, model, im for ox, oy, oz, sprite in model: key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite) - (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) = vertices + x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 = vertices left, right, bottom, top = uvs r, g, b, a = colors @@ -75,10 +73,10 @@ def read_mesh(obj_name, stage, model, im (x3 + ox, y3 + oy, -(z3 + oz)), (x4 + ox, y4 + oy, -(z4 + oz)))) - texcoords.extend(((left, bottom), - (right, bottom), - (right, top), - (left, top))) + texcoords.extend(((left, 1.-bottom), + (right, 1.-bottom), + (right, 1.-top), + (left, 1.-top))) #TODO: use them. cols.append((r, g, b, a)) @@ -131,10 +129,10 @@ def read(stage_path): anm_path = os.path.join(dirname, 'stg{}bg.anm'.format(stage_number)) with open(anm_path, "rb") as filehandle: - anm = ANM0.read(filehandle) - anm_wrapper = AnmWrapper((anm,), (0,)) + anm = ANM.read(filehandle) - models = build_models(stage, anm_wrapper) + entry = anm[0] #XXX + models = build_models(stage, entry) texture_path = os.path.join(dirname, 'stg{}bg.png'.format(stage_number)) image = bpy.data.images.load(texture_path) @@ -146,5 +144,5 @@ def read(stage_path): meshes.append(mesh) for i, (model_id, ox, oy, oz) in enumerate(stage.object_instances): - name = '{}-object{}'.format(obj_name, i) + name = '{}-object{:02}'.format(obj_name, i) add_object(name, meshes[model_id], (ox, oy, -oz))