Author Topic: get/use camera position/orientation and lights of a 3D Scene  (Read 12023 times)

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
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!

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #1 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)

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #2 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!!!

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #3 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.

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #4 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.

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #5 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!!!

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #6 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:
« Last Edit: June 04, 2013, 05:39:39 PM by jerome_j »

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #7 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

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #8 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' ?
« Last Edit: June 12, 2013, 05:06:30 PM by jerome_j »

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #9 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!

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #10 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 ...

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #11 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?

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #12 on: June 15, 2013, 12:03:23 PM »
What value did you expect ?

Jan_K.

  • Jr. Member
  • **
  • Posts: 14
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #13 on: June 15, 2013, 05:54:26 PM »
I expected the Transform lookAt Matrix and the Mat4x4 lookAt Matrix to be the same...

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: get/use camera position/orientation and lights of a 3D Scene
« Reply #14 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.
« Last Edit: June 15, 2013, 11:43:37 PM by jerome_j »