Confused as to how Fitmesh works

Blitz3D Forums/Blitz3D Beginners Area/Confused as to how Fitmesh works

Kendo(Posted 2008) [#1]
I am creating a 3DModel scene editor and i want to scan through a list of models , each one of which will be displayed at screen centre. I have no problem with that, i just need to parent displayed "temporary" model display to camera.
However i want the models to be displayed all the same size. No problem i thought, i'll use fitmesh, thus:

tmpry.tempmodel = new tempmodel
tmpry\obj=copyentity(3Dmodel(g))  ;  load my chosen model
entityparent tmpry\obj, cam, 0
fitmesh tmpry\obj,0,0,0,6,6,6,1

positionentity tmpry\obj,-3, -4,10


This works for displaying any model in my "expected area".

But then my problems start when i select the model (having first unparented it - entityparent tmpry\obj,0 )and try to place it on a terrain using pickedX#, pickedY#, pickedZ. Whereas, before trying to use fitmesh in my program, the model would drop nicely right onto the picked coordinates, now using fitmesh the model floats above the ground, and is displaced a distance on the X and Y axis ( roughly i need to adjust picked coords by -1.85) to get approx right.

This discrepancy would be even greater if i hadnt made fitmesh x,y,z coords 0,0,0.

Can anyone put me straight please?

Also, i want to scale the selected 3d Model up or down, but i dont understand whether or not fitmesh has scaled the model in real terms or just temporarily. If it has rescaled in real terms, does that mean that scaleentity 3dmodel, 1,1, 1 is now the "base" size of the model?

As always your assistance would be greatly appreciated


Warner(Posted 2008) [#2]
All mesh commands affect the model's data itself, as Entity do not. So ScaleEntity mesh,1,1,1 will still be the base size.
A good example is RotateMesh. If you use it too often, the model might get deformed because of rounding errors.
Entity properties only affect the model's matrix. That means the actual mesh data is not altered, only the way it is being rendered and dealt with in terms of collisions and picking.

FitMesh describes a box, so to center it around zero, you need:
FitMesh mesh, -1, -1, -1, 2, 2, 2
Where (-1,-1,-1) is one corner of the box and (2,2,2) is the width/height/depth.

To be able to place it on the ground, you'll need:
FitMesh mesh,-1,0,-1,2,2,2


Kendo(Posted 2008) [#3]
Many thanks Warner for your help.

Changing my fitmesh command to read -3,0,-3,6,6,6 now enables me to place the model on the terrain at the correct picked coords on the X and Z axis. Most models seat correctly on the ground on the Y axis but not all - presumably this is to do with a specific model's unique centre of origin?

Thankyou for explaining the difference between "mesh" and "entity" commands. I think i grasped the principle!

The problem i now have is:
obviously using the fitmesh command on my "menu display" model has rescaled the mesh. How do I best determine what that rescaling factor is so that i can then apply it in the same ratio to my "copy" model I am going to place on the terrain using the scaleentity command?


PowerPC603(Posted 2008) [#4]
You can get the size of the mesh with MeshWidth/MeshHeight/MeshDepth.

If you want the model to fit in a box of size 6x6x6 and your mesh would be 18x18x18, then your scaling factor would be 0,333333, as you need to scale it down with a factor 3 to make it fit within that box of 6x6x6.


Kendo(Posted 2008) [#5]
Many thanks PowerPC603. All is sorted now!