Having a little trouble here, loading a 3DS mesh that has several child objects in it using the loadanimmesh command, while I can move, rotate, etc. these child objects using findchild, if I try to get coordinates either global or translated I always get 0,0,0 using entityX, etc. or tform... is it not possible to get the coordinates of a child object that is loaded as part of a mesh? short of finding the correct surface and using the vertices mins/maxes...
mesh child objects...
Blitz3D Forums/Blitz3D Programming/mesh child objects... entityX(Entity,1) should do the trick.
The centre of the child meshes, could in fact be the centre of the parent mesh. You may have to move the centre of the mesh, using the fitmesh command. Best thing to do if that's the case is:
Find the centre of the child mesh, using vertex co-ords commands. I have put together these functions for doing this.
Use them like this:
These are the functions you will need.
NOW, you need to fitmesh around (0,0,0) by doing:
Then, you place the mesh back at it's centre point, using the centre co-ords you obtained earlier.
That should centre the mesh around 0,0,0 mesh axis, and move the entity to it's previous co-ords. The entity shouldn't actually position though. Hope that helps :o)
Find the centre of the child mesh, using vertex co-ords commands. I have put together these functions for doing this.
Use them like this:
centre_x = find_centre_x(mesh) centre_y = find_centre_y(mesh) centre_z = find_centre_z(mesh)
These are the functions you will need.
Function find_lowest_vertex#(mesh) lowest# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedY#() < lowest Then lowest = TFormedY#() End If Next Next Return lowest End Function Function find_highest_vertex#(mesh) highest# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedY#() > highest Then highest = TFormedY#() End If Next Next Return highest End Function Function find_leftmost_vertex#(mesh) leftmost# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedX#() < leftmost Then leftmost = TFormedX#() End If Next Next Return leftmost End Function Function find_rightmost_vertex#(mesh) rightmost# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedX#() > rightmost Then rightmost = TFormedX#() End If Next Next Return rightmost End Function Function find_zmost_vertex#(mesh) ; the furthest away on the Z axis zmost# = -999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedZ#() > zmost Then zmost = TFormedZ#() End If Next Next Return zmost End Function Function find_zleast_vertex#(mesh) ; the closest on the Z axis zleast# = 999999.0 no_surfaces = CountSurfaces(mesh) For sloop = 1 To no_surfaces Surface_Handle = GetSurface(mesh, sloop) For loop = 0 To CountVertices(surface_handle)-1 TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0 If TFormedZ#() < zleast Then zleast = TFormedZ#() End If Next Next Return zleast End Function Function find_centre_y#(entity) hv# = find_highest_vertex#(entity) lv# = find_lowest_vertex#(entity) centre_y# = lv + ((hv - lv)/2) Return centre_y End Function Function find_centre_x#(entity) rm# = find_rightmost_vertex#(entity) lm# = find_leftmost_vertex#(entity) centre_x# = lm + ((rm-lm)/2) DebugLog(" mesh width = "+ (rm-lm)) Return centre_x End Function Function find_centre_z#(entity) zm# = find_zmost_vertex#(entity) zl# = find_zleast_vertex#(entity) centre_z# = zl + ((zm - zl)/2) Return centre_z End Function
NOW, you need to fitmesh around (0,0,0) by doing:
FitMesh mesh,-MeshWidth(mesh)/2,-MeshHeight(mesh)/2,-MeshDepth(mesh)/2,MeshWidth(mesh),MeshHeight(mesh),MeshDepth(mesh)
Then, you place the mesh back at it's centre point, using the centre co-ords you obtained earlier.
PositionEntity mesh,centre_x,centre_y,centre_z,TRUE
That should centre the mesh around 0,0,0 mesh axis, and move the entity to it's previous co-ords. The entity shouldn't actually position though. Hope that helps :o)
Cheers for that ross, I think I'm gonna need it, entityx#(entity,true) always returns 0 on any of the children and they couldn't all be at mesh 0,0,0 even if one was which isn't the case.