Skip to content

Commit 0f74975

Browse files
pandaGaumeDrigax
andauthored
fix Light export (#963)
Light export has been suffering from default auto animation set which is pin it as "dummy" node. Plus inconsitency with direction when point light or ambient Co-authored-by: Nicholas Barlow <whoisdrigax@gmail.com>
1 parent 85e64a3 commit 0f74975

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

Maya/Exporter/BabylonExporter.Animation.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ private void _exporNodeAnimation(BabylonNode babylonNode, MFnTransform mFnTransf
4444
{
4545
try
4646
{
47-
babylonNode.animations = getAnimationsFunc(mFnTransform).ToArray();
48-
49-
// TODO - Retreive from Maya
50-
babylonNode.autoAnimate = true;
51-
babylonNode.autoAnimateFrom = Loader.GetMinTime();
52-
babylonNode.autoAnimateTo = Loader.GetMaxTime();
53-
babylonNode.autoAnimateLoop = true;
47+
var animations = getAnimationsFunc(mFnTransform).ToArray();
48+
babylonNode.animations = animations != null && animations.Length != 0 ? animations : null;
49+
if (babylonNode.animations != null)
50+
{
51+
// TODO - Retreive from Maya
52+
babylonNode.autoAnimate = true;
53+
babylonNode.autoAnimateFrom = Loader.GetMinTime();
54+
babylonNode.autoAnimateTo = Loader.GetMaxTime();
55+
babylonNode.autoAnimateLoop = true;
56+
}
5457
}
5558
catch (Exception e)
5659
{

Maya/Exporter/BabylonExporter.Light.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
136136
// User custom attributes
137137
babylonLight.metadata = ExportCustomAttributeFromTransform(mFnLightTransform);
138138

139-
MVector vDir = new MVector(0, 0, -1);
140-
MTransformationMatrix transformationMatrix;
141-
142139
// Animations
143140
if (exportParameters.exportAnimations)
144141
{
@@ -186,13 +183,6 @@ private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
186183
ExportHierarchy(babylonLight, mFnLightTransform);
187184
// Position / rotation / scaling
188185
ExportTransform(babylonLight, mFnLightTransform);
189-
190-
// Direction
191-
vDir = new MVector(0, 0, -1);
192-
transformationMatrix = new MTransformationMatrix(mFnLightTransform.transformationMatrix);
193-
vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
194-
vDir.normalize();
195-
babylonLight.direction = new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };
196186
}
197187

198188
// Common fields
@@ -211,6 +201,7 @@ private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
211201
babylonLight.type = 2;
212202
babylonLight.angle = (float)mFnSpotLight.coneAngle;
213203
babylonLight.exponent = 1;
204+
babylonLight.direction = ComputeDirection(mFnLightTransform, new MVector(0, 0, -1));
214205

215206
if (mFnSpotLight.useDecayRegions)
216207
{
@@ -219,6 +210,7 @@ private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
219210
break;
220211
case MFn.Type.kDirectionalLight:
221212
babylonLight.type = 1;
213+
babylonLight.direction = ComputeDirection(mFnLightTransform, new MVector(0, 0, -1));
222214
break;
223215
case MFn.Type.kAmbientLight:
224216
babylonLight.type = 3;
@@ -231,11 +223,7 @@ private BabylonNode ExportLight(MDagPath mDagPath, BabylonScene babylonScene)
231223
// Direction
232224
if (!createDummy)
233225
{
234-
vDir = new MVector(0, 1, 0);
235-
transformationMatrix = new MTransformationMatrix(mFnLightTransform.transformationMatrix);
236-
vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
237-
vDir.normalize();
238-
babylonLight.direction = new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };
226+
babylonLight.direction = ComputeDirection(mFnLightTransform, new MVector(0, 1, 0));
239227
}
240228
break;
241229
case MFn.Type.kAreaLight:
@@ -293,5 +281,14 @@ private bool IsLightExportable(MFnDagNode mFnDagNode, MDagPath mDagPath)
293281
{
294282
return IsNodeExportable(mFnDagNode, mDagPath);
295283
}
296-
}
284+
285+
private float[] ComputeDirection(MFnTransform mFnLightTransform, MVector vDir)
286+
{
287+
var transformationMatrix = new MTransformationMatrix(mFnLightTransform.transformationMatrix);
288+
vDir = vDir.multiply(transformationMatrix.asMatrixProperty);
289+
vDir.normalize();
290+
return new[] { (float)vDir.x, (float)vDir.y, -(float)vDir.z };
291+
}
292+
293+
}
297294
}

0 commit comments

Comments
 (0)