Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Custom mesh centering  (Read 389 times)
Craigomatic
Customers
Community Member
*****
Posts: 78


« on: August 18, 2008, 11:25:19 PM »

I've found the TVMesh.SetMeshCenter to be a little flaky in some circumstances (ie: wheels on a physics vehicle) and limiting in that there isn't a corresponding function for TVActor, so I figured why not sidestep that and use a matrix based approach.

My approach
- Load asset at the origin
- Get BoundingBox of the asset
- Calculate and store an offset vector based on the max and min values returned from the BoundingBox
- Each SetMatrix:
   - translate the passed matrix by the offset vector to get a translation matrix
   - invert the translation matrix
   - multiply the translation matrix by the original matrix that was to be set
   - set the new matrix

In general this works ok with position and rotation, assuming I don't fiddle with the scale of the asset after it has been loaded. The moment the scale changes on the incoming matrix, my theoretical centre stays where it was, but the distance between it and the asset increases:

Before scale



After scale


The custom centre is represented by the axis.

Im speculating that I need to re-calculate the bounding box each time scale changes to re-calculate the position offset. There must be a better way? Any ideas?

Edit: Calculating the BoundingBox each setmatrix now works correctly with scale. Im still interested to hear alternative ideas though Smiley
« Last Edit: August 19, 2008, 02:55:46 AM by Craigomatic » Logged
jviper
Community Member
*
Posts: 1381

Discipline in training


« Reply #1 on: August 19, 2008, 12:41:21 AM »

Best option: correct the actor position in the modeller.

Another option: In your modeller, create a Root Bone, and make sure all of the other bones fall child to it. Then you can just adjust the root bone to the scale.
« Last Edit: August 19, 2008, 12:48:09 AM by jviper » Logged

JAbstract.....Don't just imagine, make it happen!
Craigomatic
Customers
Community Member
*****
Posts: 78


« Reply #2 on: August 19, 2008, 02:40:16 AM »

Best option: correct the actor position in the modeller.

This would be ideal, but I don't have control over the assets being created - it's all user generated, and in the context of its use, important that all models have a unified centre.
Logged
jviper
Community Member
*
Posts: 1381

Discipline in training


« Reply #3 on: August 19, 2008, 11:00:56 AM »

Hmm,well if you do not have control of the TVActor creation then there is little you can do. TVMesh gives you access to each vertex and you can offset the positions of all of the verticies so that the mesh has a different center. Unfortunately TVActor brings no such luxtuary because it would mess up the animation. I would say if your using TVActor but do not intend on ever animating it, then I would switch to TVMesh.
Logged

JAbstract.....Don't just imagine, make it happen!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks