Author Topic: How to get Object3D's Position when loaded from .3ds  (Read 4125 times)

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
How to get Object3D's Position when loaded from .3ds
« on: January 01, 2015, 05:53:19 pm »
I am confused all the get Methods which return a SimpleVector for the Object3D are not the ones i am looking for nearly all are 0,0,0,0

I just want to get the Position or Translation (the getTranslation Method does not work for me its 0,0,0,0) of an Object created in Blender and saved as .3ds file

In Blender for example a created cube is at 4,5,1 so how can i get this position after loading it into jpct-ae?

The getName() Method works nicely so i just want to get the Name and the position so i get something like :
"Cube001 at (4,5,1)"
« Last Edit: January 01, 2015, 05:55:14 pm by dubbox »

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #1 on: January 01, 2015, 07:31:09 pm »
Because you have not translated the cube in you program yet. It is still at it's initial position. That it's not in the physical center of your exported 3ds file does not really matter for JPCT...
Question: What do you want to achieve exactly? Why not just set the cube at the center and translate it in the engine?
edit: Take a look at getCenter()/ getTransformedCenter. If you only have one object in the scene, it might achieve what you want.
« Last Edit: January 01, 2015, 07:33:09 pm by Irony »

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #2 on: January 01, 2015, 07:36:06 pm »
The thing is i have build an building in blender and want to implement listeners to open doors when you are near to them so i have to Check for the position of the door

i can read the position in blender and set the camera to it then i am really at the position like i am in blender but i cannot access this position by calling any method in jpct it would be nicer to read it in jpct

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #3 on: January 01, 2015, 07:50:10 pm »
If you export the doors as seperate files, getCenter should work.

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #4 on: January 01, 2015, 07:57:51 pm »
Its all in one file bute in that file are multiple objects so when i use the loader class i get an Object3d array of the size 36 so i have to seperate each object to an extra file?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to get Object3D's Position when loaded from .3ds
« Reply #5 on: January 01, 2015, 08:03:05 pm »
The different positions in a nutshell:

  • getTranslation() -  That's the translation that has been applied to the object in world space. If it hasn't been translated, this will be (0,0,0).
  • getOrigin() - The origin if set. The origin is a kind of pre-translation that doesn't change over time, i.e. the normal translations add up with the origin. If none has been set, this will be (0,0,0)
  • getCenter() - The center of the object in object space. This will be calculated when calling build(). Otherwise, it will be (0,0,0).
  • getRotationPivot() - The rotation pivot of the object in object space, i.e. the point around which the object will be rotated. After calling build() and when not using http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#useRotationPivotFrom3DS, this will be equal to getCenter().
  • getTransformedCenter() -  The point in world space to which the object's object space center will be transformed given it's current translations and rotations.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to get Object3D's Position when loaded from .3ds
« Reply #6 on: January 01, 2015, 08:04:22 pm »
Its all in one file bute in that file are multiple objects so when i use the loader class i get an Object3d array of the size 36 so i have to seperate each object to an extra file?
No, you don't. If their position is fine after loading them (i.e. their translation has been baked into their object space coordinates by Blender), then just call build() on them and use getCenter().
« Last Edit: January 01, 2015, 08:07:07 pm by EgonOlsen »

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #7 on: January 01, 2015, 09:28:37 pm »
Thank you very much now it works just fine :))

Do you know if empties do work with jpct? Empties are just objects without meshes just a position

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to get Object3D's Position when loaded from .3ds
« Reply #8 on: January 02, 2015, 12:41:19 am »
No, these won't be loaded. But you can assign some mesh to it, load it but only use it's position instead.

Offline dubbox

  • byte
  • *
  • Posts: 24
    • View Profile
Re: How to get Object3D's Position when loaded from .3ds
« Reply #9 on: January 02, 2015, 01:03:13 am »
Thats a nice workaround so i just dont add thrse objects to the world object and they wont be rendered but i can use their positions :)