Jump to content

setMeshMaterial making mesh invisible?


Bricktronic

Recommended Posts

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. :?: :?: :?:

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

@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:

 

// 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.

Link to comment
Share on other sites

@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:

 

// 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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

// 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:

 

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...