For question 2 above here''s the code I've pieced together from
various examples:

package
{
        import flash.display.*;
        import flash.events.*;
        import fl.controls.Button;

        import away3d.loaders.Obj;
        import away3d.events.LoaderEvent;
        import away3d.loaders.Object3DLoader;
        import away3d.core.base.*;
        import away3d.core.render.*;
        import away3d.cameras.*;
        import away3d.containers.*;
        import away3d.core.utils.*;
        import away3d.lights.*;
        import away3d.materials.*;

        [SWF(backgroundColor="#888888", frameRate="30", quality="LOW",
width="500", height="400")]

        public class Test65 extends Sprite
        {

                private var scene:Scene3D;
                private var camera:HoverCamera3D
                private var view:View3D;
                private var light:DirectionalLight3D;
                private var navigate:Boolean = false;
                private var lastMouseX:Number;
                private var lastMouseY:Number;
                private var lastzoom:Number;
                private var lastMouseYzoom:Number;
                private var lastRotationX:Number;
                private var lastRotationY:Number;
                private var move:Boolean = false;
                private var lastPanAngle:Number;
                private var lastTiltAngle:Number;
                private var cZoom:Number=6;
                public var obj1:Object3DLoader;
                private var obj2:Object3DLoader;
                private var obj3:Object3DLoader;
                private var objtoload:Number;
                private var textBut:Button;

                public function Test65()
                {
                        init();
                }

                private function init():void
                {
                        initEngine();
                        initObjects();
                        initLights();
                        initButton();
                        initListeners();
                }

                private function initEngine():void
                {
                        scene = new Scene3D();
                        camera = new HoverCamera3D({zoom:cZoom, focus:200, 
distance:1500});
                        camera.targetpanangle = camera.panangle = -180;
                        camera.targettiltangle = camera.tiltangle = 15;
                        camera.yfactor = 0.8;

                        view = new View3D({scene:scene, camera:camera});
                        view.x = 300;
                        view.y = 200;
                        addChild( view );
                }

                private function initButton():void
                {
                        textBut=new Button();
                        textBut.label="Change Obj";
                        textBut.toggle=true;
                        textBut.move(20,10);
                        addChild(textBut);
                }

                private function initObjects():void
                {

                var material:BitmapFileMaterial = new 
BitmapFileMaterial("assett/
teapot_1.jpg");
                var material2:BitmapFileMaterial = new 
BitmapFileMaterial("assett/
teapot_2.jpg");
                var material3:BitmapFileMaterial = new 
BitmapFileMaterial("assett/
teapot_3.jpg");
                obj1 = Obj.load("assett/teapot_1.obj", { material:material } );
                obj2 = Obj.load("assett/teapot_2.obj",  {material:material2 } );
                obj3 = Obj.load("assett/teapot_3.obj",  {material:material3 } );
                //obj1.addOnSuccess(onLoaderSuccess);
                //scene.addChild(obj1)

                }

                private function initLights():void
                {
                light = new DirectionalLight3D({x:1, y:1, z:-1, ambient:0.0});
                scene.addChild(light);
                }

                private function initListeners():void
                {
                textBut.addEventListener( MouseEvent.MOUSE_DOWN, 
txtButMouseDown );
                stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
                stage.addEventListener( MouseEvent.MOUSE_UP, onMouseUp );
                addEventListener( Event.ENTER_FRAME, onEnterFrame );
                }

                private function onMouseDown(e:MouseEvent):void

                {
                lastzoom = cZoom;
                lastMouseYzoom = stage.mouseY;
                lastPanAngle = camera.targetpanangle;
                lastMouseX = stage.mouseX;
                move = true;
                }

                private function txtButMouseDown(event:MouseEvent):void
                {
                if(objtoload = 3){objtoload=0}
                objtoload+=1;

                if (objtoload=2) { scene.removeChild(obj1);scene.removeChild
(obj3);scene.addChild(obj2); }
                if (objtoload=3) { scene.removeChild(obj1);scene.removeChild
(obj2);scene.addChild(obj3); }
                if (objtoload=1) { scene.removeChild(obj2);scene.removeChild
(obj3);scene.addChild(obj1); }
                }

                private function onMouseUp(e:MouseEvent):void
                {
                move = false;
                }

                private function onEnterFrame( e:Event ):void
                {
                var cameraSpeed:Number = 0.8;
                if (move)
                {
                camera.targetpanangle = cameraSpeed*(stage.mouseX - lastMouseX) 
+
lastPanAngle;
                cZoom = 0.03*cameraSpeed*(stage.mouseY - lastMouseYzoom) + 
lastzoom;
                        if(cZoom > 8)
                        {
                        cZoom = 7.9;
                        }
                        if(cZoom < 1)
                        {
                        cZoom = 1.1;
                        }
                        camera.zoom=cZoom;
                        camera.hover();
                        scene.updateTime();
                        view.render();
                        }
                }


                private function onResize(event:Event):void
                {
                        view.x = stage.stageWidth / 2;
            view.y = stage.stageHeight / 2;
                }
        }
}

On Apr 23, 9:26 pm, jojo <[email protected]> wrote:
> Hello,
>
> I'm new to oop, flash, and away3d but trying hard reading
> examples,etc ... just can't get mind around certain concepts ...
>
> Couple questions ...
>
> Suppose I read in an exported .obj file (textures come in fine) as
> such:
>
> import away3d.loaders.Obj;
>
> public var obj1:Object3DLoader;
>
> var material:BitmapFileMaterial = new BitmapFileMaterial
> ("bitmap1.jpg");
>
> obj1 = Obj.load("teepot1.obj", { material:material } );
>
> All good to that point ...
>
> 1. How do I get access to mesh vertices to be able to manipulate obj1?
> I know it's mesh.vertices but all examples I've seen just don't make
> sense (not sure the basic setup). Could I get a little extra
> clarification as to where to begin having obj1 in hand?
>
> 2. If I then read in another obj file (which I verified can be read in
> and texture file is ok) how do I switch back and forth displaying one
> or the other?
>
> I've tried:
>
> if (objtoload=2) { scene.addChild(obj2);scene.removeChild(obj1); }
>
> via a button handler but I get the original obj and then a cube of
> some sort with a texture of text saying "Loading Geometry ..." over
> top of original obj ...
>
> using Flash CS4 (demo), away3D 3.3.3, btw
>
> Thanks

Reply via email to