Skip to content

Commit

Permalink
Merge pull request #1 from Roblox/feature/add-more-uploadable-types
Browse files Browse the repository at this point in the history
Allow selecting `Armature`, `Curve`, `MetaBall`, `Text`
  • Loading branch information
Nightriff authored Jul 13, 2023
2 parents 3c5fc48 + 8f395c9 commit 277a1ea
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/get_selected_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,34 @@
# SPDX-License-Identifier: MIT

"""
Returns objects selected in any outliner by the user, only including collections and meshes.
For a collection to be selectable, it must contain a mesh descendant.
Returns objects selected in any outliner by the user, only including "uploadable" objects.
For a collection to be selectable, it must contain an uploadable descendant.
"""

import bpy

UPLOADABLE_TYPES = [
bpy.types.Mesh,
bpy.types.Armature,
bpy.types.Curve,
bpy.types.MetaBall,
bpy.types.Text,
]

def __is_mesh(instance):
return isinstance(instance, bpy.types.Object) and isinstance(instance.data, bpy.types.Mesh)

def __is_uploadable_object(instance):
is_object = isinstance(instance, bpy.types.Object)
if not is_object:
return False
is_uploadable_type = any(isinstance(instance.data, uploadable_type) for uploadable_type in UPLOADABLE_TYPES)
return is_uploadable_type

def __contains_mesh(collection):

def __contains_uploadable_object(collection):
if isinstance(collection, bpy.types.Collection):
return any(__is_mesh(child) for child in collection.all_objects)
return any(__is_uploadable_object(child) for child in collection.all_objects)
else:
return False


def get_selected_objects(context):
Expand All @@ -55,7 +69,7 @@ def get_selected_objects(context):
continue

# Avoid counting objects that can't be uploaded (Open Cloud servers require a mesh inside the asset)
if not (__is_mesh(selected_object) or __contains_mesh(selected_object)):
if not (__is_uploadable_object(selected_object) or __contains_uploadable_object(selected_object)):
continue

objects.append(selected_object)
Expand Down

0 comments on commit 277a1ea

Please sign in to comment.