+ loadmodel->normalmins[j] = aliasbboxmin[j];
+ loadmodel->normalmaxs[j] = aliasbboxmax[j];
+ loadmodel->rotatedmins[j] = -modelradius;
+ loadmodel->rotatedmaxs[j] = modelradius;
+ }
+ loadmodel->yawmins[0] = loadmodel->yawmins[1] = -(loadmodel->yawmaxs[0] = loadmodel->yawmaxs[1] = modelyawradius);
+ loadmodel->yawmins[2] = loadmodel->normalmins[2];
+ loadmodel->yawmaxs[2] = loadmodel->normalmaxs[2];
+}
+
+static void zymswapintblock(int *m, int size)
+{
+ size /= 4;
+ while(size--)
+ {
+ *m = BigLong(*m);
+ m++;
+ }
+}
+
+void Mod_LoadZymoticModel(model_t *mod, void *buffer)
+{
+ int i, pbase, *bonecount, numposes;
+ unsigned int count, a, b, c, *renderlist, *renderlistend;
+ rtexture_t **texture;
+ char *shadername;
+ zymtype1header_t *pinmodel, *pheader;
+ zymscene_t *scene;
+ zymbone_t *bone;
+ float corner[2], modelradius;
+
+ pinmodel = (void *)buffer;
+
+ if (memcmp(pinmodel->id, "ZYMOTICMODEL", 12))
+ Host_Error ("Mod_LoadZymoticModel: %s is not a zymotic model\n");
+
+ if (BigLong(pinmodel->type) != 1)
+ Host_Error ("Mod_LoadZymoticModel: only type 1 (skeletal pose) models are currently supported (name = %s)\n", loadmodel->name);
+
+ loadmodel->type = mod_alias;
+ loadmodel->aliastype = ALIASTYPE_ZYM;
+
+ loadmodel->zymdata_header = pheader = Mem_Alloc(loadmodel->mempool, BigLong(pinmodel->filesize));
+
+ pbase = (int) pheader;
+
+ memcpy(pheader, pinmodel, BigLong(pinmodel->filesize));
+
+ // byteswap header
+#define SWAPLONG(var) var = BigLong(var)
+#define SWAPFLOAT(var) var = BigFloat(var)
+#define SWAPVEC(var) SWAPFLOAT(var[0]);SWAPFLOAT(var[1]);SWAPFLOAT(var[2])
+ SWAPLONG(pheader->type);
+ SWAPLONG(pheader->filesize);
+ SWAPVEC(pheader->mins);
+ SWAPVEC(pheader->maxs);
+ SWAPFLOAT(pheader->radius);
+ SWAPLONG(pheader->numverts);
+ SWAPLONG(pheader->numtris);
+ SWAPLONG(pheader->numshaders);
+ SWAPLONG(pheader->numbones);
+ SWAPLONG(pheader->numscenes);
+
+#define SWAPLUMPINFO(var) SWAPLONG(pheader->lump_##var.start);SWAPLONG(pheader->lump_##var.length)
+ SWAPLUMPINFO(scenes);
+ SWAPLUMPINFO(poses);
+ SWAPLUMPINFO(bones);
+ SWAPLUMPINFO(vertbonecounts);
+ SWAPLUMPINFO(verts);
+ SWAPLUMPINFO(texcoords);
+ SWAPLUMPINFO(render);
+ SWAPLUMPINFO(shaders);
+ SWAPLUMPINFO(trizone);
+
+ loadmodel->flags = 0; // there are no flags
+ loadmodel->numframes = pheader->numscenes;
+ loadmodel->synctype = ST_SYNC;
+ loadmodel->numtris = pheader->numtris;
+
+ // FIXME: add skin support and texturing and shaders and...
+ loadmodel->skinscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) + sizeof(skinframe_t));
+ loadmodel->skinscenes[0].firstframe = 0;
+ loadmodel->skinscenes[0].framecount = 1;
+ loadmodel->skinscenes[0].loop = true;
+ loadmodel->skinscenes[0].framerate = 10;
+ loadmodel->skinframes = (void *)(loadmodel->skinscenes + 1);
+ loadmodel->skinframes->base = NULL;
+ loadmodel->skinframes->fog = NULL;
+ loadmodel->skinframes->pants = NULL;
+ loadmodel->skinframes->shirt = NULL;
+ loadmodel->skinframes->glow = NULL;
+ loadmodel->skinframes->merged = NULL;
+ loadmodel->numskins = 1;
+ numposes = pheader->lump_poses.length / sizeof(float[3][4]) / pheader->numbones;
+
+ // go through the lumps, swapping things
+
+// zymlump_t lump_scenes; // zymscene_t scene[numscenes]; // name and other information for each scene (see zymscene struct)
+ scene = (void *) (pheader->lump_scenes.start + pbase);
+ loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
+ for (i = 0;i < pheader->numscenes;i++)
+ {
+ SWAPVEC(scene->mins);
+ SWAPVEC(scene->maxs);
+ SWAPFLOAT(scene->radius);
+ SWAPFLOAT(scene->framerate);
+ SWAPLONG(scene->flags);
+ SWAPLONG(scene->start);
+ SWAPLONG(scene->length);
+
+ memcpy(loadmodel->animscenes[i].name, scene->name, 32);
+ loadmodel->animscenes[i].firstframe = scene->start;
+ loadmodel->animscenes[i].framecount = scene->length;
+ loadmodel->animscenes[i].framerate = scene->framerate;
+ loadmodel->animscenes[i].loop = (scene->flags & ZYMSCENEFLAG_NOLOOP) == 0;
+
+ if ((unsigned int) loadmodel->animscenes[i].firstframe >= numposes)
+ Host_Error("Mod_LoadZymoticModel: scene firstframe (%i) >= numposes (%i)\n", loadmodel->animscenes[i].firstframe, numposes);
+ if ((unsigned int) loadmodel->animscenes[i].firstframe + (unsigned int) loadmodel->animscenes[i].framecount > numposes)
+ Host_Error("Mod_LoadZymoticModel: scene firstframe (%i) + framecount (%i) >= numposes (%i)\n", loadmodel->animscenes[i].firstframe, loadmodel->animscenes[i].framecount, numposes);
+ if (loadmodel->animscenes[i].framerate < 0)
+ Host_Error("Mod_LoadZymoticModel: scene framerate (%f) < 0\n", loadmodel->animscenes[i].framerate);
+ scene++;
+ }
+
+// zymlump_t lump_poses; // float pose[numposes][numbones][3][4]; // animation data
+ zymswapintblock((void *) (pheader->lump_poses.start + pbase), pheader->lump_poses.length);
+
+// zymlump_t lump_bones; // zymbone_t bone[numbones];
+ bone = (void *) (pheader->lump_bones.start + pbase);
+ for (i = 0;i < pheader->numbones;i++)
+ {
+ SWAPLONG(bone[i].flags);
+ SWAPLONG(bone[i].parent);
+ if (bone[i].parent >= i)
+ Host_Error("Mod_LoadZymoticModel: bone[i].parent >= i in %s\n", loadmodel->name);