From 6d68cfa579ea07b52c310f7e2d9013f05de28c46 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Tue, 13 Apr 2021 10:12:00 +0100 Subject: [PATCH 1/3] Let Blender load scene settings from Ftrack --- openpype/hosts/blender/api/__init__.py | 40 +++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/openpype/hosts/blender/api/__init__.py b/openpype/hosts/blender/api/__init__.py index c5b0a44072..66102a2ae1 100644 --- a/openpype/hosts/blender/api/__init__.py +++ b/openpype/hosts/blender/api/__init__.py @@ -51,18 +51,38 @@ def set_start_end_frames(): "name": asset_name }) - # Default frame start/end - frameStart = 0 - frameEnd = 100 + scene = bpy.context.scene - # Check if frameStart/frameEnd are set - if asset_doc["data"]["frameStart"]: - frameStart = asset_doc["data"]["frameStart"] - if asset_doc["data"]["frameEnd"]: - frameEnd = asset_doc["data"]["frameEnd"] + # Default scene settings + frameStart = scene.frame_start + frameEnd = scene.frame_end + fps = scene.render.fps + resolution_x = scene.render.resolution_x + resolution_y = scene.render.resolution_y + + # Check if settings are set + data = asset_doc.get("data") + + if not data: + return + + if data.get("frameStart"): + frameStart = data.get("frameStart") + if data.get("frameEnd"): + frameEnd = data.get("frameEnd") + if data.get("fps"): + fps = data.get("fps") + if data.get("resolutionWidth"): + resolution_x = data.get("resolutionWidth") + if data.get("resolutionHeight"): + resolution_y = data.get("resolutionHeight") + + scene.frame_start = frameStart + scene.frame_end = frameEnd + scene.render.fps = fps + scene.render.resolution_x = resolution_x + scene.render.resolution_y = resolution_y - bpy.context.scene.frame_start = frameStart - bpy.context.scene.frame_end = frameEnd def on_new(arg1, arg2): set_start_end_frames() From db777ee3f46254fc17939357c8fae9f6c98aaff5 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Tue, 13 Apr 2021 10:12:26 +0100 Subject: [PATCH 2/3] Added new validator for Object Mode for objects in the scene --- .../plugins/publish/validate_object_mode.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 openpype/hosts/blender/plugins/publish/validate_object_mode.py diff --git a/openpype/hosts/blender/plugins/publish/validate_object_mode.py b/openpype/hosts/blender/plugins/publish/validate_object_mode.py new file mode 100644 index 0000000000..97456a581e --- /dev/null +++ b/openpype/hosts/blender/plugins/publish/validate_object_mode.py @@ -0,0 +1,36 @@ +from typing import List + +import bpy + +import pyblish.api +import openpype.hosts.blender.api.action + + +class ValidateObjectIsInObjectMode(pyblish.api.InstancePlugin): + """Validate that the current object is in Object Mode.""" + + order = pyblish.api.ValidatorOrder - 0.01 + hosts = ["blender"] + families = ["model", "rig"] + category = "geometry" + label = "Object is in Object Mode" + actions = [openpype.hosts.blender.api.action.SelectInvalidAction] + optional = True + + @classmethod + def get_invalid(cls, instance) -> List: + invalid = [] + for obj in [obj for obj in instance]: + try: + if obj.type == 'MESH' or obj.type == 'ARMATURE': + # Check if the object is in object mode. + if not obj.mode == 'OBJECT': + invalid.append(obj) + except: + continue + return invalid + + def process(self, instance): + invalid = self.get_invalid(instance) + if invalid: + raise RuntimeError(f"Object found in instance is not in Object Mode: {invalid}") From 2a872de0df42bf088fc3680a9ff0ea6bee9efb1b Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Tue, 13 Apr 2021 10:23:30 +0100 Subject: [PATCH 3/3] Fixed Hound violations --- .../hosts/blender/plugins/publish/validate_object_mode.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/blender/plugins/publish/validate_object_mode.py b/openpype/hosts/blender/plugins/publish/validate_object_mode.py index 97456a581e..1c82628c1c 100644 --- a/openpype/hosts/blender/plugins/publish/validate_object_mode.py +++ b/openpype/hosts/blender/plugins/publish/validate_object_mode.py @@ -1,7 +1,5 @@ from typing import List -import bpy - import pyblish.api import openpype.hosts.blender.api.action @@ -26,11 +24,12 @@ class ValidateObjectIsInObjectMode(pyblish.api.InstancePlugin): # Check if the object is in object mode. if not obj.mode == 'OBJECT': invalid.append(obj) - except: + except Exception: continue return invalid def process(self, instance): invalid = self.get_invalid(instance) if invalid: - raise RuntimeError(f"Object found in instance is not in Object Mode: {invalid}") + raise RuntimeError( + f"Object found in instance is not in Object Mode: {invalid}")