Retrieving local coords of 3D models.

Blitz3D Forums/Blitz3D Programming/Retrieving local coords of 3D models.

Jeremy Alessi(Posted 2003) [#1]
In Aerial Antics most of the modeling is done in 3DS Max. Each model is offset in that program and positioned relative to other major objects. The thing is that when we open the model in Blitz it retains the offset, which isn't a problem (we want it to position right as we load it in the editor).

The problem is that the local and global coords are the same and I'd like to make the loader read the local offset, move the mesh back to 0,0,0 (local) and then global position it to it's correct place (where it actually appeared to be even though it was listed as being positioned at 0,0,0).

This was never a problem before, but now we're using some real time shadows (Sswift's system) and it's hard to get good results because all the receivers are positioned at 0,0,0 making little use of the range system it has.

The only solution I thought of was creating a bone and placing it at the local origin and then making it the parent of the real mesh, then I should be able to find the distance between them and global position the mesh properly. If there are any other solutions that I'm over looking it'd be great.


jhocking(Posted 2003) [#2]
I'm not sure I understand your problem but let me take a guess at things. If your local and global coordinates are the same that means that the object's pivot point is set at the global origin of 0,0,0. So what you need to do is move the object's pivot point before exporting; 3D Studio Max has a convenient "Center in Object" button for manipulating pivot points.


Binary_Moon(Posted 2003) [#3]
If you create meshes in max and then load them the hadle returned from loadanimmesh is an invisible pivot that is positioned at the center of the world. If you loop through all the children you should be able to get their individual positions (make sure you use the global flag).

Something like

mainmesh=loadanimmesh("levelfile")

for ent=1 to countchildren(mainmesh)
   child=getchild(mainmesh,ent)
   x=entityx(child,true)
   y=entityy(child,true)
   z=entityz(child,true)
next


I haven't checked this but am pretty sure it worsk ok. If you start moving the 'mainmesh' around then the x,y,z values will be relative to the parent but as long as you stay at 0,0,0 then it should work fine


jhocking(Posted 2003) [#4]
Good call, I didn't think of that. To expand on his little code snippet, you'd call Receive_Shadow(child) while looping through all the child objects and not need to actually check the entity's position manually:

mainmesh=LoadAnimMesh("levelfile")

For ent=1 to CountChildren(mainmesh)
   child=GetChild(mainmesh,ent)
   Receive_Shadow(child)
Next

BTW, that's the first time I've used the [code] tags. Hooray for me.

Oh, and I use sswift's shadow system too. Works pretty well don't it?


Jeremy Alessi(Posted 2003) [#5]
Yes it works good, but it's very slow on some of our locales. In the park we have it works great. I can have some (2-3) objects cast textured or rendered shadows and the main animated character cast a rendered shadow along with about 10 trees casting static shadows on a 3DS made terrain while also receiving real time shadows and it's fast. We really need to break up our receivers on some locales I think. It seems that a high poly receiver is slower than several low poly receivers.


Michael Reitzenstein(Posted 2003) [#6]
BAN - Have you tried EntityX( Entity, True )? The B3D model I have seems to indicate that that is where the problem lies.


Jeremy Alessi(Posted 2003) [#7]
That would return the global coord, but my models are in fact positioned at 0,0,0 globablly. They have a local offset, but since there is no parent entity at 0,0,0 the mesh also returns 0,0,0 for it's local coords.


Michael Reitzenstein(Posted 2003) [#8]
The model that I looked at had the entity as a child of the root node - are you loading it with LoadAnimMesh?


Jeremy Alessi(Posted 2003) [#9]
Well, that's what I'm going to do. I was only wondering if there was a way to do it without loading it like that.


Bot Builder(Posted 2003) [#10]
try this:

Function Mid3dHandle(mesh)
 ux=-1000
 uy=-1000
 uz=-1000
 lx=1000
 ly=1000
 lz=1000
 cs=CountSurfaces(mesh)
 For s=1 To cs
  surf=GetSurface(mesh,s)
  cv=CountVertices(surf)-1
  For v=0 To cv
   vx=VertexX(surf,v)
   vy=VertexY(surf,v)
   vz=VertexZ(surf,v)
   If vx<lx Then lx=vx
   If vx>ux Then ux=vx
   If vy<ly Then ly=vy
   If vy>uy Then uy=vy
   If vz<lz Then lz=vz
   If vz>uz Then uz=vz
  Next
 Next
 ax=(ux+lx)/2
 ay=(uy+ly)/2
 az=(uz+lz)/2
 PositionMesh mesh,-ax,-ay,-az
End Function

(my own function)
It should center the mesh around the handle. I'm not sure if this is what your looking for, but owell. try it.


Jeremy Alessi(Posted 2003) [#11]
That's cool, might be useful.