]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_alias.h
chthon lightning no longer uses beam polygons
[xonotic/darkplaces.git] / model_alias.h
index 2b0031e200724c959cbc0e81db375628f0daad86..7e5a88c44469e229f61ea169f13111cdbc99ea80 100644 (file)
@@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
 
+#ifndef MODEL_ALIAS_H
+#define MODEL_ALIAS_H
+
 /*
 ==============================================================================
 
@@ -29,45 +32,6 @@ Alias models are position independent, so the cache manager can move them.
 
 #include "modelgen.h"
 
-/*
-typedef struct
-{
-       int                                     firstpose;
-       int                                     numposes;
-       float                           interval;
-       trivertx_t                      bboxmin;
-       trivertx_t                      bboxmax;
-       int                                     frame;
-       char                            name[16];
-} maliasframedesc_t;
-
-typedef struct
-{
-       trivertx_t                      bboxmin;
-       trivertx_t                      bboxmax;
-       int                                     frame;
-} maliasgroupframedesc_t;
-
-typedef struct
-{
-       int                                             numframes;
-       int                                             intervals;
-       maliasgroupframedesc_t  frames[1];
-} maliasgroup_t;
-
-typedef struct mtriangle_s {
-       int                                     facesfront;
-       int                                     vertindex[3];
-} mtriangle_t;
-*/
-
-// LordHavoc: new vertex format
-typedef struct {
-       byte v[3]; // location
-       signed char n[3]; // surface normal for lighting *127.0
-} trivert2;
-
-#define        MAX_SKINS       32
 typedef struct {
        int                     ident;
        int                     version;
@@ -86,28 +50,6 @@ typedef struct {
        float           size;
 } daliashdr_t;
 
-typedef struct
-{
-       char name[16]; // LordHavoc: only kept this for reasons of viewthing support
-       unsigned short start;
-       unsigned short length;
-       float rate; // in poses per second
-} maliasframe_t;
-
-typedef struct
-{
-       vec3_t          scale;
-       vec3_t          scale_origin;
-       int                     numverts;
-       int                     numtris;
-       int                     numframes;
-       int                     numposes;
-       int                     framedata; // LordHavoc: unsigned short start
-       int                     texdata; // LordHavoc: texture coordinate array
-       int                     posedata; // LordHavoc: vertex data for all the poses
-       int                     tridata; // LordHavoc: vertex indices for the triangles
-} maliashdr_t;
-
 #define        MAXALIASVERTS   4096
 #define        MAXALIASFRAMES  1024
 #define        MAXALIASTRIS    4096
@@ -123,13 +65,11 @@ typedef struct
 // LordHavoc: grabbed this from the Q2 utility source,
 // renamed a things to avoid conflicts
 
-#define MD2IDALIASHEADER               (('2'<<24)+('P'<<16)+('D'<<8)+'I')
 #define MD2ALIAS_VERSION       8
 
 #define        MD2MAX_TRIANGLES        4096
 #define MD2MAX_VERTS           4096
 #define MD2MAX_FRAMES          1024
-#define MD2MAX_SKINS   32
 #define        MD2MAX_SKINNAME 64
 // sanity checking size
 #define MD2MAX_SIZE    (16777216)
@@ -151,25 +91,8 @@ typedef struct
        float           scale[3];       // multiply byte verts by this
        float           translate[3];   // then add this
        char            name[16];       // frame name from grabbing
-       trivertx_t      verts[1];       // variable sized
 } md2frame_t;
 
-// LordHavoc: memory representation is different than disk
-typedef struct
-{
-       float           scale[3];       // multiply byte verts by this
-       float           translate[3];   // then add this
-       trivert2        verts[1];       // variable sized
-} md2memframe_t;
-
-// must match md2memframe_t, this is just used for sizeof()
-typedef struct
-{
-       float           scale[3];       // multiply byte verts by this
-       float           translate[3];   // then add this
-} md2memframesize_t;
-
-
 // the glcmd format:
 // a positive integer starts a tristrip command, followed by that many
 // vertex structures.
@@ -199,25 +122,176 @@ typedef struct
        int                     ofs_st;                 // byte offset from start for stverts
        int                     ofs_tris;               // offset for dtriangles
        int                     ofs_frames;             // offset for first frame
-       int                     ofs_glcmds;     
+       int                     ofs_glcmds;
        int                     ofs_end;                // end of file
 } md2_t;
 
-typedef struct
+// LordHavoc: mdl, md2 and md3 models are converted to the same internal format
+#define ALIASTYPE_ALIAS 1
+#define ALIASTYPE_ZYM 2
+
+extern void Mod_LoadQ1AliasModel (struct model_s *mod, void *buffer);
+extern void Mod_LoadQ2AliasModel (struct model_s *mod, void *buffer);
+extern void Mod_LoadQ3AliasModel (struct model_s *mod, void *buffer);
+
+extern void Mod_AliasInit(void);
+
+#include "model_zymotic.h"
+
+// all md3 ints, floats, and shorts, are little endian, and thus need to be
+// passed through LittleLong/LittleFloat/LittleShort to avoid breaking on
+// bigendian machines (Macs for example)
+#define MD3VERSION 15
+#define MD3NAME 64
+#define MD3FRAMENAME 16
+
+// the origin is at 1/64th scale
+// the pitch and yaw are encoded as 8 bits each
+typedef struct md3vertex_s
 {
-       int                     framesize;              // byte size of each frame
+       short origin[3], normalpitchyaw;
+}
+md3vertex_t;
 
-       int                     num_skins;
-       int                     num_xyz;
-       int                     num_st;                 // greater than num_xyz for seams
-       int                     num_tris;
-       int                     num_glcmds;             // dwords in strip/fan command list
-       int                     num_frames;
+// one per frame
+typedef struct md3frameinfo_s
+{
+       float mins[3];
+       float maxs[3];
+       float origin[3];
+       float radius;
+       char name[MD3FRAMENAME];
+}
+md3frameinfo_t;
+
+// one per tag per frame
+typedef struct md3tag_s
+{
+       char name[MD3NAME];
+       float origin[3];
+       float rotationmatrix[9];
+}
+md3tag_t;
+
+// one per shader per mesh
+typedef struct md3shader_s
+{
+       char name[MD3NAME];
+       // engine field (yes this empty int does exist in the file)
+       int shadernum;
+}
+md3shader_t;
+
+// one per mesh per model
+//
+// note that the lump_ offsets in this struct are relative to the beginning
+// of the mesh struct
+//
+// to find the next mesh in the file, you must go to lump_end, which puts you
+// at the beginning of the next mesh
+typedef struct md3mesh_s
+{
+       char identifier[4]; // "IDP3"
+       char name[MD3NAME];
+       int flags;
+       int num_frames;
+       int num_shaders;
+       int num_vertices;
+       int num_triangles;
+       int lump_elements;
+       int lump_shaders;
+       int lump_texcoords;
+       int lump_framevertices;
+       int lump_end;
+}
+md3mesh_t;
+
+// this struct is at the beginning of the md3 file
+//
+// note that the lump_ offsets in this struct are relative to the beginning
+// of the header struct (which is the beginning of the file)
+typedef struct md3modelheader_s
+{
+       char identifier[4]; // "IDP3"
+       int version; // 15
+       char name[MD3NAME];
+       int flags;
+       int num_frames;
+       int num_tags;
+       int num_meshes;
+       int num_skins;
+       int lump_frameinfo;
+       int lump_tags;
+       int lump_meshes;
+       int lump_end;
+}
+md3modelheader_t;
+
+// LordHavoc: all quake series 'alias' models (mdl, md2, md3) are converted to this vertex format
+typedef struct aliasvertex_s
+{
+       // location
+       float origin[3];
+       // surface normal
+       float normal[3];
+       // S texture vector
+       float svector[3];
+}
+aliasvertex_t;
+
+// this layer is fog (completely specialized behavior)
+#define ALIASLAYER_FOG 1
+// alpha blending
+#define ALIASLAYER_ALPHA 2
+// additive blending
+#define ALIASLAYER_ADD 4
+// apply diffuse lighting
+#define ALIASLAYER_DIFFUSE 8
+// apply specular lighting
+#define ALIASLAYER_SPECULAR 16
+// tint with pants color
+#define ALIASLAYER_COLORMAP_PANTS 32
+// tint with shirt color
+#define ALIASLAYER_COLORMAP_SHIRT 64
+// don't draw this layer if colormap is not used
+#define ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED 128
+// don't draw this layer if colormap is used
+#define ALIASLAYER_NODRAW_IF_COLORMAPPED 256
+// draw this layer for realtime lighting passes, otherwise don't
+#define ALIASLAYER_DRAW_PER_LIGHT 512
+
+typedef struct aliaslayer_s
+{
+       int flags;
+       rtexture_t *texture;
+       rtexture_t *nmap;
+}
+aliaslayer_t;
 
-       int                     ofs_tris;               // offset for dtriangles
-       int                     ofs_frames;             // offset for first frame
-       int                     ofs_glcmds;     
-} md2mem_t;
+// indicates this skin is transparent
+#define ALIASSKIN_TRANSPARENT 1
+
+typedef struct aliasskin_s
+{
+       int flags;
+       int num_layers;
+       aliaslayer_t *data_layers;
+}
+aliasskin_t;
+
+typedef struct aliasmesh_s
+{
+       int num_skins;
+       int num_triangles;
+       int num_frames;
+       int num_vertices;
+       aliasskin_t *data_skins;
+       int *data_elements;
+       int *data_neighbors;
+       float *data_texcoords;
+       aliasvertex_t *data_vertices;
+}
+aliasmesh_t;
+
+#endif
 
-#define ALIASTYPE_MDL 1
-#define ALIASTYPE_MD2 2