1
Fork 0

feat: Implement object transformation

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-04-07 14:32:21 +02:00
parent 888e8e48fa
commit 0c7613f735
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -18,6 +18,7 @@
import zlib import zlib
import json import json
import bpy import bpy
import math
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
@ -234,6 +235,23 @@ def create_object(self, context, name, node_data, geometries):
return mesh return mesh
def matrix_from_list(list):
"""
Builds a square Matrix from a list of values in column order.
When cross-referencing the `bsi_importer` and Maya's Python docs,
it appears as though matrices stored in `.bsi` should be row ordered,
but they are, in fact, column ordered.
"""
stride = math.sqrt(len(list))
rows = []
for i in range(stride):
row = (list[i], list[i+stride], list[i+(stride*2)], list[i+(stride*3)])
rows.append(row)
return Matrix(rows)
def import_node(self, context, name, node_data, global_data): def import_node(self, context, name, node_data, global_data):
"""Import a BSI node. Recurses into child nodes.""" """Import a BSI node. Recurses into child nodes."""
print("[import_node]", name, node_data) print("[import_node]", name, node_data)
@ -246,11 +264,13 @@ def import_node(self, context, name, node_data, global_data):
else: else:
print("[import_node] Adding empty for '{}'".format(name)) print("[import_node] Adding empty for '{}'".format(name))
obj = bpy.data.objects.new(name, None) obj = bpy.data.objects.new(name, None)
# Decrease axis size to prevent overcrowding in the viewport
obj.empty_display_size = 0.1
# Needs to happen before scaling can be applied.
# TODO: Check if above is true, was seen on Stackoverflow.
obj.matrix_world = Matrix() obj.matrix_world = Matrix()
# TODO: Apply tranformation matrix in `node_data["local"]` if "local" in node_data:
mat = matrix_from_list(node_data["local"])
obj.matrix_local = mat
if "children" in node_data: if "children" in node_data:
for child_name, child_data in node_data["children"].items(): for child_name, child_data in node_data["children"].items():