Dae Interaction

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dae Interaction

ericcat
hi,

I've built a cube from 3dmax and export it as .dae.
And then I try to add an click event on it, but it doesn't work..

package {
        import flash.display.Sprite;
        import flash.events.Event;
        import org.papervision3d.view.Viewport3D;
        import org.papervision3d.scenes.Scene3D;
        import org.papervision3d.cameras.Camera3D;
        import org.papervision3d.objects.parsers.DAE;
        import org.papervision3d.events.InteractiveScene3DEvent;
        import org.papervision3d.render.BasicRenderEngine;

        public class test2 extends Sprite {

        private var viewport:Viewport3D;
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var cube:DAE;
        private var renderer:BasicRenderEngine;

        public function test2():void {
                init();
        }
        public function init() {
                viewport = new Viewport3D(550, 400, false, true);
                addChild(viewport);
                scene = new Scene3D();
                camera = new Camera3D();
                renderer = new BasicRenderEngine();

                cube=new DAE();
                cube.load("collada.dae");
                scene.addChild(cube);
                cube.addEventListener(Event.COMPLETE, completeHandler);

                addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        public function completeHandler( e:Event ):void {
        cube.getChildByName("Box01").addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, onClick );
        }
        public function onClick(evt:InteractiveScene3DEvent):void {
                trace("Hello");
        }
        public function onEnterFrame(e:Event):void {
                cube.rotationY+=2;
                renderer.renderScene(scene, camera, viewport);
        }
        }
}

It can show my cube, and there is no error message.
But there is no respond when I click the cube.

Can anyone help me?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Dae Interaction

Tim Knip-2
Hi,

You need to use an 'interactive material' for your cube.

First get the material-name you gave the cube in your 3D-modelling-app.
(Or look at the @symbol attribute of the <instance_material> elements
in the file).

Ok, lets assume the Box's material was named 'Default', then do something like :

Do this in your FileLoadEvent.LOAD_COMPLETE handler.

// create some material
var material : MaterialObject3D = ...

// make interactive!
material.interactive = true;

// now replace the 'loaded' material with your custom material
myDAE.replaceMaterialByName( material, "Default" );

Or alternatively:

// create some interactive material
var material : MaterialObject3D = ....
material.interactive = true;

// add it to a materials list
var materials : MaterialsList = new MaterialsList();
materials.addMaterial( material, "Default" );

var dae : DAE = new DAE();

// pass materials-list as second parameter to DAE#load
dae.load( "path/to/dae", materials );

Hope this helps!
Tim

2008/6/28 ericcat <[hidden email]>:

>
> hi,
>
> I've built a cube from 3dmax and export it as .dae.
> And then I try to add an click event on it, but it doesn't work..
>
> package {
>        import flash.display.Sprite;
>        import flash.events.Event;
>        import org.papervision3d.view.Viewport3D;
>        import org.papervision3d.scenes.Scene3D;
>        import org.papervision3d.cameras.Camera3D;
>        import org.papervision3d.objects.parsers.DAE;
>        import org.papervision3d.events.InteractiveScene3DEvent;
>        import org.papervision3d.render.BasicRenderEngine;
>
>        public class test2 extends Sprite {
>
>        private var viewport:Viewport3D;
>        private var scene:Scene3D;
>        private var camera:Camera3D;
>        private var cube:DAE;
>        private var renderer:BasicRenderEngine;
>
>        public function test2():void {
>                init();
>        }
>        public function init() {
>                viewport = new Viewport3D(550, 400, false, true);
>                addChild(viewport);
>                scene = new Scene3D();
>                camera = new Camera3D();
>                renderer = new BasicRenderEngine();
>
>                cube=new DAE();
>                cube.load("collada.dae");
>                scene.addChild(cube);
>                cube.addEventListener(Event.COMPLETE, completeHandler);
>
>                addEventListener(Event.ENTER_FRAME, onEnterFrame);
>        }
>        public function completeHandler( e:Event ):void {
>        cube.getChildByName("Box01").addEventListener(
> InteractiveScene3DEvent.OBJECT_CLICK, onClick );
>        }
>        public function onClick(evt:InteractiveScene3DEvent):void {
>                trace("Hello");
>        }
>        public function onEnterFrame(e:Event):void {
>                cube.rotationY+=2;
>                renderer.renderScene(scene, camera, viewport);
>        }
>        }
> }
>
> It can show my cube, and there is no error message.
> But there is no respond when I click the cube.
>
> Can anyone help me?
>
> Thanks.
> --
> View this message in context: http://www.nabble.com/Dae-Interaction-tp18170487p18170487.html
> Sent from the Papervision3D mailing list archive at Nabble.com.
>
>
> _______________________________________________
> Papervision3D mailing list
> [hidden email]
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>

_______________________________________________
Papervision3D mailing list
[hidden email]
http://osflash.org/mailman/listinfo/papervision3d_osflash.org
Reply | Threaded
Open this post in threaded view
|

Re: Dae Interaction

ericcat
ya, it works.

Thanks alot
Reply | Threaded
Open this post in threaded view
|

Re: Dae Interaction

KieranD
This post has NOT been accepted by the mailing list yet.
Hey guys, thanks so much for this post. However I have what seems like a small error.
I can also see the DAE model when compiled, but the click will nit return a trace.
Can anyone please help?
DAE model is called : MaxJug2.DAE
The texture for this model is called : JugTexture.jpg

Here is the code:

package  {
       
        import flash.display.Sprite;
       
        import flash.events.Event;
        import org.papervision3d.events.FileLoadEvent;
        import org.papervision3d.objects.DisplayObject3D;
        import org.papervision3d.objects.parsers.DAE;
        import org.papervision3d.view.BasicView;
       
        import org.papervision3d.events.InteractiveScene3DEvent;
        import org.papervision3d.view.Viewport3D;
        import org.papervision3d.scenes.Scene3D;
        import org.papervision3d.render.BasicRenderEngine;
        import org.papervision3d.cameras.Camera3D;
        import org.papervision3d.core.proto.MaterialObject3D;
        import org.papervision3d.materials.utils.MaterialsList;
       
        public class clicktest extends Sprite
        {
               
                private var viewport:Viewport3D;
                private var scene:Scene3D;
                private var camera:Camera3D;
                private var model:DisplayObject3D;
                private var renderer:BasicRenderEngine;
               
               
                public function clicktest() {
                       
                        stage.frameRate = 40;
                       
                        init();
                       
                }
               
                       
                        private function init():void
                {
                       
                        viewport = new Viewport3D(550, 400, false, true);
            addChild(viewport);
            scene = new Scene3D();
            camera = new Camera3D();
            renderer = new BasicRenderEngine();
                       
                       
                       
                        //import model
                        model = new DAE();
                        model.addEventListener(Event.COMPLETE, completeHandler);
                        DAE(model).load("MaxJug2.DAE");
                        scene.addChild(model);
                        //model.scale = 2;
                       
                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
                       
                }
               
                public function completeHandler( e:Event ):void {
                       
        model.getChildByName("Box01").addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, onClick );
               
                // create some interactive material
                var material : MaterialObject3D =
                material.interactive = true;
               
                // add it to a materials list
                var materials : MaterialsList = new MaterialsList();
                materials.addMaterial( material, "JugTexture.jpg" );
               
                var dae : DAE = new DAE();
               
                // pass materials-list as second parameter to DAE#load
                dae.load( "MaxJug2.DAE", materials );
               
        }
               
                public function onClick(evt:InteractiveScene3DEvent):void
                {
                trace("clicked");
        }
               
                public function onEnterFrame(e:Event):void {
                model.rotationY+=2;
                renderer.renderScene(scene, camera, viewport);
        }
                }
        }

Thanks once again for this post, I hope someone could point out the problem.

Kieran