Page 1 of 2

Tutorial Request MD3 and attachment support

Posted: Mon Dec 14, 2009 8:03 pm
by ceriux
Iv found tutorials for implementing md2's but not md3's i was wondering if anyone would be kind enough to make up a tutorial for it. id be extremely appreciative if who did would. thanks for if anyone does!

Re: Tutorial Request MD3 and attachment support

Posted: Tue Dec 15, 2009 2:57 am
by Baker
ceriux wrote:Iv found tutorials for implementing md2's but not md3's i was wondering if anyone would be kind enough to make up a tutorial for it. id be extremely appreciative if who did would. thanks for if anyone does!
Depending on how things go, this could happen this week.

And if not this week, it is an automatic for by the end of the year.

By the way, do have any links for the md2 implementation? I know MH has a mostly written tutorial for md2, but I'd just like to lazily assess where the changes are while trying to wrap up a few things this week.

Posted: Tue Dec 15, 2009 3:13 am
by ceriux
this is the only one i know of.

http://www.quake-1.com/docs/quakesrc.org/98.html

Posted: Tue Dec 15, 2009 3:59 pm
by Downsider
Wouldn't implementing some kind of MD3 tagging require a change to Quake's protocol?

Re: Tutorial Request MD3 and attachment support

Posted: Tue Dec 15, 2009 7:05 pm
by mh
Baker wrote:I know MH has a mostly written tutorial for md2.
That reminds me, I need to drag that one out from wherever I've hidden it, finalize it and post it.

Posted: Wed Dec 16, 2009 4:03 am
by revelator
i had one in the tutorial discussion section on quakesrc once but after the site went down most got lost so might be hard recovering.

i still have the engine i fiddled with back then but its an older version and doesnt have shadows implemented yet (later version had) and is based on code from dr labman where the new one was based of harvens md3 code.

ill see if i can polish it up to the code i posted back then.

Posted: Wed Dec 23, 2009 7:48 am
by ceriux
any updates? sorry i leave around the first of the year so =/ i been gettin kinda blah about stuff lol... -.- i can make visual content for engine tutorial trade =D

Posted: Wed Dec 23, 2009 8:02 am
by Baker
Well ... I'm working on the Universal Servers project at the moment (amazing stuff!) ... but let me see what I can do.

It won't have attachment support, that's an extension --- someone else will have to add their 2 cents in on how to best achieve attachment support. And it'll be standard single model md3 ... no torso, legs, head stuff.

Let me quickly assess how long it would take to write up the md3 tutorial and build a test GLQuake .... if it will take approximately an hour or less I'll do it right now ...

Posted: Wed Dec 23, 2009 8:04 am
by ceriux
oh dont rush yourself. like i said im leaving around the first of the year. my needs arnt that important as to those of the entire community!

Posted: Wed Dec 23, 2009 8:20 am
by Baker
ceriux wrote:oh dont rush yourself. like i said im leaving around the first of the year. my needs arnt that important as to those of the entire community!
Changes are located in almost exclusively:

gl_model.h
gl_model.c
gl_rmain.c

Ah, it'd be funny to add md3 support into crusty old GLQuake just for fun and doesn't look too hard. I think I'll do it now just because it'd be funny.

Posted: Wed Dec 23, 2009 9:14 am
by Baker
Planning ....

1) Will need to check for md3 vs. mdl format header on load
2) Mark such models
3) Load their textures; they are 24 bit. Have the textures loaded from the progs folder like DarkPlaces does it. The default GLQuake 8-bit texture extension cannot be used; software renderer is 8-bit (WinQuake) can't be used [I wonder if FTEQW's 24-bit software render does Q3 models? Hmmm]
4) When drawing all the entities, handle md3 separately
5) The code to render and light the md3 models.

Posted: Wed Dec 23, 2009 9:30 am
by revelator
on it still ;) takes a while though i had made some very massive changes to get shadows etc. to work on the new code i started out having two different rendering sections one that handled nor mal mdl and one for md3 the latter code had all this wrapped up in the same function (was pretty messy before) :P.

hmm with csqc this could become very interresting indeed 8)

Part 1

Posted: Wed Dec 30, 2009 11:36 am
by Baker
Part 1 ... revision possible ... modelling after JoeQuake and the Qrack implementation

1a. gl_model.h

Add mod_md3 to the model types ...
typedef enum {mod_brush, mod_sprite, mod_alias, mod_md3} modtype_t;
1b. Locate the following ...

Code: Select all

//
// Whole model
//
And insert the Q3 model header declarations before ...

Code: Select all

//===================================================================
/*
==============================================================================

				Q3 MODELS

==============================================================================
*/

typedef struct
{
	int		ident;
	int		version;
	char		name[MAX_QPATH];
	int      	flags;
	int		numframes;
	int		numtags;
	int		numsurfs;
	int		numskins;
	int		ofsframes;
	int		ofstags;
	int		ofssurfs;
	int		ofsend;
} md3header_t;

typedef struct
{
	vec3_t		mins, maxs;
	vec3_t		pos;
	float		radius;
	char		name[16];
} md3frame_t;

typedef struct
{
	char		name[MAX_QPATH];
	vec3_t		pos;
	vec3_t		rot[3];
} md3tag_t;

typedef struct
{
	int		ident;
	char		name[MAX_QPATH];
	int		flags;
	int		numframes;
	int		numshaders;
	int		numverts;
	int		numtris;
	int		ofstris;
	int		ofsshaders;
	int		ofstc;
	int		ofsverts;
	int		ofsend;
} md3surface_t;

typedef struct
{
	char		name[MAX_QPATH];
	int		index;
} md3shader_t;

typedef struct
{
	char		name[MAX_QPATH];
	int		index;
	int		gl_texnum, fb_texnum;
} md3shader_mem_t;

typedef struct
{
	int		indexes[3];
} md3triangle_t;

typedef struct
{
	float		s, t;
} md3tc_t;

typedef struct
{
	short		vec[3];
	unsigned short	normal;
} md3vert_t;

typedef struct
{
	vec3_t		vec;
	vec3_t		normal;
	byte		anorm_pitch, anorm_yaw;
	unsigned short	oldnormal;	// needed for normal lighting
} md3vert_mem_t;

#define	MD3_XYZ_SCALE	(1.0 / 64)

#define	MAXMD3FRAMES	1024
#define	MAXMD3TAGS	16
#define	MAXMD3SURFS	32
#define	MAXMD3SHADERS	256
#define	MAXMD3VERTS	4096
#define	MAXMD3TRIS	8192

typedef struct animdata_s
{
	int	offset;
	int	num_frames;
	int	loop_frames;
	float	interval;
} animdata_t;
1c. Locate and add the yellow, allowing us to know the type of alias model loaded ...
typedef struct model_s
{
char name[MAX_QPATH];
qboolean needload; // bmodels and sprites don't cache normally

modtype_t type;


int aliastype; // Alternate model format support

int numframes;
synctype_t synctype;

int flags;

//
// volume occupied by the model graphics
//
vec3_t mins, maxs;
Remainder of the tutorial will follow as time permits.

Part 2

Posted: Wed Dec 30, 2009 1:34 pm
by Baker
Continued ... all subject to revision:

2a. gl_rmain.c

In R_DrawEntitiesOnList we need to check for MD3 ...
// draw sprites seperately, because of alpha blending
for (i=0 ; i<cl_numvisedicts ; i++)
{
currententity = cl_visedicts;

switch (currententity->model->type)
{
case mod_alias:
R_DrawAliasModel (currententity);
break;

case mod_md3:
R_DrawQ3Model (currententity);
break;


case mod_brush:
R_DrawBrushModel (currententity);
break;

default:
break;
}
}


2b. Likewise for the view model (R_DrawViewModel), we need to check for MD3 ...

// hack the depth range to prevent view model from poking into walls
glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));

switch (currententity->model->type)
{
case mod_alias:
R_DrawAliasModel (currententity);
break;

case mod_md3:
R_DrawQ3Model (currententity);
break;
}


glDepthRange (gldepthmin, gldepthmax);

Posted: Wed Dec 30, 2009 7:16 pm
by ceriux
baker all of this is for MD3 support without attachments?