FBX Camera/Light Import

Started by WAS, April 14, 2022, 10:39:01 PM

Previous topic - Next topic

WAS

If I created a tool to spit out a TGC conversion of a FBX file that contained cameras and lights, would that be of any use to anyone?

I discovered THREE.js which can load FBX files, and can search elements by property such as type of object = camera / light. Then I can take properties from it, such as  location, colours, intensity focals, etc, etc, and convert them to Terragen shaders (IE Light source and Cameras).

Dune

You can do that directly from TG, just highlight some nodes (reds, blues, pops, objects, light, camera) and save as tgc. So I don't think a conversion would add to that, unless it's meant to convert externally made fbx files.

Hannes

Quote from: Dune on April 15, 2022, 01:19:26 AM...unless it's meant to convert externally made fbx files.
I guess, that's what Jordan meant. In this case that would be quite useful.

WAS

#3
Seems very a doable. Here is a test on Blenders default camera.

Screenshot_183.jpg

I just need to figure out all the relevant information that I need to port to terragen by inspecting terragen's camera XML.

Then I'll know how to port them and can just traverse the file for cameras, spit out terragen node XML to a new TGC file.

I apparently can't do lights though. I mean, Blender can export "Lamps" to FBX, but I see nothing in Three.js to detect a lamp or anything, so may give up on that or look into another way to detect them.

I know there may need to be some conversion, as what if the up value is not x: 0 y: 1 z: 0. That means up value wouldn't match TG if it was on Z like blender or something.

And what location do I use? World? Or quaternion? I think world. But gah.  Ah It is Position i need, need to convert from centimeters to meters.


WAS

#4
Progress. The whole program is pretty much finished. I just gotta do the conversion of data for TG.

In Blender there is no units to choose from like cm/m/km, and I read FBX are unitless, but that unit relates to centimeters. Wonder if it's safe to assume that's always the case and thus can just divide by 100 for TG meters.

pixelpusher636

Nice work WAS! looks like you have your hands full with this one. These types of projects are better than word games and puzzles and in the end you might be contributing a very handy tool!
The more I use Terragen, the more I realize the world is not so small.

Hannes

Looks amazing already, Jordan!

WAS

So it turns out lights are exported in FBX! At least when I tried it for point lights and spotlights, it worked.

I'll need to overcome the rotation issue I am having to make this a reality for spotlights, though. Though I'm not sure if it has all the data for the inner and out radiuses like TG has. It has penumbra.

Object { uuid: "a95c2865-d7e3-4c8c-a6c3-116b52cfeccc", name: "Light001", type: "SpotLight", parent: {...}, children: [], up: {...}, position: {...}, rotation: {...}, quaternion: {...}, scale: {...}, ... }
ID: 208779770
angle: 0.39610249718425905
animations: Array []
castShadow: true
children: Array []
color: Object { r: 1, g: 1, b: 1 }
decay: 1
distance: 0
frustumCulled: true
id: 6
intensity: 1000
layers: Object { mask: 1 }
matrix: Object { elements: (16) [...] }
matrixAutoUpdate: true
matrixWorld: Object { elements: (16) [...] }
matrixWorldNeedsUpdate: true
modelViewMatrix: Object { elements: (16) [...] }
name: "Light001"
normalMatrix: Object { elements: (9) [...] }
parent: Object { uuid: "3e53bf0a-f057-4c37-a28b-594e3ed08a1e", name: "", type: "Group", ... }
penumbra: 1
position: Object { x: 340.47123100693716, y: 629.259258776291, z: -729.150530555407 }
quaternion: Object { _x: 0.24208312730982715, _y: 0.8821301342975071, _z: -0.3903021825655597, ... }
receiveShadow: false
renderOrder: 0
rotation: Object { _x: 2.3832431594438743, _y: -0.38247666937830405, _z: -2.7599005707590663, ... }
scale: Object { x: 99.99999999999999, y: 100, z: 100 }
x: 99.99999999999999
y: 100
z: 100
<prototype>: Object { isVector3: true, setEulerFromRotationMatrix: setEulerFromRotationMatrix(), setEulerFromQuaternion: setEulerFromQuaternion(), ... }
shadow: Object { bias: 0, normalBias: 0, radius: 1, ... }
target: Object { uuid: "fab7e365-86a1-4da4-8942-783d1105cc54", name: "", type: "Object3D", ... }
type: "SpotLight"
up: Object { x: 0, y: 1, z: 0 }
userData: Object { transformData: {...} }
uuid: "a95c2865-d7e3-4c8c-a6c3-116b52cfeccc"
visible: true
<prototype>: Object { isSpotLight: true, ... }
fbxcam2terragen.js:116:15
Object { uuid: "5afe719b-fc9d-4148-badd-4efcbc3ee8b2", name: "Light", type: "PointLight", parent: {...}, children: [], up: {...}, position: {...}, rotation: {...}, quaternion: {...}, scale: {...}, ... }
ID: 769181406
animations: Array []
castShadow: true
children: Array []
color: Object { r: 1, g: 1, b: 1 }
decay: 1
distance: 0
frustumCulled: true
id: 11
intensity: 1000
layers: Object { mask: 1 }
matrix: Object { elements: (16) [...] }
matrixAutoUpdate: true
matrixWorld: Object { elements: (16) [...] }
matrixWorldNeedsUpdate: true
modelViewMatrix: Object { elements: (16) [...] }
name: "Light"
normalMatrix: Object { elements: (9) [...] }
parent: Object { uuid: "3e53bf0a-f057-4c37-a28b-594e3ed08a1e", name: "", type: "Group", ... }
position: Object { x: -407.6245422363281, y: 590.38623046875, z: 100.54539489746094 }
quaternion: Object { _x: 0.27217137405281344, _y: -0.5709475072389063, _z: 0.16907575617850534, ... }
receiveShadow: false
renderOrder: 0
rotation: Object { _x: 1.251466785769911, _y: -0.8805682577499379, _z: 1.0963767490876004, ... }
scale: Object { x: 100.00000762939453, y: 100.00000000000001, z: 99.99999999999999 }
x: 100.00000762939453
y: 100.00000000000001
z: 99.99999999999999
<prototype>: Object { isVector3: true, setEulerFromRotationMatrix: setEulerFromRotationMatrix(), setEulerFromQuaternion: setEulerFromQuaternion(), ... }
shadow: Object { bias: 0, normalBias: 0, radius: 1, ... }
type: "PointLight"
up: Object { x: 0, y: 1, z: 0 }
userData: Object { transformData: {...} }
uuid: "5afe719b-fc9d-4148-badd-4efcbc3ee8b2"
visible: true
<prototype>: Object { isPointLight: true, ... }
fbxcam2terragen.js:109:15

WAS

#8
Figured out the rotation issue. Now to implement the lights.

Implemented... now I just need to figure out rotation, again. As I was wrong. If anyone wants to try FBX files with cameras/lights and see if they can find a Euler Order and rotation offset that works for TG,  that would be nice. Lots of combinations to try.

https://nwdagroup.com/terragen-tools/fbx2terragen/

WAS

FBX2Terragen should be working for perspective cameras now. My issue with rotation seems to be exclusive to spot lights, where Blender is inexplicably saving a seemingly random rotation, and location offset from where it should be. 

Cameras on the other hand seem to be working fine. 

Blender FBX2Terragen Settings:
Euler Order: YXZ
Offset: 0 90 0
Swap X with Z: Checked