Jump to content

shop_materialpath from attribute


bonassus

Recommended Posts

 

I have become aware of an awesome script that generates redshift materials from a shop_materialpath attribute. This makes importing FBX files much more manageable. 

big thanks to kaiserlicht!

http://kaiserlicht.at/tools/

 Currently it assigns a random color to the diffuse_color channel. Unfortunately i'm not very sophisticated with my python scripting. I wonder if there is a way to get the color from from the geometries material  and assign it to the diffuse_color channel. Or even better, if it could get the texture paths and assign them to a rs texture. I though I would post this here in hopes that a python genius on here might have the answer to share. 

here is the script

import hou
import random
import re
def main():

	sel = hou.selectedNodes()
	if sel:
		node = hou.selectedNodes()[0]
		if node.type().category() == hou.sopNodeTypeCategory():

			if node.geometry().findPrimAttrib('shop_materialpath'):

				shop_materialpath_atrr = node.geometry().primStringAttribValues('shop_materialpath')
				materials =  list(set(shop_materialpath_atrr))

				# Get the last Part and remove empty Materials
				materials = [x for x in materials if x !=""]

				matnet = node.parent().createNode('matnet',node_name="matnet",run_init_scripts=False)

	 	 	
		 	 	materialNode = node.parent().createNode('material')
		 	 	materialNode.setFirstInput(node)
		 	 	materialNode.setDisplayFlag(True)
				materialNode.setRenderFlag(True)

		 	 	materialNode.moveToGoodPosition()


	 	 		materialNode.parm('num_materials').set(len(materials))
	 	 		for i in xrange(len(materials)):

	 	 			matname = materials[i].rsplit("/", 1)
	 	 			if len(matname)>1:
	 	 				matname = matname[1]
 	 				else:
 	 					matname = matname[0]


 					matname = re.sub('[^a-zA-Z0-9-_*.]', '_', matname)
	 	 			
					# Create and Connect RS Material Builder
				 	redshift_vopnet = matnet.createNode('redshift_vopnet',node_name=matname,run_init_scripts=True)
				 	rsmaterial = redshift_vopnet.createNode('redshift::Material')
				 	rsroot = hou.node(str(redshift_vopnet.path())+"/redshift_material1")
				 	rsroot.setFirstInput(rsmaterial)

	 	 			# add random diffuse value
 	 				color = [0,0,0]

 	 				for j in xrange(len(color)):
 	 					color[j] = random.uniform(0.3,1)
	 	 			rsmaterial.parmTuple('diffuse_color').set(color)



	 	 			redshift_vopnet.moveToGoodPosition()

	 	 			materialNode.parm('group'+str(i+1)).set("@shop_materialpath="+str(materials[i]))

	 	 			materialNode.parm('shop_materialpath'+str(i+1)).set("../"+matnet.name()+"/"+redshift_vopnet.name())



main()

 

 

thanks.

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.
Note: Your post will require moderator approval before it will be visible.

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