Notifications
Clear all

[Closed] Proper way to get light rotations for exporting

I’m trying to make a script to copy/paste lights into unreal engine 5.11+

The problem is the rotations, I can’t get it to work, once pasted into unreal the rotation is all wrong for some lights but it’s fine for others.

I was trying to follow the code on the datasmith c++ code but its still not working

(
_LightSpot_strStart = 
"Begin Map
   Begin Level
"
	
_LightSpot_end =
"End Level
Begin Surface
End Surface
End Map
"	
	
_LightSpot_str = 
"Begin Actor Class=/Script/Engine.SpotLight Name=% 
			Archetype=/Script/Engine.SpotLight'/Script/Engine.Default__SpotLight'
			Begin Object Class=/Script/Engine.ArrowComponent Name=\"ArrowComponent0\"
			Archetype=/Script/Engine.ArrowComponent'Default__SpotLight:ArrowComponent0'
		 End Object
		 Begin Object Class=SpotLightComponent Name=\"LightComponent0\"
				Archetype=SpotLightComponent'Default__SpotLight:LightComponent0'
			  End Object
				Begin Object Name=\"ArrowComponent0\"
			AttachParent=LightComponent0
		 End Object
			 Begin Object Name=\"LightComponent0\"
			 SourceRadius=2.0
			 IntensityUnits=Lumens
			 bUseTemperature=True
			 IESBrightnessScale=0.100000
			 LightGuid=D40F03274E2FB63E3A1BBA9C54B5D3C3
			 IndirectLightingIntensity=3.000000
			 bPrecomputedLightingIsValid=False
			 RelativeLocation=(X=%,Y=%,Z=%)
			 RelativeRotation=(Pitch=%,Yaw=%,Roll=%)
			 Mobility=Movable
		 End Object				
		 SpotLightComponent=LightComponent0
		 ArrowComponent=ArrowComponent0
		 LightComponent=LightComponent0
		 RootComponent=LightComponent0
		 ActorLabel=\"%\"
	  End Actor
"	
	
	fn copyLightToClipboard theLights =
	(
		strFile = stringstream ""
		format _LightSpot_strStart to:strFile 
		
		for c = 1 to theLights.count do
		(
		_Name = theLights[c].name
		_expScale = 2.54
		_Pos =  theLights[c].pos * _expScale
		
		quatRot =  theLights[c].transform.rotationpart as quat		
		quatRot.y = quatRot.y * -1
		
		quatRot = quatRot * (quat 90 0 -90 1)
		theRotation = quatToEuler2 quatRot
		
		x = theRotation.y
		y = theRotation.z
		z = theRotation.x
		
		theRotation.x = x 
		theRotation.y = y
          theRotation.z = z
		
		format _LightSpot_str _Name _Pos.x (_Pos.y*-1) _Pos.z theRotation.x theRotation.y theRotation.z  _Name  to:strFile
		)
		
		format _LightSpot_end to:strFile
		setClipBoardText  strFile
		free strFile		
	)
	
	theLights = selection as array
	copyLightToClipboard theLights
)

Any suggestions are appreciated.
Guillermo

6 Replies

you should reset the scale in max , UE won’t get the negative scale
or you should set info as metadata , and set in UE

Thanks for the replay, but I’m must be doing something else wrong as its not the scale.

while scale was reset from -1 to 1 , the rotation flipped

Just got back to this issue. And I still can’t get it working

It seems the problem are lights that have been mirrored in max, even do they don’t show anything wrong transform dialog or pivot but when exported they are flipped

Can you further explain what can be done to get the correct information into unreal ?

below is part of our pre2UE script , it could emend the vraylight which is plane type , when done , the light will same as max in UE (vraylight use datasmith to export and import)

l is vraylight object

s=l.transform.controller.scale
if l.type == 0 do
(
	if s.z < 0 do
		in coordsys local
			rotate l (EulerAngles 0 180 0)
	l.transform.controller.scale = [1,1,1]
)
l.size0 *=abs s.x
if l.type == 0 do
	l.size1 *= abs s.y

Appreciate the code sample.

Thanks,