I wrote a function which creates corresponding obj.cfg files for exported models generated by the writeobj(...) function. Located in worldio.cpp. If you implement such a function I would turn to Sauer-enhanced. Below is the example code and the documentation. You have to paste it into worldio.cpp file of Sauerbraten:
<code>
/*
Write a Cube 2 level as model file and create a matching texture config.
usage: writemodel [name] [scale 0/1.0] [noclip 0] [ambiente 0/100%] [specscale 0/1.0] [info]
This command writes Cube 2-map geometry as textured wavefront obj file to packages/model/[name] folder.
Multiple subdires are allowed and - if required - created. Shaderparameters are translated as good as possible.
Alpha-blending is only supported for images with alpha channel. Dont use the alpha-material,
just apply an alpha-texture as normal stdworld texture or with spec/bump/env/glow parameters. The created model will turn it on.
Alpha-materials and sky-surfaces are removed. Use a plain, white diffuse-map with envworld shader turned on to get a skybox-effect then.
Also mdlenvmap command with the required skybox has to be added manually to the object config. See mdlenvmap of the model-doc.
Supported shaders: *specworld, *envworld, specmap or glowmap, envmap, bump*, alpha-channel
Shaderparams (monochrome only): envscale, specscale, glowcolor
Parameters:
name: model name, located in the packages/models folder.
scale: size of the model, default is 1.0 (400%).
noclip: create a clip-box by default (0) or disable clipping, if specified (1).
ambient: see mdlambient command, zero means default value (100%) or -1 turns ambient off.
specscale: specularity scale of the model, see mdlspec in the models-doc: zero means default (100%, 1.5?) or -1 turns specularity off entirely.
This value is usefull to adjust specularity of textures, for example phillipk textures require a higher value (3.0)
while mitaman's meters are looking better with values <1.0
info: write shader info, in case manual adjustment of the output file is required
Example script commands:
mapmodelreset;writemodel test;mmodel test;newent mapmodel 0;
Those commands called in editing mode writes the curent level as model test and loads it as model number 0.
Note: the mapmodel list is also cleared and an instance of the model is being created - near the curent selection.
Bugs:
* parallax is not working and if glow-map is specified, the specularity is disabled because masks have to contain
spec- and glowmap which mismatches then. Also texscroll, alpha-material and pulseglow are ignored.
* Sometimes the glow is too dark, when glow is enabled and the underlaying diffusetexture has dark pixels at this position.
* Glow, spec and envmap-colors are interpreted as monochrome values.
* When plain envworld shaders is specified, the reflection of the model is not plain, because the chrome-map has to be enabled.
Use a plain diffuse-map with envworld shader to get mirror, or skybox-effects then.
* The texturedata of your model must have the same packadir as your model when using two or more subfolders.
Sauerbraten would requires a objdir command or similar to fix this issue.
* The *.mtl file can be removed, its not required.
* When stencil-buffer is disabled, alpha-blending cuts off models behind an alpha surface (this is a cube-specific blendfunc bug)
Tested with textures of aard(default), philipk(glow, spec), lunaran, mitaman(spec) and painkillah(envmap) and some envworld/specworld shaders.
License of this code-snipped: zlib, author: scasd
*/
void writemodel(char *name, char *scale, char *noclip, char *ambient, char *spec, char *noremip, char *writeinfo)
{
if (strlen (name) <= 0)
{
conoutf("usage: writemodel [name] [scale 0/1.0] [noclip 0] [ambiente 0] [specscale 0/1.0] [info 0]");
return;
}
if (strchr(name, '/') || strchr(name, '\\'))
conoutf("WARNING: the texturedata of the model must have the same packadir as the model when using two or more subfolders !");
defformatstring(mdldir)("packages/models/%s", path(name));
defformatstring(fname)("%s/model", mdldir);
extern void remip_(); remip_(); writeobj(fname); // write optimized obj model - bloat snatch
extern vector<vtxarray *> valist; // find used materials...
vector<int> usedmtl;
loopv(valist) loopj(valist[i]->texs) if(usedmtl.find(valist[i]->eslist[j].texture) < 0) usedmtl.add(valist[i]->eslist[j].texture);
usedmtl.sort(mtlsort);
// create relative texture path, the makerelpath() function bugs with painkillah's texture config
int slashes = 2; { char *p = name + strlen(name); while(--p > name) if (*p == '/' || *p == '\\') slashes++; }
char *fixpath = new char[3 * slashes + 1]; fixpath[0] = 0; while (slashes--) strcat (fixpath, "../");
#define EXBRAC(s) (s[0] == '<' ? ( &((strrchr(s, '>')) ?: ">")[1] ) : s) // remove <brackets> of path, painkillah textures require this
// generate texture config file
defformatstring(cfgname)("%s/obj.cfg", mdldir);
stream *f = openfile(cfgname, "w");
if(!f) return;
f->printf("// config file of Cube 2 obj-model\n\n");
float specscale = (atof(spec) ?: 1.0f) * 2.0f; // default scale is 1.0 = 100% specularity
int defaultspec = (specscale < -0.0f) ? -1 : (int)(100.0f * specscale);
f->printf("objload \"model.obj\"\nmdlglare 0.1 1\nmdlalphatest 0.01\nmdlscale %i\nmdlcollide %i\nmdlambient %i\nmdlspec -1\n\n",
(int)(atof(scale) * 400.0f) ?: 400, atoi(noclip) ? 0 : 1, atoi(ambient) ?: 100);
int info = atoi(writeinfo);
loopv(usedmtl) // collect shader data of material slots...
{
int id = usedmtl[i]; VSlot &vslot = lookupvslot(id, false); Slot *slot = vslot.slot;
int shtype = slot->shader->type, sw = shtype & SHADER_NORMALSLMS, ew = shtype & SHADER_ENVMAP; // specworld, envworld
int mask = (sw||ew) ? 0 : -1, gm = slot->texmask & (1<<TEX_GLOW), sm = slot->texmask & (1<<TEX_SPEC); // glowmap, specmap
// write shader info, in case manual adjustment of the output file is required
if (info)
{
f->printf("// shader-type: %i%s%s, shader params: %i\n", shtype, (sw?", specworld":""), (ew?", envworld":""), slot->params.length());
if (slot->params.length()) loopvj(slot->params)
{
ShaderParam *param = &vslot.slot->params[j];
f->printf("// %s: %.3f, %.3f, %.3f, %.3f\n", param->name, param->val[0], param->val[1], param->val[2], param->val[3]);
}
if (gm) f->printf("// glowcolor: %.3f, %.3f, %.3f\n", vslot.glowcolor[0], vslot.glowcolor[1], vslot.glowcolor[2]);
else if (sm) f->printf("// envscale: %.3f, %.3f, %.3f\n", vslot.envscale[0], vslot.envscale[1], vslot.envscale[2]);
}
// cycle slots and write skin/mask with their custom properties
if (slot->sts[0].t->bpp == 32) f->printf("objcullface slot%d 0\n", id);
loopvj (slot->sts) if (slot->sts[j].type == (gm ? TEX_GLOW : TEX_SPEC)) mask = j; // only address specmap, if no glow is specified
else if (slot->sts[j].type == TEX_NORMAL) f->printf("objbumpmap slot%d %s%s\n", id, fixpath, EXBRAC(slot->sts[j].name));
f->printf("objskin slot%d %s%s", id, fixpath, EXBRAC(slot->sts[0].name));
if (mask >= 0)
{
vec *vses = &vslot.envscale; float maxenv = max(vses->x, max(vses->y, vses->z)), minenv = min(vses->x, min(vses->y, vses->z));
f->printf(" %s%s %.4f %.4f\n", fixpath, EXBRAC(slot->sts[mask].name), (ew ? 1.0 : maxenv), (ew ? 1.0 : minenv) );
// toggle objspec and objglow
if (!gm && (sw || sm))
{
int slotspec = defaultspec; ShaderParam *param; // find specscale shader parameter, index: 1
if (sm) loopvj(slot->params) if ((param = &slot->params[j])->type == SHPARAM_LOOKUP && param->index == 1)
slotspec = (int)((param->val[0] + param->val[1] + param->val[2]) * 33.3333333f * specscale);
f->printf("objspec slot%d %i\n", id, slotspec);
}
f->printf("objglow slot%d %i\n\n", id, gm ? (int)(max(vslot.glowcolor[0], max(vslot.glowcolor[1], vslot.glowcolor[2])) * 300.0f) : -1);
} else f->printf("\n\n"); // plain texture without masks
}
delete f; conoutf("wrote model %s", mdldir);
delete fixpath;
#undef EXBRAC
}
COMMAND(writemodel, "ssssss");
</code>
PS: I made a mappack containing top-rated quadropolis maps, mostly not in svn. It consists of maps with at least 8.5/10 points and more than 15 votes. If you want to include those in Sauer-enhanced, just tell me, and I will upload it. There are lots of textures and Mapmodels in it. By the way, nice work with your map spaceshift, I love the texture which change its color when looking to one of the flags.
reply to this message
|