1
Fork 0

feat: Use proper Vector data type

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-04-07 11:58:58 +02:00
parent 1c6d160a1a
commit 888e8e48fa
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -18,7 +18,7 @@
import zlib import zlib
import json import json
import bpy import bpy
import mathutils from mathutils import Vector, Matrix
def parse_sjson(file_path, skip_editor_data=True): def parse_sjson(file_path, skip_editor_data=True):
@ -181,9 +181,9 @@ def create_object(self, context, name, node_data, geometries):
and additional data from the file. and additional data from the file.
""" """
print("[create_object]", name, node_data) print("[create_object]", name, node_data)
# A list of tuples, where each tuple represents a Vector3(x, y, z). # A list of vectors that represent vertex locations.
vertices = [] vertices = []
# A list of tuples, where each tuple contains three indices into `vertices`. # A list of vectors, where each vector contains three indices into `vertices`.
# Those three indices define the vertices that make up the face. # Those three indices define the vertices that make up the face.
faces = [] faces = []
@ -207,20 +207,20 @@ def create_object(self, context, name, node_data, geometries):
# Iterate over data in sets of three values that represent # Iterate over data in sets of three values that represent
# `x`, `y` and `z`. # `x`, `y` and `z`.
for j in range(0, len(stream_data), 3): for j in range(0, len(stream_data), 3):
vertices.append(( vertices.append(Vector((
stream_data[j], stream_data[j],
stream_data[j + 1], stream_data[j + 1],
stream_data[j + 2], stream_data[j + 2],
)) )))
# Get face definitions. Values are vertex indices. # Get face definitions. Values are vertex indices.
# Iteration works just like vertices above. # Iteration works just like vertices above.
for j in range(0, len(index_stream), 3): for j in range(0, len(index_stream), 3):
faces.append(( faces.append(Vector((
index_stream[j], index_stream[j],
index_stream[j + 1], index_stream[j + 1],
index_stream[j + 2], index_stream[j + 2],
)) )))
else: else:
# TODO: Implement other channel types # TODO: Implement other channel types
self.report( self.report(
@ -249,7 +249,7 @@ def import_node(self, context, name, node_data, global_data):
# Needs to happen before scaling can be applied. # Needs to happen before scaling can be applied.
# TODO: Check if above is true, was seen on Stackoverflow. # TODO: Check if above is true, was seen on Stackoverflow.
obj.matrix_world = mathutils.Matrix() obj.matrix_world = Matrix()
# TODO: Apply tranformation matrix in `node_data["local"]` # TODO: Apply tranformation matrix in `node_data["local"]`
if "children" in node_data: if "children" in node_data: