⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 materialobject3d.as

📁 一个2D基于verlet的Flash物理引擎。它用AS3编写而成。Fisix的目标是应用到游戏等计算量很大的实时应用中。尽管flash比c/c++要慢,很棒的物理引擎
💻 AS
字号:
/*
 *  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.
 */

// _______________________________________________________________________ MaterialObject3D

package org.papervision3d.core.proto
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.events.EventDispatcher;
	import flash.geom.Matrix;
	import flash.utils.Dictionary;
	
	import org.papervision3d.core.geom.renderables.Triangle3D;
	import org.papervision3d.core.layers.RenderLayer;
	import org.papervision3d.core.render.data.RenderSessionData;
	import org.papervision3d.core.render.draw.ITriangleDrawer;
	import org.papervision3d.core.render.material.MaterialManager;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.DisplayObject3D;


	/**
	* The MaterialObject3D class is the base class for all materials.
	* <p/>
	* Materials collects data about how objects appear when rendered.
	* <p/>
	* A material is data that you assign to objects or faces, so that they appear a certain way when rendered. Materials affect the line and fill colors.
	* <p/>
	* Materials create greater realism in a scene. A material describes how an object reflects or transmits light.
	* <p/>
	* You assign materials to individual objects or a selection of faces; a single object can contain different materials.
	* <p/>
	* MaterialObject3D is an abstract base class; therefore, you cannot call MaterialObject3D directly.
	*/
	public class MaterialObject3D extends EventDispatcher implements ITriangleDrawer
	{
				
		/**
		* A transparent or opaque BitmapData texture.
		*/
		public var bitmap :BitmapData;

		/**
		* A Boolean value that determines whether the BitmapData texture is smoothed when rendered.
		*/
		public var smooth :Boolean = false;

		/**
		* A Boolean value that determines whether the texture is tiled when rendered. Defaults to false.
		*/
		public var tiled :Boolean = false;

		/**
		* A RGB color value to draw the faces outline.
		*/
		public var lineColor :Number = DEFAULT_COLOR;

		/**
		* An 8-bit alpha value for the faces outline. If zero, no outline is drawn.
		*/
		public var lineAlpha :Number = 0;
		
		/**
		* An value for the thickness of the faces line.
		*/
		public var lineThickness:Number = 1;

		/**
		* A RGB color value to fill the faces with. Only used if no texture is provided.
		*/
		public var fillColor :Number = DEFAULT_COLOR;

		/**
		* An 8-bit alpha value fill the faces with. If this value is zero and no texture is provided or is undefined, a fill is not created.
		*/
		public var fillAlpha :Number = 0;

		/**
		* A Boolean value that indicates whether the faces are double sided.
		*/
		public function get doubleSided():Boolean
		{
			return ! this.oneSide;
		}

		public function set doubleSided( double:Boolean ):void
		{
			this.oneSide = ! double;
		}

		/**
		* A Boolean value that indicates whether the faces are single sided. It has preference over doubleSided.
		*/
		public var oneSide :Boolean = true;

		/**
		* A Boolean value that indicates whether the faces are invisible (not drawn).
		*/
		public var invisible :Boolean = false;

		/**
		* A Boolean value that indicates whether the face is flipped. Only used if doubleSided or not singeSided.
		*/
		public var opposite :Boolean = false;

		/**
		* The scene where the object belongs.
		*/
		public var scene :SceneObject3D;

		/**
		* Color used for DEFAULT material.
		*/
		static public var DEFAULT_COLOR :int = 0x000000;

		/**
		* Color used for DEBUG material.
		*/
		static public var DEBUG_COLOR :int = 0xFF00FF;

		/**
		* The name of the material.
		*/
		public var name :String;

		/**
		* [internal-use] [read-only] Unique id of this instance.
		*/
		public var id :Number;

		/**
		 * Internal use
		 */
		public var maxU :Number;

		/**
		 * Internal use
		 */
		public var maxV :Number;
		 
		 /**
		* Holds the original size of the bitmap before it was resized by Automip mapping
		*/
		 public var widthOffset:Number = 0;
		/**
		* Holds the original size of the bitmap before it was resized by Automip mapping
		*/
		 public var heightOffset:Number = 0;
		
		/**
		 * Defines if this material will be interactive;
		 */
		public var interactive:Boolean = false;
		protected var objects:Dictionary;
		
		public var renderLayer:RenderLayer = null;

		/**
		* Creates a new MaterialObject3D object.
		*
		* @param	initObject	[optional] - An object that contains properties for the newly created material.
		*/
		public function MaterialObject3D()
		{
			this.id = _totalMaterialObjects++;
			MaterialManager.registerMaterial(this);
			objects = new Dictionary();
		}

		/**
		* Returns a MaterialObject3D object with the default magenta wireframe values.
		*
		* @return A MaterialObject3D object.
		*/
		static public function get DEFAULT():MaterialObject3D
		{
			var defMaterial :MaterialObject3D = new WireframeMaterial(); //RH, it now returns a wireframe material.
			defMaterial.lineColor   = 0xFFFFFF * Math.random();
			defMaterial.lineAlpha   = 1;
			defMaterial.fillColor   = DEFAULT_COLOR;
			defMaterial.fillAlpha   = 1;
			defMaterial.doubleSided = false;

			return defMaterial;
		}

		static public function get DEBUG():MaterialObject3D
		{
			var defMaterial :MaterialObject3D = new MaterialObject3D();

			defMaterial.lineColor   = 0xFFFFFF * Math.random();
			defMaterial.lineAlpha   = 1;
			defMaterial.fillColor   = DEBUG_COLOR;
			defMaterial.fillAlpha   = 0.37;
			defMaterial.doubleSided = true;

			return defMaterial;
		}
		
		
		/**
		 *	drawTriangle();
		 *
		 * Draws the triangle to screen.
		 *
		 */
		public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData = null, altUV:Matrix=null):void
		{
			
		}
		
		/**
		* Updates the BitmapData bitmap from the given texture.
		*
		* Draws the current MovieClip image onto bitmap.
		*/
		public function updateBitmap():void {}


		/**
		* Copies the properties of a material.
		*
		* @param	material	Material to copy from.
		*/
		public function copy( material :MaterialObject3D ):void
		{
			this.bitmap    = material.bitmap;
	//		this.animated  = material.animated;
			this.smooth    = material.smooth;

			this.lineColor = material.lineColor;
			this.lineAlpha = material.lineAlpha;
			this.fillColor = material.fillColor;
			this.fillAlpha = material.fillAlpha;
			
			this.oneSide   = material.oneSide;
			this.opposite  = material.opposite;

			this.invisible = material.invisible;
			this.scene     = material.scene;
			this.name      = material.name;
			
			this.maxU      = material.maxU;
			this.maxV      = material.maxV;
		}

		/**
		* Creates a copy of the material.
		*
		* @return	A newly created material that contains the same properties.
		*/
		public function clone():MaterialObject3D
		{
			var cloned:MaterialObject3D = new MaterialObject3D();
			cloned.copy(this);
			return cloned;
		}
		
		public function registerObject(displayObject3D:DisplayObject3D):void
		{
			objects[displayObject3D] = displayObject3D;
		}
		
		public function unregisterObject(displayObject3D:DisplayObject3D):void
		{
			if(objects[displayObject3D] != null){
				delete objects[displayObject3D];
			}
		}
		
		protected function destroy():void
		{
			MaterialManager.unRegisterMaterial(this);
		}

		/**
		* Returns a string value representing the material properties.
		*
		* @return	A string.
		*/
		override public function toString():String
		{
			return '[MaterialObject3D] bitmap:' + this.bitmap + ' lineColor:' + this.lineColor + ' fillColor:' + fillColor;
		}

		static private var _totalMaterialObjects :Number = 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -