Added support to Blender for JSON layout loading and publishing

This commit is contained in:
Simone Barbieri 2021-04-21 17:27:17 +01:00
parent 25dfd09bbf
commit 602ca108f1
5 changed files with 116 additions and 19 deletions

View file

@ -367,13 +367,13 @@ class UnrealLayoutLoader(plugin.AssetLoader):
# Y axis mirrored
obj.location = (
location.get('x'),
-location.get('y'),
location.get('y'),
location.get('z')
)
obj.rotation_euler = (
rotation.get('x') + math.pi / 2,
-rotation.get('y'),
-rotation.get('z')
rotation.get('x'),
rotation.get('y'),
rotation.get('z')
)
obj.scale = (
scale.get('x'),

View file

@ -108,19 +108,21 @@ class BlendModelLoader(plugin.AssetLoader):
self.__class__.__name__,
)
container_metadata = container.get(
blender.pipeline.AVALON_PROPERTY)
metadata = container.get(blender.pipeline.AVALON_PROPERTY)
container_metadata["libpath"] = libpath
container_metadata["lib_container"] = lib_container
metadata["libpath"] = libpath
metadata["lib_container"] = lib_container
obj_container = self._process(
libpath, lib_container, container_name, None)
container_metadata["obj_container"] = obj_container
metadata["obj_container"] = obj_container
# Save the list of objects in the metadata container
container_metadata["objects"] = obj_container.all_objects
metadata["objects"] = obj_container.all_objects
metadata["parent"] = str(context["representation"]["parent"])
metadata["family"] = context["representation"]["context"]["family"]
nodes = list(container.objects)
nodes.append(container)

View file

@ -155,18 +155,20 @@ class BlendRigLoader(plugin.AssetLoader):
self.__class__.__name__,
)
container_metadata = container.get(
blender.pipeline.AVALON_PROPERTY)
metadata = container.get(blender.pipeline.AVALON_PROPERTY)
container_metadata["libpath"] = libpath
container_metadata["lib_container"] = lib_container
metadata["libpath"] = libpath
metadata["lib_container"] = lib_container
obj_container = self._process(
libpath, lib_container, collection_name, None, None)
container_metadata["obj_container"] = obj_container
metadata["obj_container"] = obj_container
# Save the list of objects in the metadata container
container_metadata["objects"] = obj_container.all_objects
metadata["objects"] = obj_container.all_objects
metadata["parent"] = str(context["representation"]["parent"])
metadata["family"] = context["representation"]["context"]["family"]
nodes = list(container.objects)
nodes.append(container)

View file

@ -0,0 +1,93 @@
import os
import json
import math
import bpy
from avalon import blender, io
import openpype.api
class ExtractLayout(openpype.api.Extractor):
"""Extract a layout."""
label = "Extract Layout"
hosts = ["blender"]
families = ["layout"]
optional = True
def process(self, instance):
# Define extract output file path
stagingdir = self.staging_dir(instance)
# Perform extraction
self.log.info("Performing extraction..")
json_data = []
for collection in instance:
for asset in collection.children:
collection = bpy.data.collections[asset.name]
container = bpy.data.collections[asset.name + '_CON']
metadata = container.get(blender.pipeline.AVALON_PROPERTY)
parent = metadata["parent"]
family = metadata["family"]
self.log.debug("Parent: {}".format(parent))
blend = io.find_one(
{
"type": "representation",
"parent": io.ObjectId(parent),
"name": "blend"
},
projection={"_id": True})
blend_id = blend["_id"]
json_element = {}
json_element["reference"] = str(blend_id)
json_element["family"] = family
json_element["instance_name"] = asset.name
json_element["asset_name"] = metadata["lib_container"]
json_element["file_path"] = metadata["libpath"]
obj = collection.objects[0]
json_element["transform"] = {
"translation": {
"x": obj.location.x,
"y": obj.location.y,
"z": obj.location.z
},
"rotation": {
"x": obj.rotation_euler.x,
"y": obj.rotation_euler.y,
"z": obj.rotation_euler.z,
},
"scale": {
"x": obj.scale.x,
"y": obj.scale.y,
"z": obj.scale.z
}
}
json_data.append(json_element)
json_filename = "{}.json".format(instance.name)
json_path = os.path.join(stagingdir, json_filename)
with open(json_path, "w+") as file:
json.dump(json_data, fp=file, indent=2)
if "representations" not in instance.data:
instance.data["representations"] = []
representation = {
'name': 'json',
'ext': 'json',
'files': json_filename,
"stagingDir": stagingdir,
}
instance.data["representations"].append(representation)
self.log.info("Extracted instance '%s' to: %s",
instance.name, representation)

View file

@ -78,14 +78,14 @@ class ExtractLayout(openpype.api.Extractor):
json_element["transform"] = {
"translation": {
"x": transform.translation.x,
"x": -transform.translation.x,
"y": transform.translation.y,
"z": transform.translation.z
},
"rotation": {
"x": math.radians(transform.rotation.euler().x),
"x": math.radians(transform.rotation.euler().x + 90.0),
"y": math.radians(transform.rotation.euler().y),
"z": math.radians(transform.rotation.euler().z),
"z": math.radians(180.0 - transform.rotation.euler().z)
},
"scale": {
"x": transform.scale3d.x,