setMeshMaterial making mesh invisible?

Level design, models, animations, physics, etc.
7 posts Page 1 of 1
Bricktronic
Posts: 8
Joined: Mon Aug 29, 2016 11:53 pm
  by Bricktronic » Thu Sep 08, 2016 7:36 am
So I'm working on player customization GUI, however, I can't seem to get the mesh to switch materials in the GuiObjectView.. I've been researching for hours, and dumping over and over, but I can't seem to come across an explanation, thus I'm here. If there's a way to access the object through the GuiObjectView, please do tell. I've tried getObject(), and that returns nothing with any number in the args. I basically need the ID of the player model I've set inside the GuiObjectView.

function replaceSimpleMaterial(%matname,%mapto,%RGBA)
{
if(%e==1)
{
%se = "emissive[0] = 1;";
%add = "emissive";
}

if(%g==1)
{
%sg = "glow[0] = 1;";
%add = %add @ "glow";
}

%r = getWord(%RGBA,0);
%g = getWord(%RGBA,1);
%b = getWord(%RGBA,2);
%a = getWord(%RGBA,3);
$eval = "singleton Material(" @ %matname @ %add @ %cl @ ")" NL
"{" NL
"mapTo = " @ %mapto @ ";" NL
"diffuseColor[0] = \"" @ %r-0.1 SPC %g-0.1 SPC %b-0.1 SPC %a @ "\";" NL
"specular[0] = \"" @ %r SPC %g SPC %b SPC %a @ "\";" NL
"specularPower[0] = " @ 50 @ ";" NL
%se NL
%sg NL
"translucentBlendOp = \"None\";" NL
"};";
eval($eval);
DecoyDAE.setMeshMaterial(%mapto SPC 2,%matname @ %add @ %cl);
echo(%RGBA);
}


I'm using DecoyDAE at the moment, which just makes the targeted node disappear. :?: :?: :?:
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Thu Sep 08, 2016 3:47 pm
When I was constructing character creation GUI's I'm pretty sure that was something I ended up having to 'fix' in source. I mean, it's not broken, just needed the support plugged in so to speak. IIRC, the GuiObjectView class didn't originally support the rendering of different skins using 'mapTo'. Since you bring it up, 'mapTo' specifically rings a bell and jogs my memory...seems like I may have even had to change something higher up the enheritance chain.

Man, I really need to tidy up my updated GuiObjectView class resource and get it out the door. That's a lot of script you're having to go through for something that can be handled with 'setSkinName' using my updated resource. I know it's not helpful to you in this moment, but I will make it a point to upload it very soon. People just need stuff like this! Give me a lil bit to clean up my code and get a little bit of a 'how to' typed up for the resource and it will fix any problems you've likely had with the GuiObjectView!

P.S. Are you comfortable with replacing your GuiObjectView.h and .cpp files in source(maybe another file or so I'll have to check when getting the resource ready)? Sorry should have asked before offering out a resource that requires source updates. :roll:
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Thu Sep 08, 2016 7:36 pm
@
User avatar
Bricktronic
: I skimmed over my updated GuiObjectView code and stumbled on the 'stock' T3D console function for setting skins. Before we overkill this thing completely, try to use this:

Code: Select all

// Define the skin we want to apply to the main model in the control.
%skinName = "disco_gideon";

// Inform the GuiObjectView control to update the skin to the defined skin.
%thisGuiObjectView.setSkin(%skinName);


That might be more along the lines of what you were looking for to begin with. Sorry, I've been running all my builds custom for quite some time and have a tendency to overlook "what was stock" sometimes. I believe, dealing with skins, what my resource achieves is it allows the model to have multiple skins at the same time. As in, if you have a model with multiple sub-meshes that each have their own material. Anyhow, as promised, I'm still polishing my updated resource.
Bricktronic
Posts: 8
Joined: Mon Aug 29, 2016 11:53 pm
by Bricktronic » Fri Sep 09, 2016 2:55 am
TorqueFan wrote:@Bricktronic: I skimmed over my updated GuiObjectView code and stumbled on the 'stock' T3D console function for setting skins. Before we overkill this thing completely, try to use this:

Code: Select all

// Define the skin we want to apply to the main model in the control.
%skinName = "disco_gideon";

// Inform the GuiObjectView control to update the skin to the defined skin.
%thisGuiObjectView.setSkin(%skinName);


That might be more along the lines of what you were looking for to begin with. Sorry, I've been running all my builds custom for quite some time and have a tendency to overlook "what was stock" sometimes. I believe, dealing with skins, what my resource achieves is it allows the model to have multiple skins at the same time. As in, if you have a model with multiple sub-meshes that each have their own material. Anyhow, as promised, I'm still polishing my updated resource.


Thanks for the replies, I'll try it soon. I'll have to research into how to use skins, as I'm used to TGE rather than T3D. I'm willing to add the C++ code, if you're kind enough to pass it on, however, if I can use skinning, I'd rather do that. We're struggling a bit as a team, as none of us know much C++, and we're all new to the latest T3D. Thanks! :D
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Fri Sep 09, 2016 3:09 am
Cool, yea IIRC you should be able to call setSkin() to choose a skin for the model displayed in the GuiObjectView using the stock code. Yes, of course I am willing to share my GuiObjectView code! I've been meaning to upload it as a resource for awhile so it's coming soon!

Now, dealing with skinning in the first place is just a little bit tricky but it's not too bad once you learn the ins and outs of naming the materials. I'll post more detail specifically about skinning and proper material setup either a bit later tonight( if I get the time ) or tomorrow. It's worth going over here one solid time for any who may be reading as well. Stay tuned!
Bricktronic
Posts: 8
Joined: Mon Aug 29, 2016 11:53 pm
by Bricktronic » Fri Sep 09, 2016 4:02 am
TorqueFan wrote:Cool, yea IIRC you should be able to call setSkin() to choose a skin for the model displayed in the GuiObjectView using the stock code. Yes, of course I am willing to share my GuiObjectView code! I've been meaning to upload it as a resource for awhile so it's coming soon!

Now, dealing with skinning in the first place is just a little bit tricky but it's not too bad once you learn the ins and outs of naming the materials. I'll post more detail specifically about skinning and proper material setup either a bit later tonight( if I get the time ) or tomorrow. It's worth going over here one solid time for any who may be reading as well. Stay tuned!


I found a way to bypass all that. I used a duplicate of the playermodel, scripted it, and now it just replaces the main material of the datablock. Thanks! :D
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Fri Sep 09, 2016 4:24 am
Haha, you posted as I was typing this all up so it's getting posted anyways! Check it out if you get a chance though, using Torque's skinning system can be really powerful once you get it nailed down. In this example you could use a single texture for any number of materials with added color to the diffuse of each material. Additionally a single model for as many materials as necessary! Anyways, glad you guys got it sorted =)

Gonna try for a quick rundown of how to handle material definitions for skinning in 3, 2, 1...

Naming the Materials
Let's try for a really simple scenario. We'll use one single image, called "shirt_d". For skins we'll re-use the same image and just add color to the diffuse. This looks like so:

Code: Select all

// default shirt(white shirt diffuse texture)
singleton Material( Mat_PlayerShirt ) {
   mapTo = "White_PlayerShirt";
   diffuseColor[0] = "1 1 1 1";
   diffuseMap[0] = "shirt_d";
   materialTag0 = "Player";
};

// Blue shirt
singleton Material( Mat_Blue_PlayerShirt : Mat_PlayerShirt ) {
   mapTo = "Blue_PlayerShirt";   
   diffuseColor[0] = "0.58 0.81 1 1";
};


Okay so the Mat_Blue_PlayerShirt enherits from Mat_PlayerShirt, so we didn't even have to name the texture since we're just going to apply some color to the same diffuse!

Another important thing about this example is that I did NOT use the standard naming convention of "base_PlayerShirt" for my default material. This was on purpose to illustrate that you have the freedom to name your "mapTo" material whatever you like. Just be sure that any materials that enherit from it are named properly and the name here is the same as the name of the material on your model. Here's what I mean:

  1. Your base default texture is named "Mat_PlayerShirt".
  2. The base default texture's "mapTo" field is "whatever_PlayerShirt". Use whatever 'base' prefix you want, OR use the default "base_PlayerShirt".
  3. The next texture you create will need to enherit from the base texture. Declare it like this:
    singleton Material( Mat_New_PlayerShirt : Mat_PlayerShirt )
  4. Any of the textures you created as above in point 3 need to label their "mapTo" property precisely. In point 3 the material is named "Mat_New_PlayerShirt" so the "mapTo" field would be "New_PlayerShirt".

The Object Datablock
In order for all of that material preparation to pay off, the datablock that's loading up the model needs to declare its skins. For datablock types that support skinning, the field looks like this:

Code: Select all

datablock PlayerData(DefaultPlayerData)
{
...
availableSkins = "White   Blue";  // example 1
availableSkins = "whatever   New";  // example 2
availableSkins = "base   New"; // default example
...
};


So we only use the prefix of the "mapTo" field for each material we want to add to the datablock's skin list. Also important to note is the availableSkins field wants you to enter a tab-delimited list of prefix strings.
So just be sure you enter it in like: whatever(TAB)Blue(TAB)Green
7 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest