Skip to content

Commit 27339c7

Browse files
* Transform coordinate spaces
1 parent 28e4240 commit 27339c7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

import-export-clausewitz/exporter.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def __init__(self, filename):
1616
def export_mesh(self, name):
1717
objects = []
1818

19+
eul = mathutils.Euler((0.0, 0.0, math.radians(180.0)), 'XYZ')
20+
eul2 = mathutils.Euler((math.radians(90.0), 0.0, 0.0), 'XYZ')
21+
mat_rot = eul.to_matrix() * eul2.to_matrix()
22+
mat_rot.invert_safe()
23+
24+
transform_mat = bpy.data.objects[name].matrix_world * mat_rot.to_4x4()
25+
1926
objects.append(pdx_data.PdxAsset())
2027

2128
world = pdx_data.PdxWorld([])
@@ -33,7 +40,10 @@ def export_mesh(self, name):
3340
bm = bmesh.new()
3441
bm.from_mesh(blender_mesh)
3542
bmesh.ops.triangulate(bm, faces=bm.faces)
36-
bm.verts.ensure_lookup_table()
43+
44+
for vert in bm.verts:
45+
vert.co = vert.co * transform_mat
46+
3747
bm.verts.index_update()
3848
bm.faces.index_update()
3949
bm.verts.ensure_lookup_table()
@@ -43,9 +53,9 @@ def export_mesh(self, name):
4353
tangents = []
4454

4555
for i in range(0, len(bm.verts)):
46-
verts.append(bm.verts[i].co * bpy.data.objects[name].matrix_world)
56+
verts.append(bm.verts[i].co)
4757
bm.verts[i].normal_update()
48-
normal_temp = bm.verts[i].normal * bpy.data.objects[name].matrix_world
58+
normal_temp = bm.verts[i].normal
4959
normal_temp.normalize()
5060
normals.append(normal_temp)
5161

import-export-clausewitz/importer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import bpy
22
import bmesh
3+
import mathutils
4+
import math
35
import os
46
import io
57
from pathlib import Path
@@ -11,6 +13,10 @@ def __init__(self, filename):
1113
self.file.read()
1214

1315
def import_mesh(self):
16+
eul = mathutils.Euler((0.0, 0.0, math.radians(180.0)), 'XYZ')
17+
eul2 = mathutils.Euler((math.radians(90.0), 0.0, 0.0), 'XYZ')
18+
mat_rot = eul.to_matrix() * eul2.to_matrix()
19+
1420
shape = self.file.nodes[1].objects[0]
1521

1622
mesh_name = shape.name # + "_mesh"
@@ -28,6 +34,9 @@ def import_mesh(self):
2834
bm = bmesh.new()
2935
bm.from_mesh(mesh)
3036

37+
for vert in bm.verts:
38+
vert.co = vert.co * mat_rot
39+
3140
bm.verts.ensure_lookup_table()
3241
bm.verts.index_update()
3342
bm.faces.index_update()
@@ -82,4 +91,4 @@ def import_mesh(self):
8291
bpy.context.scene.objects.link(o)
8392
o.empty_draw_size = 2
8493
o.empty_draw_type = 'PLAIN_AXES'
85-
o.location = (locators[i].pos[0], locators[i].pos[1], locators[i].pos[2])
94+
o.location = mathutils.Vector((locators[i].pos[0], locators[i].pos[1], locators[i].pos[2])) * mat_rot

0 commit comments

Comments
 (0)