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

📄 model.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	        for (j = 0; j < 3; j++) { // spread the mins / maxs by a	            // pixel	            out.mins[j] = in.mins[j] - 1;	            out.maxs[j] = in.maxs[j] + 1;	            out.origin[j] = in.origin[j];	        }	        out.radius = RadiusFromBounds(out.mins, out.maxs);	        out.headnode = in.headnode;	        out.firstface = in.firstface;	        out.numfaces = in.numfaces;	    }	}	/*	=================	Mod_LoadEdges	=================	*/	void Mod_LoadEdges (lump_t l)	{		medge_t[] edges;		int i, count;		if ( (l.filelen % medge_t.DISK_SIZE) != 0)			Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / medge_t.DISK_SIZE;		// out = Hunk_Alloc ( (count + 1) * sizeof(*out));			edges = new medge_t[count + 1];		loadmodel.edges = edges;		loadmodel.numedges = count;				ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++)		{			edges[i] = new medge_t(bb);		}	}	/*	=================	Mod_LoadTexinfo	=================	*/	void Mod_LoadTexinfo(lump_t l)	{		texinfo_t in;		mtexinfo_t[] out;		mtexinfo_t step;		int i, j, count;		int next;		String name;		if ((l.filelen % texinfo_t.SIZE) != 0)			Com.Error (Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / texinfo_t.SIZE;		// out = Hunk_Alloc ( count*sizeof(*out));		out = new mtexinfo_t[count];		for ( i=0 ; i<count ; i++) {			out[i] = new mtexinfo_t();		}		loadmodel.texinfo = out;		loadmodel.numtexinfo = count;				ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++) {						in = new texinfo_t(bb);						out[i].vecs = in.vecs;			out[i].flags = in.flags;			next = in.nexttexinfo;			if (next > 0)				out[i].next = loadmodel.texinfo[next];			else				out[i].next = null;			name = "textures/" +  in.texture + ".wal";			out[i].image = GL_FindImage(name, it_wall);			if (out[i].image == null) {				VID.Printf(Defines.PRINT_ALL, "Couldn't load " + name + '\n');				out[i].image = r_notexture;			}		}		// count animation frames		for (i=0 ; i<count ; i++) {			out[i].numframes = 1;			for (step = out[i].next ; (step != null) && (step != out[i]) ; step=step.next)				out[i].numframes++;		}	}	/*	================	CalcSurfaceExtents	Fills in s.texturemins[] and s.extents[]	================	*/	void CalcSurfaceExtents(msurface_t s)	{		float[] mins = {0, 0};		float[] maxs = {0, 0};		float val;		int j, e;		mvertex_t v;		int[] bmins = {0, 0};		int[] bmaxs = {0, 0};		mins[0] = mins[1] = 999999;		maxs[0] = maxs[1] = -99999;		mtexinfo_t tex = s.texinfo;			for (int i=0 ; i<s.numedges ; i++)		{			e = loadmodel.surfedges[s.firstedge+i];			if (e >= 0)				v = loadmodel.vertexes[loadmodel.edges[e].v[0]];			else				v = loadmodel.vertexes[loadmodel.edges[-e].v[1]];					for (j=0 ; j<2 ; j++)			{				val = v.position[0] * tex.vecs[j][0] + 					v.position[1] * tex.vecs[j][1] +					v.position[2] * tex.vecs[j][2] +					tex.vecs[j][3];				if (val < mins[j])					mins[j] = val;				if (val > maxs[j])					maxs[j] = val;			}		}		for (int i=0 ; i<2 ; i++)		{				bmins[i] = (int)Math.floor(mins[i]/16);			bmaxs[i] = (int)Math.ceil(maxs[i]/16);			s.texturemins[i] = (short)(bmins[i] * 16);			s.extents[i] = (short)((bmaxs[i] - bmins[i]) * 16);		}	}	/*	=================	Mod_LoadFaces	=================	*/	void Mod_LoadFaces(lump_t l) {	    	    int i, surfnum;	    int planenum, side;	    int ti;	    	    if ((l.filelen % qfiles.dface_t.SIZE) != 0)	        Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in "	                + loadmodel.name);	    	    int count = l.filelen / qfiles.dface_t.SIZE;	    // out = Hunk_Alloc ( count*sizeof(*out));	    msurface_t[] outs = new msurface_t[count];	    for (i = 0; i < count; i++) {	        outs[i] = new msurface_t();	    }	    	    loadmodel.surfaces = outs;	    loadmodel.numsurfaces = count;	    	    ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);	    bb.order(ByteOrder.LITTLE_ENDIAN);	    	    currentmodel = loadmodel;	    	    GL_BeginBuildingLightmaps(loadmodel);	    	    qfiles.dface_t in;	    msurface_t out;	    	    for (surfnum = 0; surfnum < count; surfnum++) {	        in = new qfiles.dface_t(bb);	        out = outs[surfnum];	        out.firstedge = in.firstedge;	        out.numedges = in.numedges;	        out.flags = 0;	        out.polys = null;	        	        planenum = in.planenum;	        side = in.side;	        if (side != 0)	            out.flags |= Defines.SURF_PLANEBACK;	        	        out.plane = loadmodel.planes[planenum];	        	        ti = in.texinfo;	        if (ti < 0 || ti >= loadmodel.numtexinfo)	            Com.Error(Defines.ERR_DROP,	            "MOD_LoadBmodel: bad texinfo number");	        	        out.texinfo = loadmodel.texinfo[ti];	        	        CalcSurfaceExtents(out);	        	        // lighting info	        	        for (i = 0; i < Defines.MAXLIGHTMAPS; i++)	            out.styles[i] = in.styles[i];	        	        i = in.lightofs;	        if (i == -1)	            out.samples = null;	        else {	            ByteBuffer pointer = ByteBuffer.wrap(loadmodel.lightdata);	            pointer.position(i);	            pointer = pointer.slice();	            pointer.mark();	            out.samples = pointer; // subarray	        }	        	        // set the drawing flags	        	        if ((out.texinfo.flags & Defines.SURF_WARP) != 0) {	            out.flags |= Defines.SURF_DRAWTURB;	            for (i = 0; i < 2; i++) {	                out.extents[i] = 16384;	                out.texturemins[i] = -8192;	            }	            GL_SubdivideSurface(out); // cut up polygon for warps	        }	        	        // create lightmaps and polygons	        if ((out.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33	                | Defines.SURF_TRANS66 | Defines.SURF_WARP)) == 0)	            GL_CreateSurfaceLightmap(out);	        	        if ((out.texinfo.flags & Defines.SURF_WARP) == 0)	            GL_BuildPolygonFromSurface(out);	        	    }	    GL_EndBuildingLightmaps();	}	/*	=================	Mod_SetParent	=================	*/	void Mod_SetParent(mnode_t node, mnode_t parent)	{		node.parent = parent;		if (node.contents != -1) return;		Mod_SetParent(node.children[0], node);		Mod_SetParent(node.children[1], node);	}	/*	=================	Mod_LoadNodes	=================	*/	void Mod_LoadNodes(lump_t l)	{		int i, j, count, p;		qfiles.dnode_t in;		mnode_t[] out;		if ((l.filelen % qfiles.dnode_t.SIZE) != 0)			Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);				count = l.filelen / qfiles.dnode_t.SIZE;		// out = Hunk_Alloc ( count*sizeof(*out));			out = new mnode_t[count];		loadmodel.nodes = out;		loadmodel.numnodes = count;				ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);				// initialize the tree array		for ( i=0 ; i<count ; i++) out[i] = new mnode_t(); // do first before linking 		// fill and link the nodes		for ( i=0 ; i<count ; i++)		{			in = new qfiles.dnode_t(bb);			for (j=0 ; j<3 ; j++)			{				out[i].mins[j] = in.mins[j];				out[i].maxs[j] = in.maxs[j];			}				p = in.planenum;			out[i].plane = loadmodel.planes[p];			out[i].firstsurface = in.firstface;			out[i].numsurfaces = in.numfaces;			out[i].contents = -1;	// differentiate from leafs			for (j=0 ; j<2 ; j++)			{				p = in.children[j];				if (p >= 0)					out[i].children[j] = loadmodel.nodes[p];				else					out[i].children[j] = loadmodel.leafs[-1 - p]; // mleaf_t extends mnode_t			}		}			Mod_SetParent(loadmodel.nodes[0], null);	// sets nodes and leafs	}	/*	=================	Mod_LoadLeafs	=================	*/	void Mod_LoadLeafs(lump_t l)	{		qfiles.dleaf_t in;		mleaf_t[] out;		int i, j, count, p;		if ((l.filelen % qfiles.dleaf_t.SIZE) != 0)			Com.Error (Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / qfiles.dleaf_t.SIZE;		// out = Hunk_Alloc ( count*sizeof(*out));		out = new mleaf_t[count];			loadmodel.leafs = out;		loadmodel.numleafs = count;				ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++)		{			in = new qfiles.dleaf_t(bb);			out[i] = new mleaf_t();			for (j=0 ; j<3 ; j++)			{				out[i].mins[j] = in.mins[j];				out[i].maxs[j] = in.maxs[j];			}			out[i].contents = in.contents;			out[i].cluster = in.cluster;			out[i].area = in.area;			out[i].setMarkSurface(in.firstleafface, loadmodel.marksurfaces);			out[i].nummarksurfaces = in.numleaffaces;		}		}	/*	=================	Mod_LoadMarksurfaces	=================	*/	void Mod_LoadMarksurfaces(lump_t l)	{			int i, j, count;		msurface_t[] out; 		if ((l.filelen % Defines.SIZE_OF_SHORT) != 0)			Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / Defines.SIZE_OF_SHORT;		// out = Hunk_Alloc ( count*sizeof(*out));			out = new msurface_t[count];		loadmodel.marksurfaces = out;		loadmodel.nummarksurfaces = count;		ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++)		{			j = bb.getShort();			if (j < 0 ||  j >= loadmodel.numsurfaces)				Com.Error(Defines.ERR_DROP, "Mod_ParseMarksurfaces: bad surface number");			out[i] = loadmodel.surfaces[j];		}	}	/*	=================	Mod_LoadSurfedges	=================	*/	void Mod_LoadSurfedges(lump_t l)	{			int i, count;		int[] offsets;			if ( (l.filelen % Defines.SIZE_OF_INT) != 0)			Com.Error (Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / Defines.SIZE_OF_INT;		if (count < 1 || count >= Defines.MAX_MAP_SURFEDGES)			Com.Error (Defines.ERR_DROP, "MOD_LoadBmodel: bad surfedges count in " + loadmodel.name + ": " + count);		offsets = new int[count];		loadmodel.surfedges = offsets;		loadmodel.numsurfedges = count;		ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++) offsets[i] = bb.getInt();	}	/*	=================	Mod_LoadPlanes	=================	*/	void Mod_LoadPlanes(lump_t l)	{		int i, j;		cplane_t[] out;		qfiles.dplane_t in;		int count;		int bits;		if ((l.filelen % qfiles.dplane_t.SIZE) != 0)			Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);		count = l.filelen / qfiles.dplane_t.SIZE;		// out = Hunk_Alloc ( count*2*sizeof(*out));		out = new cplane_t[count * 2];		for (i = 0; i < count; i++) {		    out[i] = new cplane_t();		}

⌨️ 快捷键说明

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