📄 gl_model.pas
字号:
Result := VectorLength (corner);
end;
{*
=================
Mod_LoadSubmodels
=================
*}
procedure Mod_LoadSubmodels (l : lump_p);
var
_in : dmodel_p;
_out : mmodel_p;
i, j,
count : integer;
begin
//Y in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
//Y _out = Hunk_Alloc ( count*sizeof(*out));
loadmodel.submodels := _out;
loadmodel.numsubmodels := count;
//Y for ( i=0 ; i<count ; i++, in++, out++)
begin
for j:=0 to 2 do
begin
// spread the mins / maxs by a pixel
_out.mins[j] := LittleFloat (_in.mins[j]) - 1;
_out.maxs[j] := LittleFloat (_in.maxs[j]) + 1;
_out.origin[j] := LittleFloat (_in.origin[j]);
end;
_out.radius := RadiusFromBounds (_out.mins, _out.maxs);
_out.headnode := LittleLong (_in.headnode);
_out.firstface := LittleLong (_in.firstface);
_out.numfaces := LittleLong (_in.numfaces);
end;
end;
{*
=================
Mod_LoadEdges
=================
*}
procedure Mod_LoadEdges (l : lump_p);
var
_in : dedge_p;
_out : medge_p;
i,
count : integer;
begin
//Y _in := (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
(*Y out = Hunk_Alloc ( (count + 1) * sizeof(*out));
loadmodel.edges := _out;*)
loadmodel.numedges := count;
// for ( i=0 ; i<count ; i++, in++, out++)
begin
_out.v[0] := {(unsigned short)}LittleShort(_in.v[0]);
_out.v[1] := {(unsigned short)}LittleShort(_in.v[1]);
end;
end;
{*
=================
Mod_LoadTexinfo
=================
*}
procedure Mod_LoadTexinfo (l : lump_p);
var
_in : texinfo_p;
_out,
step : mtexinfo_p;
i, j,
count : integer;
name : array [0..MAX_QPATH-1] of char;
next : integer;
begin
//Y in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
//Y out = Hunk_Alloc ( count*sizeof(*out));
loadmodel.texinfo := _out;
loadmodel.numtexinfo := count;
//Y for ( i=0 ; i<count ; i++, in++, out++)
begin
for j:=0 to 7 do
_out.vecs[0][j] := LittleFloat (_in.vecs[0][j]);
_out.flags := LittleLong (_in.flags);
next := LittleLong (_in.nexttexinfo);
(*Y if (next > 0)
then _out.next := loadmodel.texinfo + next
else _out.next := Nil;*)
Com_sprintf (name, sizeof(name), 'textures/%s.wal', [_in.texture]);
(*Y _out.image := GL_FindImage (name, it_wall);
if (!out.image) then*)
begin
ri.Con_Printf (PRINT_ALL, 'Couldn"t load %s\n', [name]);
//Y _out.image := r_notexture;
end;
end;
// count animation frames
for i:=0 to count-1 do
begin
//Y _out := &loadmodel.texinfo[i];
_out.numframes := 1;
(*Y for (step = out->next ; step && step != out ; step=step->next)
out->numframes++;*)
end;
end;
{*
================
CalcSurfaceExtents
Fills in s->texturemins[] and s->extents[]
================
*}
procedure CalcSurfaceExtents (s : msurface_p);
var
mins,
maxs : array [0..1] of float;
val : float;
i,j, e : integer;
v : mvertex_p;
tex : mtexinfo_p;
bmins,
bmaxs : array [0..1] of integer;
begin
mins[1] := 999999;
mins[0] := mins[1];
maxs[1] := -99999;
maxs[0] := maxs[1];
tex := s.texinfo;
for i:=0 to s.numedges-1 do
begin
e := loadmodel.surfedges[s.firstedge+i];
if (e >= 0)
then v := loadmodel.vertexes[loadmodel.edges[e].v[0]]
else v := loadmodel.vertexes[loadmodel.edges[-e].v[1]];
for j:=0 to 1 do
begin
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]) then
mins[j] := val;
if (val > maxs[j]) then
maxs[j] := val;
end;
end;
for i:=0 to 1 do
begin
bmins[i] := Floor (mins[i]/16);
bmaxs[i] := Ceil (maxs[i]/16);
s.texturemins[i] := bmins[i] * 16;
s.extents[i] := (bmaxs[i] - bmins[i]) * 16;
//id_soft if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
//id_soft ri.Sys_Error (ERR_DROP, "Bad surface extents");
end;
end;
(*void GL_BuildPolygonFromSurface(msurface_t *fa);
void GL_CreateSurfaceLightmap (msurface_t *surf);
void GL_EndBuildingLightmaps (void);
void GL_BeginBuildingLightmaps (model_t *m);*)
{*
=================
Mod_LoadFaces
=================
*}
procedure Mod_LoadFaces (l : lump_p);
var
_in : dface_p;
_out : msurface_p;
i, count, surfnum,
planenum, side,
ti : integer;
begin
//Y in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
(*Y out = Hunk_Alloc ( count*sizeof(*out));
loadmodel.surfaces := _out;*)
loadmodel.numsurfaces := count;
currentmodel := loadmodel;
(*Y GL_BeginBuildingLightmaps (loadmodel);
for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)*)
begin
_out.firstedge := LittleLong(_in.firstedge);
_out.numedges := LittleShort(_in.numedges);
_out.flags := 0;
_out.polys := Nil;
planenum := LittleShort(_in.planenum);
side := LittleShort(_in.side);
if (side <> 0) then
_out.flags := _out.flags OR SURF_PLANEBACK;
//Y _out.plane := loadmodel.planes + planenum;
ti := LittleShort (_in.texinfo);
if (ti < 0) OR (ti >= loadmodel.numtexinfo) then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: bad texinfo number', []);
//Y _out.texinfo := loadmodel.texinfo + ti;
CalcSurfaceExtents (_out);
// lighting info
for i:=0 to MAXLIGHTMAPS-1 do
_out.styles[i] := _in.styles[i];
i := LittleLong(_in.lightofs);
if (i = -1)
then _out.samples := Nil(*Y
else _out.samples := loadmodel.lightdata + i*);
// set the drawing flags
if (_out.texinfo.flags AND SURF_WARP) <> 0 then
begin
_out.flags := _out.flags OR SURF_DRAWTURB;
for i:=0 to 1 do
begin
_out.extents[i] := 16384;
_out.texturemins[i] := -8192;
end;
GL_SubdivideSurface (_out); // cut up polygon for warps
end;
// create lightmaps and polygons
// if ( !(out->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP) ) )
if ((_out.texinfo.flags AND (SURF_SKY OR SURF_TRANS33 OR SURF_TRANS66 OR SURF_WARP)) = 0) then
GL_CreateSurfaceLightmap (_out);
// if (! (out->texinfo->flags & SURF_WARP) )
if ((_out.texinfo.flags AND SURF_WARP) = 0) then
GL_BuildPolygonFromSurface (_out);
end;
GL_EndBuildingLightmaps ();
end;
{*
=================
Mod_SetParent
=================
*}
procedure Mod_SetParent (node, parent : mnode_p);
begin
node.parent := parent;
if (node.contents <> -1) then
Exit;
Mod_SetParent (node.children[0], node);
Mod_SetParent (node.children[1], node);
end;
{*
=================
Mod_LoadNodes
=================
*}
procedure Mod_LoadNodes (l : lump_p);
var
i, j,
count, p : integer;
_in : dnode_p;
_out : mnode_p;
begin
// in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
(*Y _out := Hunk_Alloc ( count*sizeof(*out));
loadmodel.nodes := _out;*)
loadmodel.numnodes := count;
//Y for ( i=0 ; i<count ; i++, in++, out++)
begin
for j:=0 to 2 do
begin
_out.minmaxs[j] := LittleShort (_in.mins[j]);
_out.minmaxs[3+j] := LittleShort (_in.maxs[j]);
end;
p := LittleLong(_in.planenum);
//Y _out.plane := loadmodel.planes + p;
_out.firstsurface := LittleShort (_in.firstface);
_out.numsurfaces := LittleShort (_in.numfaces);
_out.contents := -1; // differentiate from leafs
for j:=0 to 1 do
begin
p := LittleLong (_in.children[j]);
(*Y if (p >= 0)
then _out.children[j] := loadmodel.nodes + p
else _out.children[j] := (mnode_t * )(loadmodel.leafs + (-1 - p));*)
end;
end;
//Y Mod_SetParent (loadmodel.nodes, Nil); // sets nodes and leafs
end;
{*
=================
Mod_LoadLeafs
=================
*}
procedure Mod_LoadLeafs (l : lump_p);
var
_in : dleaf_p;
_out : mleaf_p;
i, j,
count, p : integer;
// glpoly_t *poly;*)
begin
// in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
(*Y out = Hunk_Alloc ( count*sizeof(*out));
loadmodel.leafs := _out;*)
loadmodel.numleafs := count;
//Y for ( i=0 ; i<count ; i++, in++, out++)
begin
for j:=0 to 2 do
begin
_out.minmaxs[j] := LittleShort (_in.mins[j]);
_out.minmaxs[3+j] := LittleShort (_in.maxs[j]);
end;
p := LittleLong(_in.contents);
_out.contents := p;
_out.cluster := LittleShort(_in.cluster);
_out.area := LittleShort(_in.area);
//Y _out.firstmarksurface := loadmodel.marksurfaces + LittleShort(_in.firstleafface);
_out.nummarksurfaces := LittleShort(_in.numleaffaces);
(* // gl underwater warp
#if 0
if (out->contents & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA|CONTENTS_THINWATER) )
{
for (j=0 ; j<out->nummarksurfaces ; j++)
{
out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
for (poly = out->firstmarksurface[j]->polys ; poly ; poly=poly->next)
poly->flags |= SURF_UNDERWATER;
}
}
#endif*)
end;
end;
{*
=================
Mod_LoadMarksurfaces
=================
*}
procedure Mod_LoadMarksurfaces (l : lump_p);
var
i, j, count : integer;
(* short *in;
msurface_t **out;*)
_in : pshortint;
begin
// in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
(*Y out := Hunk_Alloc ( count*sizeof(*out));
loadmodel.marksurfaces := out;*)
loadmodel.nummarksurfaces := count;
for i:=0 to count-1 do
begin
//Y j := LittleShort(_in[i]);
if (j < 0) OR (j >= loadmodel.numsurfaces) then
ri.Sys_Error (ERR_DROP, 'Mod_ParseMarksurfaces: bad surface number', []);
//Y out[i] = loadmodel->surfaces + j;
end;
end;
{*
=================
Mod_LoadSurfedges
=================
*}
procedure Mod_LoadSurfedges (l : lump_p);
var
i, count : integer;
_in, _out : PInteger;
begin
//Y in = (void * )(mod_base + l->fileofs);
if (l.filelen MOD sizeof(_in^)) <> 0 then
ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
count := l.filelen DIV sizeof(_in^);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -