mirror of
https://github.com/godotengine/godot-blender-exporter.git
synced 2026-01-05 18:10:04 +03:00
Merge pull request #57 from Jason0214/fix_spot_camera_transform
fix transform animation of spotlight and camera
This commit is contained in:
@@ -5,7 +5,7 @@ import copy
|
||||
import bpy
|
||||
import mathutils
|
||||
from . import armature
|
||||
from ..structures import (NodeTemplate, NodePath,
|
||||
from ..structures import (NodeTemplate, NodePath, fix_directional_transform,
|
||||
InternalResource, Array, fix_matrix)
|
||||
|
||||
LINEAR_INTERPOLATION = 1
|
||||
@@ -231,6 +231,12 @@ def export_transform_action(godot_node, animation_player,
|
||||
|
||||
default_frame = None
|
||||
|
||||
# the fcurve location is matrix_basis.to_translation()
|
||||
default_frame = TransformFrame(
|
||||
blender_object.matrix_basis,
|
||||
blender_object.rotation_mode
|
||||
)
|
||||
|
||||
if object_path.startswith('pose'):
|
||||
bone_name = blender_path_to_bone_name(object_path)
|
||||
|
||||
@@ -246,12 +252,6 @@ def export_transform_action(godot_node, animation_player,
|
||||
pose_bone.matrix_basis,
|
||||
pose_bone.rotation_mode
|
||||
)
|
||||
else:
|
||||
# the fcurve location is matrix_basis.to_translation()
|
||||
default_frame = TransformFrame(
|
||||
blender_object.matrix_basis,
|
||||
blender_object.rotation_mode
|
||||
)
|
||||
|
||||
transform_frames_map[object_path] = [
|
||||
copy.deepcopy(default_frame)
|
||||
@@ -273,9 +273,18 @@ def export_transform_action(godot_node, animation_player,
|
||||
# object_path equals '' represents node itself
|
||||
|
||||
# convert matrix_basis to matrix_local(parent space transform)
|
||||
normalized_frame_list = [
|
||||
blender_object.matrix_parent_inverse *
|
||||
x.to_matrix() for x in frame_list]
|
||||
if (godot_node.get_type()
|
||||
in ("SpotLight", "DirectionalLight", "Camera")):
|
||||
normalized_frame_list = [
|
||||
fix_directional_transform(
|
||||
blender_object.matrix_parent_inverse * x.to_matrix()
|
||||
) for x in frame_list
|
||||
]
|
||||
else:
|
||||
normalized_frame_list = [
|
||||
blender_object.matrix_parent_inverse *
|
||||
x.to_matrix() for x in frame_list
|
||||
]
|
||||
|
||||
track_path = NodePath(
|
||||
animation_player.parent.get_path(),
|
||||
|
||||
@@ -6,11 +6,7 @@ Anything more complex should go in it's own file
|
||||
import math
|
||||
import logging
|
||||
import mathutils
|
||||
from ..structures import NodeTemplate
|
||||
|
||||
# Used to correct spotlights and cameras, which in blender are Z-forwards and
|
||||
# in Godot are Y-forwards
|
||||
AXIS_CORRECT = mathutils.Matrix.Rotation(math.radians(-90), 4, 'X')
|
||||
from ..structures import NodeTemplate, fix_directional_transform
|
||||
|
||||
|
||||
def export_empty_node(escn_file, export_settings, node, parent_gd_node):
|
||||
@@ -43,7 +39,7 @@ def export_camera_node(escn_file, export_settings, node, parent_gd_node):
|
||||
cam_node['projection'] = 1
|
||||
cam_node['size'] = camera.ortho_scale
|
||||
|
||||
cam_node['transform'] = node.matrix_local * AXIS_CORRECT
|
||||
cam_node['transform'] = fix_directional_transform(node.matrix_local)
|
||||
escn_file.add_node(cam_node)
|
||||
|
||||
return cam_node
|
||||
@@ -93,7 +89,7 @@ def export_lamp_node(escn_file, export_settings, node, parent_gd_node):
|
||||
if light_node is not None:
|
||||
# Properties common to all lights
|
||||
light_node['light_color'] = mathutils.Color(light.color)
|
||||
light_node['transform'] = node.matrix_local * AXIS_CORRECT
|
||||
light_node['transform'] = fix_directional_transform(node.matrix_local)
|
||||
light_node['light_negative'] = light.use_negative
|
||||
light_node['light_specular'] = 1.0 if light.use_specular else 0.0
|
||||
light_node['light_energy'] = light.energy
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
This file contains classes to help dealing with the actual writing to the file
|
||||
"""
|
||||
import os
|
||||
import math
|
||||
import collections
|
||||
import mathutils
|
||||
|
||||
@@ -326,6 +327,15 @@ def fix_matrix(mtx):
|
||||
return trans
|
||||
|
||||
|
||||
_AXIS_CORRECT = mathutils.Matrix.Rotation(math.radians(-90), 4, 'X')
|
||||
|
||||
|
||||
def fix_directional_transform(mtx):
|
||||
"""Used to correct spotlights and cameras, which in blender are
|
||||
Z-forwards and in Godot are Y-forwards"""
|
||||
return mtx * _AXIS_CORRECT
|
||||
|
||||
|
||||
# ------------------ Implicit Conversions of Blender Types --------------------
|
||||
def mat4_to_string(mtx):
|
||||
"""Converts a matrix to a "Transform" string that can be parsed by Godot"""
|
||||
|
||||
63
tests/reference_exports/animation_spot_light_transform.escn
Normal file
63
tests/reference_exports/animation_spot_light_transform.escn
Normal file
@@ -0,0 +1,63 @@
|
||||
[gd_scene load_steps=1 format=2]
|
||||
|
||||
[sub_resource id=1 type="Animation"]
|
||||
|
||||
step = 0.1
|
||||
length = 1.70833
|
||||
tracks/0/type = "transform"
|
||||
tracks/0/path = NodePath("Spot:")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/keys = [0.0416667, 1.0, 4.20022, 5.71699, 1.06498, -0.601878, 0.391827, -0.180913, 0.671927, 1.0, 1.0, 1.0, 0.0833333, 1.0, 4.18484, 5.71699, 1.06498, -0.602363, 0.390783, -0.179846, 0.672386, 0.999885, 0.999985, 0.999897, 0.125, 1.0, 4.13739, 5.71699, 1.06498, -0.603855, 0.387584, -0.176577, 0.673764, 0.999537, 0.999937, 0.999588, 0.166667, 1.0, 4.05603, 5.71699, 1.06498, -0.606383, 0.382144, -0.171022, 0.67603, 0.998986, 0.999857, 0.999101, 0.208333, 1.0, 3.93926, 5.71699, 1.06498, -0.609933, 0.374415, -0.163129, 0.679105, 0.998297, 0.999747, 0.998501, 0.25, 1.0, 3.78602, 5.71699, 1.06498, -0.61445, 0.364393, -0.152889, 0.682858, 0.997569, 0.999615, 0.997882, 0.291667, 1.0, 3.59597, 5.71699, 1.06498, -0.619829, 0.352138, -0.140354, 0.687104, 0.996914, 0.999469, 0.997349, 0.333333, 1.0, 3.36963, 5.71699, 1.06498, -0.625929, 0.337785, -0.125646, 0.691612, 0.996435, 0.999321, 0.996996, 0.375, 1.0, 3.10855, 5.71699, 1.06498, -0.632581, 0.321544, -0.108964, 0.696116, 0.996205, 0.999187, 0.996886, 0.416667, 1.0, 2.81539, 5.71699, 1.06498, -0.639602, 0.303696, -0.0905819, 0.700337, 0.996249, 0.999081, 0.997032, 0.458333, 1.0, 2.4939, 5.71699, 1.06498, -0.646816, 0.284582, -0.070836, 0.704006, 0.996541, 0.999013, 0.997397, 0.5, 1.0, 2.14873, 5.71699, 1.06498, -0.654068, 0.264574, -0.0501037, 0.706884, 0.997012, 0.998993, 0.997905, 0.541667, 1.0, 1.78515, 5.71699, 1.06498, -0.661236, 0.244051, -0.0287786, 0.708786, 0.997574, 0.999023, 0.998461, 0.583333, 1.0, 1.40871, 5.71699, 1.06498, -0.668238, 0.223371, -0.00724595, 0.709585, 0.998142, 0.999099, 0.99898, 0.625, 1.0, 1.02488, 5.71699, 1.06498, -0.675027, 0.20286, 0.0141379, 0.709215, 0.998653, 0.999214, 0.999401, 0.666667, 1.0, 0.638719, 5.71699, 1.06498, -0.681589, 0.182794, 0.0350582, 0.707668, 0.999072, 0.999355, 0.999699, 0.708333, 1.0, 0.254672, 5.71699, 1.06498, -0.687934, 0.163401, 0.0552479, 0.704979, 0.999394, 0.99951, 0.999878, 0.75, 1.0, -0.123537, 5.71699, 1.06498, -0.694088, 0.144862, 0.0744886, 0.70122, 0.99963, 0.999664, 0.999965, 0.791667, 1.0, -0.492935, 5.71699, 1.06498, -0.700088, 0.127315, 0.0926074, 0.696485, 0.999799, 0.999804, 0.999995, 0.833333, 1.0, -0.851263, 5.71699, 1.06498, -0.705976, 0.110862, 0.109473, 0.690886, 0.99992, 0.99992, 1.0, 0.875, 1.0, -1.19689, 5.71699, 1.06498, -0.711794, 0.0955753, 0.124989, 0.684539, 1.0, 1.0, 1.0, 0.916667, 1.0, -1.55888, 5.71699, 1.03811, -0.718172, 0.0796779, 0.139825, 0.677, 1.00001, 1.00001, 1.0, 0.958333, 1.0, -1.96657, 5.71699, 0.956895, -0.725617, 0.0614219, 0.154628, 0.667681, 0.999908, 0.999917, 0.99998, 1.0, 1.0, -2.41819, 5.71699, 0.821159, -0.733944, 0.0409507, 0.169291, 0.656498, 0.999695, 0.999748, 0.999887, 1.04167, 1.0, -2.91047, 5.71699, 0.632038, -0.742928, 0.018479, 0.183699, 0.643406, 0.999353, 0.999519, 0.999647, 1.08333, 1.0, -3.43829, 5.71699, 0.392324, -0.752307, -0.00570422, 0.197744, 0.62841, 0.998865, 0.999244, 0.999178, 1.125, 1.0, -3.99449, 5.71699, 0.106791, -0.761796, -0.0312371, 0.211323, 0.611583, 0.998224, 0.998933, 0.998418, 1.16667, 1.0, -4.56978, 5.71699, -0.217604, -0.771098, -0.0576902, 0.224352, 0.593081, 0.997452, 0.998594, 0.997364, 1.20833, 1.0, -5.15293, 5.71699, -0.571724, -0.779925, -0.0845759, 0.236763, 0.573155, 0.996612, 0.998243, 0.996097, 1.25, 1.0, -5.73122, 5.71699, -0.944544, -0.788015, -0.111362, 0.248497, 0.55216, 0.995813, 0.997913, 0.994789, 1.29167, 1.0, -6.29125, 5.71699, -1.32375, -0.795154, -0.137489, 0.259497, 0.530554, 0.995194, 0.997654, 0.993677, 1.33333, 1.0, -6.81988, 5.71699, -1.69657, -0.801198, -0.162394, 0.269696, 0.508895, 0.994889, 0.997522, 0.993003, 1.375, 1.0, -7.30514, 5.71699, -2.05069, -0.806086, -0.18553, 0.279008, 0.48781, 0.994986, 0.997565, 0.992937, 1.41667, 1.0, -7.737, 5.71699, -2.37508, -0.809845, -0.206401, 0.287325, 0.467969, 0.995496, 0.997797, 0.993524, 1.45833, 1.0, -8.1079, 5.71699, -2.66062, -0.81258, -0.224578, 0.294531, 0.450034, 0.99634, 0.998193, 0.99466, 1.5, 1.0, -8.41278, 5.71699, -2.90033, -0.814454, -0.239724, 0.300514, 0.434612, 0.997369, 0.998689, 0.996121, 1.54167, 1.0, -8.64898, 5.71699, -3.08945, -0.815658, -0.2516, 0.305186, 0.422209, 0.9984, 0.999196, 0.997624, 1.58333, 1.0, -8.81586, 5.71699, -3.22519, -0.816373, -0.260071, 0.308496, 0.413193, 0.999258, 0.999624, 0.998893, 1.625, 1.0, -8.91436, 5.71699, -3.30641, -0.816744, -0.265103, 0.310441, 0.40777, 0.999813, 0.999905, 0.99972, 1.66667, 1.0, -8.94658, 5.71699, -3.33328, -0.816858, -0.266755, 0.311071, 0.405979, 1.0, 1.0, 1.0]
|
||||
|
||||
[sub_resource id=2 type="SpatialMaterial"]
|
||||
|
||||
flags_unshaded = false
|
||||
flags_vertex_lighting = false
|
||||
flags_transparent = false
|
||||
vertex_color_use_as_albedo = false
|
||||
albedo_color = Color(0.8, 0.8, 0.8, 1.0)
|
||||
subsurf_scatter_enabled = false
|
||||
|
||||
[sub_resource id=3 type="ArrayMesh"]
|
||||
|
||||
surfaces/0 = {
|
||||
"material":SubResource(2),
|
||||
"primitive":4,
|
||||
"arrays":[
|
||||
Vector3Array(1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 0.999999, 1.0, 1.0, 1.0, 1.0, -0.999999, 1.0, 1.0, -0.999999, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 0.999999, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -0.999999, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 0.999999, 1.0, 1.0, 1.0, 1.0, -0.999999, 0.999999, 1.0, 1.0, 1.0, -1.0, 1.0, 0.999999, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0),
|
||||
Vector3Array(2.98023e-08, -1.0, 0.0, 2.98023e-08, -1.0, 0.0, 2.98023e-08, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, -2.38419e-07, 0.0, 1.0, -2.38419e-07, 0.0, 1.0, -2.38419e-07, 0.0, -8.9407e-08, -4.76837e-07, 1.0, -8.9407e-08, -4.76837e-07, 1.0, -8.9407e-08, -4.76837e-07, 1.0, -1.0, -1.19209e-07, -2.38419e-07, -1.0, -1.19209e-07, -2.38419e-07, -1.0, -1.19209e-07, -2.38419e-07, 2.68221e-07, 2.38419e-07, -1.0, 2.68221e-07, 2.38419e-07, -1.0, 2.68221e-07, 2.38419e-07, -1.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 5.96047e-08, 1.0, 0.0, 5.96047e-08, 1.0, 0.0, 5.96047e-08, 1.0, 0.0, 1.0, 3.27825e-07, 5.96046e-07, 1.0, 3.27825e-07, 5.96046e-07, 1.0, 3.27825e-07, 5.96046e-07, -4.76837e-07, 1.19209e-07, 1.0, -4.76837e-07, 1.19209e-07, 1.0, -4.76837e-07, 1.19209e-07, 1.0, -1.0, -1.49012e-07, -2.38419e-07, -1.0, -1.49012e-07, -2.38419e-07, -1.0, -1.49012e-07, -2.38419e-07, 2.08616e-07, 8.9407e-08, -1.0, 2.08616e-07, 8.9407e-08, -1.0, 2.08616e-07, 8.9407e-08, -1.0),
|
||||
null, ; No Tangents,
|
||||
null, ; no Vertex Colors,
|
||||
null, ; No UV1,
|
||||
null, ; No UV2,
|
||||
null, ; No Bones,
|
||||
null, ; No Weights,
|
||||
IntArray(0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 15, 17, 16, 18, 20, 19, 21, 23, 22, 24, 26, 25, 27, 29, 28, 30, 32, 31, 33, 35, 34)
|
||||
],
|
||||
"morph_arrays":[]
|
||||
}
|
||||
[node type="Spatial" name="Scene"]
|
||||
|
||||
|
||||
[node name="Spot" type="SpotLight" parent="."]
|
||||
|
||||
spot_range = 10.0
|
||||
spot_angle = 22.5
|
||||
spot_angle_attenuation = 1.25
|
||||
shadow_enabled = true
|
||||
light_color = Color(1.0, 1.0, 1.0, 1.0)
|
||||
transform = Transform(0.664154, 0.183225, -0.724795, 0.688378, -0.528045, 0.497297, -0.291607, -0.829215, -0.476831, -8.94658, 5.71699, -3.33328)
|
||||
light_negative = false
|
||||
light_specular = 1.0
|
||||
light_energy = 1.0
|
||||
|
||||
[node name="SpotAnimation" type="AnimationPlayer" parent="."]
|
||||
|
||||
root_node = NodePath("..:")
|
||||
anims/SpotAction = SubResource(1)
|
||||
|
||||
[node name="Cube" type="MeshInstance" parent="."]
|
||||
|
||||
mesh = SubResource(3)
|
||||
visible = true
|
||||
transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
|
||||
BIN
tests/test_scenes/animation_spot_light_transform.blend
Normal file
BIN
tests/test_scenes/animation_spot_light_transform.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user