Redefine “center position” of a mesh?—solved

Software: Away3D 4.x

Somokon, Member
Posted: 29 July 2011 12:15 AM   Total Posts: 75

Hello,

I have 512 cube objects, which I have successfully merged into a single mesh (using the Merge class), so that it now looks like a large 8x8x8 cube:

merge = new Merge(truetrue);
var 
meshes:Vector.<Mesh> = new Vector.<Mesh>();
   
for (var 
i:int 08i++) {
   
for (var j:int 08j++) {
      
for (var k:int 08k++) {
      
      
var cube:Cube = new Cube(material252525);
      
      if (
== && == && == 0{
         cube
.position = new Vector3D(-87.512.5100);
      
}
      
else
         
cube.position = new Vector3D(12.5*i12.5*j12.5*k);
      
      
meshes.push(cube);
      
}
   }
}
   
var mergedMesh:Mesh merge.applyToMeshes(meshes.shift(), meshes);
view.scene.addChild(mergedMesh); 


However, the fact that the “position” of the merged mesh is defined to be the position of the first small cube I created (-87.5, 12.5, 100), rather than the “real center” of the large merged mesh (0, 100, 100), is causing me problems in some other stuff I want to do.

Does anyone know how I would go about redefining which point in the mesh is the “position”?

I tried MeshHelper.recenter(mergedMesh) from the MeshHelper class, but it doesn’t seem to do what I want.

Thanks

   

Avatar
Fabrice Closier, Administrator
Posted: 29 July 2011 08:05 AM   Total Posts: 1265   [ # 1 ]

“Meshhelper.recenter doesn’t seem to do what I want” Can you define please?
The method recenters the object(s) vertices in object space. So if you do not see changes on screen after you apply, that might be because you need to change the mesh position. Or is it something else?

   

Somokon, Member
Posted: 29 July 2011 05:01 PM   Total Posts: 75   [ # 2 ]

Hi Fabrice,

On taking a closer look MeshHelper.recenter is indeed the right function to use.

However, in the recenter function I had to change

applyPosition(mesh, (Bounds.minX+Bounds.maxX)*.5, (Bounds.minY+Bounds.maxY)*.5, (Bounds.minZ+Bounds.maxZ)*.5); 

to

applyPosition(mesh, (Bounds.minX+Bounds.maxX)*.25, (Bounds.minY+Bounds.maxY)*.25, (Bounds.minZ+Bounds.maxZ)*.25); 

to get the vertices to position properly.

The merged mesh contain two subgeometries that seem to refer to the same vertex data.  So calling the applyPositions function actually offsets the vertices by twice the needed amount.

I’m not sure if this is a bug or working as intended in the Merge class.

   

Avatar
Fabrice Closier, Administrator
Posted: 29 July 2011 07:32 PM   Total Posts: 1265   [ # 3 ]

Please send me offline a test class that reproduce the issue (or is the snippet above doing this?), I’ll try look at this asap.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X