Redimensioning an existing mesh/geometry

Software: Away3D 4.x

OEGInc, Newbie
Posted: 10 April 2014 04:53 PM   Total Posts: 27

Let’s say I create a plane such as (this is off the top of my head, so please forgive typo’s):

var planeGeometry:Geometry = new PlaneGeometry(100100);
var 
planeMesh:Mesh = new Mesh(planeGeometry, new ColorMaterial(0xFF0000));
addChild(planeMesh); 

And then I decide I want the plane to be 200 x 100, what is the best way to resize the existing plane?

Currently, I remove the plane, create a new one of the proper size, and then re-add it to the scene.  The problem is, I am doing this 60 times per second and garbage collection doesn’t have time to kick in and my memory creeps skyward.  Not to mention that it’s extremely inefficient.

I figure I probably need to access the subGeometry of the mesh, but I’m not quite sure how to go about doing that.

Thanks for any help/pointers you can give!
—Rob

 

   

rdoi, Member
Posted: 25 April 2014 01:56 PM   Total Posts: 86   [ # 1 ]

so… what would be the problem to resize the geometry itself?

planeGeometry.width= 200;

or

PlaneGeometry(planeMesh.geometry).width= 200;

Im not sure how efficient it is to rearrange the vertices, but I am sure its better than recreate a new one.

   

Avatar
Fabrice Closier, Administrator
Posted: 25 April 2014 02:59 PM   Total Posts: 1265   [ # 2 ]

Just make one geometry, ‘mysavedGeometry’. make it 1x1.
for each new plane, just make new Mesh(mysavedGeometry, material);
then simply do mesh.scaleX = 200; same for scaleY

By having a size of 1x1, each new plane gets the size you need by multiplying the size 1 by your factor (the expected size). no need to alter vertices, no percent ratio required.

   

OEGInc, Newbie
Posted: 25 April 2014 04:11 PM   Total Posts: 27   [ # 3 ]
Fabrice Closier - 25 April 2014 02:59 PM

Just make one geometry, ‘mysavedGeometry’. make it 1x1.
for each new plane, just make new Mesh(mysavedGeometry, material);
then simply do mesh.scaleX = 200; same for scaleY

By having a size of 1x1, each new plane gets the size you need by multiplying the size 1 by your factor (the expected size). no need to alter vertices, no percent ratio required.

Beautiful and elegant Fabrice.  Your solution worked flawlessly!  Thank you so much. 

I can see definitely need to spend more time thinking outside of the box..

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X