From 0c7613f7353201a756300865faba271695d503ac Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 7 Apr 2021 14:32:21 +0200 Subject: [PATCH] feat: Implement object transformation Signed-off-by: Lucas Schwiderski --- addons/bitsquid/import_bsi.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/addons/bitsquid/import_bsi.py b/addons/bitsquid/import_bsi.py index 896d78f..d55a230 100644 --- a/addons/bitsquid/import_bsi.py +++ b/addons/bitsquid/import_bsi.py @@ -18,6 +18,7 @@ import zlib import json import bpy +import math from mathutils import Vector, Matrix @@ -234,6 +235,23 @@ def create_object(self, context, name, node_data, geometries): 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): """Import a BSI node. Recurses into child nodes.""" print("[import_node]", name, node_data) @@ -246,11 +264,13 @@ def import_node(self, context, name, node_data, global_data): else: print("[import_node] Adding empty for '{}'".format(name)) 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() - # 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: for child_name, child_data in node_data["children"].items():