FBX Export: Spot Light Rotation and Position Differ from Camera Position and Rotation #97634

Closed
opened 2022-04-26 20:34:50 +02:00 by Jordan · 16 comments

System Information
Operating system: Windows 10
Graphics card: RX 580 (4GB)

Blender Version
Broken: 3.1
Worked: Haven't tested

Spot Light exported to FBX has a seemingly random rotation, and location is offset from source. I am using Three.js to export cameras, and lights to Terragen , which doesn't support these features in it's FBX reader. I have checked the source code for Three.JS and it is not modulating these values, and I am even using the raw FBX Tree attributes. This variance between camera position/rotation and spot light position/rotation are being baked into the file by Blender.

This may be something I am just unaware of, but it seems like random behavior. I ensured the euler for the cameras and spot light was correct.

Exact steps for others to reproduce the error
Export a scene with cameras and spot lights to convert them to a TGC (Terragen Clip File) or observe the data in the console.

FBX Converter
https://nwdagroup.com/terragen-tools/fbx2terragen/
Test FBX File
4-axis-cameras-plus-lights.fbx
Blend File
4-axis-cameras-plus-lights.blend

Terragen Conversion Settings for Blender XYZ Euler
Euler Order: YXZ
Offset:0 90 0
Swap X with Z: Checked

**System Information** Operating system: Windows 10 Graphics card: RX 580 (4GB) **Blender Version** Broken: 3.1 Worked: *Haven't tested* Spot Light exported to FBX has a seemingly random rotation, and location is offset from source. I am using Three.js to export cameras, and lights to [Terragen ](https://planetside.co.uk/), which doesn't support these features in it's FBX reader. I have checked the source code for Three.JS and it is not modulating these values, and I am even using the raw FBX Tree attributes. This variance between camera position/rotation and spot light position/rotation are being baked into the file by Blender. This may be something I am just unaware of, but it seems like random behavior. I ensured the euler for the cameras *and* spot light was correct. **Exact steps for others to reproduce the error** Export a scene with cameras and spot lights to convert them to a TGC (Terragen Clip File) or observe the data in the console. **FBX Converter** https://nwdagroup.com/terragen-tools/fbx2terragen/ **Test FBX File** [4-axis-cameras-plus-lights.fbx](https://archive.blender.org/developer/F13030390/4-axis-cameras-plus-lights.fbx) **Blend File** [4-axis-cameras-plus-lights.blend](https://archive.blender.org/developer/F13030392/4-axis-cameras-plus-lights.blend) *Terragen Conversion Settings for Blender XYZ Euler* Euler Order: **YXZ** Offset:**0 90 0** Swap X with Z: **Checked**
Author

Added subscriber: @WASasquatch

Added subscriber: @WASasquatch
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

The converter expects +Y is UP and +Z is FORWARD which is not the default. Did you make sure to account for that?
The lights also import fine in other programs, so this is probably an axis incompatibility. So can you try different configurations and see if any of the works?

The converter expects `+Y is UP and +Z is FORWARD` which is not the default. Did you make sure to account for that? The lights also import fine in other programs, so this is probably an axis incompatibility. So can you try different configurations and see if any of the works?
Author

As already noted, the offset in both position, and rotation is baked into the FBX file itself, from Blender, even when it's in the exact same location, and rotation of a camera in the same spot.

The converter is written by me, and that is just how to get the correct orientation within the target software, not Blender. It also doesn't change any value, these are raw values from the FBXNodeTree within the FBX file baked by Blender.

Obviously something is wrong if a spot light at the same location, rotation (literally copied within Blender) comes out with a random location and rotation within the FBX file created by Blender.

Have you looked at the supplied file, and exported a FBX from it in 3.1? Y+ is set UP, and Z+ forward is required for Terragen, but this doesn't modulate any values to be saved in the file, so why is a different type of object getting different location and rotation values?

I am converting Camera, Point Light, and Spot Light, and the only object that has an issue, all while utilizing the same settings, and even in the same location and rotation as a camera for exact reference, is the Spot Light. The same rules applied to every other object in the converter are applied to the Spot Light, so it should yield the same location and rotation as the camera at that location. But it's floating off from that location, and looking in a totally random direction.

Additionally, I have tried all the Eulers within Blender, and Z/Y settings, but naturally, this just messes up the entire converter, as it's working fine, save for one specific type of object, the Spot LIght.

As already noted, the offset in both position, and rotation is baked into the FBX file itself, from Blender, even when it's in the exact same location, and rotation of a camera in the same spot. The converter is written by me, and that is just how to get the correct orientation within the target software, not Blender. It also doesn't change any value, these are raw values from the FBXNodeTree within the FBX file baked by Blender. Obviously something is wrong if a spot light at the same location, rotation (literally copied within Blender) comes out with a random location and rotation within the FBX file created by Blender. Have you looked at the supplied file, and exported a FBX from it in 3.1? Y+ is set UP, and Z+ forward is required for Terragen, but this doesn't modulate any values to be saved in the file, so why is a different type of object getting different location and rotation values? I am converting Camera, Point Light, and Spot Light, and the only object that has an issue, all while utilizing the same settings, and even in the same location and rotation as a camera for exact reference, is the Spot Light. The same rules applied to every other object in the converter are applied to the Spot Light, so it should yield the same location and rotation as the camera at that location. But it's floating off from that location, and looking in a totally random direction. Additionally, I have tried all the Eulers within Blender, and Z/Y settings, but naturally, this just messes up the entire converter, as it's working fine, save for one specific type of object, the Spot LIght.
Member

Well the FBX file can't really contain random values because it can be correctly imported back. So it must be a compatibility issue, possibly due to the exported.
But looking at a dump of the exported FBX file, I find:

		{"id": "Light.001", 
			"rotation": [-0.115075,  0.881120,  0.277816,  0.364972], 
			"scale": [ 100.000000,  99.999992,  99.999992], 
			"translation": [-250.000000,  500.000000,  250.000000]}

With rotations and translations matching those of Blender after axis conversion. It should be noted that cameras and lights are exported with different transformations as far as I can see, to transform into FBX space. Lights are rotated 90 degrees around x and cameras around y. So I wound't expect them to be the same.

What random values do you see in the exported file?

Well the FBX file can't really contain random values because it can be correctly imported back. So it must be a compatibility issue, possibly due to the exported. But looking at a dump of the exported FBX file, I find: ``` {"id": "Light.001", "rotation": [-0.115075, 0.881120, 0.277816, 0.364972], "scale": [ 100.000000, 99.999992, 99.999992], "translation": [-250.000000, 500.000000, 250.000000]} ``` With rotations and translations matching those of Blender after axis conversion. It should be noted that cameras and lights are exported with different transformations as far as I can see, to transform into FBX space. Lights are rotated 90 degrees around x and cameras around y. So I wound't expect them to be the same. What random values do you see in the exported file?
Author

The default data before the exporter touches anything is:

Camera

position: Object { x: 250, y: 200, z: -250 }
x: 250
y: 200
z: -250
rotation: Object { _x: -3.1415920811452525, _y: -0.7853980727851162, _z: 2.617994246027166, … }
_order: "XYZ"
_x: -3.1415920811452525
_y: -0.7853980727851162
_z: 2.617994246027166

Spotlight

position: Object { x: 311.2372438157516, y: 250.00001785004994, z: -311.2372412076495 }
x: 311.2372438157516
y: 250.00001785004994
z: -311.2372412076495
rotation: Object { _x: 1.9583931751202461, _y: 0.36136719684331386, _z: -2.4278683133620076, … }
_order: "XYZ"
_x: 1.9583931751202461
_y: 0.36136719684331386
_z: -2.4278683133620076

For Camera and Spotlight in the same location/rotation. For me it seems random. As for the camera offset, I did discover that, and it is applied for the final export for the cameras on Y. I hadn't realized lights would need one on X (which also seems arbitrarily random and makes little sense, is there a reason? That doesn't seem to match any logic for any end-program's euler order and coordinate system, and would inherently conflict with them)

At the same same, it doesn't appear a simple offset on X is the issue here.

The exporter at https://nwdagroup.com/terragen-tools/fbx2terragen/ will spit out all the data it uses regarding objects in the Developer Tools Console if you want to see it live or see about a file you created (maybe my Blender is bugged?)

Firefox/Chrome Console: Ctrl + Shift + J

camera-spotlight-light.fbx
camera-spotlight-light.blend

The default data before the exporter touches anything is: Camera ``` position: Object { x: 250, y: 200, z: -250 } x: 250 y: 200 z: -250 rotation: Object { _x: -3.1415920811452525, _y: -0.7853980727851162, _z: 2.617994246027166, … } _order: "XYZ" _x: -3.1415920811452525 _y: -0.7853980727851162 _z: 2.617994246027166 ``` Spotlight ``` position: Object { x: 311.2372438157516, y: 250.00001785004994, z: -311.2372412076495 } x: 311.2372438157516 y: 250.00001785004994 z: -311.2372412076495 rotation: Object { _x: 1.9583931751202461, _y: 0.36136719684331386, _z: -2.4278683133620076, … } _order: "XYZ" _x: 1.9583931751202461 _y: 0.36136719684331386 _z: -2.4278683133620076 ``` For Camera and Spotlight in the same location/rotation. For me it seems random. As for the camera offset, I did discover that, and it is applied for the final export for the cameras on Y. I hadn't realized lights would need one on X (which also seems arbitrarily random and makes little sense, is there a reason? That doesn't seem to match any logic for any end-program's euler order and coordinate system, and would inherently conflict with them) At the same same, it doesn't appear a simple offset on X is the issue here. The exporter at https://nwdagroup.com/terragen-tools/fbx2terragen/ will spit out all the data it uses regarding objects in the Developer Tools Console if you want to see it live or see about a file you created (maybe my Blender is bugged?) Firefox/Chrome Console: **Ctrl + Shift + J** [camera-spotlight-light.fbx](https://archive.blender.org/developer/F13072911/camera-spotlight-light.fbx) [camera-spotlight-light.blend](https://archive.blender.org/developer/F13072912/camera-spotlight-light.blend)
Member

Dumping this same file using the FBX SDK gives me:

		{"id": "Light.001", 
			"rotation": [ 0.461940, -0.331414,  0.191342,  0.800103], 
			"scale": [ 100.000000,  100.000008,  100.000000], 
			"translation": [-250.000000,  200.000000,  250.000000]}

Which is consistent with the values in Blender, so are we really sure that online converter is parsing things correctly?
Did you try any other software and check how it reads that FBX file?

Dumping this same file using the FBX SDK gives me: ``` {"id": "Light.001", "rotation": [ 0.461940, -0.331414, 0.191342, 0.800103], "scale": [ 100.000000, 100.000008, 100.000000], "translation": [-250.000000, 200.000000, 250.000000]} ``` Which is consistent with the values in Blender, so are we really sure that online converter is parsing things correctly? Did you try any other software and check how it reads that FBX file?
Author

Off-Topic: I suddenly can't reply by email, it says the server is misconfigured.

I don't have any other DCC that can read FBX, besides blender. I mean, Terragen can, but only for objects. For some reason, it can't do cameras, and lights. Which is why I am developing this with Three.js.

I have made a report about it with Three.JS but they said the values are not be modulated, and couldn't offer me anymore support. I did dig through the code, and couldn't find anything be modulated. It loads the data from the FBXNodeTree, and just applies the data raw to the creation of a camera/light/object. And they have gone silent on the issue which has brought me here.

However, it being consistent with Blender doesn't mean it's right? Especially when I am applying a different coordinate system? Y+ Up, and Z+ Forward? Shouldn't it then NOT relate to Blender and relate to the coordinate system I am targeting?

If I can find the exact reason for why this is happening, or what sort of offset is happening here I could probably provide Three.js info on how to fix this issue. They have admitted not much time was spent on the FBX importer.

Off-Topic: I suddenly can't reply by email, it says the server is misconfigured. I don't have any other DCC that can read FBX, besides blender. I mean, Terragen can, but only for objects. For some reason, it can't do cameras, and lights. Which is why I am developing this with Three.js. I have made a report about it with Three.JS but they said the values are not be modulated, and couldn't offer me anymore support. I did dig through the code, and couldn't find anything be modulated. It loads the data from the FBXNodeTree, and just applies the data raw to the creation of a camera/light/object. And they have gone silent on the issue which has brought me here. However, it being consistent with Blender doesn't mean it's right? Especially when I am applying a different coordinate system? Y+ Up, and Z+ Forward? Shouldn't it then NOT relate to Blender and relate to the coordinate system I am targeting? If I can find the exact reason for why this is happening, or what sort of offset is happening here I could probably provide Three.js info on how to fix this issue. They have admitted not much time was spent on the FBX importer.
Member

I meant consistent in the sense that they are identical to the values in blender after the transformation to the FBX space.
I don't have time this week to look into this further, so I will pick it up later. Since you are on Windows, can you try to download the FBX Review application and check the FBX file there? Maybe this will give us some insights.

I meant consistent in the sense that they are identical to the values in blender *after* the transformation to the FBX space. I don't have time this week to look into this further, so I will pick it up later. Since you are on Windows, can you try to download the FBX Review application and check the FBX file there? Maybe this will give us some insights.
Author

Oh, I didn't know about that software. I download FBX SDK (Since it apparently replaces FBX Converter, which contained FBX Explorerer) but hadn't opened it up yet. I'll check out FBX Review. I also made a fresh post with Three.js regarding observations here, and that something somewhere may be modulating these values when reading the FBX files (maybe one of them math utilities). Maybe this will narrow down where someone looks there.

Oh, I didn't know about that software. I download FBX SDK (Since it apparently replaces FBX Converter, which contained FBX Explorerer) but hadn't opened it up yet. I'll check out FBX Review. I also made a fresh post with Three.js regarding observations here, and that something somewhere may be modulating these values when reading the FBX files (maybe one of them math utilities). Maybe this will narrow down where someone looks there.
Member

Did you get the time to investigate the issue in FBX Explorer?

Did you get the time to investigate the issue in FBX Explorer?
Author

I did, and I saw the same thing you saw. So the change must be coming from Three.js, but they are not helping me. I tried looking all over but couldn't specifically find any alterations to rotation or centre. I am at a loss right now.

I did, and I saw the same thing you saw. So the change must be coming from Three.js, but they are not helping me. I tried looking all over but couldn't specifically find any alterations to rotation or centre. I am at a loss right now.
Member

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
Member

FBX is a rather hard format to get right, so if you can use an alternative format, that would be best. Maybe GLTF.
Since we can't confirm that this is an issue in Blender itself, I will archive this for now. If you have new information, feel free to add them here and we can reopen and investigate then.

FBX is a rather hard format to get right, so if you can use an alternative format, that would be best. Maybe GLTF. Since we can't confirm that this is an issue in Blender itself, I will archive this for now. If you have new information, feel free to add them here and we can reopen and investigate then.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#97634
No description provided.