4. Basic Template Usage


Now that you've created you're base template, you'll probably be eager to try it out.

Let's start by simply creating a rotating cone, much like this one:

By using the base class that you created, you can really quickly build this simple example.First, create a new project in FlashDevelop. Call it "ConeExample" or something similar.Go to "Project > Properties..." and type "cone.swf" into the Output File field. Under the Classpaths tab, you need to add two classpaths this time.Firstly in the classpaths tab, click Add Classpath... Navigate to your GreatWhite source code directory and click OK

Now we need to add our template to the project. Click on "Add Classpath..." again, and this time go into the directory where you saved your base template. This will probably be "My Documents/PaperBase", if you called the project the same name as mine. Find the folder that contains PaperBase.as and click OK.

We now need to create the code.

Right click on "ConeExample" under the project tree, go to Add and choose New Class.

Name the class Main.as.

Right click on Main.as, under ConeExample in the project tree, and click on Always Compile.

You're now ready to start coding.

Firstly, add the following lines to Main.as, under the line "package {"

import PaperBase;
import org.papervision3d.objects.primitives.Cone;

Those lines will import all of the packages we need.

Next, change the line:

public class Main {

To

public class Main extends PaperBase {

This will make our project import all of the functions and code that we wrote in PaperBase.as. We can now add just a few lines to make our papervision project work.

We'll need a cone object to add to the scene. Directly underneath the line

public class Main extends PaperBase {

You need to insert the line:

public var cone:Cone = new Cone();

This line will make a new cone object, and hold it in the variable called "cone".

Now, when the project is run, the code in "public function Main() {" is called. We want to initialise our papervision skeleton when our project runs. To do this, change the function so that it looks like this:

public function Main() {
    init();
}

This will run the PaperBase init function when your project runs.

You now need to override two functions from PaperBase. These are init3d and processFrame.

We'll need to add our cone to our scene in init3d, then rotate it a bit every time processFrame is called. To do this, add the following code directly below the Main() function.

override protected function init3d():void {
    cone.scale = 3; // Make the cone bigger
    cone.pitch(-40); // Tilt it towards the camera
    default_scene.addChild(cone); // Add it to the scene
}

override protected function processFrame():void {
    cone.yaw(5); // Rotate it a bit
}

These two "override" functions will be run instead of the ones in PaperBase. When you run your project you should see the cone rotating! Try playing with the values, adding and changing bits in the two functions above.

The final code should look like this:

Actionscript:
  1. package  {
  2.     
  3.     import PaperBase;
  4.     import org.papervision3d.objects.primitives.Cone;
  5.     
  6.     public class Main extends PaperBase {
  7.       
  8.        public var cone:Cone = new Cone();
  9.       
  10.        public function Main() {
  11.          init();
  12.        }
  13.       
  14.        override protected function init3d():void {
  15.          cone.scale = 3;
  16.          cone.pitch(-40)
  17.          default_scene.addChild(cone);
  18.        }
  19.       
  20.        override protected function processFrame():void {
  21.          cone.yaw(7);
  22.        }
  23.       
  24.     }
  25.     
  26. }

59 Comments

  1. Comment by Erik Olson on February 1, 2008 4:41 am

    I'm getting the error "Ambiguous reference to Vertex3D". I have the correct reference to the Vertex3D class.

    What am I missing?

  2. Comment by Luke on February 1, 2008 1:09 pm

    Hi,

    To be honest I haven't got a clue!

    Could you post the line of code that it takes you to when you double click the error?

    Thanks,
    Luke

  3. Comment by Mike on February 5, 2008 1:52 pm

    Hi,

    I am using Flash CS3 on a Mac and I successfully (no errors) ported the tutorial to CS3. But: I got nothing to see in the SWF.
    Can you give me a hint? Did I miss somthing? Like creating an initial movieclip and name it somehow?

    Regards.

    Mike

  4. Comment by Mike on February 5, 2008 1:54 pm

    Addition:

    This is the output after compilation:

    Papervision3D Public Alpha 2.0 - Great White (3.12.07)

    PV3D 2.0a WARNING : DO NOT USE WITH BETA 9 PLAYERS. ONLY WITH OFFICIAL TO TEST.
    CHECK YOUR VERSION!
    DisplayObject3D: null
    DisplayObject3D: null
    DisplayObject3D: null
    DisplayObject3D: vsn-mats
    BitmapFileMaterial: Loading bitmap from http://papervision2.com/wp-content/downloads/dae/Cow.png

    (Doesn't help, does it?)

  5. Comment by Luke on February 5, 2008 7:23 pm

    Hi Mike!

    Ok, the output shows that Papervision 3d is initialising, and working, so that's good.

    Two suggestions:

    1: When you call init(), pass it the width and height of your movie, so the line might read like this:

    Actionscript:
    1. init(550,400);

    (550 is the width, 400 is the height)

    2: If that doesn't work then maybe the viewport isn't being added to the stage properly. The code that adds the viewport to the scene is in PaperBase.as, the line:

    Actionscript:
    1. addChild(viewport);

    Try changing that to one of the following:

    Actionscript:
    1. root.addChild(viewport);

    OR

    Actionscript:
    1. stage.addChild(viewport);

    Tell me if it works!
    -Luke

  6. Comment by Mike on February 6, 2008 2:57 pm

    Hi Luke,

    at first: I am impressed how fast you're answering. Thanks.

    Then: Your suggestion about the root or stage did the trick. But I could not use it directly in the PaperBase class.

    I had to push it through all Methods:

    cmd action in ConeExample.fla:

    Actionscript:
    1. import ConeExample;
    2.  
    3. var $coneExample:ConeExample = new ConeExample();
    4. //this is the current root, passed to the Main - method.
    5. $coneExample.Main(this.root);
    6.  
    7.  
    8.  
    9. ConeExample.as:
    10.  
    11. package  {
    12.     
    13.     import base.PaperBase;
    14.     import org.papervision3d.objects.primitives.Cone;
    15.     
    16.     public class ConeExample extends PaperBase {
    17.      
    18.        public var cone:Cone = new Cone();
    19.      
    20.        public function Main($root) {
    21.         init($root, 550, 440);
    22.        }
    23.      
    24.        override protected function init3d():void {
    25.         cone.scale = 3;
    26.         cone.pitch(-40)
    27.         default_scene.addChild(cone);
    28.        }
    29.      
    30.        override protected function processFrame():void {
    31.         cone.yaw(7);
    32.        }
    33.      
    34.     }
    35.     
    36. }
    37.  
    38.  
    39. PaperBase.as:
    40.  
    41. package base  {
    42.     // These lines make differant 'pieces' available in your code.
    43.     import flash.display.Sprite; // To extend this class
    44.     import flash.events.Event; // To work out when a frame is entered.
    45.     
    46.     import org.papervision3d.view.Viewport3D; // We need a viewport
    47.     import org.papervision3d.cameras.*; // Import all types of camera
    48.     import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
    49.     import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
    50.     
    51.     public class PaperBase extends Sprite { //Must be "extends Sprite"
    52.      
    53.        public var viewport:Viewport3D; // The Viewport
    54.        public var renderer:BasicRenderEngine; // Rendering engine
    55.        // -- Scenes -- //
    56.        public var default_scene:Scene3D; // A Scene
    57.        // -- Cameras --//
    58.        public var default_camera:Camera3D; // A Camera
    59.      
    60.        public function init($root, vpWidth:Number = 800, vpHeight:Number = 600):void {
    61.         initPapervision(vpWidth, vpHeight, $root); // Initialise papervision
    62.         init3d(); // Initialise the 3d stuff..
    63.         init2d(); // Initialise the interface..
    64.         initEvents(); // Set up any event listeners..
    65.        }
    66.      
    67.        protected function initPapervision(vpWidth:Number, vpHeight:Number, $root):void {
    68.         // Here is where we initialise everything we need to
    69.         // render a papervision scene.
    70.         viewport = new Viewport3D(vpWidth, vpHeight);
    71.         // The viewport is the object added to the flash scene.
    72.         // You 'look at' the papervision scene through the viewport
    73.         // window, which is placed on the flash stage.
    74.         $root.addChild(viewport); // Add the viewport to the stage.
    75.         // Initialise the rendering engine.
    76.         renderer = new BasicRenderEngine();
    77.         // -- Initialise the Scenes -- //
    78.         default_scene = new Scene3D();
    79.         // -- Initialise the Cameras -- //
    80.         default_camera = new Camera3D(); // The argument passed to the camera
    81.         // is the object that it should look at. I've passed the scene object
    82.         // so that the camera is always pointing at the centre of the scene.
    83.        }
    84.      
    85.        protected function init3d():void {
    86.         // This function should hold all of the stages needed
    87.         // to initialise everything used for papervision.
    88.         // Models, materials, cameras etc.
    89.        }
    90.      
    91.        protected function init2d():void {
    92.         // This function should create all of the 2d items
    93.         // that will be overlayed on your papervision project.
    94.         // User interfaces, Heads up displays etc.
    95.        }
    96.      
    97.        protected function initEvents():void {
    98.         // This function makes the onFrame function get called for
    99.         // every frame.
    100.         addEventListener(Event.ENTER_FRAME, onEnterFrame);
    101.         // This line of code makes the onEnterFrame function get
    102.         // called when every frame is entered.
    103.        }
    104.      
    105.        protected function processFrame():void {
    106.         // Process any movement or animation here.
    107.        }
    108.      
    109.        protected function onEnterFrame( ThisEvent:Event ):void {
    110.         //We need to render the scene and update anything here.
    111.         processFrame();
    112.         renderer.renderScene(default_scene, default_camera, viewport);
    113.        }
    114.      
    115.     }
    116.     
    117. }

    With this,the cone example works in Flash CS3 as well. Again: Thanks a lot.

    Mike

  7. Comment by CaioToOn! on February 6, 2008 2:58 pm

    Hi, Mike.

    Did you defined the "Document class" of the FLA file? Because I did tried with the Flash CS3 and it works fine.

    Bye,
    CaioToOn!

  8. Comment by milo on February 14, 2008 1:48 pm

    Hi CaioToOn,

    with this "trick" it works without passing the root to the methods. I did not know about that, because I am coming from AS2. But after your hint, I red about the "All-is-a-class" - priciple in AS3. And I like it very much, because it is much closer to OOP, then it was before.

    Thanks for the hint.

    Mike

  9. Comment by David on February 18, 2008 12:36 am

    I am trying to run this from flash and i get this error:

    1020: Method marked override must override another method.
    1020: Method marked override must override another method.

    ??

  10. Comment by Luke on February 18, 2008 9:48 am

    Hi David,

    Not sure I can help you there sorry.. If you supply more info about the error I might be able to help.

    Thanks for visiting!
    -Luke

  11. Comment by Chuck Durham on February 18, 2008 8:52 pm

    Hey thanks a ton for the Tutorials, they are awesome. I wanted to see if anyone else is getting the same issue I am having. Everything I am doing with the Papervision3D shows up towards the lower right corner of my screen. I am assuming that following the above example you would have the cone and everything lined up at (0,0,0) origin. Anyone have any ideas - I have a Dell XPS M1730, NVIDIA 8700 running at a resolution of 1920 x 1200 (if this makes any difference). Anyone have this issue? Most of the demos I run seem to layout fine.

  12. Comment by Luke on February 18, 2008 8:58 pm

    Hi Chuck,

    Thanks for your comment on my site.

    I have an idea what the problem might be.

    Try changing the code:

    public function Main() {
    init();
    }

    Change that code to:

    public function Main() {
    init(400,300);
    }

    Then right click on the project in the project tree and click Properties. In the SWF settings boxes, set the width setting to 400 and height to 300.

    I hope this helps!

    -Luke

  13. Comment by Mediakid on February 20, 2008 6:54 am

    Man ~ you are awesome !

    applause!

  14. Comment by Alex Ionescu on February 20, 2008 7:18 pm

    Thank you for the tutorials and the replies - this is a great resource. Can you show how to build a tile-based world, with a little random vertex displacement, so that it does not look completely flat? Thanks!

  15. Comment by michael on February 20, 2008 7:48 pm

    I don't really have a clue, but I'm guessing that I'm missing something?

    1046: Type was not found or was not a compile-time constant: Viewport3D.

  16. Comment by Luke on February 20, 2008 7:52 pm

    Thanks Mediakid for the kind words!

    Alex,

    I'll try to put an example together within a few weeks, but It's quite a tall order, will take a lot of time to script something like that!

    Michael,

    Check that you've imported the papervision library correctly, and the import line for Viewport3D is at the top of your file.

    -Luke

  17. Comment by Alan on February 23, 2008 9:59 pm

    @Chuck (or anyone else)

    If you compiling your .swf from flash, you need to match your .swf's stage properties to those specified in the PaperBase.as init().
    This function sets the width and heights to 800 and 600.

    To get around this without breaking encapsulation (as it is) in your main.as change:

    CODE:
    1. public function Main() {
    2.     init();
    3. }

    to

    CODE:
    1. public function Main()
    2.         {
    3.             super.init(1200,600)
    4.         }

    "1200" and "600" is the width and height of my Fl stage. Change those numbers to your height and width.

  18. Comment by Shampi on February 25, 2008 11:26 am

    Hi
    I have a different problem here, I'm sure it's simple

    The error is : Error: Access of undefined property scene.

    So on this line : scene.addChild(cone);

    It just doesn't work...

  19. Comment by Shampi on February 25, 2008 2:20 pm

    Sorry,

    Problem resolved

  20. Comment by xemel3000 on March 3, 2008 3:51 am

    Can we go back to the top of this thread in regards to the Vertex 3D error? Was that ever resolved, because I get the same thing.

  21. Comment by JoseLuis Torres on March 3, 2008 5:17 pm

    Hi guys,

    I followed up each instruction but I received this error message:

    Main.as(11): col: 28 Error: The definition of base class PaperBase was not found.

    When I type the code I found the PaperBase class, so I'm not sure why it tells me that
    it didn't find it.

    Thanks

  22. Comment by JoseLuis Torres on March 3, 2008 5:23 pm

    Nevermind,

    I just click on Build Project and it worked.

    Regards

    Jose Luis

  23. Comment by jak on March 7, 2008 1:44 pm

    I got nothing to see in the SWF.Can you hel me?
    When click on "cone.swf" under ConeExample(AS3) i receive
    "Swf error:Unable to read beyond the end of the stream"

    Thanks

  24. Comment by Creyke on March 7, 2008 5:29 pm

    This is a fantastic resource. Thank you very much.

  25. Comment by Héctor on March 7, 2008 6:49 pm

    Thanks for the tutorials, they´ve been very handy

  26. Comment by jak on March 8, 2008 2:22 pm

    Help FD3 with Papervision3D.

    Hi,
    I am new to flash development

    1.I have downloaded FlashDevelop 3.0.0 Beta 6 , Flex 3 SDK and Papervision 3d 2.0.
    Flex SDK Location = C:\FlexSDK\
    Installed it successfully.
    2.create a "Base Class":
    2.1. I started a new as3 EMPTY Project
    (Create a new FlashDevelop Project select “ActionScript 3 -> Empty Project)
    name :PaperBase,Locatons: ..\My Documents\Papervision
    Click on the Classpaths tab and click Add Classpath for Papervision 3d(Browse to the src folder)
    2.2 Add > New Class name:PaperBase.as and select "Always Compile".
    2.3.PaperBase.as source code :

    package {
    import flash.display.Sprite;
    import flash.events.Event;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.cameras.*;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.render.BasicRenderEngine;

    public class PaperBase extends Sprite {
    public var viewport:Viewport3D;
    public var renderer:BasicRenderEngine;
    public var default_scene:Scene3D;
    public var default_camera:Camera3D;
    public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
    initPapervision(vpWidth, vpHeight);
    init3d();
    init2d();
    initEvents();
    }

    protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
    viewport = new Viewport3D(vpWidth, vpHeight);
    addChild(viewport);
    renderer = new BasicRenderEngine();
    default_scene = new Scene3D();
    default_camera = new Camera3D();
    }

    protected function init3d():void {

    }

    protected function init2d():void {

    }

    protected function initEvents():void {
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }

    protected function processFrame():void {

    }

    protected function onEnterFrame( ThisEvent:Event ):void {
    processFrame();
    renderer.renderScene(default_scene, default_camera, viewport);
    }

    }

    }

    3.Create a new FlashDevelop Project ( select “ActionScript 3 -> Empty Project) :name:"ConeExample" ,
    Locatons: ..\My Documents\,
    type "cone.swf" into the Output Fil and add Classpath for PaperBase and Papervision 3d.
    Right click on "ConeExample" under the project tree, go to Add and choose New Class.
    Name the class Main.as.
    Right click on Main.as, under ConeExample in the project tree, and click on Always Compile.
    3.1 Main.as:
    package {
    import PaperBase;
    import org.papervision3d.objects.primitives.Cone;
    public class Main extends PaperBase {
    public var cone:Cone = new Cone();
    public function Main() {
    init();
    }
    override protected function init3d():void {
    cone.scale = 3;
    cone.pitch(-40)
    default_scene.addChild(cone);
    }
    override protected function processFrame():void {
    cone.yaw(7);
    }
    }
    }

    I see white background. Nothing on the screen.
    Can anyone help me?

  27. Comment by Jim_Nastiq on March 24, 2008 4:29 pm

    Hi,

    thx for the tutorial but i can't make it works! cone.swf is empty(white), i've followed each step but it doesn't work...
    no error at compilation, just an error on the cone.swf : Impossible to read beyond the stream's end(a bad traduction from french ;-) )

  28. Comment by mojito on April 1, 2008 4:42 am

    I couldnt get this to work using just flash develop, but using the IDE it does work without error. The error seems to be that flash develop doesnt see the papervision properly or half sees it as it does seem to import the class ???

    here is the first of similar (same cause) error

    C:\work\as3\ConeExample\PaperBase.as(20): col: 23 Error: Type was not found or was not a compile-time constant: BasicRenderEngine.

    What I did differently was have my document Main.as AND PaperBase.as in the project folder. I dont see the problem as it all compiles but something IS wrong.

  29. Comment by Hokusai_spain on April 4, 2008 11:26 am

    About "Ambiguous reference to Vertex3D". try to remove olders versions of Papervision classes files that you have in your classes path.

  30. Comment by Homer on April 13, 2008 10:26 am

    When I test the project I can't see anything in the swf. This is the message that returns FlashDeveloper:

    Waiting for Player to connect
    Failed to connect; session timed out.
    Ensure that:
    1. you compiled your Flash movie with debugging on, and
    2. you are running the Debugger version of the Flash Player.

  31. Comment by chemkid on April 29, 2008 8:50 am

    hi there! thank you luke for all your information.

    one quick note to everybody who came here after playing with pv3d before and tried the tutorials from luke (and what to try everything in flash cs3,too):

    1. the flashdevelop + flex sdk is cool!
    2. everything works in flash cs3, too!

    - here comes my note:

    3. delete the links to papervision classes in your flash cs3 preferences! use only the links to papervision and paperbase from luke in the "publish" settings of your cs3 document and link the main.as to the document class.

    have fun!

    chem!

  32. Comment by Frank on April 29, 2008 11:32 pm

    Hi.

    These are some great tutorials, the best I have found on using Papervision3d. I am new to the Flash Developer but it seems pretty simple to use. My question is after I put in all the code for the Cone.as what do I do to use it or display anything? I have tried to build and execute the file after putting in all of the code but keep coming up with this error:

    C:\ppv3d\ConeExample/Main.as:7: characters 0-7 : parse error Unexpected package

    The package it is referring to is the package created in the fourth tutorial, this tutorial. I am just wondering if anyone knows what the issue is or if I am doing anything wrong or perhaps leaving some steps out.

    Feel free to ask questions to help better understand my situation as I would be greatly appreciative of anything that can help me with this issue.

    Here is the code i have from tutorial four.

    /**
    * ...
    * @author Default
    * @version 0.1
    */

    package{
    import PaperBase;
    import org.papervision3d.objects.primitives.Cone;

    public class Main extends PaperBase {

    public var cone:Cone = new Cone();

    public function Main() {
    init();
    }

    override protected function init3d():Void {
    cone.scale = 3; // Make the coen bigger
    cone.pitch( -40); // Tilt it towards the camera
    default_scene.addChild(cone); // Add it to the scene
    }

    override protected function processFrame():Void {
    cone.yaw(5); // Rotate it a bit
    }

    }

  33. Comment by barry on April 30, 2008 10:26 am

    Hi,

    I'm just starting out using PV3D and I cant get your examples to run.

    I have great white "org" folder in the same folder as my project.

    I get an error saying 1020: Method marked override must override another method.

    Can you help?

  34. Comment by Fran on May 3, 2008 4:13 am

    I was also having the blank screen problem using Flex. I spent some time tracking down the problem and found a solution. I created a new Flex project and made the mxml file look like this:

    If your Main class is not in the source root folder you'll have add an import for it.

  35. Comment by Fran on May 3, 2008 4:16 am

    Sorry the comment box ate the XML, I'll try again:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml "
    layout="absolute"
    creationComplete="complete()"
    >

    <mx:Script>
    <![CDATA[
    import mx.core.UIComponent;

    public function complete() : void
    {
    var sprite:Main = new Main();

    var component:UIComponent = new UIComponent();
    component.addChild(sprite);

    addChild(component);
    }

    ]]>
    </mx:Script>

    </mx:Application>

  36. Comment by Carlos on May 9, 2008 1:39 am

    Hello, I got this message " TriangleMesh 1020: Method marked override must override another method ". I'm sure that I did the installation and the pathing stuff correct, anyone can help me. none of the examples runs, there always appears the same error.

    ThankU

  37. Comment by Kevin on May 13, 2008 10:46 am

    hi!

    i did everthing like in this tut, i think, and my cone is displayed and rotating but it is not rotating cleanly. it is some kind of wiggling while rotating!

    but why?

  38. Comment by Kevin on May 13, 2008 1:38 pm

    here is my example: http://www.pixelfiction.de/pv/cone.html

    this sux! :(

  39. Comment by pester on May 15, 2008 11:38 am

    Hi, im just learning pv3d and these tutorials are great, although i have tried the Cone Example and the Complex Cow Model tutorials and both of them are not rotating smoothly as in the examples, the just randomly jump and spin around.

    Can anyone help?

  40. Comment by Jason Fistner on May 16, 2008 2:28 am

    something changed in Great White in the last 2 months.
    this example does not work as shown any more.
    it DID work 2 months ago. ~ March 15

  41. Comment by Jason Fistner on May 16, 2008 3:10 am

    In DisplayObject3d.as, the directional vectors are not being cloned during yaw or roll. The object is losing it's sense of direction.

  42. Comment by pester on May 19, 2008 3:30 pm

    Thanks for letting me know, was driving me crazy!

  43. Comment by nwebb on May 20, 2008 7:28 pm

    @pester - I had the same issue. The repository has since been updated. Try downloading the src again and the problem should go away :]

  44. Comment by xcorrect on May 29, 2008 7:12 am

    I did this again and again, and it says package is unexpectable, omg! y this happens to me :(

  45. Comment by xcorrect on May 29, 2008 7:23 am

    i'm getting this actually.,

    col: 7 Error: Syntax error: package is unexpected.
    package {
    ^
    Build halted with errors (mxmlc).
    Done (1)

    i think Build halted with errors means the two class paths are overlapping, isnt it? Plz help!

  46. Comment by Bluesed on June 1, 2008 11:05 am

    I'm using the PaperBase.as class with FlexBuilder3 and GreatWhite.
    Here is how I figured out how to use it.

    First thing I did was to CREATE A NEW folder(PaperBase) in the same directory as where I have the Papervision3d classes. ex. ..\org\papervision3d\PaperBase
    Copy/paste the file PaperBase.as into the new folder.

    Start Flex

    In flexbuilder: File->New->Actionscript project

    Chose a name like Papertutorial for the project and CLICK 'NEXT'
    in the 'Source path' tab I click 'Add Folder' and browse to the ..\papervision3d folder and click 'Accept/OK' to add the folder.

    I usually create a separate 'Main source folder' for the project in the browse tab.

    Click 'Finish' to start building the project setup.

    I create a Main.as: File -> New-> Actionsriptclass
    Set the name to Main.as and the Superclass to PaperBase and click 'Finish' to create the file.

    In you project class(PaperTutorial.as) you need to create and add an instance of the main in the constructor.

    public function PaperTutorial()
    {
    var main:Main = new Main();
    addChild(main);
    }

    Now you should be able to write/copy/paste the examples from this tutorial into your Main.as and run the examples.

  47. Comment by Bluesed on June 1, 2008 11:20 am

    Forgot to tell on IMPORTANT CHANGE!
    You need to change the package declaration in the PaperBase.as to
    package org.papervision3d.PaperBase{

    and you need to include it in the Main.as

    package
    {
    import org.papervision3d.PaperBase.PaperBase;

    public class Main extends PaperBase
    {
    public function Main()
    {
    super();
    }

    }
    }

  48. Comment by Jim on June 4, 2008 5:57 pm

    I've been using this base class or a while but I'm still not sure if I'm implementing it properly when working with a larger project. It works fine when working with one class, but when I additionally extend this class to another Papervison3D class in the same SWF there seems to be a performance issue. I'm convinced it has something to do with viewport and not having set the stage property in PaperBase. If I try to define the stage from the Document Class and call that class in PaperBase I get both 3D objects appearing at the same time on the stage. But if I leave PaperBase alone to find it's own display property performance is effected, more noticeably if there are even more than two 3D classes in the project. It seems to me like the viewport is not being removed from the display list each time class is called to be removed but I can't figure out how to prove it. Does anyone know how this should be set-up?

  49. Comment by Cesare Sassoli on June 8, 2008 10:19 pm

    Thanx you very much
    finally,
    my cube rotate in mad direction!!!

    override protected function init3d():void {
    cone.scale = 3;
    cone.pitch(-16)
    default_scene.addChild(cone);
    cone.x = 100; cone.y = 700;
    addEventListener(Event.ENTER_FRAME, prova);
    }

    private function prova(ev){
    //cone.x = cone.x + 8;
    if (r<20){r++;}else {r=-30;};
    cone.pitch(r);
    }

  50. Comment by ben on June 19, 2008 3:34 pm

    @xcorrect - I bet you just copied and pasted the example text! - but you didn't read "View as Plain Text". I did the same! but recopying at just plain text makes it work...

    great tutorials btw.

  51. Comment by Bill on June 20, 2008 1:58 am

    I'm getting the

    1046: Type was not found or was not a compile-time constant: Viewport3D.

  52. Comment by capo on June 25, 2008 9:31 am

    Hello.

    Firts of all i would like to thanks to the author of this website.
    You do a great job here :)

    Your scripts working (today) :D very good(flash CS3 - but the file Paper Base i have in the same folder of my project).

    Yesterday i had a problem with them and i saw a blank swf file. I was so angry. Then all examples from papaervision example folder were blank after compilation so I...reinstal the flash. Now there is no problem with the compilation.
    Yours and papervision examples are working fine. This is not the best solution but works :)
    I do not know why the problem occur but i'm happy that is gone.

    Thank you Luke for your work. I'm waiting for new posts and tips from you about Papervision :)

  53. Comment by patrick on July 2, 2008 4:25 pm

    hullo. I also get:

    Vertices3D.as, Line 163: 1000: Ambiguous reference to Vertex3D. vertex : Vertex3D,

    Vertices3D.as, Line 222: 1000: Ambiguous reference to Vertex3D. for each(var v:Vertex3D in vertices)

    Bug in GreatWhite? I'm running in CS3 on Mac

  54. Comment by patrick on July 2, 2008 4:58 pm

    Hokusai_spain is correct. I removed the references to previous versions of Papervision and the issue was resolved.

  55. Comment by jasonw on July 4, 2008 4:52 pm

    I'm experiencing some strange behavior using the examples in Flex 3.

    In my PaperBase class, the default width (vpwidth) is 800 and the default height (vpheight) is 600.

    In my ConeExample class, I set both the width and height to 100. Yet when I test the app, the display area is actually 238x238.

    Why is that?

  56. Comment by dusan on July 5, 2008 6:19 am

    I have one other problem. When i use this code, i do get result only in FlashDevelop when i press build or test. When i move this code to my Apache web server and load the page in web browser then, all i see is this:
    http://hq.mednmleko.com:8080/papervision2/
    I was trying to edit papervision2Config.xml to suit my needs and still I cannot set the relative path for those libraries mentioned in this config file :(( Can anyone give me any suggestion, how do we export or build the code, so it could be used on the web site.

  57. Comment by franco on July 8, 2008 1:20 pm

    I get this error

    C:\..\My Documents\spinningCone\Main.as(14): col: 11 Error: The protected attribute can only be used on class property definitions. in the RESULTS and the OUTPUT.

    Then I copied and pasted the code found here but I still get the same error.
    Anybody know what could be the problem?
    I don't know where to start looking.
    I'm using FD3 and Papervision 2

    Here is my code for this tut
    //
    package {

    import PaperBase;
    import org.papervision3d.objects.primitives.Cone;

    public class Main extends PaperBase {
    public var cone = new Cone();
    }

    public function Main() {
    init();
    }

    override protected function init3d():void {
    cone.scale = 3; //makes cone bigger
    cone.pitch( -40) //tilt it towards the camera
    default_scene.addChild(cone); //add the cone to the scene
    }

    override protected function processFrame():void {
    cone.yaw(5); //rotation
    }
    }
    //
    Thanx

  58. Comment by franco on July 8, 2008 1:28 pm

    nevermind...blind and stupid me missed the one '}' after I declare the cone var. Shouldn't be there. Will teach me to go over my code one more time before posting anything.

  59. Comment by sander on July 16, 2008 8:38 pm

    Hey there!

    everything seems to work well, apart from calling the yaw() an pitch() methods, and i cannot quit figure out what is going wrong or what i am doing wrong. Annyone an idea?
    This is the error i get..

    1195: Attempted access of inaccessible method pitch through a reference with static type org.papervision3d.objects.primitives:Cone.

Comments RSS TrackBack Identifier URI

Leave a comment


Papervision 2 is proudly powered by WordPress and themed by Mukka-mu