1 - Automating the process
Since we are currently working with about 50 Modular Kit pieces and 20 Material IDs it would be very tedious to manually set up the Materials. So I did a bit of testing.
All the pieces come with an attribute called 'shop_materialpath', which I can use to get the faces with different IDs.
Material ID List |
I also couldn't figure out how to edit the parameters via Python, since the geometry of the nodes is read only and the python node doesn't own the geometry, because it is not connected to the geometry nodes.
However I can use Python to create nodes, so I created an Attribute Wrangle node in each Modular Kit Node, containing the necessary logic to assign the 'unreal_material' attribute + values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node = hou.pwd() | |
# Add code to modify contained geometries. | |
# Use drop down menu to select examples. | |
subnetNode = node.parent() | |
children = subnetNode.children() | |
#assign unreal material attribute via VEX | |
attribWString = """int numPrims = @numprim; | |
for(int p = 0; p < numPrims; p++){ | |
string mat = primattrib(geoself(), 'shop_materialpath', p, 1); | |
mat = tolower(mat); | |
mat = re_replace(' ', '_', mat); | |
mat = 'mat_' + mat; | |
setprimattrib(geoself(), 'unreal_material', p, chs('../../' + mat), 'set'); | |
}""" | |
for c in children: | |
if c.type().name() and 'SM_' in c.name(): | |
name = c.name() | |
n = hou.node('../' + name + '/' + name) | |
if str(n) != 'None': | |
n.setHardLocked(True) | |
a = hou.node('../' + name + '/unreal_material') | |
if str(a) == 'None': | |
a = c.createNode('attribwrangle') | |
a.setName('unreal_material') | |
a.setFirstInput(n) | |
a.moveToGoodPosition() | |
a.parm('snippet').set(attribWString) | |
a.setDisplayFlag(True) | |
a.setRenderFlag(True) | |
else: | |
a.moveToGoodPosition() | |
a.parm('snippet').set(attribWString) | |
a.setDisplayFlag(True) | |
a.setRenderFlag(True) | |
I also locked the geometry files, so the HDA has no file dependencies.
2 - Unreal
So, to keep it short: It works.
Material IDs in Unreal |
Now that I got this working I will move on to LODs and hopefully soon more Shader and Engine work.
No comments:
Post a Comment