RE: modeling for pioneer
Posted: Sat Jul 10, 2010 7:19 pm
how to place decals randomly on a shipthe idea:you would like to customize your ships with decals, little signs that make them more unique, likewise on WW2 Bombers
solution:
Code:
-- small sub-model for use in all models to place (cutout) decals on them, texture can have a alpha channel for a cutout decal but it's not a mustdefine_model('decal', {info = {lod_pixels = {20, 50, 100, 0},bounding_radius = 1,materials = {'decal'}},static = function(lod)end,dynamic = function(lod)math.randomseed(tonumber(string.sub((string.gsub(reg,"%W", 1)),5,7),36)) --[[ generates number from ship registration# for random seed, any string is converted to a number, with replacement of non-alphanumerical by 1, because you might like to "hack" your savegame to give your ship a name instead of a reg#, e.g. "KILLER!" or " LUCKY-7", then decal selection still works! further modelviewers given reg# "IR-L33T" still works with that to
--]] local dec = math.random() -- randomizes 0 to 1, uses seed for a uniqe fractal number in between 0 to 1 (inclusive), identical numbers produces the same random result set_material('decal', 1,1,1, 0.9, .7,.7,.7,10) -- creates semi-transparent material to cut out alpha channel, has to be 0use_material('decal')if dec < .15 thentexture('models/decals/decal_a.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) -- calls the texture for the decal,elseif dec < .29 thentexture('models/decals/decal_b.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) -- if sequence could be expandet to 10000!(limited by reg# length) different decals, but max. 20 will be ok
else if dec < .43 thentexture('models/decals/decal_c.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) -- when adding a additional one, divide 1 through no. of total decals, add one to result in hundreth unitselse if dec < .58 then texture('models/decals/decal_d.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) -- feel free to exchange the existing ones with your own style else if dec < .72 then texture('models/decals/decal_e.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) -- accepts any quadratical sized texture, recommendet are 100x100 - 200x200 else if dec < .86 then texture('models/decals/decal_f.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) else texture('models/decals/decal_g.png', v(0,0,0), v(0,0,-1), v(0,-1,0)) end endend endendendquad(v(0,0,0), v(0,1,0), v(0,1,1), v(0,0,1)) -- creates a quadratic shape 1m x 1m for the decalend})
create a new folder into "....data\models\" named decals put the above script named decals.lua and your textures for the decals into the new folder, of course they have to be named like it's given in the script (decal_a to decal_g). you can expand the script if you like, to have more variations. recommendet texture size is 100x100 - 200x200 pixels regular quadratic to make it work, with a optional alpha channel to cutout the decals. of course this works only on new ships models, which includes a call for the decal model, it will look like this:
Code:
if lod > 1 thencall_model('decal', v(3.56,0.6,-5), v(1,0,0), v(-0.235,1,0), 1.2) call_model('decal', v(-3.56,0.6,-4), v(-1,0,0), v(0.235,1,0), 1.2) end
the example code is from my IP Shuttle for a left and rightside placement (i guess you have recognized them allready)you can download my decals folder from here (the shuttle who uses them as a first example isn't finished yet, i'm still not satisfied
): decals.zip
Code:
-- small sub-model for use in all models to place (cutout) decals on them, texture can have a alpha channel for a cutout decal but it's not a mustdefine_model('decal', {info = {lod_pixels = {20, 50, 100, 0},bounding_radius = 1,materials = {'decal'}},static = function(lod)end,dynamic = function(lod)math.randomseed(tonumber(string.sub((string.gsub(reg,"%W", 1)),5,7),36)) --[[ generates number from ship registration# for random seed, any string is converted to a number, with replacement of non-alphanumerical by 1, because you might like to "hack" your savegame to give your ship a name instead of a reg#, e.g. "KILLER!" or " LUCKY-7", then decal selection still works! further modelviewers given reg# "IR-L33T" still works with that to
create a new folder into "....data\models\" named decals put the above script named decals.lua and your textures for the decals into the new folder, of course they have to be named like it's given in the script (decal_a to decal_g). you can expand the script if you like, to have more variations. recommendet texture size is 100x100 - 200x200 pixels regular quadratic to make it work, with a optional alpha channel to cutout the decals. of course this works only on new ships models, which includes a call for the decal model, it will look like this:
Code:
if lod > 1 thencall_model('decal', v(3.56,0.6,-5), v(1,0,0), v(-0.235,1,0), 1.2) call_model('decal', v(-3.56,0.6,-4), v(-1,0,0), v(0.235,1,0), 1.2) end
the example code is from my IP Shuttle for a left and rightside placement (i guess you have recognized them allready)you can download my decals folder from here (the shuttle who uses them as a first example isn't finished yet, i'm still not satisfied