Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender: Model publish uv map name validator #224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import inspect
from typing import List

import bpy

import pyblish.api

from ayon_core.pipeline.publish import (
ValidateContentsOrder,
OptionalPyblishPluginMixin,
PublishValidationError,
RepairAction
)
import ayon_core.hosts.blender.api.action


class ValidateModelMeshUvMap1(
pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin,
):
"""Validate model mesh uvs are named `map1`.

This is solely to get them to work nicely for the Maya pipeline.
"""

order = ValidateContentsOrder
hosts = ["blender"]
families = ["model"]
label = "Mesh UVs named map1"
actions = [ayon_core.hosts.blender.api.action.SelectInvalidAction,
RepairAction]
optional = True
enabled = False
moonyuet marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def get_invalid(cls, instance) -> List:

invalid = []
for obj in instance:
if obj.mode != "OBJECT":
cls.log.warning(
f"Mesh object {obj.name} should be in 'OBJECT' mode"
" to be properly checked."
)

obj_data = obj.data
if isinstance(obj_data, bpy.types.Mesh):
mesh = obj_data

# Ignore mesh without UVs
if not mesh.uv_layers:
continue

# If mesh has map1 all is ok
if mesh.uv_layers.get("map1"):
continue

cls.log.warning(
f"Mesh object {obj.name} should be in 'OBJECT' mode"
" to be properly checked."
)
invalid.append(obj)

return invalid

@classmethod
def repair(cls, instance):
for obj in cls.get_invalid(instance):
mesh = obj.data

# Rename the first UV set to map1
mesh.uv_layers[0].name = "map1"

def process(self, instance):
if not self.is_active(instance.data):
return

invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
f"Meshes found in instance without valid UV's: {invalid}",
description=self.get_description()
)

def get_description(self):
return inspect.cleandoc(
"""## Meshes must have map1 uv set

To accompany a better Maya-focused pipeline with Alembics it is
expected that a Mesh has a `map1` UV set. Blender defaults to
a UV set named `UVMap` and thus needs to be renamed.

"""
)
9 changes: 9 additions & 0 deletions server_addon/blender/server/settings/publish_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class PublishPuginsModel(BaseSettingsModel):
default_factory=ValidatePluginModel,
title="Validate Mesh No Negative Scale"
)
ValidateModelMeshUvMap1: ValidatePluginModel = SettingsField(
default_factory=ValidatePluginModel,
title="Validate Model Mesh Has UV map named map1"
)
ValidateTransformZero: ValidatePluginModel = SettingsField(
default_factory=ValidatePluginModel,
title="Validate Transform Zero"
Expand Down Expand Up @@ -181,6 +185,11 @@ class PublishPuginsModel(BaseSettingsModel):
"optional": False,
"active": True
},
"ValidateModelMeshUvMap1": {
"enabled": False,
"optional": True,
"active": True
},
"ValidateTransformZero": {
"enabled": False,
"optional": True,
Expand Down
2 changes: 1 addition & 1 deletion server_addon/blender/server/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.7"
__version__ = "0.1.8"