Game Development Community

Using one mesh multiple times with different texture

by Duion · in Torque 3D Professional · 05/28/2013 (2:04 pm) · 22 replies

Is there a way to re-use one mesh with multiple textures in the editor?

Situation: I have a lot of identical meshes, but had to export them with different material and name to have them seperate because the variation is just in the textures.

Is there a way to split the object in the engine using one base model and just change the texture, this way the model just has to be exported one time.

Something like this is done with the soldier player model, but I need to select the skin in the editor.

Is there an easy way to script this? Or is it a stupid idea? At the moment I am considering if this makes sense instead of exporting the same model multiple times just with changed material, because I plan to have a lot of shapes with interchangeable textures.
Page «Previous 1 2
#1
05/28/2013 (2:37 pm)
there is and i will write it up just might take a bit since i have to investigate a issue regarding skins on PhysicsShapes
seems skins arent working on those oO

if thats k i will supply later a example datablock.
#2
05/28/2013 (2:58 pm)
If you follow the skin "base_whatever" naming convention when exporting the material/mesh you can do it with the object's skin setting in the editor. I forget what the console function for statics are (do a dump) but it's setSkinName(%skin) for players. Works the same.

There should be documentation about this somewhere, even if it's just in the script manual chm.
#3
05/28/2013 (3:00 pm)
I think setSkinName is a thing. But I'm pretty sure I had trouble with it last time I tried to use it. This was a while ago, though.

Whoops, ninjaed by Steve.
#4
05/28/2013 (3:08 pm)
Yes, I noticed that something isn't working as supposed.

Basically the situation is I have a crate for example and I have the skin in brown, blue, red, green, yellow and so on and I want to be able to select the skin in game editor, but without much trouble, since it should be an improvement over exporting the same model multiple times.
I name my shapes something like this crate_01_blue, crate_01_red and so on and the textures "crate_01_blue_diffuse", "crate_01_blue_normal"... I also have individual normal and specular maps in some cases, so the whole material needs to be changed, so you can push out more individuality of the same mesh.

This would also be a nice feature of future Torque3D versions.
#5
05/28/2013 (3:17 pm)
Alright lets hit it

Note this should work for RigidShape and others
...

datablock RigidShapeData( MyBarrel )
{	
   category = "RigidShape";
	
   shapeFile = "art/shapes/barrel/metalbarrel.dts";
   emap = true;
   -------
   -------
   // available skins (see materials.cs in model folder)
   availableSkins =  "base	blue	green	red	yellow	rust	steel";
};

the last line - availableSkins = ... tells T3D wich Skins the Model has

now thats for the datablock part lets head to the Material.cs (nasty part)

singleton Material(Mat_metalbarrel)
{
   mapTo = "base_metalbarrel";
   diffuseColor[0] = "0.64 0.64 0.64 1";
   specular[0] = "0.5 0.5 0.5 1";
   specularPower[0] = "50";
   doubleSided = "0";
   translucentBlendOp = "None";
   diffuseMap[0] = "art/textures/myTextures/barrelblack_D.tga";
   normalMap[0] = "art/textures/myTextures/barrelfull_N.tga";
   specularMap[0] = "art/textures/myTextures/barrel_S.tga";
};

singleton Material(Mat_Blue_metalbarrel : Mat_metalbarrel)
{
   mapTo = "Blue_metalbarrel";
   diffuseMap[0] = "art/textures/myTextures/barrelblue_D.tga";
   normalMap[0] = "art/textures/myTextures/barrelsoft_N.tga";
   specularMap[0] = "art/textures/myTextures/barrel_S.tga";
};

singleton Material(Mat_Green_metalbarrel : Mat_metalbarrel)
{
   mapTo = "Green_metalbarrel";
   diffuseMap[0] = "art/textures/myTextures/barrelgreen_D.tga";
   normalMap[0] = "art/textures/myTextures/barrelsoft_N.tga";
   specularMap[0] = "art/textures/myTextures/barrel_S.tga";
};
....

now as u can see the important part here is
singleton Material(Mat_Blue_metalbarrel : Mat_metalbarrel) // where you tell the T3D the new name of the Material thats to be used

and ofc dont forget
mapTo = "Green_metalbarrel"; //where you tell T3D to base the new Material of the base Material


now in Blender/ or whatever 3dapp
when u export your Model
call its Material base_Mytexture

when you look up thats how it works - thsi way u only export the model with 1 Material and u export it only once

now in T3D to actually change the material of your model
spawn your model
look at the Inspector TAB
under General there should be a field called skin
now there simply insert
one of your skin names
remember
// available skins (see materials.cs in model folder)
   availableSkins =  "base	blue	green	red	yellow	rust";

that means: skin| red - thats all u just swapped the material of your model

hope this helps a bit
#6
05/28/2013 (3:47 pm)
Can I just add the line
"availableSkins = "base blue green red yellow rust steel"; "
into the metalbarrel.cs file located in the models folder?

Something like this:

singleton TSShapeConstructor(metalbarrelDae)
{
baseShape = "./metalbarrel.dae";
loadLights = "0";
availableSkins = "base blue green red yellow rust steel";
};

The materials part I can understand so far.
#7
05/28/2013 (3:57 pm)
ye thats all u actually need in the datablock
its important so that T3D knows what the skins are called

but regarding the singleton TSShapeConstructor...
i have to admit am not sure that it works with singleton :/

as my T3D is a bit lets say Physics oriented and am
not realy usin multiple materials on singletons but go on try
either way am pretty sure its supposed to be added in the datablocks of the model - so far all my Models have multiple Materials

as its a Crate u might want to go the RigidShape Way
this way you would have a physical object that could be pushed around
#8
05/28/2013 (4:01 pm)
I did not manage to make good working physics so far, the default Torque physics are not very good and physx I don't want to use, because of having to rely on third party software, but now there is also bullet physics, maybe I will give that a try, but at the moment the vehicles are also broken with that, like in physx.
But I need this function also on normal shapes anyway, because some objects can not have physics because the static part of the level is build out of them.
#9
05/29/2013 (5:05 pm)
Can't get it to work neither with a rigid shape nor with static, nothing works.

This is my materials.cs

singleton Material(Mat_oilbarrel_01)
{
   mapTo = "base_oilbarrel_01";
   diffuseMap[0] = "./oilbarrel_01_blue_D";
   normalMap[0] = "./oilbarrel_01_N";
   specularMap[0] = "./oilbarrel_01_S";
   materialTag0 = "metal";
 };
 
 singleton Material(Mat_bare_oilbarrel_01 : oilbarrel_01)  
 {
   mapTo = "bare_oilbarrel_01";
   diffuseMap[0] = "./oilbarrel_01_bare_D";
   normalMap[0] = "./oilbarrel_01_N";
   specularMap[0] = "./oilbarrel_01_S";
   materialTag0 = "metal";
 };
 
  singleton Material(Mat_black_oilbarrel_01 : oilbarrel_01) 
 {
   mapTo = "black_oilbarrel_01";
   diffuseMap[0] = "./oilbarrel_01_black_D";
   normalMap[0] = "./oilbarrel_01_N";
   specularMap[0] = "./oilbarrel_01_S";
   materialTag0 = "metal";
 };
#10
05/29/2013 (5:08 pm)
Oh I forgot the "Mat_" in front of the second name materials, now it works on both.
By the way is the "Mat_" prefix necessary? I did it without before, maybe it is to avoid confusion, to show that this is a material.
#11
05/30/2013 (5:09 am)
Now I am trying to figure out how to interchange the skins on other models.

For example now I have metalcube_01 and I want him to use the barreltexture with skins, this works even without datablock when I just export the cube with the base_oilbarrel_01 texture.

I am interested in what the line
singleton Material(Mat_black_oilbarrel_01 : Mat_oilbarrel_01)
does, is this still a normal material? Can I add more models that these materials can be used as a skin for?
For example I used my cube with the barrel skins, but I want a material "wood" to be usable with this shape also.

Ok in this case this does not make much sense, but lets say I have standardized materials and a series of standardized shapes, so that every material fits on every shape of this series. For example a block, that can have wood, metal, stone, brick etc texture. So I want to use every material as a skin for that shape, by keeping the alternative to still have them as skin for other shapes also, without creating a new material each time.

...this may sound complicated, but maybe someone gets what I mean, just want to check out the possibilities.
#12
05/30/2013 (10:21 am)
singleton Material(Mat_black_oilbarrel_01 : Mat_oilbarrel_01)
//this part
//
Mat_oilbarrel_01
//is your Models Base material
//
//and this 
Mat_black_oilbarrel_01
//is whatever u wanna call it as it just bases itself depending on your base material
as u see the important part is "Black" or whatever you gonna calll your new skin

actually this just tells T3D to base from the textures Base Material
this way u can tell T3D to use another Material on the specified mesh
and that leads us to your 2nd question

yes you actually can tell T3D to use the same texture on another model
and you should keep the naiming of the material the same
just to ensure that alll is set up correctly

as always hope this helps and if u have issues/ questions
just ask :)
#13
05/30/2013 (11:14 am)
Is the "Mat" necessary?
Hm so the skin seems to be material based, not shape based, so you can switch the skins within a material, but you cannot switch over different materials over a shape as a skin.
#14
05/30/2013 (11:45 am)
well u actually can "logic dictates"

now the real important part is
mapTo = "base_metalbarrel";

as this is what we called our material in our 3dapp

now when u look at
singleton Material(Mat_Blue_metalbarrel : Mat_metalbarrel)  
{  
   mapTo = "Blue_metalbarrel";  
   diffuseMap[0] = "art/textures/myTextures/barrelblue_D.tga";  
   normalMap[0] = "art/textures/myTextures/barrelsoft_N.tga";  
   specularMap[0] = "art/textures/myTextures/barrel_S.tga";  
}; 

///look at the mapTo
// as u can see we call a new material name that is not even present in our model
//but due the fact that we base of the base_ Material we can call
// give it a different name
#15
05/30/2013 (1:30 pm)
Yes, but I cannot switch the base material, the skins are build upon one base material.
For on shape I can chose either a material "metal"- blue, red, green etc OR "wood"- blue, red, green etc.
But I can make a base material for all of them, or I can even make one super material and all others are skins, this way I can change all textures without changing materials...
#16
05/30/2013 (3:29 pm)
It seems to work without the datablock, just the materials file is enough, for using the skins.
#17
05/31/2013 (6:41 am)
You will need to add the new skin "on top of the base skin" I did this with some nasty models.

Read page 78-83 in "Torque 3D Game Development Cookbook" and read this link
#18
05/31/2013 (8:14 am)
In this case I would just export the model again with the updated material name, so switch "body" with "base_body" and export again.
What I want to do is retarged an existing material as a skin to an existing model.
This is not useful in most cases, but in some, it can. For example you have your playermodel with skins and want to add a rock texture you already have and is in use as a skin without creating a new material for it to avoid material spamming, so you can turn your player to stone with changing the skin.

In cases of simple shapes with seamless textures this makes much more sense, because in this case you can exchange a lot, because the skin always "fits".
#19
05/31/2013 (4:18 pm)
Ok found another complicated thing. ;)
What happens if you have multiple materials? Can you have multiple materials and change the skins of all of the materials? So far I only successfully added a second material with no skins and still can change the original base skin, but the second material remains static.
#20
05/31/2013 (4:39 pm)
sure u can (at least it should work) but atm its sorta late and ye
will write up somethin next time


Page «Previous 1 2