num = LittleLong(*((int *)buf));
// call the apropriate loader
loadmodel = mod;
- if (!memcmp(buf, "IDPO", 4)) Mod_IDP0_Load(mod, buf, bufend);
+ if (!strcasecmp(FS_FileExtension(mod->name), "obj")) Mod_OBJ_Load(mod, buf, bufend);
+ else if (!memcmp(buf, "IDPO", 4)) Mod_IDP0_Load(mod, buf, bufend);
else if (!memcmp(buf, "IDP2", 4)) Mod_IDP2_Load(mod, buf, bufend);
else if (!memcmp(buf, "IDP3", 4)) Mod_IDP3_Load(mod, buf, bufend);
else if (!memcmp(buf, "IDSP", 4)) Mod_IDSP_Load(mod, buf, bufend);
*lastvertexpointer = lastvertex;
}
+void Mod_MakeSortedSurfaces(dp_model_t *mod)
+{
+ // make an optimal set of texture-sorted batches to draw...
+ int j, t;
+ int *firstsurfacefortexture;
+ int *numsurfacesfortexture;
+ if (!mod->sortedmodelsurfaces)
+ mod->sortedmodelsurfaces = Mem_Alloc(loadmodel->mempool, mod->nummodelsurfaces * sizeof(*mod->sortedmodelsurfaces));
+ firstsurfacefortexture = Mem_Alloc(tempmempool, mod->num_textures * sizeof(*firstsurfacefortexture));
+ numsurfacesfortexture = Mem_Alloc(tempmempool, mod->num_textures * sizeof(*numsurfacesfortexture));
+ memset(numsurfacesfortexture, 0, mod->num_textures * sizeof(*numsurfacesfortexture));
+ for (j = 0;j < mod->nummodelsurfaces;j++)
+ {
+ const msurface_t *surface = mod->data_surfaces + j + mod->firstmodelsurface;
+ int t = (int)(surface->texture - mod->data_textures);
+ numsurfacesfortexture[t]++;
+ }
+ j = 0;
+ for (t = 0;t < mod->num_textures;t++)
+ {
+ firstsurfacefortexture[t] = j;
+ j += numsurfacesfortexture[t];
+ }
+ for (j = 0;j < mod->nummodelsurfaces;j++)
+ {
+ const msurface_t *surface = mod->data_surfaces + j + mod->firstmodelsurface;
+ int t = (int)(surface->texture - mod->data_textures);
+ mod->sortedmodelsurfaces[firstsurfacefortexture[t]++] = j + mod->firstmodelsurface;
+ }
+ Mem_Free(firstsurfacefortexture);
+ Mem_Free(numsurfacesfortexture);
+}
+
static void Mod_BuildVBOs(void)
{
if (!gl_support_arb_vertex_buffer_object)
static void Mod_Decompile_OBJ(dp_model_t *model, const char *filename, const char *mtlfilename, const char *originalfilename)
{
int vertexindex, surfaceindex, triangleindex, textureindex, countvertices = 0, countsurfaces = 0, countfaces = 0, counttextures = 0;
+ int a, b, c;
const char *texname;
const int *e;
const float *v, *vn, *vt;
size_t l;
size_t outbufferpos = 0;
size_t outbuffermax = 0x100000;
- char *outbuffer = Z_Malloc(outbuffermax), *oldbuffer;
+ char *outbuffer = (char *) Z_Malloc(outbuffermax), *oldbuffer;
const msurface_t *surface;
const int maxtextures = 256;
- char *texturenames = Z_Malloc(maxtextures * MAX_QPATH);
+ char *texturenames = (char *) Z_Malloc(maxtextures * MAX_QPATH);
// construct the mtllib file
l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "# mtllib for %s exported by darkplaces engine\n", originalfilename);
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
- l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "v %f %f %f\nvn %f %f %f\nvt %f %f\n", v[0], v[2], -v[1], vn[0], vn[2], vn[1], vt[0], 1-vt[1]);
+ l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "v %f %f %f\nvn %f %f %f\nvt %f %f\n", v[0], v[2], -v[1], vn[0], vn[2], -vn[1], vt[0], 1-vt[1]);
if (l > 0)
outbufferpos += l;
}
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
- l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "f %i/%i/%i %i/%i/%i %i/%i/%i\n", e[0]+1, e[0]+1, e[0]+1, e[1]+1, e[1]+1, e[1]+1, e[2]+1, e[2]+1, e[2]+1);
+ a = e[0]+1;
+ b = e[2]+1;
+ c = e[1]+1;
+ l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "f %i/%i/%i %i/%i/%i %i/%i/%i\n", a,a,a,b,b,b,c,c,c);
if (l > 0)
outbufferpos += l;
}
int transformindex;
int poseindex;
int cornerindex;
+ float modelscale;
const int *e;
const float *pose;
size_t l;
size_t outbufferpos = 0;
size_t outbuffermax = 0x100000;
- char *outbuffer = Z_Malloc(outbuffermax), *oldbuffer;
+ char *outbuffer = (char *) Z_Malloc(outbuffermax), *oldbuffer;
const msurface_t *surface;
l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "version 1\nnodes\n");
if (l > 0)
outbufferpos += l;
+ modelscale = 1;
+ if(model->num_poses >= 0)
+ modelscale = sqrt(model->data_poses[0] * model->data_poses[0] + model->data_poses[1] * model->data_poses[1] + model->data_poses[2] * model->data_poses[2]);
+ if(fabs(modelscale - 1) > 1e-4)
+ {
+ if(firstpose == 0) // only print the when writing the reference pose
+ Con_Printf("The model has an old-style model scale of %f\n", modelscale);
+ }
+ else
+ modelscale = 1;
for (transformindex = 0;transformindex < model->num_bones;transformindex++)
{
if (outbufferpos >= outbuffermax >> 1)
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
test[2][3] = pose[11];
}
#endif
- l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "%3i %f %f %f %f %f %f\n", transformindex, pose[3], pose[7], pose[11], DEG2RAD(angles[ROLL]), DEG2RAD(angles[PITCH]), DEG2RAD(angles[YAW]));
+ l = dpsnprintf(outbuffer + outbufferpos, outbuffermax - outbufferpos, "%3i %f %f %f %f %f %f\n", transformindex, pose[3] * modelscale, pose[7] * modelscale, pose[11] * modelscale, DEG2RAD(angles[ROLL]), DEG2RAD(angles[PITCH]), DEG2RAD(angles[YAW]));
if (l > 0)
outbufferpos += l;
}
{
outbuffermax *= 2;
oldbuffer = outbuffer;
- outbuffer = Z_Malloc(outbuffermax);
+ outbuffer = (char *) Z_Malloc(outbuffermax);
memcpy(outbuffer, oldbuffer, outbufferpos);
Z_Free(oldbuffer);
}
}
// export SMD if possible (only for skeletal models)
- if (mod->surfmesh.num_triangles && mod->num_poses)
+ if (mod->surfmesh.num_triangles && mod->num_bones)
{
dpsnprintf(outname, sizeof(outname), "%s_decompiled/ref1.smd", basename);
Mod_Decompile_SMD(mod, outname, 0, 1, true);
- l = dpsnprintf(zymtextbuffer + zymtextsize, sizeof(zymtextbuffer) - zymtextsize, "texturedir textures\nscale 1\norigin 0 0 0\nmesh ref1.smd\n");
+ l = dpsnprintf(zymtextbuffer + zymtextsize, sizeof(zymtextbuffer) - zymtextsize, "output out.zym\nscale 1\norigin 0 0 0\nmesh ref1.smd\n");
if (l > 0) zymtextsize += l;
l = dpsnprintf(dpmtextbuffer + dpmtextsize, sizeof(dpmtextbuffer) - dpmtextsize, "outputdir .\nmodel out\nscale 1\norigin 0 0 0\nscene ref1.smd\n");
if (l > 0) dpmtextsize += l;