Skip to main content
May 29, 2013
Question

Mirror multiple meshes in Actionscript

  • May 29, 2013
  • 1 reply
  • 1061 views

I need to include in my BasicView.fla (BasicView.as) several actionscript files, por example: MainBodyInstance.as, PaintBase.as, MainBodyBase.as, PaintInstance.as, ... (all exported to AS3 with Prefab, this far everything is clear) Now, I chose to export as AS3 only half of my 3D car, but separated the exports of the meshes to AS3 depending on if it needed to be mirrored by code to save compiler time or not, or buy materials. For example, I would need to write a code that makes a mirror on all the 3D meshes inside: MainBodyInstance.as and PaintInstance.as data. My question is, how do I mirror my file or meshes? and, where do I have to write the code, in my main BasicView.as or inside each data file (ex: inside MainBodyInstance.as)?

I found the following which I'm sure is perfect for my case, but I know to little programming to really understand how to apply this to me work. Can somebody explain or help please?:

in speudo code
loop over yourPrefabClass.meshes
  if (yourPrefabClass.meshes[indexloop].name == “theNameOfTheWheelMeshThaTIWantToMirror”)

var myWheel:Mesh = yourPrefabClass.meshes[indexloop];
var mirror:Mirror = new Mirror();
mirror.apply(myWheel, Mirror.X_AXIS, Mirror.CENTER, 0);

where X_AXIS, Y and Z define the axis to mirror on
where Mirror.MAX_BOUND define if the mirror starts on the biggest vertice value along the define axis or Mirror.MIN_BOUND the smallest. Or if you use Mirror.CENTER you want to mirror on the axis at world 0.

duplicate will ensure you get a new mirrored mesh of have teh mirror be part of the wheel mesh. In your case, means having 2 independant front wheels meshes and one rear axle mesh.

what would "yourPrefabClass" be equal to? = PaintInstance.as (for example)? What about "indexloop" AS recognizes the index on my PaintInstance.as or do I have to write one by one all the name of the meshes that are inside that file (ex: "Hood_Cover","sideclosures_mainbodytop","extmirror_bodypart_i","fender_bodypart","frontdoor_body","sidemoldingpart_i","sidemoldingpart_ii","frontdoor_doorhandlepart_i","frontdoor_doorhandlepart_ii") and then make it == to "whichEverNameIWantToGiveThatGroup" for example "LeftSidePaintCar"?

Asumming I'm right this is what I would write:

private function Mirror(): void

        {

            for (PaintInstance.meshes)

            {  

                if (PaintInstance.meshes["Hood_Cover", "sideclosures_mainbodytop", "extmirror_bodypart_i","fender_bodypart", "frontdoor_body","sidemoldingpart_i","sidemoldingpart_ii", "frontdoor_doorhandlepart_i", "frontdoor_doorhandlepart_ii"].name == “LeftSidePaintCar”)

                {

                    var LeftSidePaintCar:Mesh = PaintInstance.meshes["Hood_Cover","sideclosures_mainbodytop","extmirror_bodypart_i","fender_bodypart","frontdoor_body","sidemoldingpart_i","sidemoldingpart_ii","frontdoor_doorhandlepart_i","frontdoor_doorhandlepart_ii"];

                    var mirror:Mirror = new Mirror ();

                    mirror.apply(LeftSidePaintCar, Mirror.X_AXIS, Mirror.CENTER, 0);

                }

            }

        }

Is it okey? Can anybody correct me please?

I also read that if I want to mirror lots of meshes I have to insert a switch statemente in the class.meshes loop, and have a dedicated mirror function in the switch cases, where I could for instance push a stack of mirror commands. like:

switch(mesh.name){

  case “myWheel”:
    doMirror(mesh, [ xmax, zmin ] );

How do I do this, and where do I insert it? I don't understand 😕😕 Please help

This topic has been closed for replies.

1 reply

Inspiring
May 29, 2013

what do you use as 3D Engine (Box3D, Papervision, Away3D etc.)?

May 29, 2013

I use Away3D 4.1.0 in Flash Professional CS6

Inspiring
May 29, 2013

wouldn`t it be easier to use the Mesh.classes own clone() method for this?

http://away3d.com/livedocs/away3d/4.0/away3d/entities/Mesh.html#clone%28%29