Convert Material type

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  04 April 2013
Convert Material type

I have a scene with hundreds of mia_materials. I was requested to bring this scene into Unity, however Unity does not recognize these materials. What I need to do is for each mia_material in my scene, create a blinn, name it the same as its mia equivalent, copy the color values over, assign it to the same object the mia was assigned to, and delete the mia material. How can I do this? I am not a coder by any means but below is a script that is pointing in the right direction.

string $newMaterialType = "lambert";
string $nm = `createNode $newMaterialType`;
string $ms[] = `ls -type "phong"`;
string $pa[] = `listAttr -visible -settable -scalar $ms[0]`;
string $nma[] = `listAttr -visible -settable -scalar $nm`;
string $ca[] = stringArrayRemove($nma, $pa);
$ca = stringArrayRemove($ca, $pa);
delete $nm;
string $a; string $m; float $v; string $cl[];
for ($m in $ms)
$nm = `createNode $newMaterialType`;
$cl = `listConnections -destination true -plugs true -source false -type shadingEngine $m`;
connectAttr -f ($nm + ".outColor") ($cl[0]);
for ($a in $ca)
$v = `getAttr ($m + "." + $a)`;
catchQuiet(`setAttr ($nm + "." + $a) $v`);
delete $m;
noise Noise NOISE NOISE
  04 April 2013
Try this one below. Your example also checks if the original shader and the new one share attributes with the same name - and if so it copys the values. This one below only copys the diffuse rgb value of the mia_material to the new blinns color slot.
 	string $mias[] = {};
 	$mias = `stringArrayCatenate $mias (ls ("-type", "mia_material"))`;
 	// $mias = `stringArrayCatenate $mias (ls ("-type", "mia_material_x"))`;
 	// $mias = `stringArrayCatenate $mias (ls ("-type", "mia_material_x_passes"))`;
 	for($mia in $mias){
 		float $rgb[] = `getAttr ($mia + ".diffuse")`;
 		string $blinn = `shadingNode -asShader blinn`;
 		setAttr ($blinn + ".color") $rgb[0] $rgb[1] $rgb [2];
 		string $SG[] = `listConnections -destination 1 -plugs 0 -source 0 -type shadingEngine $mia`;
 		delete $mia;
 		connectAttr -f ($blinn + ".outColor") ($SG[0] + ".surfaceShader");
 		rename $blinn $mia;
  04 April 2013

Thank you so much, you saved me days of doing this by hand! It works perfect!
noise Noise NOISE NOISE
  04 April 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:04 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.