From 2e43491b769f90e0ceed79a705c4319e53f6c830 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 9 Oct 2022 17:02:28 +0300 Subject: [PATCH] Access vector components in Blender by name, not index --- blender/io_mspgl/animation.py | 22 +++++++++++----------- blender/io_mspgl/export_camera.py | 4 ++-- blender/io_mspgl/export_light.py | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/blender/io_mspgl/animation.py b/blender/io_mspgl/animation.py index b7576fb5..e40e7625 100644 --- a/blender/io_mspgl/animation.py +++ b/blender/io_mspgl/animation.py @@ -9,9 +9,9 @@ class Curve: for i in range(len(self.keyframe_points)-1): kf1 = self.keyframe_points[i] kf2 = self.keyframe_points[i+1] - dx = (kf2.co[0]-kf1.co[0])/3 - slope1 = (kf1.handle_right[1]-kf1.co[1])/(kf1.handle_right[0]-kf1.co[0]) - slope2 = (kf2.co[1]-kf2.handle_left[1])/(kf2.co[0]-kf2.handle_left[0]) + dx = (kf2.co.x-kf1.co.x)/3 + slope1 = (kf1.handle_right.y-kf1.co.y)/(kf1.handle_right.x-kf1.co.x) + slope2 = (kf2.co.y-kf2.handle_left.y)/(kf2.co.x-kf2.handle_left.x) if i==0: self.knots.append(mathutils.Vector(kf1.co)) @@ -44,17 +44,17 @@ class Animation: p2 = c.knots[i+2] p3 = c.knots[i+3] for j in range(50): - t = (p0[0]*(50-j)+p3[0]*j)/50 - x = (t-p0[0])/(p3[0]-p0[0]) + t = (p0.x*(50-j)+p3.x*j)/50 + x = (t-p0.x)/(p3.x-p0.x) v1 = c._curve.evaluate(t) - v2 = p0[1]*(1-x)**3+3*p1[1]*x*(1-x)**2+3*p2[1]*x**2*(1-x)+p3[1]*x**3 + v2 = p0.y*(1-x)**3+3*p1.y*x*(1-x)**2+3*p2.y*x**2*(1-x)+p3.y*x**3 keyframes_by_time = {} controls_by_time = {} self.keyframes = [] for c in self.curves: for i, k in enumerate(c.knots): - x = k[0] + x = k.x control = i%3!=0 kf_map = controls_by_time if control else keyframes_by_time if x in kf_map: @@ -71,7 +71,7 @@ class Animation: for c in self.curves: for k in c.knots: - k[0] -= self.start_time + k.x -= self.start_time for k in self.keyframes: k.time -= self.start_time @@ -82,8 +82,8 @@ class Animation: def check_looping(self, threshold): self.looping = True for c in self.curves: - first_y = c.knots[0][1] - last_y = c.knots[-1][1] + first_y = c.knots.x.y + last_y = c.knots[-1].y d = abs(last_y-first_y) if c.data_path=="rotation_euler": @@ -102,7 +102,7 @@ class Animation: for c in self.curves: for k in c.knots: - k[0] *= scale + k.x *= scale for k in self.keyframes: k.time *= scale diff --git a/blender/io_mspgl/export_camera.py b/blender/io_mspgl/export_camera.py index 1981fd3e..7108681a 100644 --- a/blender/io_mspgl/export_camera.py +++ b/blender/io_mspgl/export_camera.py @@ -11,9 +11,9 @@ class CameraExporter: resource = Resource(obj.name+".camera", "camera") position = obj.matrix_world@mathutils.Vector((0, 0, 0)) - resource.statements.append(Statement("position", position[0], position[1], position[2])) + resource.statements.append(Statement("position", position.x, position.y, position.z)) look_dir = obj.matrix_world@mathutils.Vector((0, 0, -1, 0)) - resource.statements.append(Statement("look_direction", look_dir[0], look_dir[1], look_dir[2])) + resource.statements.append(Statement("look_direction", look_dir.x, look_dir.y, look_dir.z)) right_dir = obj.matrix_world@mathutils.Vector((1, 0, 0, 0)) look_xy = mathutils.Vector((look_dir.x, look_dir.y, 0)) diff --git a/blender/io_mspgl/export_light.py b/blender/io_mspgl/export_light.py index 7ccb9663..452691cd 100644 --- a/blender/io_mspgl/export_light.py +++ b/blender/io_mspgl/export_light.py @@ -11,11 +11,11 @@ class LightExporter: if light.type=='SUN': light_res.statements.append(Statement("type", Token("directional"))) - light_res.statements.append(Statement("direction", *(-obj.matrix_world.col[2])[0:3])) + light_res.statements.append(Statement("direction", *-obj.matrix_world.col[2].xyz)) elif light.type=='POINT': light_res.statements.append(Statement("type", Token("point"))) pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0)) - light_res.statements.append(Statement("position", *obj.matrix_world.col[3][0:3])) + light_res.statements.append(Statement("position", *obj.matrix_world.col[3].xyz)) light_res.statements.append(Statement("attenuation", 1.0, 0.0, 1.0)) else: raise Exception("Can't export light {} of unknown type {}".format(light.name, light.type)) -- 2.45.2