blog
Simple working Flex papervision 3d example at Jozef Chúťka's blog
November 2, 2009
BasicRenderEngine Camera3D Cube MaterialsList Papervision 3D Scene3D Viewport3D WireframeMaterial
Simple working Flex papervision 3d example
Today I started to play with papervision3d after a long time again. If you are looking for a simple scene example try this one:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
applicationComplete="init()">
<mx:Script>
<![CDATA[
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;
private var cube:Cube;
private function init():void
{
viewport = new Viewport3D(pv3dCanvas.width, pv3dCanvas.height, false, true);
pv3dCanvas.rawChildren.addChild(viewport);
viewport.buttonMode = true;
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D();
camera.zoom = 10;
var material:WireframeMaterial = new WireframeMaterial(0x000000, 1, 1);
material.oneSide = false;
material.smooth = true;
var materials:MaterialsList = new MaterialsList();
materials.addMaterial(material, "front");
materials.addMaterial(material, "back");
materials.addMaterial(material, "right");
materials.addMaterial(material, "left");
materials.addMaterial(material, "top");
materials.addMaterial(material, "bottom");
cube = new Cube(materials, 600, 600, 600, 1, 1, 1, Cube.ALL, Cube.TOP);
cube.x = 0;
cube.y = 0;
cube.z = 0;
scene.addChild(cube);
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(event:Event):void
{
cube.rotationX++;
renderer.renderScene(scene, camera, viewport);
}
]]>
</mx:Script>
<mx:Canvas id="pv3dCanvas" width="100%" height="100%" />
</mx:Application>Do not forget to add Papervision3D.swc into your project.
You may Leave a comment or Subscribe to Comments RSS or Trackback this entry.
3 comments so far
avejidah November 17, 2009 19:40 Thanks, works well. Cleaner than the other tutorials, and works in flex 3.
Papervision Tutorial « Lars Larsen June 8, 2010 13:05 […] which shows how to use the papervision library in flex builder. After a while I found this one: Simple working Flex papervision 3d example, which shows a cube which is […]
Peter Farkas February 27, 2011 12:12 It’s so clean because the model is created programatically rather than using SketchUp. I just realized I won’t have to use SketchUp. Thanks a lot!
Leave a comment
Please be polite and on topic. Your e-mail will never be published.