FreeCamera3DController for 2.0

December 15, 2007 – 6:28 am

In my user group presentations, I often used a class called “FreeCamera3DController” which I found in a sample shared by blitzagency labs. It adds controls to your FreeCamera3D to let you click and drag as well as use the arrow or WASD keys to move the camera around the scene in 3d space. I just updated this class to be compatible with pv3d 2.0 (just had a change a few scene.container’s to viewports) and I thought others might find it as useful for debugging 3d space as I have (thanks to blitzagency again).

Click and drag below or use the arrow or WASD keys for an example:


Usage

Full Code

Download FreeCamera3DController

  1. 14 Responses to “FreeCamera3DController for 2.0”

  2. hi.

    works great, but I’d like to see some examples of interactivity with planes. In previous version of pv I could add listener to plane.container, but in 2.0 version there is no container prop. How can I make plane clickable?

    cheers :)

    By farmazone on Dec 15, 2007

  3. See this post for your answer: http://pv3d.org/2007/12/16/interactivescene3devent-example-object_press/

    By John Lindquist on Dec 16, 2007

  4. thanx. this seems to be much more intuitive than previous version. how’s about setting custom alpha to an object like: plane.alpha=.5 ?

    I’m investigating source code but… :)

    By farmazone on Dec 16, 2007

  5. Alpha is controlled by the material you apply to your 3d object:

    material = new ColorMaterial( color, alpha );

    By John Lindquist on Dec 16, 2007

  6. woow. :) changing value of a texture properties affects a plane. And if I have MovieMaterial I can store all interaction inside a class which is an asset.

    var mc:Mc=new Mc()
    material = new MovieMaterial(mc);
    material.animated = true;

    //inside class Mc
    public function onMouseOver(ev:Event):void{ Tweener.addTween(this,{alpha:.2,time:2})
    }

    that’s the way I like it :D

    thanx for this

    By farmazone on Dec 17, 2007

  7. hey!, i know this is a bit delayed - but i was wondering about where the specific freecamera3dcontroller class is located at the blitz site? i cant seem to find it at the moment.

    cheers.

    By alex on Apr 25, 2008

  8. @alex- There’s a link on the bottom of this post that says “Download FreeCamera3DController”.

    By John Lindquist on Apr 25, 2008

  9. ha! cheers john - i actually went through all the blitz sample files and finally found it - so far so good -

    buuuut - the file goes “1119: Access of possibly
    undefined property container through a reference with static type org.papervision3d.scenes:Scene3D.”

    in the output for all this bit:

    public function FreeCamera3DController(camera:FreeCamera3D,scene:Scene3D){
    this.camera = camera;
    this.scene = scene;
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownEvent);
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpEvent);
    *scene.container.stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownEvent );
    *scene.container.stage.addEventListener( KeyboardEvent.KEY_UP, keyUpEvent );
    *scene.container.addEventListener(Event.ENTER_FRAME,enterFrameEvent);
    }

    protected function mouseDownEvent(event:MouseEvent):void{
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveEvent);
    *startPoint = new Point(scene.container.mouseX,scene.container.mouseY);
    *startRotationY = camera.rotationY;
    *startRotationX = camera.rotationX;
    }

    protected function mouseMoveEvent(event:MouseEvent):void{
    *targetRotationY = startRotationY - (startPoint.x - scene.container.mouseX) / 2;
    *targetRotationX = startRotationX + (startPoint.y - scene.container.mouseY) / 2;
    }- though

    sorry for the length - is it something to do with the freecamer3dcontroller.as file not being able to find the default classes?

    sorry if this is long winded…
    and cheers for replying so quickly..

    By alex on Apr 25, 2008

  10. ha! cheers john - i actually went through all the blitz sample files and finally found it - so far so good -

    buuuut - the file goes “1119: Access of possibly
    undefined property container through a reference with static type org.papervision3d.scenes:Scene3D.”

    in the output for all this bit:

    (every line that’s got a asterix (*))
    public function FreeCamera3DController(camera:FreeCamera3D,scene:Scene3D){
    this.camera = camera;
    this.scene = scene;
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownEvent);
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpEvent);
    *scene.container.stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownEvent );
    *scene.container.stage.addEventListener( KeyboardEvent.KEY_UP, keyUpEvent );
    *scene.container.addEventListener(Event.ENTER_FRAME,enterFrameEvent);
    }

    protected function mouseDownEvent(event:MouseEvent):void{
    *scene.container.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveEvent);
    *startPoint = new Point(scene.container.mouseX,scene.container.mouseY);
    *startRotationY = camera.rotationY;
    *startRotationX = camera.rotationX;
    }

    protected function mouseMoveEvent(event:MouseEvent):void{
    *targetRotationY = startRotationY - (startPoint.x - scene.container.mouseX) / 2;
    *targetRotationX = startRotationX + (startPoint.y - scene.container.mouseY) / 2;
    }

    sorry for the length - is it something to do with the freecamer3dcontroller.as file not being able to find the default classes?

    sorry if this is long winded…
    and cheers for replying so quickly..

    By alex on Apr 25, 2008

  11. gaa! dbl post sorry.

    By alex on Apr 25, 2008

  12. @alex- blitz’s class no longer works for pv3d 2.0. Download this one: http://pv3d.org/files/FreeCamera3DController.zip like I said in and earlier comment.

    By John Lindquist on Apr 25, 2008

  13. thanks, john got it working perfectly - though another question relating to it - in the previous version 1.9 (phunky i think) you didn’t have to declare/import the ‘viewport3d’ instead just put it into a new container i.e:

    [code]
    var container:Sprite = new Sprite()
    addChild(container);
    container.x = stage.stageWidth* .5;
    container.y = stage.stageHeight * .5;
    [/code]

    i would then pas this into the scene3d…
    [code]
    var scene:Scene3d = new Scene3d(container, true)
    [/code]

    i wanted to do the same thing in version 2.0 (great white).
    so i can import the whole papervision Sprite to (for example) frame one of my .fla - or any other spot - as it currently always infront/obscuring any graphics in my scene

    not sure what i would do in this case..

    private function initPapervision():void
    {
    viewport = new Viewport3D();
    addChild( viewport );

    scene = new Scene3D();
    camera = new FreeCamera3D();

    renderer = new BasicRenderEngine();

    cheers, alex

    By alex on Apr 27, 2008

  14. create a Sprite Containeur, addChild this sprite on the stage;

    then addChild the viewport on the sprite ;

    private function initPapervision():void
    {
    var spriteContaineur:Sprite = new Sprite();
    addChild(spriteContaineur);
    viewport = new Viewport3D();
    spriteContaineur.addChild( viewport );

    scene = new Scene3D();
    camera = new FreeCamera3D();

    renderer = new BasicRenderEngine();

    after it , all new DisplayObjects you will add on the stage will be above the pv3d Scene;

    By Timmy on Apr 27, 2008

  15. ahhh~ just what i needed :D
    1 extra Q, how to stop the action of camera when it reach a limit? Cause the code now if i keep on pressing the camera will be moving like forever~

    By Hwang on May 5, 2008

Post a Comment