Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Unreal: animation, layout and setdress updates #695

Merged
merged 24 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1718635
Unreal support for model and rig assets
simonebarbieri Aug 11, 2020
9d737c2
Implemented layout asset in Unreal
simonebarbieri Aug 11, 2020
3c65258
Blender can load layout exported from Unreal as json
simonebarbieri Aug 12, 2020
1c27e66
Updated the loading of the layout to support nested containers
simonebarbieri Aug 13, 2020
5d1d88a
Implemented remove method for layout asset
simonebarbieri Aug 13, 2020
daba0c0
Implemented update for the layout
simonebarbieri Aug 17, 2020
c80dfdf
Fix rotation when loading from Unreal
simonebarbieri Aug 24, 2020
f95f997
Improved generation of custom context
simonebarbieri Sep 30, 2020
ea248a4
Implemented creator for setdress and updated creator for animation
simonebarbieri Sep 30, 2020
e4e4387
Updated naming for some variables
simonebarbieri Sep 30, 2020
525c4fe
Create the subset for animation and setdress when loading a layout
simonebarbieri Sep 30, 2020
bce22ac
Implemented extraction of the animation and setdress
simonebarbieri Sep 30, 2020
2ac826f
Implemented loading of animation and setdress in Unreal
simonebarbieri Sep 30, 2020
8581339
Fix the drivers to link to the local objects
simonebarbieri Oct 1, 2020
3fb4ee1
Fixed problem with rig loader
simonebarbieri Oct 7, 2020
15b782f
Improved remove and update for layout loader
simonebarbieri Oct 14, 2020
24703b0
Improved loading and update for rigs and staticmeshes
simonebarbieri Oct 20, 2020
41bede0
Improved loading for setdress and animation and implemented update
simonebarbieri Nov 3, 2020
53d2423
Improvements on loading for unreal
simonebarbieri Nov 3, 2020
6e0c621
Handle exception if asset container is not found when extracting layout
simonebarbieri Nov 3, 2020
3dab7be
Improved remove function to delete parent directory if empty
simonebarbieri Nov 4, 2020
a06bac6
Fix problem with update that didn't update some metadata
simonebarbieri Nov 6, 2020
b59887b
Pep8 compliance
simonebarbieri Nov 6, 2020
be59efa
Fixed constraints not referencing the local objects
simonebarbieri Dec 1, 2020
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
69 changes: 41 additions & 28 deletions pype/hosts/blender/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from avalon import api

VALID_EXTENSIONS = [".blend"]
VALID_EXTENSIONS = [".blend", ".json"]


def asset_name(
Expand All @@ -29,15 +29,19 @@ def get_unique_number(
c for c in bpy.data.collections
if c.name == 'AVALON_CONTAINERS'
]
loaded_assets = []
containers = []
# First, add the children of avalon containers
for c in avalon_containers:
loaded_assets.extend(c.children)
collections_names = [
c.name for c in loaded_assets
containers.extend(c.children)
# then keep looping to include all the children
for c in containers:
containers.extend(c.children)
container_names = [
c.name for c in containers
]
count = 1
name = f"{asset}_{count:0>2}_{subset}_CON"
while name in collections_names:
while name in container_names:
count += 1
name = f"{asset}_{count:0>2}_{subset}_CON"
return f"{count:0>2}"
Expand All @@ -59,20 +63,20 @@ def create_blender_context(active: Optional[bpy.types.Object] = None,
if not isinstance(selected, list):
selected = [selected]

override_context = bpy.context.copy()

for win in bpy.context.window_manager.windows:
for area in win.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override_context = {
'window': win,
'screen': win.screen,
'area': area,
'region': region,
'scene': bpy.context.scene,
'active_object': active,
'selected_objects': selected
}
override_context['window'] = win
override_context['screen'] = win.screen
override_context['area'] = area
override_context['region'] = region
override_context['scene'] = bpy.context.scene
override_context['active_object'] = active
override_context['selected_objects'] = selected
return override_context
raise Exception("Could not create a custom Blender context.")

Expand Down Expand Up @@ -175,33 +179,42 @@ def load(self,
# just re-using the collection
assert Path(self.fname).exists(), f"{self.fname} doesn't exist."

self.process_asset(
asset = context["asset"]["name"]
subset = context["subset"]["name"]
unique_number = get_unique_number(
asset, subset
)
namespace = namespace or f"{asset}_{unique_number}"
name = name or asset_name(
asset, subset, unique_number
)

nodes = self.process_asset(
context=context,
name=name,
namespace=namespace,
options=options,
)

# Only containerise if anything was loaded by the Loader.
nodes = self[:]
if not nodes:
return None

# Only containerise if it's not already a collection from a .blend file.
representation = context["representation"]["name"]
if representation != "blend":
from avalon.blender.pipeline import containerise
return containerise(
name=name,
namespace=namespace,
nodes=nodes,
context=context,
loader=self.__class__.__name__,
)
# representation = context["representation"]["name"]
# if representation != "blend":
# from avalon.blender.pipeline import containerise
# return containerise(
# name=name,
# namespace=namespace,
# nodes=nodes,
# context=context,
# loader=self.__class__.__name__,
# )

asset = context["asset"]["name"]
subset = context["subset"]["name"]
instance_name = asset_name(asset, subset, namespace)
instance_name = asset_name(asset, subset, unique_number) + '_CON'

return self._get_instance_collection(instance_name, nodes)

Expand Down
32 changes: 5 additions & 27 deletions pype/plugins/blender/create/create_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import bpy

from avalon import api
from avalon.blender import Creator, lib
from avalon import api, blender
import pype.hosts.blender.plugin


class CreateAnimation(Creator):
class CreateAnimation(blender.Creator):
"""Animation output for character rigs"""

name = "animationMain"
Expand All @@ -16,37 +15,16 @@ class CreateAnimation(Creator):
icon = "male"

def process(self):

asset = self.data["asset"]
subset = self.data["subset"]
name = pype.hosts.blender.plugin.asset_name(asset, subset)
collection = bpy.data.collections.new(name=name)
bpy.context.scene.collection.children.link(collection)
self.data['task'] = api.Session.get('AVALON_TASK')
lib.imprint(collection, self.data)

# Add the rig object and all the children meshes to
# a set and link them all at the end to avoid duplicates.
# Blender crashes if trying to link an object that is already linked.
# This links automatically the children meshes if they were not
# selected, and doesn't link them twice if they, insted,
# were manually selected by the user.
objects_to_link = set()
blender.lib.imprint(collection, self.data)

if (self.options or {}).get("useSelection"):

for obj in lib.get_selection():

objects_to_link.add(obj)

if obj.type == 'ARMATURE':

for subobj in obj.children:

objects_to_link.add(subobj)

for obj in objects_to_link:

collection.objects.link(obj)
for obj in blender.lib.get_selection():
collection.objects.link(obj)

return collection
24 changes: 24 additions & 0 deletions pype/plugins/blender/create/create_setdress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import bpy

from avalon import api, blender
import pype.hosts.blender.plugin

class CreateSetDress(blender.Creator):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

"""A grouped package of loaded content"""

name = "setdressMain"
label = "Set Dress"
family = "setdress"
icon = "cubes"
defaults = ["Main", "Anim"]

def process(self):
asset = self.data["asset"]
subset = self.data["subset"]
name = pype.hosts.blender.plugin.asset_name(asset, subset)
collection = bpy.data.collections.new(name=name)
bpy.context.scene.collection.children.link(collection)
self.data['task'] = api.Session.get('AVALON_TASK')
blender.lib.imprint(collection, self.data)

return collection
Loading