PDA

View Full Version : Need help with papervision



rondog
December 24th, 2008, 05:39 PM
I've just been tinkering with it a bit and would like to know if their is some sort of setting to have like a child of a Plane so if the parent moves, the child does also? Here is a link to what I have now:

http://ronnieswietek.com/hosted/as3tree/tree.swf

I am going for a diorama look and want it to look as if that wood in the back is holding the tree up. The problem is the way it is rotating is not working. Here is my code:


import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.materials.BitmapFileMaterial;

var viewport:Viewport3D;
var scene:Scene3D;
var camera:Camera3D;
var tree:Plane;
var stand:Plane;
var renderer:BasicRenderEngine;

init3D();
createPlane();
addEventListeners();

function init3D():void
{
// VIEWPORT
viewport = new Viewport3D(0, 0, true, false);
addChild(viewport);
//
// RENDERER
renderer = new BasicRenderEngine();
//
// SCENE
scene = new Scene3D();
//
// CAMERA
camera = new Camera3D();
camera.zoom = 11;
camera.focus = 100;
}

function createPlane():void
{
BitmapFileMaterial.LOADING_COLOR = 0x0000FF;
BitmapFileMaterial.ERROR_COLOR = 0xFF0000;
//
var treeMaterial:BitmapFileMaterial = new BitmapFileMaterial("tree-side-1.png");
var standMaterial:BitmapFileMaterial = new BitmapFileMaterial("wood.png");
treeMaterial.doubleSided = true;
standMaterial.doubleSided = true;
//
tree = new Plane(treeMaterial, 191, 175, 5, 5 );
stand = new Plane(standMaterial, 23, 80, 5, 5 );
//
scene.addChild(stand);
scene.addChild(tree);
stand.x = 30;
stand.y = -60;
stand.z = 0;
stand.rotationX = -45;
}

function addEventListeners():void
{
addEventListener(Event.ENTER_FRAME, __onEnterFrame);
}

function removeEventListeners():void
{
removeEventListener(Event.ENTER_FRAME, __onEnterFrame);
}


function __onEnterFrame(e:Event):void
{
tree.rotationY = viewport.mouseX / 2;
stand.rotationY = viewport.mouseX / 2;
renderer.renderScene(scene, camera, viewport);
}

mathew.er
December 27th, 2008, 09:25 PM
The problem is that you transform the planes independently, might help putting them in some kinf on a container and transorming that instead... the child elements will retain their position in local space. By briefly looking at the Scene3D docs, it seems it doesn't have means to transform objects inside it. You'll probably need to create a third object, might be just an empty DisplayObject3D..


// create another property called holder
var holder : DisplayObject3D;

// then, in createPlane()
holder = new DisplayObject3D ();
tree = new Plane(treeMaterial, 191, 175, 5, 5 );
stand = new Plane(standMaterial, 23, 80, 5, 5 );

holder.addChild ( stand );
holder.addChild ( tree );

scene.addChild ( holder );

// and in the __onEnterFrame change it to rotate just that one thing
holder.rotation = rotationY = viewport.mouseX / 2;