Code contains explanations ..
// import the necessary files..
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
//dictionary objects holds objects as key
var planebycontainer:Dictionary=new Dictionary();
var container:MovieClip=new MovieClip();
container.x=stage.stageWidth*0.5;
container.y=stage.stageHeight*0.5;
addChild(container);
this.frameRate=40;
//creating scene basic for papervision; among multiple scenes Scene3D is basic one
var scene:Scene3D=new MovieScene3D(container);
//camera to see objects
var camera:Camera3D=new Camera3D();
//initial camera zoom is (0,0,0);
//to zoom object into scene..
camera.zoom=10;
//star making planes...
//create material-by attaching bitmap using BitmapAssetMaterial
var bam:BitmapAssetMaterial=new BitmapAssetMaterial("FlashIcon");
//by default material applied to one side of object(here plane);
bam.oneSide=false;
bam.smooth=true;
for (var i:int=0; i<5; i++) {
//new Plane(material,height, width,triangle num,triangle num)---triangle num to control quality
var p:Plane=new Plane(bam,150,75,2,2);
p.x=50*i;//gives value from -500 to 500
p.y=40;
p.z=40*i;
//p.y=Math.random()*1000-500;
//p.z=Math.random()*1000-500;
//p.x=500
p.rotationY=45;//rotate individual
//p.addEventListener(MouseEvent.CLICK,clicker);
scene.addChild(p);
var container2:Sprite = p.container;
//here we have container as key and plane as value later we retrive plane by using container
planebycontainer[container2]=p
container2.buttonMode = true;
//adding event listeners for mouse events
container2.addEventListener( MouseEvent.ROLL_OVER, doRollOver );
container2.addEventListener( MouseEvent.CLICK, clicker );
container2.addEventListener( MouseEvent.ROLL_OUT, doRollOut );
}
scene.renderCamera(camera);
this.addEventListener(Event.ENTER_FRAME,render);
function render(e:Event) {
//render places object in scene
scene.renderCamera(camera);
}
function doRollOver(evt:MouseEvent) {
var sprit:Sprite=evt.target as Sprite;
sprit.alpha = 0.5;
}
function doRollOut(evt:MouseEvent) {
var sprit:Sprite=evt.target as Sprite;
sprit.alpha = 1;
}
function clicker(evt:MouseEvent) {
//here we retrieve the plane which is clicked
var sprit:Sprite=evt.target as Sprite;
var p:Plane=planebycontainer[sprit]
trace(p)
}
Basic papervision example
4 comments:
Thank you so much! i was tearing my hair out how to do event handlers on individual planes. Thanks again!
Hi,
I run you example perfectly, but when trying to merge it into my project I get a problem:
If I trace p.container, I always get a null value. I don't get that sprite object for the Plane, for some reason...
Why might this be?? I have changed my scene to MovieScene3D...
HI,
The Scene3D class lets you create a scene where all objects are rendered in the same container.
But this is not case of MovieScene3D
tell me what u want to do...
if u paste ur code i can help u...
:)
this blog may be helpful , but ads are killing it..
p.s. sorry for my english..
Post a Comment