@@ -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