Hey Ventilator

I can get your script to work, but when I tried implementing it myself I got an error 'crash in bmap_getcolor'.

Any ideas? Thank you!

Code:

plugindir = ".";

//////////////////////////////
// supertrace
//////////////////////////////
dllfunction drawuvs(entity, &positionandscale, &color, alpha); // slow!
dllfunction tc_beginbuild();
dllfunction tc_addentity(entity);
dllfunction tc_endbuild();
dllfunction supertrace(&p0, &p1);
dllfunction bmap_getcolor(bitmap, &recolor, xx, yy); // much faster than pixel_for_bmap() (doesn't work with dds!)
var trace_uv1[3];
var trace_uv2[3];


//////////////////////////////
// mesh lightmapping
//////////////////////////////

dllfunction ent_loadseconduvset(entity1, entity2);
dllfunction ent_exportmesh(entity, filename);
dllfunction ent_importmesh(entity, filename);

material* tempmaterial;

bmap bmap_lightmap = "pingvillage_lm.tga";

material mtl_lightmap
{
skin1 = bmap_lightmap;

effect=
"
texture mtlSkin1;
texture entSkin1;

technique t0
{
pass p0
{
Texture[0]=<mtlSkin1>;
Texture[1]=<entSkin1>;

// mix light map with dynamic lighting
TexCoordIndex[0] = 1;
ColorArg1[0] = Texture;
ColorOp[0] = AddSigned;
ColorArg2[0] = Diffuse;

// apply lighting to texture
TexCoordIndex[1] = 0;
ColorArg1[1] = Texture;
ColorOp[1] = Modulate2x;
ColorArg2[1] = Current;
}
}
";
}

var color[3];
ACTION lightmapped_mesh {
my.scale_z *= 1.12;
my.nofog = on;
my.polygon = on;
my.unlit = on;
my.ambient = 80;

my.material = mtl_lightmap; // assign light map material
ent_importmesh(my, "pingvillage_lm.mesh"); // load and assign the previously saved mesh which contains both uv-sets


/* temp_ent = ent_create("pingvillage_lm.mdl", nullvector, 0); // load model with light map uv-set
ent_loadseconduvset(my,temp_ent); // generate and assign a new mesh with both uv-sets
ent_remove(temp_ent); // tempentity isn't needed anymore
ent_exportmesh(my,"pingvillage_lm.mesh"); // save mesh with both uv-sets for reuse */

tc_beginbuild();
tc_addentity(my);
tc_endbuild();

WHILE (1) {
WHILE (!player) { wait(1); }
temp_ent = ptr_for_handle(player.animated_attach);
you = supertrace(vector(player.x,player.y,player.z),vector(player.x,player.y,player.z - 4000));
// you = supertrace(vector(camera.x, camera.y, camera.z), vector(camera.x, camera.y, -10000));
if (you)
{
bmap_getcolor(bmap_lightmap, color, trace_uv2.x * 1024, trace_uv2.y * 1024);
temp_ent.light = on;
temp_ent.blue = color.blue;
temp_ent.green = color.green;
temp_ent.red = color.red;
}
wait(1);
}
}