
In a previous tutorial (Creating a Papervision Base Template) we created a base Papervision template that we could re-use. Now however Papervision includes a form of this base template called BasicView.as
With just a few lines of code you're up and running. Here is the very simple / basic use of BasicView.as:
-
package
-
{
-
import flash.events.Event;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.view.BasicView;
-
-
/**
-
* ...
-
* @author Charlie Schulze, charlie[at]woveninteractive[dot]com
-
*/
-
-
public class Main extends BasicView
-
{
-
protected var plane:Plane;
-
protected var colorMaterial:ColorMaterial;
-
-
public function Main():void
-
{
-
super();
-
-
//Create one material and make it doublesided
-
colorMaterial = new ColorMaterial(0xFF0000, .5);
-
colorMaterial.doubleSided = true;
-
-
//Create a plane using the colorMaterial
-
plane = new Plane(colorMaterial, 100, 100);
-
scene.addChild(plane);
-
-
//Start the rendering
-
startRendering();
-
}
-
-
override protected function onRenderTick(event:Event = null):void
-
{
-
super.onRenderTick(event);
-
-
//Rotate the plane
-
plane.yaw(2);
-
}
-
}
-
}
This very simple example you will just see a single light red plane rotating.
That is all you need to do to get started in Papervision. Test it out. Don't forget to add your 3D objects to the scene.
-
scene.addChild(plane);
Here is what the BasicView.as class looks like:
-
package org.papervision3d.view
-
{
-
import org.papervision3d.cameras.SpringCamera3D;
-
import org.papervision3d.cameras.Camera3D;
-
import org.papervision3d.cameras.CameraType;
-
import org.papervision3d.cameras.DebugCamera3D;
-
import org.papervision3d.core.view.IView;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.render.BasicRenderEngine;
-
import org.papervision3d.scenes.Scene3D;
-
-
/**
-
* <p>
-
* BasicView provides a simple template for quickly setting up
-
* basic Papervision3D projects by creating a viewport, scene,
-
* camera, and renderer for you. Because BasicView is a subclass of
-
* Sprite, it can be added to any DisplayObject.
-
*
-
* </p>
-
*
-
* <p>
-
* <p>
-
* Example:
-
* </p>
-
* <pre><code>
-
* var width:Number = 640;
-
* var heigth:Number = 480;
-
* var scaleToStage:Boolean = true;
-
* var interactive:Boolean = true;
-
* var cameraType:String = Camera3D.TYPE;
-
*
-
* var myBasicView:BasicView = new BasicView(width, height, scaleToStage, interactive, cameraType);
-
* myDisplayObject.addChild(myBasicView);
-
* </code></pre>
-
* </p>
-
* @author Ralph Hauwert
-
*/
-
public class BasicView extends AbstractView implements IView
-
{
-
/**
-
* @param viewportWidth Width of the viewport
-
* @param viewportHeight Height of the viewport
-
* @param scaleToStage Whether you viewport should scale with the stage
-
* @param interactive Whether your scene should be interactive
-
* @param cameraType A String for the type of camera. @see org.papervision3d.cameras.CameraType
-
*
-
*/
-
public function BasicView(viewportWidth:Number = 640, viewportHeight:Number = 480, scaleToStage:Boolean = true, interactive:Boolean = false, cameraType:String = "Target")
-
{
-
super();
-
-
scene = new Scene3D();
-
viewport = new Viewport3D(viewportWidth, viewportHeight, scaleToStage, interactive);
-
addChild(viewport);
-
renderer = new BasicRenderEngine();
-
-
switch(cameraType)
-
{
-
case CameraType.DEBUG:
-
_camera = new DebugCamera3D(viewport);
-
break;
-
case CameraType.TARGET:
-
_camera = new Camera3D(60);
-
_camera.target = DisplayObject3D.ZERO;
-
break;
-
case CameraType.SPRING:
-
_camera = new SpringCamera3D();
-
_camera.target = DisplayObject3D.ZERO;
-
break;
-
case CameraType.FREE:
-
default:
-
_camera = new Camera3D(60);
-
break;
-
}
-
-
cameraAsCamera3D.update(viewport.sizeRectangle);
-
}
-
-
/**
-
* Exposes the camera as a <code>Camera3D</code>
-
*/
-
public function get cameraAsCamera3D():Camera3D
-
{
-
return _camera as Camera3D;
-
}
-
-
/**
-
* Exposes the camera as a <code>DebugCamera3D</code>
-
*/
-
public function get cameraAsDebugCamera3D():DebugCamera3D
-
{
-
return _camera as DebugCamera3D;
-
}
-
}
-
}
Since BasicView.as extends AbstractView.as you can see a few more of the methods available to you just by extending BasicView.as
-
package org.papervision3d.view
-
{
-
import flash.display.Sprite;
-
import flash.events.Event;
-
-
import org.papervision3d.core.proto.CameraObject3D;
-
import org.papervision3d.core.view.IView;
-
import org.papervision3d.render.BasicRenderEngine;
-
import org.papervision3d.scenes.Scene3D;
-
-
/**
-
* @Author Ralph Hauwert
-
*/
-
public class AbstractView extends Sprite implements IView
-
{
-
protected var _camera:CameraObject3D;
-
protected var _height:Number;
-
protected var _width:Number;
-
-
public var scene:Scene3D;
-
public var viewport:Viewport3D;
-
public var renderer:BasicRenderEngine;
-
-
public function AbstractView()
-
{
-
super();
-
}
-
-
public function startRendering():void
-
{
-
addEventListener(Event.ENTER_FRAME, onRenderTick);
-
viewport.containerSprite.cacheAsBitmap = false;
-
}
-
-
public function stopRendering(reRender:Boolean = false, cacheAsBitmap:Boolean = false):void
-
{
-
removeEventListener(Event.ENTER_FRAME, onRenderTick);
-
if(reRender){
-
onRenderTick();
-
}
-
if(cacheAsBitmap){
-
viewport.containerSprite.cacheAsBitmap = true;
-
}else{
-
viewport.containerSprite.cacheAsBitmap = false;
-
}
-
}
-
-
public function singleRender():void
-
{
-
onRenderTick();
-
}
-
-
protected function onRenderTick(event:Event = null):void
-
{
-
renderer.renderScene(scene, _camera, viewport);
-
}
-
-
public function get camera():CameraObject3D
-
{
-
return _camera;
-
}
-
-
public function set viewportWidth(width:Number):void
-
{
-
_width = width;
-
viewport.width = width;
-
}
-
-
public function get viewportWidth():Number
-
{
-
return _width;
-
}
-
-
public function set viewportHeight(height:Number):void
-
{
-
_height = height;
-
viewport.height = height;
-
}
-
-
public function get viewportHeight():Number
-
{
-
return _height;
-
}
-
-
}
-
}


really good tutorial ! ! !
Thanks for the great tutorials. :)
it works! it lives! thank you. I was able to bring in CINEMA4D this way. Version 10.
I change .dae
but
INFO: Viewport autoScaleToStage : Papervision has changed the Stage scale mode.
INFO: BitmapFileMaterial: Loading bitmap from daeModel/guy.jpg
ERROR: BitmapFileMaterial: Unable to load file daeModel/guy.jpg
ERROR: COLLADA file load error
Can you help me?
This is a terrible first tutorial. It explains nothing about what Papervision does, how to set it up, and how to make an actual running application.
This:
scene.addChild(plane);
tells me nothing. What the heck is scene?
@disappointed –
The title is “Getting Started using BasicView.as” BasicView.as is a class used by papervision; if you’re reading this tutorial you should have some knowledge of papervision itself. This is what I would consider the “infant stage tutorial” why don’t you come back (or not come back because I don’t care) when you’ve read over the documentation and understand the “baby stage” of papervision.
And next time don’t be a wuss. Leave your email address; try and be part of the community instead of a heckler. If you simply asked – “what is a scene” your question would have been answered.
Charlie
Here are the docs. Happy reading..
http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/index.html
hey y’all i was trying to follow charlie’s advice – get started on the baby stage learning process, however the official docs over at papervision3d seem to be just a collection of function and class definitions. I need the very basics! I know the (rudimentary) principles of AS.
Any nods in the right direction!?
v best
Maxx
hi,
tuts are helpfull,
i wonder that using basicview class is simple or can we make other advanced staff…
for exammple it uses spring cam, can i change it and how..
thanks for furter advance detail..
I’m with maxxer. This Tutorial looks good but it’s one step ahead of me and I really need an idiots guide to Papervision basics. Any links anyone?