Bonzai Engine Forum

Bonzai Engine & Tools => Bonzai Engine => Topic started by: Jan_K. on May 17, 2013, 04:58:25 PM

Title: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on May 17, 2013, 04:58:25 PM
Hallo! And thanks for your great work. We use the engine in a project in university to display a 3D-Scene that was created in Maya. For now we can display our textured scene as .fbx file using the code of the tutorial.

My question is: can we use the camera position/orientation and the lights that are stored in the 3D-scene? And if so, how does the code look like?:)
Alternatively wo could use a dae file for example if fbx causes problems...

Thanks!
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on May 17, 2013, 05:49:39 PM
The fbx parser ignore lights. Camera (position and orientation) nodes are parsed but not stored in the Model (don't have any geometry data).

We can eventually introduce some kind of way to give access to camera/light data read by the model parser, if you need.
(The dae parser currently ignore both camera and light)
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on May 18, 2013, 10:58:55 AM
Yes it would be great if you could provide a way to give access to camera and lights:) How would you do this exactly? Thanks!!!
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on May 18, 2013, 12:03:15 PM
Probably a listener you could register to the ModelReaderSettings (with onRead methods for camera/light).

With fbx, you'll only get camera and light transform (other light parameters are not parsed yet).
For now, only 3ds format parse camera and lights which are accessible with Ds3Reader.getLights/Camera when the option settings.options.setReaderReadExtraData is used.
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on May 29, 2013, 06:09:38 PM
The last build adds ModelReaderSettings.extraAsset to access camera from fbx, and more generally camera/light/spline from model reader when supported.
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 04, 2013, 05:15:40 PM
Hello Jerome. Thanks for introducing the onReadCamera and onReadLight methods to the new build!
Unfortunately it is not clear to me how to access Camera and Light information with them as the metods are of type "void". So they are not ment to read out e.g. camera position of the 3D-Scene?! Do i set the position with them? Or do i have to add the StreamListener?

as a reminder: my aim is just to have the camera of the engine at the same position like in the 3d-Scene. And i am using .fbx files...

Thanks very much!!!
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 04, 2013, 05:34:40 PM
Use the methods parameters which contains the data read, ie the parameters of onReadSpline are respectivelly the name and the Spline read. They are callback methods (called by the parsers), which you can receive by implementing the interface as below:
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 12, 2013, 04:35:23 PM
Hello Jerome.

I have implemented the code like this:

The lookAt of the Camera is stored in the Mat4x4 "KameraPosition" which seems to work. When i print it our to the console it says: Transform(
   0,0000   1,2000   -3,2780
   false
   0,0000   0,7071   0,0000   0,7071
   0,0000   0,0000   0,0000   1,0000
   1,0000   1,0000   1,0000
)

But i wand the camera to automatically take this values. So my thought was this:

Shouldn't the Matrix now be stored in "LookAtMatrix"? It says it is "null" when i print it out to the console...Thanks
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 12, 2013, 05:04:16 PM
Yes, Transform.getLookAtMatrix stores the result in the matrix paramenter. In your case, the variable LookAtMatrix.

Mat4x4 objects prints in the format "Mat4x4(...)", you can't have "null" except if you've missed to allocated it with the new operator. What variable have you printed ? What is the type of 'camera' ?
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 14, 2013, 01:52:15 PM
I dont really know what is meant by " allocating it with the new operator". I printed out the variable "LookAtMatrix" which is Mat4x4. When i print out "KameraPosition" which is of type Transform at the same line in the code it works.. I print it out in the renderUI method like this:

I just want to take the LookatMatrix which is read out by the parser and take it as input for camera.setlookat method...
"camera" is of type Volume Manipulator. I didn't change it from the tutorial...

Thanks!
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 14, 2013, 01:59:52 PM
Did you have the line
before using LookAtMatrix variable ?

The simplest way to see what's in your variable would be to put a breakpoint in eclipse and run in debug ...
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 14, 2013, 06:58:06 PM
That line was missing:) Now i have:

Kamera: Transform(
   0,0000   1,2000   -3,2780
   false
   0,0000   0,7071   0,0000   0,7071
   0,0000   0,0000   0,0000   1,0000
   1,0000   1,0000   1,0000
)
LookAtMatrix: Mat4x4(
   0,0000   -0,0000   1,0000   3,2780
   0,0000   1,0000   0,0000   -1,2000
   -1,0000   -0,0000   0,0000   0,0000
   0,0000   0,0000   0,0000   1,0000
)

The Transform "camera" is different from the Mat4x4 is was written in :( How can i fix this? Or do i have to use getLookAtUp; getLookAtLeft; getLookAtForward and getPosition methods separately?
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 15, 2013, 12:03:23 PM
What value did you expect ?
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 15, 2013, 05:54:26 PM
I expected the Transform lookAt Matrix and the Mat4x4 lookAt Matrix to be the same...
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 15, 2013, 11:40:35 PM
Then why are you comparing a position transform to a lookat/view matrix ?
Positioning an object (with a position matrix/transform) and viewing from that position (a view/lookat matrix) is different thing and therefore represented by different matrices.

Use Transform.getMatrix to have a position matrix, which you can compare to a position transform.
Or extract the lookat position (there's some helper in Mat4x4.getLookAt***) which you can compare with the position transform.
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on June 25, 2013, 02:00:12 PM
Hello Jerome. Now i can set the Position of my camera. Thanks for that. But i got another Problem:
I want the camera to stay at the same position when i use the mouse to look around in the scene (like in an ego-shooter for example)
Now the camera position is always changed when i use the mouse to look around. So the pivot point seems not to be at the camera position. Is there a way to fix this?

Thanks much!
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on June 26, 2013, 03:45:52 PM
You're using the VolumeManipulator. This camera is for manipulating volume, this is the camera used in the viewer tool and some tutorial. The pivot is at the volume center, not at the viewer position.

You may wish to try instead the FreeCamera from the gamekit package, which possibly seem to do what you need.
The gamekit demo uses it in CameraMover (also used in the editor tool) and also shows how to sync the camera position with another object. The script moves a GameObject, but you can do same with a model if you need to.
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on July 03, 2013, 04:15:44 PM
Hello Jerome. Now i want to read out the Lights of the Scene. I implemented the onReadLight method like this:

"Lights" is of type Light. But wenn i print out "Lights" it says null. When i try to get Position or Colour of the Light like this:

   
and print out "LightPosi" and "LightColor" the console says:
LightPosi: Vec4(0.0, 0.0, 0.0, 0.0)
LightColor: null

What information is stored in the Light that is parsed by the onReadLight-method? Only Position or colours and other attributes too? Do you see an error in my code? Any idea why its "null"? Thanks
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: jerome_j on July 08, 2013, 10:28:02 AM
Are you sure you're LightColor prints null, or you get a NullPointerException stack when trying to use Lights ?
Have you even checked onReadLight has been called ?
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on July 17, 2013, 03:49:35 PM
No the onReadLights()-method is not even called but there are several Lights in the scene... All of another type...Are there lights in one of the scenes of the tutorial to test it? Did you test it with fbx file extension?

THX
Title: Re: get/use camera position/orientation and lights of a 3D Scene
Post by: Jan_K. on July 17, 2013, 03:52:30 PM
Our scene is available at: https://www.dropbox.com/s/ujgbk2rxwbtxc03/kleinerSendesaal10.fbx if you want to load it:)