This tutorial is designed for Flash Actionscript 3.0 with PV3D 2.0 (GreatWhite) repositries..
Before you begin, please make sure that you have downloaded the necessary PV3D repositries
from the SVN. [if you dont know how to this, then please check step 1 AND step 4 in this tutorial]
If you have already done this then please read on!
first off, we will create an empty .FLA file (this will allow us to read the .as file we will make
and will help us run it!)
File > New (ctrl+N)
select Flash File (Actionscript3) and click ok.
Now save that under whatever name you like.
Now we need to create an Actionscript file (.as)
File > new (Ctrl+N)
select Actionscript File and click ok.
Now save this using whatever name you like – I will call it Example.as
It is in this example.as file where we will write our code. but first we need to link
it to the .FLA file we made earlier.
click on the tab to open your .FLA file and look near the bottom of your screen, in the
properties tab, for something called Document Class in the text box to the right of it, enter
your .as file name – in this case example and click on the little pencil icon to scan for the file.
now that the files are linked we can compile and run our actionscript when we need to test
out our video.
now for the code – put this in you .as file:
package{ import org.papervision3d.objects.primitives.*; import org.papervision3d.view.BasicView; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.utils.MaterialsList; //For importing objects import org.papervision3d.objects.parsers.DAE; import org.papervision3d.objects.DisplayObject3D; [SWF(width="640", height="320", backgroundColor="#000000", frameRate="60")] public class Example extends BasicView { //private var myMaterials:Object; public function Example() { var sphere:Sphere = new Sphere(); sphere.x = 150; scene.addChild(sphere); //text output in debuger window to see if code //is going through loop trace("DRAW sphere"); var plane:Plane = new Plane(); plane.x = -150; scene.addChild(plane); trace("DRAW plane"); var cylinder:Cylinder = new Cylinder(); scene.addChild(cylinder); trace("DRAW cylinder"); startRendering(); } } }
Now to test what we have written, press ctrl+enter key and wait for the results!
For a 3D cube, add the following code, before “startRendering()”
//FOR 3D CUBE //code for material - more will be covered on this later var frontMaterial:WireframeMaterial = new WireframeMaterial(); var backMaterial:WireframeMaterial = new WireframeMaterial(); var leftMaterial:WireframeMaterial = new WireframeMaterial(); var rightMaterial:WireframeMaterial = new WireframeMaterial(); var topMaterial:WireframeMaterial = new WireframeMaterial(); var bottomMaterial:WireframeMaterial = new WireframeMaterial(); var materialsList:MaterialsList = new MaterialsList(); materialsList.addMaterial(frontMaterial, "front"); materialsList.addMaterial(backMaterial, "back"); materialsList.addMaterial(leftMaterial, "left"); materialsList.addMaterial(rightMaterial, "right"); materialsList.addMaterial(topMaterial, "top"); materialsList.addMaterial(bottomMaterial, "bottom"); var cube:Cube = new Cube(materialsList); //cube.x = 100; //need to rotate cube, otherwise it will look like a Plane. cube.rotationY = 45; cube.rotationX = 45; scene.addChild(cube); //END 3D Cube
A tutorial for loading in 3D objects made in a 3D package such as Max can be found here
Hi,
I have followed the steps above but when I press ctrl+enter the swf file is blank!! Nothing happens!!
Do I need to add anything to the fla file?
Cheers
mane_uk
Make sure you have these checks in place:
1 – Have you made sure that you have linked the .as file to the .fla file correctly?
2 – Have you pointed Flash to the Papervision Directory (i.e. where all the papervision classes are stored?) follow this tutorial http://thierryzoghbi.co.uk/blog/2009/02/how-to-install-and-use-papervision3d-and-collada-tutorial/
3 – are you using BasicView to Render the scene?
Make sure you have followed the steps above exactly, if you need more help let me know.
Hi
Tried your tutorial here and got the following errors:
1017: The definition of base class BasicView was not found.
5000: The class ‘Example’ must subclass ‘flash.display.MovieClip’ since it is linked to a library symbol of that type.
Used Extension Manager for PV3DComponents_v1.5.1.mxp …I’m using CS4 is that the issue?
For the first error have you made sure you have imported the BasicView class?
import org.papervision3d.view.BasicView;
For your second error, im not sure whats going on there, since my code has not used MovieClip – if you have flash.display.MovieClip imported, try removing it and see what happens.
If you have same material that you want for all your sides you can use:
var myMaterial:SomeMaterial…
var cube:Cube = new Cube( {all:myMaterial} );
Im having the same problems as ‘Proto’
I have imported the BasicViewClass;
“package {
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
//For importing objects…”
and i believe the second problem is just exampling a subclass. Basically ‘Example’ needs a ‘SubClass’.
your help much appreciated
Hi! i am new to ppv3d and i am now with a problem, hope you can help.
i created an 3D pyramid, it already rotates and have different colors on each side so it looks more “3D”.
The problem now is I wanted to divide the pyramid (not physically) but with a line (or lines). like this:
/\
/ \
/ \
/______\
to this (50% of height):
/\
/__\
/ \
/______\
the idea is to divide the pyramid in x parts (not equal). i don’t need you to “write” the code to do this (divide is x parts) but if you can explain just how can I divide the pyramid (like: i want a horizontal line at 50% of height or if it has height of 500 i can say “horizontal line at 100 of the 500).
sorry if this is bad written 😛
hope you can help, many thanks!
To people having a blank scene:
Make sure that your .fla and .as names are the same as the class defined in the .as file. E.g. ” public class Example extends BasicView {” then call your file “Example.as” and “Example.fla” otherwise you won’t see anything.
Trust me, this had me tripping up for ages!