前两天写了个DX中读取BSP的例子,看了很多的DEMO代码都是C++,最后自己转了个DELPHI,代码不长,把关于文件头的给贴了出来,如果想要原代码可以QQ找我,QQ:370620516
TQ3Header = packed record
bspID : array[0..3] of char;
version : integer;
end;
PQ3Header = ^TQ3Header;
TQ3FileLump = packed record
offset : integer;
length : integer;
end;
PQ3FileLump = ^TQ3FileLump;
TQ3Texture = packed record
filename : array[0..63] of char;
flags : integer;
contents : integer;
end;
PQ3Texture = ^TQ3Texture;
TQ3Face = packed record
texID : integer;
effect : integer;
Facetype : integer;
startVertexIndex : integer;
totalVertices : integer;
meshVertexIndex : integer;
totalMeshVertices : integer;
lightmapID : integer;
lightMapCorner : array[0..1] of integer;
lightMapSize : array[0..1] of integer;
lightMapPos : TPoint3;
lightMapVectors : array[0..1] of TPoint3;
normal : TPoint3;
size : array[0..1] of integer;
end;
PQ3Face = ^TQ3Face;
TQ3Vertex = packed record
vertex : TPoint3;
texCoord : TPoint2;
lightmapCoord : TPoint2;
normal : TPoint3;
color : array[0..3] of Byte;
end;
TQ3LightMap = packed record
lightMap : array[0..127,0..127,0..2] of Byte;
end;
TQ3LumpOffsets = (
EnitiesOffset = 0,
iTextureOffset,
iPlanesOffset,
iNodesOffset,
iLeafOffset,
iLeafFacesOffset,
iLeafBrushesOffset,
iModelsOffset,
iBrushesOffset,
iBrushesSidesOffset,
iVerticesOffset,//
iMeshVerticesOffset,
iShaderFilesOffset,
iFacesOffset,
iLightMapsOffset,
iLightVolumeOffset,
iVisibleDataOffset,
iMaxLumpsOffset
);
const
MaxLumpsOffset = ord( iMaxLumpsOffset );
Declaration : Array[0..5] of TD3DVERTEXELEMENT9 = (
(Stream:0; Offset:0; _Type:D3DDECLTYPE_FLOAT3; Method:D3DDECLMETHOD_DEFAULT; Usage:D3DDECLUSAGE_POSITION; UsageIndex:0),
(Stream:0; Offset: 12; _Type:D3DDECLTYPE_FLOAT2; Method:D3DDECLMETHOD_DEFAULT; Usage:D3DDECLUSAGE_TEXCOORD; UsageIndex:0),
(Stream:0; Offset:20; _Type:D3DDECLTYPE_FLOAT2; Method:D3DDECLMETHOD_DEFAULT; Usage:D3DDECLUSAGE_TEXCOORD; UsageIndex:1),
(Stream:0; Offset:28; _Type:D3DDECLTYPE_FLOAT3; Method:D3DDECLMETHOD_DEFAULT; Usage: D3DDECLUSAGE_NORMAL; UsageIndex:0),
(Stream:0; Offset:40; _Type:D3DDECLTYPE_UBYTE4; Method:D3DDECLMETHOD_DEFAULT; Usage:D3DDECLUSAGE_COLOR; UsageIndex:0),
(Stream:$FF; Offset:0; _Type:D3DDECLTYPE_UNUSED; Method:D3DDECLMETHOD_DEFAULT; Usage:D3DDECLUSAGE_POSITION; UsageIndex:0)//保留位
);
type
TVRBSPInfo = packed record
textureNum : integer;
VertexNum : integer;
LightMapNum : integer;
FaceNum : integer;
Vertexes : array of TQ3Vertex;
Faces : array of TQ3Face;
textures : array of TQ3Texture;
lightmaps : array of TQ3LightMap;
end;
附张图片: