Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Mirror multiple meshes in Actionscript

Guest
May 29, 2013 May 29, 2013

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

TOPICS
ActionScript
997
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 29, 2013 May 29, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2013 May 29, 2013

I use Away3D 4.1.0 in Flash Professional CS6

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 29, 2013 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2013 May 29, 2013

Maybe yes, I don't know how to use it though. And I don't want just to close the meshes, I want to mirror it from coordinates x0,y0,z0. Is it possible with clone()? Can you make an example please

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 29, 2013 May 29, 2013

since I don`t know details about how you load Meshes/Models in your project I would suggest putting all your meshes into an Array and looping though the contents when you want them cloned.

//put a Mesh into an Array

var _mesh:Mesh = new Mesh();

var _meshArray:Array = new Array();

_meshArray.push(_mesh);

//looping through the array and using MeshHelper to clone and mirror the meshes

for(var i:int=0;i<_meshArray.length;i++){

  MeshHelper.clone(_meshArray,"mirrorMesh"+i);

  MeshHelper.applyScales(_meshArray,-1,1,1);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2013 May 29, 2013

I load my models in my main BasicView2.as like this:

package  {

  import away3d.containers.*;

          import away3d.controllers.*;

          import away3d.entities.*;

          import away3d.materials.*;

          import away3d.primitives.*;

          import away3d.utils.*;

          import away3d.cameras.*;

          import away3d.loaders.Loader3D;

          import away3d.events.LoaderEvent;

          import away3d.loaders.parsers.Parsers;

          import away3d.lights.*;

          import away3d.materials.lightpickers.StaticLightPicker;

// my models

          import PaintBase;

          import MainBodyBase;

          import PaintInstance;

          import MainBodyInstance;

 

          import flash.display.*;

          import flash.events.*;

          import flash.geom.Vector3D;

          import flash.net.URLRequest;

          [SWF(backgroundColor="#000000", frameRate="60", quality="LOW")]

public class BasicView2 extends MovieClip

          {

 

                    //engine variables

                    private var _view:View3D;

  //scene objects

                    private var _model:PaintBase;

                    private var _model1:MainBodyBase;

                    private var _model2:PaintInstance;

                    private var _model3:MainBodyInstance;

                    private var scene:Scene3D;

                    private var camera:Camera3D;

                    private var cameraController:HoverController;

 

                    //navigation variables

                    private var move:Boolean = false;

                    private var lastPanAngle:Number;

                    private var lastTiltAngle:Number;

                    private var lastMouseX:Number;

                    private var lastMouseY:Number;

 

 

                    //light objects

                    private var light1:DirectionalLight;

                    private var light2:DirectionalLight;

                    private var lightPicker:StaticLightPicker;

 

 

                    /**

                     * Constructor

                     */

                    public function BasicView2()

                    {

                              stage.scaleMode = StageScaleMode.NO_SCALE;

                              stage.align = StageAlign.TOP_LEFT;

 

                              //setup the view

                              _view = new View3D();

 

                              scene = new Scene3D();

 

                              camera = new Camera3D();

 

                              _view.scene = scene;

                              _view.camera = camera;

 

                              Parsers.enableAllBundled();

 

                              cameraController = new HoverController(camera);

                              cameraController.distance = 500;

                              cameraController.minTiltAngle = 0;

                              cameraController.maxTiltAngle = 90;

                              cameraController.panAngle = 45;

                              cameraController.tiltAngle = 20;

 

                              initLights();

                              //setup the camera

                              _view.camera.z = -600;

                              _view.camera.y = 500;

                              _view.camera.lookAt(new Vector3D());

 

                              //setup the scene

                              _model = new PaintBase();

                              _model1 = new MainBodyBase();

                              _model2 = new PaintInstance();

                              _model3 = new MainBodyInstance();

 

                              _view.scene.addChild(_model)

                              _view.scene.addChild(_model1)

                              _view.scene.addChild(_model2)

                              _view.scene.addChild(_model3)

 

                              this.addChild(_view);

                              //setup the render loop

 

                              addEventListener(Event.ENTER_FRAME, _onEnterFrame);

                              stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

                              stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

                              stage.addEventListener(Event.RESIZE, onResize);

                              onResize();

 

                    }

         /**

                     * Initialise the lights

                     */

                    private function initLights():void

                    {

                              light1 = new DirectionalLight();

                              light1.direction = new Vector3D(0, -1, 0);

                              light1.ambient = 0.1;

                              light1.diffuse = 0.7;

 

                              scene.addChild(light1);

 

                              light2 = new DirectionalLight();

                              light2.direction = new Vector3D(0, -1, 0);

                              light2.color = 0x00FFFF;

                              light2.ambient = 0.1;

                              light2.diffuse = 0.7;

 

                              scene.addChild(light2);

 

                              lightPicker = new StaticLightPicker([light1, light2]);

                    }

 

                    private function onLoadError(ev : LoaderEvent) : Boolean

                    {

                              trace('onLoadError');

                              trace('Could not find', ev.url);

                              if (hasEventListener(LoaderEvent.LOAD_ERROR)) {

                                        dispatchEvent(ev);

                                        return true;

                              }

                              else {

                                        return false;

                              }

                    }

                    private function onResourceComplete(ev : Event) : void

                    {

                              trace('onResourceComplete');

                    }

 

                    private function onClickRect(e:MouseEvent):void

                    {

 

                    }

 

                                        /**

                     * Mouse down listener for navigation

                     */

                    private function onDown(event:MouseEvent):void

                    {

                              lastPanAngle = cameraController.panAngle;

                              lastTiltAngle = cameraController.tiltAngle;

                              lastMouseX = stage.mouseX;

                              lastMouseY = stage.mouseY;

                              move = true;

                              stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);

                    }

 

                    /**

                     * Mouse up listener for navigation

                     */

                    private function onUp(event:MouseEvent):void

                    {

                              move = false;

                              stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);

                    }

 

                                        /**

                     * Mouse stage leave listener for navigation

                     */

                    private function onStageMouseLeave(event:Event):void

                    {

                              move = false;

                              stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);

                    }

 

                    /**

                     * render loop

                     */

                    private function _onEnterFrame(e:Event):void

                    {

                              if (move) {

                                        cameraController.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;

                                        cameraController.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;

                              }

 

                              _view.render();

                    }

        

        private function onResize(event:Event = null):voi

        {

                   _view.width = stage.stageWidth;

                   _view.height = stage.stageHeight;

        }

        

     }

}

You suggest that I put all my models (the ones to mirror: [PaintInstance, MainBodyInstance]) in an Array, or all the meshes that are inside each model inside an Array(PaintInstance: [Hood_Cover, sideclosures_mainbodytop, extmirror_bodypart_i, fender_bodypart, frontdoor_body, sidemoldingpart_i, sidemoldingpart_ii, frontdoor_doorhandlepart_i, frontdoor_doorhandlepart_ii])?

This will make all the meshes inside each model (model PaintInstance, and model MainBodyInstance) to mirror? Where should I code this then, in my main BasicView2.as? inside:

public class BasicView2 extends MovieClip

     {

           public function BasicView2()

           {

                 var _mesh:Mesh=new Mesh();

                  var -meshArray:Array= new Array ();

                  _meshArray.push(_mesh);

          

                 for(var i:int=0; i<_meshArray.lenght; i++) {

                               MeshHelper.clone(_meshArray, PaintInstance + i);

                               MeshHelper.applyScales(_meshArray, -1,1,1);

                 }

or should I write the above inside PaintInstance.as (inside each and every model I import to my main BasicView2.as)?:

package

{

          import ASBase;

          import away3d.containers.ObjectContainer3D;

          import away3d.entities.Mesh;

          import away3d.core.base.Geometry;

          import away3d.materials.MaterialBase;

          import away3d.core.base.Geometry;

          import away3d.materials.ColorMaterial;

          import data.Hood_coverData;

          import flash.display.Bitmap;

          import data.Sideclosures_mainbodytopData;

          import data.Extmirror_bodypart_iData;

          import data.Fender_bodypartData;

          import data.Frontdoor_bodyData;

          import data.Sidemoldingpart_iData;

          import data.Sidemoldingpart_iiData;

          import data.Frontdoor_doorhandlepart_iData;

          import data.Frontdoor_doorhandlepart_iiData;

          public class PaintInstance extends ASBase

          {

                    function PaintInstance ():void

                    {

                              super();

                              buildMaterials();

                              generate();

                    }

                    private function generate():void

                    {

                              var cont_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var cont:ObjectContainer3D = buildContainer( cont_rd, "cont", null);

                              var hood_coverData:Hood_coverData = new Hood_coverData();

                              var geomhood_cover:Geometry = hood_coverData.geometryData;

                              var hood_cover_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var hood_cover:Mesh = buildMesh(geomhood_cover, hood_cover_rd, "hood_cover", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              hood_cover.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var sideclosures_mainbodytopData:Sideclosures_mainbodytopData = new Sideclosures_mainbodytopData();

                              var geomsideclosures_mainbodytop:Geometry = sideclosures_mainbodytopData.geometryData;

                              var sideclosures_mainbodytop_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var sideclosures_mainbodytop:Mesh = buildMesh(geomsideclosures_mainbodytop, sideclosures_mainbodytop_rd, "sideclosures_mainbodytop", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              sideclosures_mainbodytop.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var extmirror_bodypart_iData:Extmirror_bodypart_iData = new Extmirror_bodypart_iData();

                              var geomextmirror_bodypart_i:Geometry = extmirror_bodypart_iData.geometryData;

                              var extmirror_bodypart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var extmirror_bodypart_i:Mesh = buildMesh(geomextmirror_bodypart_i, extmirror_bodypart_i_rd, "extmirror_bodypart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              extmirror_bodypart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var fender_bodypartData:Fender_bodypartData = new Fender_bodypartData();

                              var geomfender_bodypart:Geometry = fender_bodypartData.geometryData;

                              var fender_bodypart_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var fender_bodypart:Mesh = buildMesh(geomfender_bodypart, fender_bodypart_rd, "fender_bodypart", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              fender_bodypart.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var frontdoor_bodyData:Frontdoor_bodyData = new Frontdoor_bodyData();

                              var geomfrontdoor_body:Geometry = frontdoor_bodyData.geometryData;

                              var frontdoor_body_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var frontdoor_body:Mesh = buildMesh(geomfrontdoor_body, frontdoor_body_rd, "frontdoor_body", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              frontdoor_body.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var sidemoldingpart_iData:Sidemoldingpart_iData = new Sidemoldingpart_iData();

                              var geomsidemoldingpart_i:Geometry = sidemoldingpart_iData.geometryData;

                              var sidemoldingpart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var sidemoldingpart_i:Mesh = buildMesh(geomsidemoldingpart_i, sidemoldingpart_i_rd, "sidemoldingpart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              sidemoldingpart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var sidemoldingpart_iiData:Sidemoldingpart_iiData = new Sidemoldingpart_iiData();

                              var geomsidemoldingpart_ii:Geometry = sidemoldingpart_iiData.geometryData;

                              var sidemoldingpart_ii_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var sidemoldingpart_ii:Mesh = buildMesh(geomsidemoldingpart_ii, sidemoldingpart_ii_rd, "sidemoldingpart_ii", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              sidemoldingpart_ii.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var frontdoor_doorhandlepart_iData:Frontdoor_doorhandlepart_iData = new Frontdoor_doorhandlepart_iData();

                              var geomfrontdoor_doorhandlepart_i:Geometry = frontdoor_doorhandlepart_iData.geometryData;

                              var frontdoor_doorhandlepart_i_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var frontdoor_doorhandlepart_i:Mesh = buildMesh(geomfrontdoor_doorhandlepart_i, frontdoor_doorhandlepart_i_rd, "frontdoor_doorhandlepart_i", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              frontdoor_doorhandlepart_i.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                              var frontdoor_doorhandlepart_iiData:Frontdoor_doorhandlepart_iiData = new Frontdoor_doorhandlepart_iiData();

                              var geomfrontdoor_doorhandlepart_ii:Geometry = frontdoor_doorhandlepart_iiData.geometryData;

                              var frontdoor_doorhandlepart_ii_rd:Vector.<Number> = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);

                              var frontdoor_doorhandlepart_ii:Mesh = buildMesh(geomfrontdoor_doorhandlepart_ii, frontdoor_doorhandlepart_ii_rd, "frontdoor_doorhandlepart_ii", getMaterialFromID("FrontDoor_DoorHandlePart_II0"), cont);

                              frontdoor_doorhandlepart_ii.subMeshes[0].material = getMaterialFromID("FrontDoor_DoorHandlePart_II0");

                    }

                    private function buildMaterials():void

                    {

                              var material:MaterialBase;

                              material = generateMaterial("FrontDoor_DoorHandlePart_II0", 0xFF0000);

                              ColorMaterial(material).alpha = 1;

                              ColorMaterial(material).ambientColor = 0x0;

                              ColorMaterial(material).specularColor = 0x0;

                              ColorMaterial(material).specular = 0;

 

                    }

          }

}

Sorry, this is so confusing for me. Thanks a lot for your pacience

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 29, 2013 May 29, 2013
LATEST

Too much code 😉

Sorry if I gave you a wrong impression, I am neither an Expert in Away3D nor with Prefab3D. These frameworks are in my opinion too bad documented/too little used to be easy accessible without a solid understanding of how to program in a object oriented way. Imo you will have a better chance to find answers on the forums that deal with this special combination.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines