child coordinates from AnimMesh

Blitz3D Forums/Blitz3D Programming/child coordinates from AnimMesh

semar(Posted 2009) [#1]
All,
basically the question is: how to get the 3D world coordinates of a child entity contained in a mesh, which has been loaded into B3D with LoadAnimMesh ?
The coordinates I get are always 0,0,0, even if in the .b3D model, the cube is located in another place than 0,0,0.

I wonder why ?

I describe the steps I follow:

mesh = LoadAnimMesh("test.b3d")
child = FindChild(mesh,"cube01")
Print EntityX(child) ;prints 0
Print EntityY(child)
Print EntityZ(child)


Now, using EntityX(child,true) or EntityX(child) makes no difference. I still get 0 - for all three coordinates.

I've seen, there's a workaround to this problem; using TFormVector on a surface of the child, and then using TFormedX and the like.

But doing so, I obtain the coordinates of a vertex surface, while I need to get the center of the child entity.

I explain the scenario where I'm working on, to give a better understanding.

I'm creating a 3d level - a dungeon for example.
In the level, I put other entities to be used as 'torches'. Then, there will be put a particle emitter at each torch coordinates.

Now, I need to get the right coordinates of the torches, in order to attach the particle emitters in a correct way.

How would you do that ? Would you use a different approach to accomplish this task ?

[EDIT]Seems that loading a .x file does give the right coordinates for the child. So does the B3D format retain the child coordinates, or is it flawed ? (or perhaps the problem is located in the B3D exporter that DeleD 3D uses...)
???

[EDIT 2]
So I've found two solutions:
1) export the model as .X file. Then, EntityX(child,true) does provide the right 3D World coordinates of the child entity.

- OR -
2) use the .B3D file, but instead of EntityX(child,true), which sadly provides always 0, use this function instead:
For i = 1 To CountSurfaces(child)
surf = GetSurface(child,i)
nb_vert = CountVertices(surf)
tot_nb_vert = tot_nb_vert + nb_vert
For j = 0 To (nb_vert - 1)
x = x + VertexX(surf,j)
y = y + VertexY(surf,j)
z = z + VertexZ(surf,j)
Next
Next

;then the x,y,zcoords are : x/tot_nb_vert,y/tot_nb_vert,z/tot_nb_vert 



Sergio.


Charrua(Posted 2009) [#2]
hi
i think you have to use the Global flag.
i you don't use it, you have the coords relative to the parent.
if an entity haven't a parent EntityX returns the global coordinates but ir it has one, then, ir returns the position of the child relative to it parent,

hope it helps

(sorry, i didn't read all the thread, oviously didn't help!)

juan


semar(Posted 2009) [#3]
Mucias gracias, pero hay siempre lo mismo problemo !

Thanks, but the problem still remains. The function I've posted must be used in order to retrieve the correct coordinates.

Hasta luego,
Sergio.


Charrua(Posted 2009) [#4]
i have little or no experience with loadanimesh and 3d formats in general, but i think that is the Exporter you are using.

See the demo example of Giles (you know it?) in the .bb they give, they use GetChild to search (recursively) for specific objects (to get custon variables) and i inserted EntityX, Y and Z (after each entity is reached) with and without global flag and both game the correct 3d world coordinates. (working with a .b3d).

try to ger another exporter, is it posibly, or a config setting on the software, may be?

Juan


Ross C(Posted 2009) [#5]
This is a common problem i've found. You need to loop through every vertex in the child mesh, and find the centre co-ord.

What happens is the centre of the mesh, upon using loadanimmesh, is the same as the centre of any attached mesh. The mesh seems to have been rebuild off it's axis. I first noticed this when using Gile[s]. Your entity you import will rotate about it's own centre axis fine and well, until you save the scene (or export as .b3d). Upon loading the whole mesh still has it's seperate entities, but they now all share the same centre point, mesh wise and entity wise.

So anyway, you need to:
- loop through all the vertices in the child mesh,
- find the centre point using that information,
- move the MESH (PositionMesh?) the opposite of the centre point, so it's positioned back at the 0,0,0 ,
- move the ENTITY back to the centre point location

I'm sure someone created a function for this...