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

📄 model.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			loadmodel.planes = out;		loadmodel.numplanes = count;				ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen);		bb.order(ByteOrder.LITTLE_ENDIAN);		for ( i=0 ; i<count ; i++)		{			bits = 0;			in = new qfiles.dplane_t(bb);			for (j=0 ; j<3 ; j++)			{				out[i].normal[j] = in.normal[j];				if (out[i].normal[j] < 0)					bits |= (1<<j);			}			out[i].dist = in.dist;			out[i].type = (byte)in.type;			out[i].signbits = (byte)bits;		}	}	/*	=================	Mod_LoadBrushModel	=================	*/	void Mod_LoadBrushModel(model_t mod, ByteBuffer buffer)	{		int i;		qfiles.dheader_t	header;		mmodel_t bm;			loadmodel.type = mod_brush;		if (loadmodel != mod_known[0])			Com.Error(Defines.ERR_DROP, "Loaded a brush model after the world");		header = new qfiles.dheader_t(buffer);		i = header.version;		if (i != Defines.BSPVERSION)			Com.Error (Defines.ERR_DROP, "Mod_LoadBrushModel: " + mod.name + " has wrong version number (" + i + " should be " + Defines.BSPVERSION + ")");		mod_base = fileBuffer; //(byte *)header;		// load into heap		Mod_LoadVertexes(header.lumps[Defines.LUMP_VERTEXES]); // ok		Mod_LoadEdges(header.lumps[Defines.LUMP_EDGES]); // ok		Mod_LoadSurfedges(header.lumps[Defines.LUMP_SURFEDGES]); // ok		Mod_LoadLighting(header.lumps[Defines.LUMP_LIGHTING]); // ok		Mod_LoadPlanes(header.lumps[Defines.LUMP_PLANES]); // ok		Mod_LoadTexinfo(header.lumps[Defines.LUMP_TEXINFO]); // ok		Mod_LoadFaces(header.lumps[Defines.LUMP_FACES]); // ok		Mod_LoadMarksurfaces(header.lumps[Defines.LUMP_LEAFFACES]);		Mod_LoadVisibility(header.lumps[Defines.LUMP_VISIBILITY]); // ok		Mod_LoadLeafs(header.lumps[Defines.LUMP_LEAFS]); // ok		Mod_LoadNodes(header.lumps[Defines.LUMP_NODES]); // ok		Mod_LoadSubmodels(header.lumps[Defines.LUMP_MODELS]);		mod.numframes = 2;		// regular and alternate animation			//		// set up the submodels		//		model_t	starmod;		for (i=0 ; i<mod.numsubmodels ; i++)		{			bm = mod.submodels[i];			starmod = mod_inline[i] = loadmodel.copy();			starmod.firstmodelsurface = bm.firstface;			starmod.nummodelsurfaces = bm.numfaces;			starmod.firstnode = bm.headnode;			if (starmod.firstnode >= loadmodel.numnodes)				Com.Error(Defines.ERR_DROP, "Inline model " + i + " has bad firstnode");			Math3D.VectorCopy(bm.maxs, starmod.maxs);			Math3D.VectorCopy(bm.mins, starmod.mins);			starmod.radius = bm.radius;				if (i == 0)				loadmodel = starmod.copy();			starmod.numleafs = bm.visleafs;		}	}	/*	==============================================================================	ALIAS MODELS	==============================================================================	*/	/*	=================	Mod_LoadAliasModel	=================	*/	void Mod_LoadAliasModel (model_t mod, ByteBuffer buffer)	{		int i, j;		qfiles.dmdl_t pheader;		qfiles.dstvert_t[] poutst;		qfiles.dtriangle_t[] pouttri;		qfiles.daliasframe_t[] poutframe;		int[] poutcmd;		pheader = new qfiles.dmdl_t(buffer);		if (pheader.version != qfiles.ALIAS_VERSION)			Com.Error(Defines.ERR_DROP, "%s has wrong version number (%i should be %i)",					 new Vargs(3).add(mod.name).add(pheader.version).add(qfiles.ALIAS_VERSION));		if (pheader.skinheight > MAX_LBM_HEIGHT)			Com.Error(Defines.ERR_DROP, "model "+ mod.name +" has a skin taller than " + MAX_LBM_HEIGHT);		if (pheader.num_xyz <= 0)			Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no vertices");		if (pheader.num_xyz > qfiles.MAX_VERTS)			Com.Error(Defines.ERR_DROP, "model " + mod.name +" has too many vertices");		if (pheader.num_st <= 0)			Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no st vertices");		if (pheader.num_tris <= 0)			Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no triangles");		if (pheader.num_frames <= 0)			Com.Error(Defines.ERR_DROP, "model " + mod.name + " has no frames");		//		// load base s and t vertices (not used in gl version)		//		poutst = new qfiles.dstvert_t[pheader.num_st]; 		buffer.position(pheader.ofs_st);		for (i=0 ; i<pheader.num_st ; i++)		{			poutst[i] = new qfiles.dstvert_t(buffer);		} 		//		//	   load triangle lists		//		pouttri = new qfiles.dtriangle_t[pheader.num_tris];		buffer.position(pheader.ofs_tris);		for (i=0 ; i<pheader.num_tris ; i++)		{			pouttri[i] = new qfiles.dtriangle_t(buffer);		}		//		//	   load the frames		//		poutframe = new qfiles.daliasframe_t[pheader.num_frames];		buffer.position(pheader.ofs_frames);		for (i=0 ; i<pheader.num_frames ; i++)		{			poutframe[i] = new qfiles.daliasframe_t(buffer);			// verts are all 8 bit, so no swapping needed			poutframe[i].verts = new int[pheader.num_xyz];			for (int k=0; k < pheader.num_xyz; k++) {				poutframe[i].verts[k] = buffer.getInt();				}		}		mod.type = mod_alias;		//		// load the glcmds		//		poutcmd = new int[pheader.num_glcmds];		buffer.position(pheader.ofs_glcmds);		for (i=0 ; i<pheader.num_glcmds ; i++)			poutcmd[i] = buffer.getInt(); // LittleLong (pincmd[i]);		// register all skins		String[] skinNames = new String[pheader.num_skins];		byte[] nameBuf = new byte[qfiles.MAX_SKINNAME];		buffer.position(pheader.ofs_skins);		for (i=0 ; i<pheader.num_skins ; i++)		{			buffer.get(nameBuf);			skinNames[i] = new String(nameBuf);			int n = skinNames[i].indexOf('\0');			if (n > -1) {				skinNames[i] = skinNames[i].substring(0, n);			}				mod.skins[i] = GL_FindImage(skinNames[i], it_skin);		}				// set the model arrays		pheader.skinNames = skinNames; // skin names		pheader.stVerts = poutst; // textur koordinaten		pheader.triAngles = pouttri; // dreiecke		pheader.glCmds = poutcmd; // STRIP or FAN		pheader.aliasFrames = poutframe; // frames mit vertex array				mod.extradata = pheader;					mod.mins[0] = -32;		mod.mins[1] = -32;		mod.mins[2] = -32;		mod.maxs[0] = 32;		mod.maxs[1] = 32;		mod.maxs[2] = 32;				precompileGLCmds(pheader);	}	/*	==============================================================================	SPRITE MODELS	==============================================================================	*/	/*	=================	Mod_LoadSpriteModel	=================	*/	void Mod_LoadSpriteModel(model_t mod, ByteBuffer buffer)	{		qfiles.dsprite_t sprout = new qfiles.dsprite_t(buffer);				if (sprout.version != qfiles.SPRITE_VERSION)			Com.Error(Defines.ERR_DROP, "%s has wrong version number (%i should be %i)",				new Vargs(3).add(mod.name).add(sprout.version).add(qfiles.SPRITE_VERSION));		if (sprout.numframes > qfiles.MAX_MD2SKINS)			Com.Error(Defines.ERR_DROP, "%s has too many frames (%i > %i)",				new Vargs(3).add(mod.name).add(sprout.numframes).add(qfiles.MAX_MD2SKINS));		for (int i=0 ; i<sprout.numframes ; i++)		{			mod.skins[i] = GL_FindImage(sprout.frames[i].name,	it_sprite);		}		mod.type = mod_sprite;		mod.extradata = sprout;	}//	  =============================================================================	/*	@@@@@@@@@@@@@@@@@@@@@	R_BeginRegistration	Specifies the model that will be used as the world	@@@@@@@@@@@@@@@@@@@@@	*/	protected void R_BeginRegistration(String model)	{		resetModelArrays();		Polygon.reset();		cvar_t flushmap;		registration_sequence++;		r_oldviewcluster = -1;		// force markleafs		String fullname = "maps/" + model + ".bsp";		// explicitly free the old map if different		// this guarantees that mod_known[0] is the world map		flushmap = Cvar.Get("flushmap", "0", 0);		if ( !mod_known[0].name.equals(fullname) || flushmap.value != 0.0f)			Mod_Free(mod_known[0]);		r_worldmodel = Mod_ForName(fullname, true);		r_viewcluster = -1;	}	/*	@@@@@@@@@@@@@@@@@@@@@	R_RegisterModel	@@@@@@@@@@@@@@@@@@@@@	*/	protected model_t R_RegisterModel(String name)	{		model_t	mod = null;		int		i;		qfiles.dsprite_t sprout;		qfiles.dmdl_t pheader;		mod = Mod_ForName(name, false);		if (mod != null)		{			mod.registration_sequence = registration_sequence;			// register any images used by the models			if (mod.type == mod_sprite)			{				sprout = (qfiles.dsprite_t)mod.extradata;				for (i=0 ; i<sprout.numframes ; i++)					mod.skins[i] = GL_FindImage(sprout.frames[i].name, it_sprite);			}			else if (mod.type == mod_alias)			{				pheader = (qfiles.dmdl_t)mod.extradata;				for (i=0 ; i<pheader.num_skins ; i++)					mod.skins[i] = GL_FindImage(pheader.skinNames[i], it_skin);				// PGM				mod.numframes = pheader.num_frames;				// PGM			}			else if (mod.type == mod_brush)			{				for (i=0 ; i<mod.numtexinfo ; i++)					mod.texinfo[i].image.registration_sequence = registration_sequence;			}		}		return mod;	}	/*	@@@@@@@@@@@@@@@@@@@@@	R_EndRegistration	@@@@@@@@@@@@@@@@@@@@@	*/	protected void R_EndRegistration()	{		model_t	mod;		for (int i=0; i<mod_numknown ; i++)		{			mod = mod_known[i];			if (mod.name.length() == 0)				continue;			if (mod.registration_sequence != registration_sequence)			{	// don't need this model				Mod_Free(mod);			} else {				// precompile AliasModels				if (mod.type == mod_alias)					precompileGLCmds((qfiles.dmdl_t)mod.extradata);			}		}		GL_FreeUnusedImages();		//modelMemoryUsage();	}//	  =============================================================================	/*	================	Mod_Free	================	*/	void Mod_Free (model_t mod)	{		mod.clear();	}	/*	================	Mod_FreeAll	================	*/	void Mod_FreeAll()	{		for (int i=0 ; i<mod_numknown ; i++)		{			if (mod_known[i].extradata != null)				Mod_Free(mod_known[i]);		}	}	/*	 * new functions for vertex array handling	 */	static final int MODEL_BUFFER_SIZE = 50000;	static FloatBuffer globalModelTextureCoordBuf = BufferUtils.createFloatBuffer(MODEL_BUFFER_SIZE * 2);	static IntBuffer globalModelVertexIndexBuf = BufferUtils.createIntBuffer(MODEL_BUFFER_SIZE);		void precompileGLCmds(qfiles.dmdl_t model) {		model.textureCoordBuf = globalModelTextureCoordBuf.slice();		model.vertexIndexBuf = globalModelVertexIndexBuf.slice();		Vector tmp = new Vector();					int count = 0;		int[] order = model.glCmds;		int orderIndex = 0;		while (true)		{			// get the vertex count and primitive type			count = order[orderIndex++];			if (count == 0)				break;		// done			tmp.addElement(new Integer(count));							if (count < 0)			{				count = -count;				//gl.glBegin (GL.GL_TRIANGLE_FAN);			}			else			{				//gl.glBegin (GL.GL_TRIANGLE_STRIP);			}			do {				// texture coordinates come from the draw list				globalModelTextureCoordBuf.put(Float.intBitsToFloat(order[orderIndex + 0]));				globalModelTextureCoordBuf.put(Float.intBitsToFloat(order[orderIndex + 1]));				globalModelVertexIndexBuf.put(order[orderIndex + 2]);				orderIndex += 3;			} while (--count != 0);		}					int size = tmp.size();					model.counts = new int[size];		model.indexElements = new IntBuffer[size];					count = 0;		int pos = 0;		for (int i = 0; i < model.counts.length; i++) {			count = ((Integer)tmp.get(i)).intValue();			model.counts[i] = count;							count = (count < 0) ? -count : count;			model.vertexIndexBuf.position(pos);			model.indexElements[i] = model.vertexIndexBuf.slice();			model.indexElements[i].limit(count);			pos += count;		}	}			static void resetModelArrays() {		globalModelTextureCoordBuf.rewind();		globalModelVertexIndexBuf.rewind();	}			static void modelMemoryUsage() {		System.out.println("AliasModels: globalVertexBuffer size " + globalModelVertexIndexBuf.position());	}}

⌨️ 快捷键说明

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