In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: PV edge material

just testing :)
trying to sort fp9 problem http://forum.papervision3d.org/viewtopic.php?f=14&t=896
Get Adobe Flash player
by JohnBrookes 10 Aug 2009
    Embed
/**
 * Copyright JohnBrookes ( http://wonderfl.net/user/JohnBrookes )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3yzf
 */

// forked from JohnBrookes's PV edge material
//just testing :)
//trying to sort fp9 problem http://forum.papervision3d.org/viewtopic.php?f=14&t=896
package
{
	import flash.events.Event;
	import org.papervision3d.core.math.Number3D;
//	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.view.BasicView;
	
	public class PVtest extends BasicView
	{
		
		private static var CUBE_DIM:Number = 100;
		private static var CUBE_SIDES:int = 3;
		private static var CUBE_SPACING:Number =  20;
		private var bigCubeMiddlePoint:Number = -(CUBE_SIDES * (CUBE_DIM+CUBE_SPACING))*.5;
		private var bigCube:DisplayObject3D;
		
		public function PVtest():void
		{
			init();
			singleRender();
			addEventListener(Event.ENTER_FRAME, tick);
		}
		
		private function init():void
		{
			scene.addChild(generateCube());
			
		}
		private function createMaterialList( color:uint ):MaterialsList {
            var ml:MaterialsList = new MaterialsList();
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "front" );
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "back" );
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "top" );
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "bottom" );
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "right" );
            ml.addMaterial( new CubeEdgeMaterial( 0x000000, 1, 1, color, 1, false ), "left" );
           
           
            return ml;
        }
		 private function generateCube():DisplayObject3D {
                  //Current little cube which will be generated in for loop
                  var cube:Cube;
                  //Final cube which will be returned
                  bigCube = new DisplayObject3D();
                  //Material for cube creation
                  var cubeMaterialsList:MaterialsList;
                 var count:int = 0;
                  //Symbol explanation: i -> x, j -> y, k -> z
                  for ( var i:uint = 0; i < CUBE_SIDES; i++ ) {
                      for ( var j:uint = 0; j < CUBE_SIDES; j++ ) {
                          for ( var k:uint = 0; k < CUBE_SIDES; k++ ) {
                              cubeMaterialsList = createMaterialList( Math.random()*0xFFFFFF );
                              cube = new Cube( cubeMaterialsList, CUBE_DIM, CUBE_DIM, CUBE_DIM, 1, 1, 1 );
                              //Put cube in position relative to big cube middle
                              cube.x = bigCubeMiddlePoint + i * ( CUBE_DIM + CUBE_SPACING ) + CUBE_DIM / 2;
                              cube.y = bigCubeMiddlePoint + j * ( CUBE_DIM + CUBE_SPACING ) + CUBE_DIM / 2;
                              cube.z = bigCubeMiddlePoint + k * ( CUBE_DIM + CUBE_SPACING ) + CUBE_DIM / 2;
                              //Set cube name so that later it can be identified
                              cube.name = "x" + ( i + 1) + "y" + ( j + 1) + "z" + ( k + 1);
                              bigCube.addChild( cube );
							  count++;
                          }
                      }
                  }
                 trace(count);
                  return bigCube;
              }
		
		private function tick(e:Event):void 
		{
			bigCube.yaw(1);
			camera.orbit(viewport.mouseY-viewport.viewportHeight/2, viewport.mouseX - viewport.viewportWidth/2)
			singleRender();
		}
	}
}	
//package org.papervision3d.materials
//{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
 
import org.papervision3d.core.material.TriangleMaterial;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.render.command.RenderTriangle;
import org.papervision3d.core.render.data.RenderSessionData;
import org.papervision3d.core.render.draw.ITriangleDrawer;
 
/**
* The CubeEdgeMaterial class creates a solid color material and coloured edges.
* Only works on cubes with 1,1,1 segments
*
*/
class CubeEdgeMaterial extends TriangleMaterial implements ITriangleDrawer
{
   
    /**
    * The CubeEdgeMaterial class creates a solid color material and coloured edges.
    * +++ONLY USE ON 1,1,1 SEGMENT CUBES+++
    *
    * @param    asset               A BitmapData object.
    */
    public function CubeEdgeMaterial( lineColor:Number=0x0000FF, lineAlpha:Number = 1,lineThickness:Number=1, cubeColor:Number=0xFF00FF, alpha:Number = 1, interactive:Boolean = false )
    {
        this.lineColor = lineColor;
        this.lineAlpha = lineAlpha;
        this.lineThickness = lineThickness
       
        this.fillColor = cubeColor;
        this.fillAlpha = alpha;
        this.interactive = interactive;
    }
   
    /**
     *  drawTriangle
     */
   
    override public function drawTriangle(tri:RenderTriangle, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
       
        var x0:Number = tri.v0.x;
        var y0:Number = tri.v0.y;
        var x1:Number = tri.v1.x;
        var y1:Number = tri.v1.y;
        var x2:Number = tri.v2.x;
        var y2:Number = tri.v2.y;
       
		//no idea why but fp9 wants this
        graphics.beginFill( fillColor, fillAlpha );
        graphics.moveTo( x0, y0 );
        graphics.lineTo( x1, y1 );
        graphics.lineTo( x2, y2 );
        graphics.lineTo( x0, y0 );
            
            if (tri.uv1.v > 0.9 && tri.uv1.v < 1.1)
            {
           graphics.lineStyle(lineThickness, lineColor, lineAlpha );
            graphics.moveTo( x0, y0 );
            graphics.lineTo( x1, y1 );
            graphics.lineTo( x2, y2 );
			graphics.lineStyle();
            }
            if (tri.uv1.v < 0.1)
            {
				graphics.lineStyle(lineThickness, lineColor, lineAlpha );
            graphics.moveTo( x1, y1 );
            graphics.lineTo( x0, y0 );
            graphics.lineTo( x2, y2 );
			graphics.lineStyle();
            }
             graphics.beginFill( fillColor, fillAlpha );
			graphics.moveTo( x0, y0 );
			graphics.lineTo( x1, y1 );
			graphics.lineTo( x2, y2 );
			graphics.lineTo( x0, y0 );
			
       renderSessionData.renderStatistics.triangles++;
       
    }
   
    /**
    * Returns a string value representing the material properties in the specified ColorMaterial object.
    *
    * @return   A string.
    */
    public override function toString(): String
    {
        return 'ColorMaterial - color:' + this.fillColor + ' alpha:' + this.fillAlpha;
    }
   
    override public function clone():MaterialObject3D
    {
        var cloned:MaterialObject3D = new CubeEdgeMaterial();
        cloned.copy(this);
        return cloned;
    }
 
 
}
//}