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

📄 mesh.as

📁 著名的flash 3d引擎 away 3d的源代码
💻 AS
📖 第 1 页 / 共 3 页
字号:
                if (_tri.material == null)                    if (_backface)                        _tri.material = _backmat;                    else                        _tri.material = _material;								//do not draw material if visible is false                if (_tri.material != null)                    if (!_tri.material.visible)                        _tri.material = null;								//if there is no material and no outline, continue                if (outline == null)                    if (_tri.material == null)                        continue;				                if (pushback)                    _tri.screenZ = _tri.maxZ;                if (pushfront)                    _tri.screenZ = _tri.minZ;								_uvmaterial = (_tri.material is IUVMaterial || _tri.material is ILayerMaterial);								//swap ScreenVerticies if _triangle facing away from camera                if (_backface) {                    // Make cleaner                    _vt = _tri.v1;                    _tri.v1 = _tri.v2;                    _tri.v2 = _vt;					                    _tri.area = -_tri.area;                                        if (_uvmaterial) {						//pass accross uv values		                _tri.uv0 = face._uv0;		                _tri.uv1 = face._uv2;		                _tri.uv2 = face._uv1;                    }                } else if (_uvmaterial) {					//pass accross uv values	                _tri.uv0 = face._uv0;	                _tri.uv1 = face._uv1;	                _tri.uv2 = face._uv2;                }                                //check if face swapped direction                if (_tri.backface != _backface) {                	_tri.backface = _backface;                	_tri.texturemapping = null;                }                                if (outline != null && !_backface)                {                    _n01 = _neighbour01[face];                    if (_n01 == null || _n01.front(projection) <= 0)                    	consumer.primitive(createDrawSegment(outline, projection, _tri.v0, _tri.v1));                    _n12 = _neighbour12[face];                    if (_n12 == null || _n12.front(projection) <= 0)                    	consumer.primitive(createDrawSegment(outline, projection, _tri.v1, _tri.v2));                    _n20 = _neighbour20[face];                    if (_n20 == null || _n20.front(projection) <= 0)                    	consumer.primitive(createDrawSegment(outline, projection, _tri.v2, _tri.v0));                    if (_tri.material == null)                    	continue;                }                _tri.projection = projection;                consumer.primitive(_tri);            }        }				/**		 * Duplicates the mesh properties to another 3d object.		 * 		 * @param	object	[optional]	The new object instance into which all properties are copied. The default is <code>Mesh</code>.		 * @return						The new object instance with duplicated properties applied.		 */        public override function clone(object:* = null):*        {            var mesh:Mesh = object || new Mesh();            super.clone(mesh);            mesh.material = material;            mesh.outline = outline;            mesh.back = back;            mesh.bothsides = bothsides;            mesh.debugbb = debugbb;            var clonedvertices:Dictionary = new Dictionary();            var clonevertex:Function = function(vertex:Vertex):Vertex            {                var result:Vertex = clonedvertices[vertex];                if (result == null)                {                    result = new Vertex(vertex._x, vertex._y, vertex._z);                    result.extra = (vertex.extra is IClonable) ? (vertex.extra as IClonable).clone() : vertex.extra;                    clonedvertices[vertex] = result;                }                return result;            };            var cloneduvs:Dictionary = new Dictionary();            var cloneuv:Function = function(uv:UV):UV            {                if (uv == null)                    return null;                var result:UV = cloneduvs[uv];                if (result == null)                {                    result = new UV(uv._u, uv._v);                    cloneduvs[uv] = result;                }                return result;            };                        for each (var face:Face in _faces)                mesh.addFace(new Face(clonevertex(face._v0), clonevertex(face._v1), clonevertex(face._v2), face.material, cloneuv(face._uv0), cloneuv(face._uv1), cloneuv(face._uv2)));            return mesh;        }		 		public var indexes:Array; 		 		/** 		 * Returns a formatted string containing a self contained AS3 class definition that can be used to re-create the mesh. 		 *  		 * @param	classname	[optional]	Defines the class name used in the output string. Defaults to <code>Away3DObject</code>. 		 * @param	packagename	[optional]	Defines the package name used in the output string. Defaults to no package. 		 * @param	round		[optional]	Rounds all values to 4 decimal places. Defaults to false. 		 * @param	animated	[optional]	Defines whether animation data should be saved. Defaults to false. 		 *  		 * @return	A string to be pasted into a new .as file 		 */ 		public function asAS3Class(classname:String = null, packagename:String = "", round:Boolean = false, animated:Boolean = false):String        {            classname = classname || name || "Away3DObject";						var importextra:String  = (animated)? "\timport flash.utils.Dictionary;\n" : "";             var source:String = "package "+packagename+"\n{\n\timport away3d.core.base.*;\n\timport away3d.core.utils.*;\n"+importextra+"\n\tpublic class "+classname+" extends Mesh\n\t{\n";            source += "\t\tprivate var varr:Array = [];\n\t\tprivate var uvarr:Array = [];\n\t\tprivate var scaling:Number;\n";						if(animated){				source += "\t\tprivate var fnarr:Array = [];\n\n";				source += "\n\t\tprivate function v():void\n\t\t{\n";				source += "\t\t\tfor(var i:int = 0;i<vcount;i++){\n\t\t\t\tvarr.push(new Vertex(0,0,0));\n\t\t\t}\n\t\t}\n\n";			} else{				source += "\n\t\tprivate function v(x:Number,y:Number,z:Number):void\n\t\t{\n";				source += "\t\t\tvarr.push(new Vertex(x*scaling, y*scaling, z*scaling));\n\t\t}\n\n";			}            source += "\t\tprivate function uv(u:Number,v:Number):void\n\t\t{\n";            source += "\t\t\tuvarr.push(new UV(u,v));\n\t\t}\n\n";            source += "\t\tprivate function f(vn0:int, vn1:int, vn2:int, uvn0:int, uvn1:int, uvn2:int):void\n\t\t{\n";            source += "\t\t\taddFace(new Face(varr[vn0],varr[vn1],varr[vn2], null, uvarr[uvn0],uvarr[uvn1],uvarr[uvn2]));\n\t\t}\n\n";            source += "\t\tpublic function "+classname+"(init:Object = null)\n\t\t{\n\t\t\tsuper(init);\n\t\t\tinit = Init.parse(init);\n\t\t\tscaling = init.getNumber(\"scaling\", 1);\n\t\t\tbuild();\n\t\t\ttype = \".as\";\n\t\t}\n\n";            source += "\t\tprivate function build():void\n\t\t{\n";							var refvertices:Dictionary = new Dictionary();            var verticeslist:Array = [];            var remembervertex:Function = function(vertex:Vertex):void            {                if (refvertices[vertex] == null)                {                    refvertices[vertex] = verticeslist.length;                    verticeslist.push(vertex);                }            };            var refuvs:Dictionary = new Dictionary();            var uvslist:Array = [];            var rememberuv:Function = function(uv:UV):void            {                if (uv == null)                    return;                if (refuvs[uv] == null)                {                    refuvs[uv] = uvslist.length;                    uvslist.push(uv);                }            };            for each (var face:Face in _faces)            {                remembervertex(face._v0);                remembervertex(face._v1);                remembervertex(face._v2);                rememberuv(face._uv0);                rememberuv(face._uv1);                rememberuv(face._uv2);            } 						var uv:UV;			var v:Vertex;			var myPattern:RegExp;			var myPattern2:RegExp;						if(animated){				myPattern = new RegExp("vcount","g");				source = source.replace(myPattern, verticeslist.length);				source += "\n\t\t\tv();\n\n";													} else{				for each (v in verticeslist)					source += (round)? "\t\t\tv("+v._x.toFixed(4)+","+v._y.toFixed(4)+","+v._z.toFixed(4)+");\n" : "\t\t\tv("+v._x+","+v._y+","+v._z+");\n";							}			 			for each (uv in uvslist)				source += (round)? "\t\t\tuv("+uv._u.toFixed(4)+","+uv._v.toFixed(4)+");\n"  :  "\t\t\tuv("+uv._u+","+uv._v+");\n";			if(round){				var tmp:String;				myPattern2 = new RegExp(".0000","g");			}						var f:Face;				if(animated){				var ind:Array;				var auv:Array = [];				for each (f in _faces)									auv.push((round)? refuvs[f._uv0].toFixed(4)+","+refuvs[f._uv1].toFixed(4)+","+refuvs[f._uv2].toFixed(4) : refuvs[f._uv0]+","+refuvs[f._uv1]+","+refuvs[f._uv2]);								for(var i:int = 0; i< indexes.length;i++){					ind = indexes[i];					source += "\t\t\tf("+ind[0]+","+ind[1]+","+ind[2]+","+auv[i]+");\n";				}							} else{				for each (f in _faces)					source += "\t\t\tf("+refvertices[f._v0]+","+refvertices[f._v1]+","+refvertices[f._v2]+","+refuvs[f._uv0]+","+refuvs[f._uv1]+","+refuvs[f._uv2]+");\n";			}			if(round) source = source.replace(myPattern2,"");						if(animated){				var afn:Array = new Array();				var avp:Array;				var tmpnames:Array = new Array();				i= 0;				var y:int = 0;				source += "\n\t\t\tframes = new Dictionary();\n";            	source += "\t\t\tframenames = new Dictionary();\n";				source += "\t\t\tvar oFrames:Object = new Object();\n";								myPattern = new RegExp(" ","g");								for (var framename:String in framenames){					tmpnames.push(framename);				}								tmpnames.sort(); 				var fr:Frame;				for (i = 0;i<tmpnames.length;i++){					avp = new Array();					fr = frames[framenames[tmpnames[i]]];					if(tmpnames[i].indexOf(" ") != -1) tmpnames[i] = tmpnames[i].replace(myPattern,"");					afn.push("\""+tmpnames[i]+"\"");					source += "\n\t\t\toFrames."+tmpnames[i]+"=[";					for(y = 0; y<verticeslist.length ;y++){						if(round){							avp.push(fr.vertexpositions[y].x.toFixed(4));							avp.push(fr.vertexpositions[y].y.toFixed(4));							avp.push(fr.vertexpositions[y].z.toFixed(4));						} else{							avp.push(fr.vertexpositions[y].x);							avp.push(fr.vertexpositions[y].y);							avp.push(fr.vertexpositions[y].z);						}					}					if(round){						tmp = avp.toString();						tmp = tmp.replace(myPattern2,"");						source += tmp +"];\n";					} else{						source += avp.toString() +"];\n";					}				}								source += "\n\t\t\tfnarr = ["+afn.toString()+"];\n";				source += "\n\t\t\tvar y:int;\n";				source += "\t\t\tvar z:int;\n";				source += "\t\t\tvar frame:Frame;\n";				source += "\t\t\tfor(var i:int = 0;i<fnarr.length; i++){\n";				source += "\t\t\t\ttrace(\"[ \"+fnarr[i]+\" ]\");\n";				source += "\t\t\t\tframe = new Frame();\n";				source += "\t\t\t\tframenames[fnarr[i]] = i;\n";				source += "\t\t\t\tframes[i] = frame;\n";				source += "\t\t\t\tz=0;\n";				source += "\t\t\t\tfor (y = 0; y < oFrames[fnarr[i]].length; y+=3){\n";				source += "\t\t\t\t\tvar vp:VertexPosition = new VertexPosition(varr[z]);\n";				source += "\t\t\t\t\tz++;\n";				source += "\t\t\t\t\tvp.x = oFrames[fnarr[i]][y]*scaling;\n";				source += "\t\t\t\t\tvp.y = oFrames[fnarr[i]][y+1]*scaling;\n";				source += "\t\t\t\t\tvp.z = oFrames[fnarr[i]][y+2]*scaling;\n";				source += "\t\t\t\t\tframe.vertexpositions.push(vp);\n";				source += "\t\t\t\t}\n";				source += "\t\t\t\tif (i == 0)\n";				source += "\t\t\t\t\tframe.adjust();\n";				source += "\t\t\t}\n";							}			source += "\n\t\t}\n\t}\n}";			//here a setClipboard to avoid Flash slow trace window might be beter...            return source;        } 		 		/** 		 * Returns an xml representation of the mesh 		 *  		 * @return	An xml object containing mesh information 		 */        public function asXML():XML        {            var result:XML = <mesh></mesh>;            var refvertices:Dictionary = new Dictionary();            var verticeslist:Array = [];            var remembervertex:Function = function(vertex:Vertex):void            {                if (refvertices[vertex] == null)                {                    refvertices[vertex] = verticeslist.length;                    verticeslist.push(vertex);                }            };            var refuvs:Dictionary = new Dictionary();            var uvslist:Array = [];            var rememberuv:Function = function(uv:UV):void            {                if (uv == null)                    return;                if (refuvs[uv] == null)                {                    refuvs[uv] = uvslist.length;                    uvslist.push(uv);                }            };            for each (var face:Face in _faces)            {                remembervertex(face._v0);                remembervertex(face._v1);                remembervertex(face._v2);                rememberuv(face._uv0);                rememberuv(face._uv1);                rememberuv(face._uv2);            }            var vn:int = 0;            for each (var v:Vertex in verticeslist)            {                result.appendChild(<vertex id={vn} x={v._x} y={v._y} z={v._z}/>);                vn++;            }            var uvn:int = 0;            for each (var uv:UV in uvslist)            {                result.appendChild(<uv id={uvn} u={uv._u} v={uv._v}/>);                uvn++;            }            for each (var f:Face in _faces)                result.appendChild(<face v0={refvertices[f._v0]} v1={refvertices[f._v1]} v2={refvertices[f._v2]} uv0={refuvs[f._uv0]} uv1={refuvs[f._uv1]} uv2={refuvs[f._uv2]}/>);            return result;        }    }}

⌨️ 快捷键说明

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