clean up the code for validator and add the config options for glsl shader

This commit is contained in:
Kayla Man 2023-01-18 13:55:19 +08:00
parent bdc4a09635
commit 62ebd77fe1
4 changed files with 68 additions and 18 deletions

View file

@ -21,7 +21,7 @@ class ConvertGLSLShader(publish.Extractor):
meshes = cmds.ls(instance, type="mesh", long=True)
self.log.info("meshes: {}".format(meshes))
# load the glsl shader plugin
cmds.loadPlugin("glslShader.mll", quiet=True)
cmds.loadPlugin("glslShader", quiet=True)
for mesh in meshes:
@ -33,8 +33,19 @@ class ConvertGLSLShader(publish.Extractor):
glsl_shadingGrp + ".surfaceShader")
# load the maya2gltf shader
maya_dir = os.getenv("MAYA_APP_DIR")
ogsfx = maya_dir + "/maya2glTF/PBR/shaders/glTF_PBR.ogsfx"
maya_publish = (
instance.context.data["project_settings"]["maya"]["publish"]
)
ogsfx_path = maya_publish["ConvertGLSLShader"]["ogsfx_path"]
if not ogsfx_path:
maya_dir = os.getenv("MAYA_APP_DIR")
if not maya_dir:
raise RuntimeError("MAYA_APP_DIR not found")
ogsfx_path = maya_dir + "/maya2glTF/PBR/shaders/"
if not os.path.exists(ogsfx_path):
raise RuntimeError("the ogsfx file not found")
ogsfx = ogsfx_path + "glTF_PBR.ogsfx"
cmds.setAttr(glsl + ".shader", ogsfx, typ="string")
# list the materials used for the assets

View file

@ -15,8 +15,8 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
The texture naming conventions follows the UE5-style-guides:
https://github.com/Allar/ue5-style-guide#anc-textures-packing
ORM: Occulsion Roughness Metallic
ORMS: Occulsion Roughness Metallic Specular
ORM: Occlusion Roughness Metallic
ORMS: Occlusion Roughness Metallic Specular
Texture Naming Style:
@ -34,7 +34,6 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
families = ['gltf']
hosts = ['maya']
label = 'GLTF Textures Name'
actions = [openpype.hosts.maya.api.action.SelectInvalidAction]
def process(self, instance):
"""Process all the nodes in the instance"""
@ -43,7 +42,7 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
raise RuntimeError("No PBS Shader in the scene")
invalid = self.get_texture_shader_invalid(instance)
if invalid:
raise RuntimeError("Non PBS material found in "
raise RuntimeError("Non PBS material found"
"{0}".format(invalid))
invalid = self.get_texture_node_invalid(instance)
if invalid:
@ -57,7 +56,7 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
def get_texture_name_invalid(self, instance):
invalid = set()
shading_grp = self.shader_selection(instance)
shading_grp = self.get_material_from_shapes(instance)
# get the materials related to the selected assets
# get the file textures related to the PBS Shader
@ -73,7 +72,7 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
# "_D"
if not dif.endswith("_D"):
invalid.add(dif_path)
orm_packed = cmds.listConnections(shader + ".TEX_ao_mapX")[0]
orm_packed = cmds.listConnections(shader + ".TEX_ao_map")[0]
if orm_packed:
# "_ORM"
orm_path = cmds.getAttr(orm_packed + ".fileTextureName")
@ -92,7 +91,7 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
def get_texture_node_invalid(self, instance):
invalid = set()
shading_grp = self.shader_selection(instance)
shading_grp = self.get_material_from_shapes(instance)
for material in shading_grp:
main_shader = cmds.listConnections(material,
destination=True,
@ -107,16 +106,21 @@ class ValidateGLTFTexturesNames(pyblish.api.InstancePlugin):
def get_texture_shader_invalid(self, instance):
invalid = set()
shading_grp = self.shader_selection(instance)
for material in shading_grp:
main_shader = cmds.listConnections(material,
destination=True,
type="StingrayPBS")
if not main_shader:
shading_grp = self.get_material_from_shapes(instance)
for shading_group in shading_grp:
material_name = "{}.surfaceShader".format(shading_group)
material = cmds.listConnections(material_name,
source=True,
destination=False,
type="StingrayPBS")
if not material:
# add material name
material = cmds.listConnections(material_name)[0]
invalid.add(material)
return list(invalid)
def shader_selection(self, instance):
def get_material_from_shapes(self, instance):
shapes = cmds.ls(instance, type="mesh", long=True)
for shape in shapes:
shading_grp = cmds.listConnections(shape,

View file

@ -350,7 +350,7 @@
"active": true
},
"ValidateGLTFTexturesNames": {
"enabled": true,
"enabled": false,
"optional": false,
"active": true
},
@ -829,6 +829,12 @@
}
}
},
"ConvertGLSLShader": {
"enabled": false,
"optional": true,
"active": true,
"ogsfx_path": ""
},
"ExtractMayaSceneRaw": {
"enabled": true,
"add_for_families": [

View file

@ -864,6 +864,35 @@
"type": "schema",
"name": "schema_maya_capture"
},
{
"type": "dict",
"collapsible": true,
"key": "ConvertGLSLShader",
"label": "Convert PBS Shader to GLSL Shader",
"checkbox_key": "enabled",
"children": [
{
"type": "boolean",
"key": "enabled",
"label": "Enabled"
},
{
"type": "boolean",
"key": "optional",
"label": "Optional"
},
{
"type": "boolean",
"key": "active",
"label": "Active"
},
{
"type": "text",
"key": "ogsfx_path",
"label": "GLSL Shader Directory"
}
]
},
{
"type": "dict",
"collapsible": true,