📄 model.java
字号:
{ in = new qfiles.dface_t(bb); out[surfnum] = new msurface_t(); out[surfnum].firstedge = in.firstedge; out[surfnum].numedges = in.numedges; out[surfnum].flags = 0; out[surfnum].polys = null; planenum = in.planenum; side = in.side; if (side != 0) out[surfnum].flags |= Defines.SURF_PLANEBACK; out[surfnum].plane = loadmodel.planes[planenum]; ti = in.texinfo; if (ti < 0 || ti >= loadmodel.numtexinfo) Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: bad texinfo number"); out[surfnum].texinfo = loadmodel.texinfo[ti]; CalcSurfaceExtents(out[surfnum]); // lighting info for (i=0 ; i<Defines.MAXLIGHTMAPS ; i++) out[surfnum].styles[i] = in.styles[i]; i = in.lightofs; if (i == -1) out[surfnum].samples = null; else { ByteBuffer pointer = ByteBuffer.wrap(loadmodel.lightdata); pointer.position(i); pointer = pointer.slice(); pointer.mark(); out[surfnum].samples = pointer; // subarray } // set the drawing flags if ((out[surfnum].texinfo.flags & Defines.SURF_WARP) != 0) { out[surfnum].flags |= Defines.SURF_DRAWTURB; for (i=0 ; i<2 ; i++) { out[surfnum].extents[i] = 16384; out[surfnum].texturemins[i] = -8192; } GL_SubdivideSurface(out[surfnum]); // cut up polygon for warps } // create lightmaps and polygons if ((out[surfnum].texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) == 0) GL_CreateSurfaceLightmap(out[surfnum]); if ((out[surfnum].texinfo.flags & Defines.SURF_WARP) == 0) GL_BuildPolygonFromSurface(out[surfnum]); } 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]; 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); out[i] = new cplane_t(); 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).trim(); 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; } /* ============================================================================== 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) { cvar_t flushmap; Polygon.reset(); 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); } } GL_FreeUnusedImages(); }// ============================================================================= /* ================ 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]); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -