This site is optimised for Firefox 2.0 or Internet Explorer 7.

lee's Papervision3D tutorial

User avatar
easypony
 
Post Count: 97
Joined: Mon Mar 13, 2006 12:18 pm

lee's Papervision3D tutorial

Postby easypony on Sun Sep 23, 2007 6:38 pm

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
Attachments
random3D_viewer.zip
(229.1 KiB) Downloaded 555 times

ethernal has no avatar
ethernal
 
Post Count: 25
Joined: Sun Jan 07, 2007 10:29 pm
Location: Cordoba, Spain

Re: lee's Papervision3D tutorial

Postby ethernal on Sun Sep 23, 2007 8:52 pm

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?

User avatar
AlfonsoM
 
Post Count: 256
Joined: Tue Mar 14, 2006 6:56 am
Location: Los Angeles California
Flash Version: Adobe Flash CS3

Re: lee's Papervision3D tutorial

Postby AlfonsoM on Mon Sep 24, 2007 5:59 pm

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
to know wisdom and instruction; to recognize the words of understanding; to receive the instruction of wisdom, justice, and judgment, and uprightness; to give sense to the simple, knowledge and judgment to the young man
Proverbs 1: 1-4

User avatar
AlfonsoM
 
Post Count: 256
Joined: Tue Mar 14, 2006 6:56 am
Location: Los Angeles California
Flash Version: Adobe Flash CS3

Re: lee's Papervision3D tutorial

Postby AlfonsoM on Mon Sep 24, 2007 6:03 pm

one more thing change the addeventlistener

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


hope it works! :D
to know wisdom and instruction; to recognize the words of understanding; to receive the instruction of wisdom, justice, and judgment, and uprightness; to give sense to the simple, knowledge and judgment to the young man
Proverbs 1: 1-4

User avatar
easypony
 
Post Count: 97
Joined: Mon Mar 13, 2006 12:18 pm

Re: lee's Papervision3D tutorial

Postby easypony on Tue Sep 25, 2007 2:40 pm

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

User avatar
nebutch
Site Admin
 
Post Count: 3395
Joined: Wed Apr 05, 2006 12:36 am
Location: Earth, Milky Way
Flash Version: Adobe Flash CS4

Re: lee's Papervision3D tutorial

Postby nebutch on Tue Sep 25, 2007 3:47 pm

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...
Trust me, I know what I'm doing...

Image

Did this post help? If so, please consider a donation! Just click the "Donate" link at the top-right of this page.

surferdudenate has no avatar
surferdudenate
 
Post Count: 77
Joined: Mon Feb 12, 2007 10:40 pm

Re: lee's Papervision3D tutorial

Postby surferdudenate on Fri Sep 28, 2007 8:32 pm

look at the papercloud example provided by carlos along with his api. he adds click functionallity there.

Zogan has no avatar
Zogan
 
Post Count: 1
Joined: Fri Oct 05, 2007 10:04 pm

Re: lee's Papervision3D tutorial

Postby Zogan on Fri Oct 05, 2007 10:40 pm

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?

Ozren has no avatar
Ozren
 
Post Count: 11
Joined: Sat Oct 13, 2007 11:13 am

Re: lee's Papervision3D tutorial

Postby Ozren on Sat Oct 13, 2007 11:15 am

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.

Ozren has no avatar
Ozren
 
Post Count: 11
Joined: Sat Oct 13, 2007 11:13 am

Re: lee's Papervision3D tutorial

Postby Ozren on Sat Oct 13, 2007 11:22 am

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});

}


Return to Actionscript 3.0

Who is online

Users browsing this forum: Kirone and 4 guests