Take a look at the sphere on the left. Ever had this happen to you and wondered if there was a good way to get rid of it? One of the ways we use is by adding a viewport layer. This works much the same as adding a new layer in flash or adding movieclip over another in AS3.
The best thing about this approach is that it's very simple and quick to implement:
Actionscript:
-
viewportLayer = viewport.getChildLayer(sphere, true);
-
viewportLayer.addDisplayObject3D(sphere);
For even more in depth discussion on viewport layers take a look at:
http://blog.zupko.info/?p=129
Here is the full class:
Actionscript:
-
package
-
{
-
import flash.events.Event;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.objects.primitives.Sphere;
-
import org.papervision3d.view.BasicView;
-
import org.papervision3d.objects.primitives.Cone;
-
import org.papervision3d.materials.BitmapFileMaterial;
-
import org.papervision3d.view.layer.ViewportLayer;
-
-
public class Main extends BasicView
-
{
-
protected var sphere:Sphere
-
protected var plane:Plane;
-
protected var bitmapMaterial:BitmapFileMaterial;
-
protected var colorMaterial:ColorMaterial;
-
protected var viewportLayer:ViewportLayer;
-
public function Main()
-
{
-
super();
-
createChildren();
-
commitProperties();
-
startRendering();
-
}
-
protected function createChildren():void
-
{
-
-
//Create a new 3D object
-
colorMaterial = new ColorMaterial(0x000000);
-
bitmapMaterial = new BitmapFileMaterial("images/ourtex.jpg")
-
-
//Create 3D Objects
-
plane = new Plane(colorMaterial,1000,1000,5,5)
-
sphere = new Sphere(bitmapMaterial, 50, 10,10);
-
-
-
//Add to scene
-
scene.addChild(plane);
-
scene.addChild(sphere);
-
-
//To see the z-sorting issue comment out these two lines
-
viewportLayer = viewport.getChildLayer(sphere, true);
-
viewportLayer.addDisplayObject3D(sphere);
-
}
-
-
protected function commitProperties():void
-
{
-
//Set some properties
-
sphere.scale = 4;
-
sphere.pitch( -10);
-
plane.rotationX = 60;
-
}
-
override protected function onRenderTick(event:Event = null):void
-
{
-
super.onRenderTick(event);
-
-
//Rotate
-
sphere.yaw(1);
-
}
-
}
-
}


