Materials question
by Howard Dortch · in Torque 3D Professional · 03/08/2010 (10:33 am) · 14 replies
I would like to get some info on how the materials are defined.
I have an object named box with a texture named box.png
I create a new material
singleton Material(BoxMat)
{
mapto = "BoxMat";
diffuseMap[0] = "art/shapes/boxes/box.png";
};
The < singleton Material(BoxMat) > gives this material a name. Does this name have to be the same as the material used in the object?
The < mapto = "BoxMat" > seems a bit redundant if I already have it named so what is the purpose of mapto and do I have to have it in there?
The diffuseMap[0] = "path"; I assume is the path and name of the actual material I used when I created the box which again seems redundant since the box dts has the texture referenced already.
And finally in my log file I get the line:
[MaterialList::mapMaterials] Creating missing material for texture: <path removed for brevity>
I know the object is in the proper directory, the texture used to create the object is in the directory, I name it, point the diffuse map to it and it still issues errors and nothing I do to the material changes it in any way. I.E. added diffuse colors, glow, speculars etc.
Is there some explanation of how the material should be described? An is there something I can do to get the engine to recognize the fact that the thing and it's texture does really exist?
Thanks for any help....
I have an object named box with a texture named box.png
I create a new material
singleton Material(BoxMat)
{
mapto = "BoxMat";
diffuseMap[0] = "art/shapes/boxes/box.png";
};
The < singleton Material(BoxMat) > gives this material a name. Does this name have to be the same as the material used in the object?
The < mapto = "BoxMat" > seems a bit redundant if I already have it named so what is the purpose of mapto and do I have to have it in there?
The diffuseMap[0] = "path"; I assume is the path and name of the actual material I used when I created the box which again seems redundant since the box dts has the texture referenced already.
And finally in my log file I get the line:
[MaterialList::mapMaterials] Creating missing material for texture: <path removed for brevity>
I know the object is in the proper directory, the texture used to create the object is in the directory, I name it, point the diffuse map to it and it still issues errors and nothing I do to the material changes it in any way. I.E. added diffuse colors, glow, speculars etc.
Is there some explanation of how the material should be described? An is there something I can do to get the engine to recognize the fact that the thing and it's texture does really exist?
Thanks for any help....
#2
03/10/2010 (4:46 pm)
Thanks for the reply that makes a bit more sense.
#3
singleton Material(BoxMat)
{
mapto = "Box.png";
diffuseMap[0] = "box";
};
Am I still confused?
04/01/2010 (4:41 pm)
Changed it as you suggest and still has to create missing texturesingleton Material(BoxMat)
{
mapto = "Box.png";
diffuseMap[0] = "box";
};
Am I still confused?
#4
//BTW, if mapTo is equal to diffuseMap[0], it can be omitted entirely.
04/01/2010 (5:51 pm)
Have you tried mapTo="box"?//BTW, if mapTo is equal to diffuseMap[0], it can be omitted entirely.
#5
And check that you exported the shape with a material/UVmap or it'll have no where to hang the texture. (mapto)
Also select the box in-editor and then go to texture editor and choose the texture manually.
04/01/2010 (6:15 pm)
It might help if you gave the gull path to the texture from the art folder - eg: diffuseMap[0]="art/shapes/boxes/box";And check that you exported the shape with a material/UVmap or it'll have no where to hang the texture. (mapto)
Also select the box in-editor and then go to texture editor and choose the texture manually.
//example of how it works
singleton Material(SB_area13numbers_aseafb2_Module_Common_SB_area13numbers_Material0)
//the material name inside T3D
{
mapTo = "aseafb2_Module_Common_SB_area13numbers-Material0";
//the material on the UVmap
diffuseMap[0] = "art/shapes/colours/numbers";
//the actual texture image
};
#6
I had the artists go back in and write down what they named the materials in the model and mapto = "model_mat"
I mapto = "Mat_name" from the singleton Material(Mat_name)
I mapto = "Diffuse_name" with full paths
I remove mapto entirely
I add extension names (png,jpg) I remove extension names
some of the materials I get the error "can't redeclare them"
Can't map unNamed materials
There has got to be a better way..
04/11/2010 (5:05 pm)
I have tried about all posible combinations nothing works.I had the artists go back in and write down what they named the materials in the model and mapto = "model_mat"
I mapto = "Mat_name" from the singleton Material(Mat_name)
I mapto = "Diffuse_name" with full paths
I remove mapto entirely
I add extension names (png,jpg) I remove extension names
some of the materials I get the error "can't redeclare them"
Can't map unNamed materials
There has got to be a better way..
#7
I do this frequently for re-assigning my materials as discussed.
04/11/2010 (5:16 pm)
In the shape editor it should tell you the name of the material that you need to map to when viewing the shape. To get a working example: open the model in the shape editor and create a new material definition for the shape by clicking on the edit material icon. Edit to get the properties you want and save it. Find that material script definition and copy/edit it.I do this frequently for re-assigning my materials as discussed.
#8
Material = the material name in T3D. Use Singleton over datablock for dynamic changing.
MapTo = the texture it points at (the UVmapped texture from your 3D modeling app). You do need "mapTo" of your material and texture have different names, if they have the same name you can leave it out. I always include it anyway.
DiffuseMap[0] = the basic texture (layer 0), you need the full file extension if it is in a different directory to the model. I always include it anyway.
And now, a different name for material but not the image.
Both if these work, even though the Material name is different.
{edit in} And the third way ... a UV texture which doesn't exist in-game, but I want it to point to one that does (or it all goes orange)
Failed redeclaring of materials may be because of datablock intrangitence (use singleton!) or due to duplication because the material may already exist in another materials.cs file.
Hope this helps - to be honest it took me ages to get my head around the whole thing...
{EDIT} lol, I actually confused myself here for a moment - so edited.
04/11/2010 (6:35 pm)
Okay, let's start from the top. In materials.cs:Material = the material name in T3D. Use Singleton over datablock for dynamic changing.
MapTo = the texture it points at (the UVmapped texture from your 3D modeling app). You do need "mapTo" of your material and texture have different names, if they have the same name you can leave it out. I always include it anyway.
DiffuseMap[0] = the basic texture (layer 0), you need the full file extension if it is in a different directory to the model. I always include it anyway.
singleton Material(FPS_weapons)
//declare material as a singleton
{
mapTo = "FPS_weapons";
//the material to image link
//same name here as both material and image file
//not needed (but included anyway)
diffuseMap[0] = "art/shapes/weapons/yorks/FPS_weapons";
//the image file - and it's full path from "game" folder
;
};And now, a different name for material but not the image.
singleton Material(FPS_weaponZ)
//singleton - now with new material name
{
mapTo = "FPS_weapons";
//the material to image link - same name as image (UVed) file
diffuseMap[0] = "art/shapes/weapons/yorks/FPS_weapons";
//the image file - the same one
;
};Both if these work, even though the Material name is different.
{edit in} And the third way ... a UV texture which doesn't exist in-game, but I want it to point to one that does (or it all goes orange)
singleton Material(FPS_weapon_low)
//singleton - now with new material name
{
mapTo = "FPS_weapons_low";
//the material to image link - same name as image (UVed) file
//note this is not being used in T3D
//even though it's been used in the 3D modeling app to UV with
//I'm using the standard texture again "FPS_weapons"
diffuseMap[0] = "art/shapes/weapons/yorks/FPS_weapons";
//the image file - the same one
;
};Failed redeclaring of materials may be because of datablock intrangitence (use singleton!) or due to duplication because the material may already exist in another materials.cs file.
Hope this helps - to be honest it took me ages to get my head around the whole thing...
{EDIT} lol, I actually confused myself here for a moment - so edited.
#9
I delete the texture for the object, assign a new one rename the material save it and it doesn't exist in my material.cs files in my project.
@Steve when you say "same name as image (UVed) file" do you mean the texture I used to apply to the object or the name it assigned in the tool? I used milkshape to make a simple object and it says "Material01" but the actual graphic file is TireTex.jpg
singleton Material(TireTexMat)
{
mapto = "TireTex"; // Material01 < Tried this too
diffuseMap[0] = "art/shapes/vehicles/buggy/TireTex.jpg";
};
and the result either way:
Creating missing material for texture: art/shapes/vehicles/buggy/TireTex
Thanks for the help....
04/12/2010 (5:44 pm)
@Jameson I dont have a shape editor or at least can't find one. I have an object editor but it doesn't tell me anything about materials. I can select the object then open the material editor and see the material is that what you mean?I delete the texture for the object, assign a new one rename the material save it and it doesn't exist in my material.cs files in my project.
@Steve when you say "same name as image (UVed) file" do you mean the texture I used to apply to the object or the name it assigned in the tool? I used milkshape to make a simple object and it says "Material01" but the actual graphic file is TireTex.jpg
singleton Material(TireTexMat)
{
mapto = "TireTex"; // Material01 < Tried this too
diffuseMap[0] = "art/shapes/vehicles/buggy/TireTex.jpg";
};
and the result either way:
Creating missing material for texture: art/shapes/vehicles/buggy/TireTex
Thanks for the help....
#10
04/12/2010 (8:30 pm)
I'd have meant the texture ... check you are using materials.cs and don't have a typo? I once called it material.cs and had problems ... as a last resort - open up the dts file and scan down until you find the texture/materials in it --- it should be in readable English with the rest in machine gibberish.
#11
I have an object that spams the console "Creating missing material blah"
I set the mapto = "sometex"; and the console doesn't complain but the item looks inside out see through etc. I add the extension to the mapto = "sometex.png"; and now the object looks fine and no complaints. Yet another object made by the same artist does not have the extension and it looks fine and no console spam. Other items I have made with the same singleton format and mapto with or without extension spams the console. There seems to be no consistency in the failure modes.
I think this format needs addressed. We are spending way too much time on this.
Thanks for all your help....
04/16/2010 (6:39 am)
I dont think this system is working properly.I have an object that spams the console "Creating missing material blah"
I set the mapto = "sometex"; and the console doesn't complain but the item looks inside out see through etc. I add the extension to the mapto = "sometex.png"; and now the object looks fine and no complaints. Yet another object made by the same artist does not have the extension and it looks fine and no console spam. Other items I have made with the same singleton format and mapto with or without extension spams the console. There seems to be no consistency in the failure modes.
I think this format needs addressed. We are spending way too much time on this.
Thanks for all your help....
#12
You will get console spam with creation in editor because it doesn't already have a material. This should stop after saving the material and reloading.
Or are you writing the materials.cs file manually with T3D off? --which is my personal preference.
04/16/2010 (8:03 am)
Just to check -- are you assigning these in-game? Via the editor?You will get console spam with creation in editor because it doesn't already have a material. This should stop after saving the material and reloading.
Or are you writing the materials.cs file manually with T3D off? --which is my personal preference.
#13
I would like to think the engine could (and it does) create all the base textures and reserve the material.cs file for those special occasions when you might want to set a diffuse color or translucency. Would cut down on the hastle somewhat.
Speaking of which can I change a material dynamicly? Like a magic wall magicWallMaterial.setTranslucent(true,0.5);
04/16/2010 (9:11 am)
Well I did a couple in game thats when I discovered the in game save also adds the extensions to mapto = so out of game I manually edited the material.cs file and came to the conclusion I posted above.I would like to think the engine could (and it does) create all the base textures and reserve the material.cs file for those special occasions when you might want to set a diffuse color or translucency. Would cut down on the hastle somewhat.
Speaking of which can I change a material dynamicly? Like a magic wall magicWallMaterial.setTranslucent(true,0.5);
#14
04/16/2010 (9:34 am)
There is a changeMaterial() function in the some scripts - not sure what object types it's assocaited with and have never used it. Also check the resources, I remember seeing something recently.
Associate Rene Damm
So, actually, the material name is completely independent from the texture used. The important property to make the connection is "mapTo". This is actually used by the engine to find the surfaces on the model that a specific Material definition should be applied to.
In your case, "mapTo" must be "box.png" so the engine knows that when you assign box.png to a surface on the model, it should render it with the BoxMat material. This substitution is thorough in that the surface properties will be entirely defined by the Material definition. You could in fact create arbitrary texture names in your 3D application and then use "mapTo" to bind them to Materials.//probably; never tried actually
Since the Material is independent, it must also include all the texture setups which is why "diffuseMap[<stage>]" must point to the correct texture file. If the script file that the Material is defined in is in the same directory as the texture file, you can simply use a relative path like so