CenterMesh keeping original position.

Blitz3D Forums/Blitz3D Programming/CenterMesh keeping original position.

RifRaf(Posted 2009) [#1]
I hope I can explain this right, what im trying to do is take several meshes and center them.. but I want the resulting mesh to remain in the indentical space as the previous uncentered mesh. I only need to center the x\z, Y should be unchanged.
What im going to do, hopefully is use this
http://www.blitzbasic.com/codearcs/codearcs.php?code=1343
on the main map, so that each segment can be culled, currently though they are nearly always seen by the camera because their center is 0,0,0 even if they actual geometry is 1000 units away from that.

Any ideas on the best(and quickest) way to go about this?
below is a pic issustrating this. The pics texts says somthing about scale, thats not important as I use scalemesh when scaling anyway.




dynaman(Posted 2009) [#2]
Save the Y position in a variable.
Execute the centermesh command
reset the Y coordinate.

Save this as the default position. (been ages since I played with B3D so I'm not sure of th exact commands to use)


RifRaf(Posted 2009) [#3]
Thanks for the reply, but that doesnt seem to address the issue. Probably because of my poor description.

I cannot re position the mesh. it has to remain (as far as geometry goes) in the exact same place after the centermesh.
what it should boil down to is some sort of calculation before centermesh, then the centermesh, then a positionentity based off the initial calculation to get it back where it should be. But for the life of me I cant get it right.


Stevie G(Posted 2009) [#4]
Interesting, I'm using a variation of the clusterise function to split up my visible landscapes but I never thought that it was the center point that is used in culling. I'll need to check.

**EDIT**
Blitz automatically generates a bounding box for meshes which must be based on the min,max vertex values. It only uses the center point of the entity for non-mesh entities. I think what you have should already work, test it using the EntityInView command. If it didn't then the 'clusterise mesh' function would be useless.
**EDIT**

You've got 2 options, the second being easiest

1.

* Use the clustersised mesh function
* For each cluster/chunk, iterate through all vertices and find the mid point.
* Center the mesh
* Positionentity the centered mesh at the mid point you found earlier.

2.

* Use the clusterised mesh function
* For each cluster / chunk, reset the entitycullbox ( not sure the name of this function ) to coincide with the actual geometry.

Stevie


RifRaf(Posted 2009) [#5]

**EDIT**
Blitz automatically generates a bounding box for meshes which must be based on the min,max vertex values. It only uses the center point of the entity for non-mesh entities. I think what you have should already work, test it using the EntityInView command. If it didn't then the 'clusterise mesh' function would be useless



perhaps entityinview does a linepick type thing, wich uses the geometry not the bounding box. Try entityautofade and test again :)


2.

* Use the clusterised mesh function
* For each cluster / chunk, reset the entitycullbox ( not sure the name of this function ) to coincide with the actual geometry.


I never knew such a command existed, ill have to look through the docs and try to find it.


Stevie G(Posted 2009) [#6]
Entityinview does not do a linepick, entityvisible does though. I remember because it's slower than a week in the jail. I assume that entityinview simply returns a 'was rendered during the last renderworld' flag.

It's likely that entityauto fade uses the center coords of the entity rather than the center of the geometry. Why not use fog and let the rendering cull what is out of view automatically?


RifRaf(Posted 2009) [#7]
what is interesting then is that I can do a trisrendered() and this shows most chunks being drawn even if they are far behind the camera.


Stevie G(Posted 2009) [#8]
A quick check tells me that my entities are not all in view ( entityinview ) as expected ( clevels are clustered into 3 x 3 chunks ) but I've yet to check the trisrendered. I'll check tomorrow.


Ross C(Posted 2009) [#9]
I know exactly what you mean rifraf. I had this exactly same problem with my cannon game. I needed to break the model up and find the centre points, so i could rotate them around it.

What i did was this:

1. loop through every vertex in the mesh, finding the furthest -x +x -y +y -z +z. Then find the exact centre point using this information.

2. Store the x y and z distances to the world centre (0,0,0)

3. Use the positionmesh command to position the mesh around teh world centre, using the co-ords from point 2

4. Finally use the moveentity command to move the entity back to where it was. This time though, the meshes centre will be correct.

I have a fix mesh centre function for this purpose on my computer at home. I can post it (when i get home) if you want? Just be wary of scaling/moving/rotating the entity first before you centre it.


jfk EO-11110(Posted 2009) [#10]
This info about not culling a mesh when its center pivot is in view (but not a single triangle) now really confuses me. I am using a culsterisation too and so far I thought it's culling things correctly. I clearly see variations in TrisRendered, compared to the unclusterized map.

Maybe EntityAutofade works diffrent? It would make sense, I don't think ENtityAutofade is going to check for a bounding box, rather only the distance between camera and entity.


Zethrax(Posted 2009) [#11]
Here you go.

EDIT: Edited to return the total vertex count, so that it may be used to check for an empty mesh.




D4NM4N(Posted 2009) [#12]
Not sure if it is what you are after, but i wrote some code ages ago to fit all my animated models (all at different sizes) into a certain size eg. 1x1x1 blitz 3d unit.

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=1430

While it may not be exactly what you are looking for, there is some mesh measurement stuff in there so may give you the 'idea' you need :)


RifRaf(Posted 2009) [#13]
Thanks Bill, ill give that a shot!
edit: it seems to work great, thanks!


RifRaf(Posted 2009) [#14]
curious, I can cluster a mesh thats over the tri limit (meaning a model that would crash you on renderworld)
but it comes out all weird. Either of you had any luck with very high poly model clustering.


jfk EO-11110(Posted 2009) [#15]
Whenever I got a model with more than 31k Tris or 64k Vertices then I put them on additional surfaces. I did this some time ago to display a 3D scan with 200kPoints+ Actually one of those Laser Plasma Glass Cube files, that works with Dots, not with triangles. However, in Game design I never got such problems. Currently my map says "10kTris" and I am already worried :)