Papervision 3d start-up your template first tutorial

Start from this post a series of tutorials that will lead to a complete Flash templates Papervision 3d Action Script 3. Come back and visit this blog to follow the development of the project. To complete these tutorials requirements: be in possession of the Adobe Flash (at least version CS3), download the Papervision, notions of Action Script 3.
Demo
1) Download Papervision 3d
First you download the Papervision. If you had problems trying to follow some of the few online tutorials that are based on the development of a scene, the compiler output indicates a number of errors that prevent the application from working.
This is the fact that many of these basic tutorials were made with the first version of Papervision, the second review called The Great White 2.0 has undergone a number of interesting improvements, many functions have been eliminated and integrated into other functions. You will then try to run a script made the first revision while you have downloaded and you are using the latest version.
Download latest Papervision 3d stuff
2) Import Packages
Whenever you create a scene or better AS3 Papervision the first thing to do is instantiate whole series of functions (packages) that allow you to communicate with Flash to enable a 3D scene and the necessary components AS3.
import flash.display.Sprite; import flash.events.Event; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import org.papervision3d.cameras.Camera3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.materials.*; import org.papervision3d.objects.primitives.Plane; 3) Main Class
Begin to write our function, defining the class:
public class Pv3d_Tut_1 extends Sprite { private var scene:Scene3D; private var renderer:BasicRenderEngine; private var viewport:Viewport3D; private var camera:Camera3D; private var plane1:Plane; public function Pv3d_Tut_1() { init(); } } 4) Init function (created Pv3d stuff)
Define function init () which will be the container of our scene with its main
private function init():void { viewport=new Viewport3D(stage.stageWidth,stage.stageHeight,false,true); scene=new Scene3D ; renderer=new BasicRenderEngine ; camera=new Camera3D ; camera.zoom=8; camera.focus=100; addChild(viewport); initObjects(); addEventListener(Event.ENTER_FRAME,render,false,0,true); } 5) initObjects ()
Define the function initObjects (), in which objects are created and materials in the scene. Add a simple plan to our stage. This plan will be a MovieClip object, within which we can then of course call an external file, attach buttons and actions etc ... In this case I simply added a text.
private function initObjects():void { var material_mc:MovieAssetMaterial=new MovieAssetMaterial("mc_1"); material_mc.smooth=true; plane1=new Plane(material_mc,500,500,4,4); scene.addChild(plane1); } 6) Render function
And our rendering function:
private function render(event:Event):void { camera.target=plane1; renderer.renderScene(scene,camera,viewport); } I honestly do not seem so clear at this point the potential to Papervision.
We add to our function to render a few lines of code thanks to which the moving scene is related to the distance of the mouse on the size of the stage.
camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)- camera.x )*.05; camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05; 7) Full Class
package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import org.papervision3d.cameras.Camera3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.materials.*; import org.papervision3d.objects.primitives.Plane; public class Pv3d_Tut_1 extends Sprite { private var scene:Scene3D; private var renderer:BasicRenderEngine; private var viewport:Viewport3D; private var camera:Camera3D; private var plane1:Plane; public function Pv3d_Tut_1() { init(); } private function init():void { viewport=new Viewport3D(stage.stageWidth,stage.stageHeight,false,true); scene=new Scene3D ; renderer=new BasicRenderEngine ; camera=new Camera3D ; camera.zoom=8; camera.focus=100; addChild(viewport); initObjects(); addEventListener(Event.ENTER_FRAME,render,false,0,true); } private function initObjects():void { var material_mc:MovieAssetMaterial=new MovieAssetMaterial("mc_1"); material_mc.smooth=true; plane1=new Plane(material_mc,500,500,4,4); scene.addChild(plane1); } private function render(event:Event):void { camera.x += (((stage.mouseX-(stage.stageWidth * .5))*2)- camera.x )*.05; camera.y += (((stage.mouseY-(stage.stageHeight*.5))*2)-camera.y )*.05; camera.target=plane1; renderer.renderScene(scene,camera,viewport); } } } There you can see how we instantiated our symbol and we have successfully given birth to our first scene basis, usually named "Hello World".
Conclusion & downloads
Warning! As you will see the function builder is empty. Call it the init () function, which in turn refers to the function initObjects ();. This step is not necessary. I prefer to proceed in this way both to visual order, for both modularity in the development of future applications, both because it leaves the manufacturer empty function will resolve many problems that will arise later when we try to draw a class Papervison by preloading or as external swf. We will discuss later in this blog.





Comments
Nik
February 12, 2009
You are an animal! Mò .. well you get to do the tutorials? beautiful David!
Mattia
February 26, 2009
Hello my name is Matthias. Congratulations on the tutorial, everything is very clear.
I wanted to ask but ... if I wanted to use as textures for the plane a movieclip that contains buttons and actions ... how do I make it functional?
Thanks chau!
David
February 26, 2009
Hello Matthias, the files of the next post in this series are ready ... and discuss how to make their own interactive materials in Papervision3D, whether they are bitmap, which movieclip simple or animated, or external movieclip loaded at runtime.
I think being able to publish all next week. If you have extreme urgency for a commercial project, send me an email, otherwise we update soon on these pages.
daniele
March 6, 2009
They happened to be on your site (looking for an old version of pv3d in AS2)
I have to say you did a really good job and also your plans are really beautiful.
I'll still praise, waiting for the next tutorial pv3d.
:)
Papervision 3d Interactive Scene3DEvent first template tutorial
March 8, 2009
[...] Papervision 3d start-up your template first tutorial [...]
dino Roselli
March 14, 2009
Hello David, very good, even in the graphic style! is a good place to understand how aprtenza Papervision3D .... Thank you so much dino:)
dino r
March 14, 2009
When you export fla, my swf is empty why? Movie clips mc_1 that appears empty is called, or rather when I export my many mistakes. ...
David
March 14, 2009
You're talking about the tutorial files?
You papervision package at the same level. Fla file? Otherwise I can not find the library ... is the first tutorial.
dino
March 15, 2009
yes, I open the fla, export it gave me errors in the compilation.
David
March 15, 2009
Try to re-download the package Pv3d now, I had forgotten to insert a file ;-)
Papervision 3d Interactive Scene Template
May 22, 2009
[...] Papervision 3d start-up your template first tutorial [...]
Johnny
May 27, 2009
Hello David ... pardon the intrusion but I have a question from ports ...
I am developing an RIA for sharing media in Flex 3 and I'm adding a few hits on "browse" the contents of your media collection, including a CoverFlow view ... the component and 'amplifying a ViewStack based Papervision3D developed by other ...
The object already has its own camera3D, but the inner application resize event is not 'editable and / or accessible ... how can I add a camera3D to create a zoom effect on resize application?
The object described in the tutorial and 'stand-alone "? Or rather, I can apply to any 3D object to the entire main application?
Thanks in advance ...
Johnny
David
May 27, 2009
Hello J,
so I can not tell what the problem, and sincerametne not understand you when you say "zoom effect on resize. On resize defines comportamenteo browser. Certainly the class of functions that CoverFlow will "clash" with your duties.
But if you create a new room and shoot the scene with that, bypassing the class room?
hello
D
Johnny
May 28, 2009
You're right ... it was not very clear (yet spraticone Flex), but your final answer is' just what I wanted to hear me say ... so I assume that your code seems appropriate for what I should do, right?
Always thx in adv.
Johnny
David
May 28, 2009
You can create as many rooms as you want. Let us know!
hello
D
Alessia
June 6, 2009
hello david. through the tutorial and files, very nice!
premise that is a goat with flash and maybe I'm embarking on a company bigger than me, I have a question to ask: if I want to replace the plan exported from a simple object in Cinema4D. dae, how do I?
in fact my knowledge of action script verging on zero, I apologize if my question were found to be misplaced. thanks
David
June 8, 2009
Hello A
if you have a few days of patience just do a new tutorial on how to import 3D models from the cinema 4d ... proxima week! ;)
alessia
June 9, 2009
fantastic ... thanks!
Luke
August 18, 2009
Hello, I tried to replace mc_1 with my mc (text made by a logo with transparent background), but when the public is always swf with the black background, whatever the background of my scena.Come can replace the background that will my animated clip with Papervision3D?
thanks, congratulations!
Hello
Mamba
August 21, 2009
What can I say ... great tutorial!
Hello David, congratulations ...
I wanted to know how can I remove the black background to the text ... I tried to put it at 0% .. but nothing.
Basically if I change the background color (eg red) change it .. but if I put it to 0% will go black ..
What's wrong?
PS
The beginner:-D
David
August 23, 2009
Hello,
Have you tried to look at this tut?
http://davidsalvatori.com/papervision-3d-interactive-scene3devent-template-tutorial/
Mamba
August 24, 2009
Hello David, thanks for the reply.
I had seen that tutorial and downloaded the example ... but even there I get the black background with the animation of the first tutorial .. I do not understand what mistake ... I might download something else?
David
August 24, 2009
Put it this way:
var material_mc1: MovieAssetMaterial = new MovieAssetMaterial (mc_1 ", true);
or ... it is true that the material is transparent
me sap
hello
d
Mamba
August 24, 2009
Perfect!! You are a great!
but in practice - true - indicates that the MC should be transparent?
is
May 21, 2010
hello david, thanks for tutorials ...
Question: If I have a file instead. dae which is an animation of about 66 items, I can manage how the plan linking the movement to mouse movement??
max when I export the file. dae, tells me that transforms light of the scene (skylight) in a point light, it changes the illumination of the scene??
sorry ...
not to get mad ...
David
May 22, 2010
Hello,
example is the moving camera and not the plan, then you have problems, just remember that the maximum number of polygons has suggested 1500 or 3000 triangles (pv3d working with triangulations).
I do not work with Max, but the point light are the lights Pv3d (papervision3d.lights.PointLight3D), then I would say that it's okay ;-)
is
May 22, 2010
thanks for being fast in replying ...
so if you move the camera which is linked to mouse movement and not the object around me is easier ...
application for a poor ignorant: I work with CS4, which releases Pv3d should I install??
thanks so much for your wonderful work you
is
May 22, 2010
without my reply I solved by installing ...
miiii because they are ignorant ... ... ... ...
thanks thanks thanks :-)
is
May 23, 2010
help I have a problem, maybe I have so many ....
but how to import a file. DAE flash??
library does not matter.
if I add these strings
import org.papervision3d.objects.Collada;
var solid: DisplayObject3D = new Collada ("prova_1.DAE");
tells me error can not find the definition org.papervision3d.objects: Collada
error call to undefined method collada
David
May 31, 2010
hello Vale
sorry but I had not seen the advertisements .. even if you serve here is the problem
import org.papervision3d.objects.parsers.DAE;
hello
d
is
June 6, 2010
comfortable do not worry, we tried to fiddle with prof a little, and import of parsers we had arrived, but we stopped because I did not receive the file does not load the collada can you tell me if something wrong:
private var _cont: DisplayObject3D DisplayObject3D = new ();
private var dae: DAE = new DAE ();
var dae: DAE = new DAE ();
dae.load (box.DAE ");
dae.addEventListener (FileLoadEvent.LOAD_COMPLETE, loaded ());
)
public function load () (
_cont.addChild (dae);
)
)
is due
David
June 7, 2010
Hello, I would say everything is perfect except that you have not hooked to the container object 3d scene, then you see nothing ;-)
hello
d
Nuccio
June 9, 2010
Your tutorials are very clear and very helpful in my study I am doing on these new 3D worlds.
I tried to do my own processing ciu carry a piece of code:
package
(
import flash.display .*;
etc..
import org.papervision3d.cameras .*;
etc..
public class extends flash.display.Sprite ProvaMondo3D
(
public function ProvaMondo3D ()
(
swfFondo = ProvaMondo3D_swfFondo;
/ / I have a class ProvaMondo3D_swfFondo.as, located in the same folder
/ / ProvaMondo3D. As, making a preload
super ();
bottom = new swfFondo ();
addChild (background);
fondo.cacheAsBitmap = true;
etc.. etc.. etc. etc..
-------
In the FLA file I created a movieclip which, in the Properties window> Class
gave it its name swfFondo and Export in first frame.
However, it does not work as I an error:
The parameter Loader.loadBytes ByteArray () must have a length greater than 0.
at flash.display:: Loader / _loadBytes ()
at flash.display:: Loader / loadBytes ()
at mx.core:: MovieClipLoaderAsset ()
at ProvaMondo3D_swfFondo ()
ProvaMondo3D at ().
Could you help me on how to solve this problem.
Report even the classes used in the code shown above:
package
(
import flash.utils .*;
import mx.core .*;
public class extends ProvaMondo3D_swfFondo mx.core.MovieClipLoaderAsset
(
public function Dasai3D_swfFondo ()
(
dataClass = ProvaMondo3D_swfFondo_dataClass;
super ();
initialWidth = 12000 / 20;
initialHeight = 12000 / 20;
return;
)
public override function get movieClipData (): flash.utils.ByteArray
(
if (bytes == null)
(
flash.utils.ByteArray bytes = (new dataClass ());
)
return bytes;
)
(
bytes = null;
)
public var dataClass: Class;
private static var bytes: flash.utils.ByteArray = null;
)
)
package
(
import mx.core .*;
public class extends ProvaMondo3D_swfFondo_dataClass mx.core.ByteArrayAsset
(
public function ProvaMondo3D_swfFondo_dataClass ()
(
super ();
return;
)
)
)
Hello and thanks
David
June 9, 2010
hello,
without the project to me is a bit hard, from what I write does not come to anything loadBytes, try doing a trace and see what it takes ...
Nuccio
June 10, 2010
Thank you. I will try to tweak the code yet. If I can, I will give a presentable form and, if anything, I'll post.
Hello.
is
June 11, 2010
I finally managed to import the dae, but I move around ...
I'll explain better, my 3d model is a pop-up book for children, then I have various plans that open and close along with the book.
pages of the book are right coordinates, and plans no, moves or rotates them, why??
You place the code:
room = new Camera3D ();
camera.y = 12000;
camera.z = -10000;
camera.x = 7000;
camera.rotationX = 45;
camera.focus = 45;
materialList MaterialsList = new ();
bitmapFileMaterial BitmapFileMaterial = new ();
materialList.addMaterial (bitmapFileMaterial, "all");
book = new Collada ();
libro.load (libro.DAE "materialList);
libro.scale = 1;
libro.x = 0
libro.z = 100;
libro.rotationY = 0;
scene.addChild (book);
libro.addEventListener (FileLoadEvent.LOAD_COMPLETE, onLoadComplete);
is
June 11, 2010
other questions:
When you export from 3D Studio Max dae, I automatically creates a folder "images" containing all the textures, now how do I tell flash to go get the textures in that folder??
because if I insert an image, make an example
materialList MaterialsList = new ();
bitmapFileMaterial = new BitmapFileMaterial (libro.jpg);
materialList.addMaterial (bitmapFileMaterial, "all");
just give me the same texture all over the 3d model ....
David
June 17, 2010
hello, first of all, the path would bitmapFileMaterial = new BitmapFileMaterial (images / libro.jpg);
Anyways if every page should have your texture you have to load many textures as many pages, but I would direttamtne pv3d by creating many materials as bitmap pages and then assign the material to the single object going to sail your model dae ...
eg myCollada.getChildByName ("body"). mytTexture = material;
Nuccio
July 17, 2010
Hello, I downloaded an example that aims to make an interactive dae files. In the example downloaded, the file appears correctly, but his press event does not work. Here are the lines of code used:
CompositeMaterial material = new ();
material.doubleSided = true;
material.interactive = true;
material.addMaterial (new ColorMaterial (0 × 000000, 0.5));
material.addMaterial (new WireframeMaterial (0 × 000000));
materials = new MaterialsList ();
materials.addMaterial (material, "material_0_0");
object = new DAE ();
object.scale = 0.85;
object.load (Cube.dae, materials);
scene.addChild (object);
object.addEventListener (FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
DAELoadComplete private function (e: FileLoadEvent): void
(
trace ("uploaded file");
var child: DisplayObject3D object.getChildByName = ("mesh1", true);
child.addEventListener (InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress);
)
handleObjectPress private function (e: InteractiveScene3DEvent): void
(
trace ("press");
)
Dae file is used as provided by example but I only start the message of the trace command (uploaded files), but the interactivity related event Press. I checked if the file really exists dae reference "mesh1" used by getChildByNam and everything seems correct. Clearly, in the same folder as the file I also added the folders org, nochump and collada.
David
July 17, 2010
hello Nuccio,
At this point the problem is a piece of code that have not reported ... you've verified that the Viewport3D instances when this is set on interactive?
Viewport3D (viewportWidth: Number = 640, viewportHeight: Number = 480, autoScaleToStage: Boolean = false, interactive: Boolean = false, autoClipping: Boolean = true, autoCulling: Boolean = true)
d
Nuccio
July 17, 2010
Hello David,
I checked the settings of the viewport and is as follows:
private var viewport: Viewport3D;
viewport = new Viewport3D ();
viewport.autoScaleToStage = true;
viewport.interactive = true;
addChild (viewport);
The example I downloaded from a website in English ( http://osbo.com/papervision3d/dae/) , where the online version of the author is working properly.
David
July 18, 2010
Hello, I tried to download the file on the fly and even if I do not receive any kind of error, the result seems to be the one in the online (I actually renders all white) ...
How long ago that blog? To me it seems a bit dated, it may be that the version of PV3D used since the last author is another repository? Let me know if anything look better in the coming days.
hello
d