MEL Shader converter

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
Thumbs down MEL Shader converter

Hi
I am working on a shader converter .Like if there is Blinn shader with transparency and displacement map attached to it, it will convert it to Lambert with same nodes intact.
My question is - what if there is multile shaders attached to a single object (my script doesn't work in that case).
So what is the command or procedure to find out a Shader is attached to a limited faces of an object ??
Or there are multiple shaders to a single object .How do we select faces from those shaders ??
I am starting like this -

string $sEngine[] = `ls -typ shadingEngine`;
for ($Engine in $sEngine)
{
string $material[] = `listConnections -d 0 $Engine`;

if (`attributeExists "transparency" $material[0]` == 1 )
{
if (`connectionInfo -id ($material[0]+".transparency")` == 1)
{
.....and so on....
}
}
}


Plz anyone help me out.
__________________
Sunny
 
Old 01 January 2013   #2
you don't really need to do any of that work. Just re-use the existing Shader's ShadingGroups.

Take your new shader, and connect it's outColor Attr to the original shader's SG surfaceShader attr.


import maya.cmds as cmds
shaderA = 'blinn1'
shaderB = 'lambert2'
originalSGs = cmds.listConnections(shaderA, type='shadingEngine')
for sg in originalSGs:
	cmds.connectAttr('{0}.outColor'.format(shaderB), '{0}.surfaceShader'.format(sg), force=True)
 
Old 01 January 2013   #3
To determine how many shaders are applied to a mesh, find the connections between the shape node and the shadingGroups.


import maya.cmds as cmds
shape = 'pSphereShape1'
sgs = cmds.listConnections(shape, type='shadingEngine')
sgs = list(set(sgs))
materials = []
for sg in sgs:
	material = cmds.listConnections('{0}.surfaceShader'.format(sg  ))
	materials.extend(material)
print materials


Note: Text formatting may be messed up, and code may contain syntax errors...
 
Old 01 January 2013   #4
Hi rgkovach123 and thanks for the reply.
I got your point but real issue is that here I am trying to get faces of a mesh selected from a Shading Engine .
For eg : If a mesh has Blinn1 shader applied on limited faces , the faces can be selected by this - select blinn1SG;
pickWalk -d down blinn1SG;


Or if we go in Hypershade :> Right click on any shader :> there we get an option "select Object with Material". So hows maya recognising the no of faces to select.

I am not satisfied with pickWalk ,so is there any other smart way ?
__________________
Sunny
 
Old 01 January 2013   #5
Shading Groups connected to materials contain a mix of objects and faces across the entire scene.

To limit the query to a single object, you'll need to iterate through all the contents of the shading group and filter out anything not related to the source mesh.



def getMaterialOnObject(shape, material):
	result = []
	shadingGroup = cmds.listConnections(material, type='shadingEngine')[0]
	members = cmds.sets(shadingGroup, q=True)
	for m in members:
		if shape in m:
			result.append(m)
	return result


There's a little bit more to it, error checking and using long names, etc... but thats the basic idea.
 
Old 01 January 2013   #6
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 09:00 PM.


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