mabulazm Posted June 16, 2010 Share Posted June 16, 2010 Hey I am totally new to Python, so I have an idea and want to know if it possible to achieve or not. creating Box and Material ... I have done this part then I want to copy the material ... say 4 times and assign it to different primitive, but just 1 material holding 4 shaders. material 1 go to primitive 0 ... and so on. and of course change the color of the shader. cheers Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted June 16, 2010 Share Posted June 16, 2010 I give it a shot. Just create new shelf tool and place this code in scriptTAB. It creates box and material node also so you don't need create them manually. # create geo node for your box this = hou.node('/obj').createNode('geo', run_init_scripts=False) # create box inside of geo box = this.createNode('box') # create material node material = this.createNode('material') # setup material # find number of box faces numFaces = len(box.geometry().prims()) # setup material tabs tabs = material.parm('num_materials') tabs.set(numFaces) # connect material to box and correct position material.setFirstInput(box) material.moveToGoodPosition() # make material node active node material.setDisplayFlag(True) material.setRenderFlag(True) # create shop node and correct position shop = this.createNode('shopnet', 'SHOP') shop.moveToGoodPosition() # create shaders in shop # create colors color = ((0.9, 0.45, 0.0), (1.0, 1.0, 1.0), (0.9, 0.0, 0.0), (0.0, 0.45, 0.9), (0.0, 0.9, 0.0), (0.9, 0.9, 0.0)) # here we create loop using xrange instead of range # range gives you string not real iterator, # you can use both but xrange is better suited for this because it's faster # just remember that xrange is obsolete in python3 for i in xrange(numFaces): # create your shaders shader = shop.createNode('v_clay') # setup shaders shader.parmTuple('diff').set(color[i]) # correct nodes positions shader.moveToGoodPosition() # assign colors to faces material.parm('group%s' % (i+1)).set(str(i)) material.parm('shop_materialpath%s' % (i+1)).set(material.relativePathTo(shader)) Quote Link to comment Share on other sites More sharing options...
mabulazm Posted June 17, 2010 Author Share Posted June 17, 2010 (edited) WawWooooo this is exactly what am looking for, I was struggling a bit to find the name of shader, How can I find the shaders name, What about choosing from the Gallery for example Basic Surface, I have tried basic_surface but it gave me error, or it MUST be VEX. len(box.geometry().prims()) feel a bit confused about how to get this kind of informations through the help command, could you guide me in how to use it. is moveToGoodPosition() same like layoutChildren(), when to use it. sorry for being a pain Edit :which editor you are using ? cheers Edited June 17, 2010 by mabulazm Quote Link to comment Share on other sites More sharing options...
graham Posted June 17, 2010 Share Posted June 17, 2010 (edited) Items in the Material Palette aren't their own node types. They are gallery entries. The Basic Surface entry gets applied to a Material SHOP and creates a basic_surface material. To create it you need to do something like this: mat_shop = hou.node("/shop").createNode("material") try: gal = hou.galleries.galleryEntries(name_pattern="basic_surface")[0] gal.applyToNode(mat_shop) except IndexError: pass There's no direct way, such as something like hou.Geometry.numPrims(), numPoints(), etc, to get the number of primitives or points in some geometry. That leaves you with getting the number of them by actually requesting them then finding the length of the resultant list/tuple. In the case of having a lot of points/prims you should consider using hou.Geometry.iterPrims() or iterPoints() if you just need to get the number of them. These functions return a generator object that doesn't allocate all the actual elements and waste time/memory. moveToGoodPosition() basically just lays out a node based on it's inputs where as layoutChildren() lays out child nodes. If you are creating a single node then you just need to move it so you can tell it to move itself rather than telling the parent node to lay out all the children. Edited June 17, 2010 by graham Quote Link to comment Share on other sites More sharing options...
mabulazm Posted June 17, 2010 Author Share Posted June 17, 2010 graham ... thanks a lot for your reply, things getting clear now. so am thinking about, making number of colors depends on the numFaces, but to to make it vector and give it random values or can I use ... readInput(), selectFromList() to insert the color values. cheers Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted June 17, 2010 Share Posted June 17, 2010 ... but to to make it vector and give it random values or can I use ... readInput(), selectFromList() to insert the color values. If you wan't choose color before creation you need to make your own GUI for this with WX module or something simmilar. But if you don't need this maybe just add float SEED parameter to you materialSOP node that will drive random generator in the code. For randomising use hou.hmath.rand(SEED), try adding primitive num, point num or maybe actual time, anything that will generate random SEED for each face, and make your own vector3 for color from those data. Quote Link to comment Share on other sites More sharing options...
mabulazm Posted June 18, 2010 Author Share Posted June 18, 2010 Hey SWANN thanx a lot for your help, but I think it is getting more complicated for me, so maybe I will try what you have said when I get use to Python. anyway thanx again Quote Link to comment Share on other sites More sharing options...
stephane06 Posted April 20, 2020 Share Posted April 20, 2020 On 17/6/2010 at 12:28 AM, Guest Swann said: I give it a shot. Just create new shelf tool and place this code in scriptTAB. It creates box and material node also so you don't need create them manually. # create geo node for your box this = hou.node('/obj').createNode('geo', run_init_scripts=False) # create box inside of geo box = this.createNode('box') # create material node material = this.createNode('material') # setup material # find number of box faces numFaces = len(box.geometry().prims()) # setup material tabs tabs = material.parm('num_materials') tabs.set(numFaces) # connect material to box and correct position material.setFirstInput(box) material.moveToGoodPosition() # make material node active node material.setDisplayFlag(True) material.setRenderFlag(True) # create shop node and correct position shop = this.createNode('shopnet', 'SHOP') shop.moveToGoodPosition() # create shaders in shop # create colors color = ((0.9, 0.45, 0.0), (1.0, 1.0, 1.0), (0.9, 0.0, 0.0), (0.0, 0.45, 0.9), (0.0, 0.9, 0.0), (0.9, 0.9, 0.0)) # here we create loop using xrange instead of range # range gives you string not real iterator, # you can use both but xrange is better suited for this because it's faster # just remember that xrange is obsolete in python3 for i in xrange(numFaces): # create your shaders shader = shop.createNode('v_clay') # setup shaders shader.parmTuple('diff').set(color[i]) # correct nodes positions shader.moveToGoodPosition() # assign colors to faces material.parm('group%s' % (i+1)).set(str(i)) material.parm('shop_materialpath%s' % (i+1)).set(material.relativePathTo(shader)) oh man... many thanks for your sharing !!! that is a beautiful code for learning purpose a python in houdini. Thanks of lot ! (^_^) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.