Planetside Software Forums

General => Terragen Discussion => Topic started by: WAS on April 14, 2022, 10:39:01 PM

Title: FBX Camera/Light Import
Post by: WAS on April 14, 2022, 10:39:01 PM
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).
Title: Re: FBX Camera/Light Import
Post by: Dune on April 15, 2022, 01:19:26 AM
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.
Title: Re: FBX Camera/Light Import
Post by: Hannes on April 15, 2022, 02:37:36 AM
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.
Title: Re: FBX Camera/Light Import
Post by: WAS on April 16, 2022, 05:37:44 PM
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.

Title: Re: FBX Camera/Light Import
Post by: WAS on April 17, 2022, 05:11:28 PM
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.
Title: Re: FBX Camera/Light Import
Post by: pixelpusher636 on April 17, 2022, 10:27:10 PM
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!
Title: Re: FBX Camera/Light Import
Post by: Hannes on April 18, 2022, 03:43:05 AM
Looks amazing already, Jordan!
Title: Re: FBX Camera/Light Import
Post by: WAS on April 20, 2022, 11:56:10 PM
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
Title: Re: FBX Camera/Light Import
Post by: WAS on April 21, 2022, 03:29:59 PM
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/
Title: Re: FBX Camera/Light Import
Post by: WAS on April 27, 2022, 01:04:42 PM
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