Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Update the center pivot of any mesh automatically

Author
Message
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 28th Sep 2013 19:53 Edited at: 28th Sep 2013 19:55
We have seen many times , how an object rotate with a wrong center. That happens when we export the object from most 3D program. I'm trying to make a fracture mesh, and I had to find out the way to get an approximate center. The programs is done, and it works ok for my purpose, and we can even save every chunk as a new object. The problem I had, was how to get this center. I need to get the center to get more realism to the function
I thought about vertexdata....so what I did, got the minimum/maximum vertexdata position x/z and decide where to move the object. It gave me strange results, so I try to get just the maximum (no minimum) of x/z, and then add the object size x/z divided by two :

`ADDING NEW CENTER TO THE MESH
offset limb 1,0,-dex#+object size x(1)/2,0,-dez#+object size z(1)/2

It works in most cases , but sometimes it fail and object disappears mysteriously . Here is the code I have so far



Cheers.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Sep 2013 20:19
You probably need to give dex# and dez# appropriate initial values before updating them in the loop, in other words zero won't always be a sensible initial value. The simplest solution is to use vertex 0 to initialise them and then do the updating tests for vertices 1 to vert-1.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 28th Sep 2013 20:29 Edited at: 28th Sep 2013 22:21
@GG You are right...any way, I found a bug...it works only in positive values ...let see if I can mend it


Edited

Looks like I have solved the problem....now it works with negative and positive values...but I have to say than I don't understan why it works.

@GG It wasn't necesary to add initial values, .... the bucle increase or decrease variables automatically. Some times vertex 0 use to be out of the mesh...in its original 0,0,0.

Here's the first working Update.




I'm not a grumpy grandpa

Login to post a reply

Server time is: 2026-07-06 20:16:02
Your offset time is: 2026-07-06 20:16:02