Page 1 of 1

lee's Papervision3D tutorial

PostPosted: Sun Sep 23, 2007 6:38 pm
by easypony
G'day guys

I have been playing around with Lee's tutorial for papervision - very cool!!
Have got it zooming in and out with the mouse wheel and alpha.
But not having much luck with a button press/click.
I can get a click to register but because I think I am out of scope of the loop it only registers the last object. I can get a trace to tell me the number of each object but cannot target it.
Code: Select all
import flash.system.fscommand;
fscommand("fullscreen", "true");
fscommand("allowscale", "false");


import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;


var container:Sprite = new Sprite();
container.x = stage.stageWidth * 0.5;
container.y = stage.stageHeight * 0.5;
container.scaleX = container.scaleY = 2;

addChild(container);
trace(container.scaleX);

var scene:Scene3D = new Scene3D(container);
var camera:Camera3D = new Camera3D();

camera.zoom = 2;

var bam:BitmapAssetMaterial = new BitmapAssetMaterial("surf");

bam.oneSide = false;
bam.smooth = true;

for(var i:uint; i < 50; i++){
   var p:Plane = new Plane(bam, 100, 100, 2, 2);
   scene.addChild(p);
   p.x = Math.random() * 600 - 350;
   p.y = Math.random() * 600 - 350;
   p.z = Math.random() * 600 - 350;
   p.rotationY = Math.random() * 360;
   ["null"+i]addEventListener(MouseEvent.CLICK, clicked);
   trace(["null"+i])
}

function clicked (event:MouseEvent):void {
   trace("clicked= "+["null"+i]);//"this" without the quotes does not work
   }



this.addEventListener(Event.ENTER_FRAME, render);

function render(e:Event):void{
   camera.x = stage.mouseX - (stage.stageWidth * .5);
   camera.y = stage.mouseY - (stage.stageHeight * .5);
   camera.z = stage.mouseY - (stage.stageHeight * .05);
   //trace(container.scaleX);
   scene.renderCamera(camera);
}



Maybe I have to wrap it in another movie clip/sprite but I am not sure how to.
Any ideas?
Have uploaded the swf if you would like to see the zoom. (zip as it is quite large)

easy

Re: lee's Papervision3D tutorial

PostPosted: Sun Sep 23, 2007 8:52 pm
by ethernal
I'll use this post to make a question about the tutorial.

What does the final bunch of traces mean? Is it normal with papervision?

Re: lee's Papervision3D tutorial

PostPosted: Mon Sep 24, 2007 5:59 pm
by AlfonsoM
try this
Code: Select all
var pArray:Array = new Array():

for(var i:uint; i < 50; i++){
   var p:Plane = new Plane(bam, 100, 100, 2, 2);
   p.name = i // just give it a name
   pArray.push(p); // store it in an Array!
   scene.addChild(p);
   p.x = Math.random() * 600 - 350;
   p.y = Math.random() * 600 - 350;
   p.z = Math.random() * 600 - 350;
   p.rotationY = Math.random() * 360;
   ["null"+i]addEventListener(MouseEvent.CLICK, clicked);
   trace(["null"+i])
}

function clicked (event:MouseEvent):void
{
   trace("clicked= "+["null"+i]);//"this" without the quotes does not work
        for(var j:uint; j < 50; j++)
       {
            if (event.target == pArray[j])
               {
                   trace(event.target.name + " was clicked");
                }
       }
}


I got the idea from TODD! :D

Re: lee's Papervision3D tutorial

PostPosted: Mon Sep 24, 2007 6:03 pm
by AlfonsoM
one more thing change the addeventlistener

Code: Select all
p.addEventListener(MouseEvent.CLICK, clicked);


hope it works! :D

Re: lee's Papervision3D tutorial

PostPosted: Tue Sep 25, 2007 2:40 pm
by easypony
Thank you AlfonsoM

I was searching through the classes and came across a name parameter which defaulted to null but could not work out how to incorporate it. I think that is why null showed up in the trace results. Their are a few classes that perform similar tasks and was not sure if I had to import a different class for mouse events.

Now to do something with it!!

Maybe the forum could set aside a section for papervision?

All the best
easy

Re: lee's Papervision3D tutorial

PostPosted: Tue Sep 25, 2007 3:47 pm
by nebutch
easypony wrote:Maybe the forum could set aside a section for papervision?


Well, the problem with that is by the time we create a forum for every aspect of Flash/Flex/AIR and whatnot, we'll have 200 forums to barrel through. While it seems at first like a good way to get "organized", there is a point where too much can be a bad thing. ;)

Also, at this point, there really isn't a lot of demand for it. Of course, that could very well change in the future...

Re: lee's Papervision3D tutorial

PostPosted: Fri Sep 28, 2007 8:32 pm
by surferdudenate
look at the papercloud example provided by carlos along with his api. he adds click functionallity there.

Re: lee's Papervision3D tutorial

PostPosted: Fri Oct 05, 2007 10:40 pm
by Zogan
How did you people get it to work? I have tried to using:

p.addEventListener(MouseEvent.CLICK, buttonPressed);

but the p isnt a sprite and thus doesnt listen to mouse events, or am I geting something wrong? Do any one have a link to a working example?

Re: lee's Papervision3D tutorial

PostPosted: Sat Oct 13, 2007 11:15 am
by Ozren
You have to add the listener to the container not the sprite.

p.container.addEventListener....

and use Dictionary instead of Array, its easyer, but thats your choice.

Re: lee's Papervision3D tutorial

PostPosted: Sat Oct 13, 2007 11:22 am
by Ozren
Here is my part of source, hope it helps.

private var planesContiner:Dictionary = new Dictionary();

private function createMyPlanes():void{
for(var i:int = 0; i<10; i++){
var p:Plane = new Plane(bit,200,200,4,4);
p.x = Math.floor(Math.random()*1000-500);
p.y = Math.floor(Math.random()*1000-500);

scene.addChild(p);

p.container.addEventListener( MouseEvent.CLICK, rollOverObject );

planesContiner[ p.container ] = p;
}
}


// fucntion to grab the plane and do what you want with it
private function rollOverObject(event:MouseEvent):void{

var Myplane:Plane = planesContiner[ event.target ]; //thats the instance of your plane

TweenLite.to(Myplane,0.7,{rotationX:0,rotationY:0});

}