/* * PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA * AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP * PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE * ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER * RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D * ______________________________________________________________________ * papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d */ /* * Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ // ______________________________________________________________________ // GeometryObject3D: Cube package org.papervision3d.objects { import org.papervision3d.core.*; import org.papervision3d.core.proto.*; import org.papervision3d.core.geom.*; import flash.display.BitmapData; /** * The Cube class lets you create and display flat rectangle objects. *

* The rectangle can be divided in smaller segments. This is usually done to reduce linear mapping artifacts. *

* Dividing the Cube in the direction of the perspective or vanishing point, helps to reduce this problem. Perspective distortion dissapears when the Cube is facing straignt to the camera, i.e. it is perpendicular with the vanishing point of the scene. */ public class Cube extends Mesh3D { /** * Number of segments sagitally. Defaults to 1. */ public var segmentsS :Number; /** * Number of segments transversally. Defaults to 1. */ public var segmentsT :Number; /** * Number of segments horizontally. Defaults to 1. */ public var segmentsH :Number; /** * Default size of Cube if not texture is defined. */ static public var DEFAULT_SIZE :Number = 500; /** * Default size of Cube if not texture is defined. */ static public var DEFAULT_SCALE :Number = 1; /** * Default value of gridX if not defined. The default value of gridY is gridX. */ static public var DEFAULT_SEGMENTS :Number = 1; // ___________________________________________________________________________________________________ // N E W // NN NN EEEEEE WW WW // NNN NN EE WW WW WW // NNNNNN EEEE WWWWWWWW // NN NNN EE WWW WWW // NN NN EEEEEE WW WW /** * Create a new Cube object. *

* @param material A MaterialObject3D object that contains the material properties of the object. *

* @param width [optional] - Desired width or scaling factor if there's bitmap texture in material and no height is supplied. *

* @param depth [optional] - Desired depth. *

* @param height [optional] - Desired height. *

* @param segmentsS [optional] - Number of segments sagitally (plane perpendicular to width). Defaults to 1. *

* @param segmentsT [optional] - Number of segments transversally (plane perpendicular to depth). Defaults to segmentsS. *

* @param segmentsH [optional] - Number of segments horizontally (plane perpendicular to height). Defaults to segmentsS. *

* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D. *

* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object. *

* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available. */ public function Cube( material:MaterialObject3D=null, width:Number=500, depth:Number=500, height:Number=500, segmentsS:Number=1, segmentsT:Number=1, segmentsH:Number=1, initObject:Object=null ) { super( material, new Array(), new Array(), null, initObject ); this.segmentsS = segmentsS;//!=null?segmentsW:DEFAULT_SEGMENTS; // Defaults to 1 this.segmentsT = segmentsT;//!=null?segmentsH:this.segmentsW; // Defaults to segmentsW this.segmentsH = segmentsH;//!=null?segmentsT:this.segmentsW; // Defaults to segmentsW var scale :Number = DEFAULT_SCALE; if( ! height ) { if( width ) scale = width; if( material && material.bitmap ) { width = material.bitmap.width * scale; height = material.bitmap.height * scale; } else { width = DEFAULT_SIZE * scale; height = DEFAULT_SIZE * scale; } } if( ! depth ) { if( width ) scale = width; //if( material && material.bitmap ) { // width = material.bitmap.width * scale; // depth = material.bitmap.depth * scale; //} else { width = DEFAULT_SIZE * scale; depth = DEFAULT_SIZE * scale; //} } buildCube( width, height, depth ); } private function buildCube( fWidth:Number, fHeight:Number, fDepth:Number ):void { var i:Number; var j:Number; var k:Number; var iSag:Number = Math.max(1,this.segmentsS); // sagittal var iTrv:Number = Math.max(1,this.segmentsT); // transversal var iHor:Number = Math.max(1,this.segmentsH); // horizontal var aVertice :Array = this.geometry.vertices; var aFace :Array = this.geometry.faces; // vertices var aTopBottom:Array = new Array(new Array(),new Array()); var aVtc:Array = new Array(); var fZ:Number, fX:Number, fY:Number, oVtx:Vertex3D, iJsbs:int, aPlane:Array; for (i=0;i<(iHor+1);i++) { fZ = -fHeight/2 + fHeight*(i/iHor); var aLyr:Array = new Array(); var iJ:int, iJrel:int; for (j=0;j<2*(iTrv+iSag);j++) { if (j0) { for (j=0;j