General-101 / Halo-Asset-Blender-Development-Toolset

CE/H2/H3/ODST JMS/JMA/ASS exporter for Blender
https://c20.reclaimers.net/
MIT License
122 stars 21 forks source link

The export function includes hidden collections #68

Closed 77Mynameislol77 closed 2 years ago

77Mynameislol77 commented 2 years ago

I have included an example blendfile. Just export it as a JMS

Here's the export settings

image

blendfile.zip

General-101 commented 2 years ago

@jadshep Seems to be because these bits here never actually return anything except false

https://github.com/General-101/Halo-Asset-Blender-Development-Toolset/blob/master/io_scene_halo/global_functions/resource_management.py#L12

I fixed this with the following code

def gather_collection_resources(layer_collection, layer_collection_set, object_set, hidden_geo, nonrender_geo, include_this_collection = False):
    """
        Recursively gathers the relevant collections and objects for export, starting from a root layer collection.
        "include_this_collection" should be false for the root collection, else restoring visibility will cause everything to become visible regardless of stored value.
    """

    if not layer_collection.is_visible:
        return

    # Add collection to set of all included collections
    if include_this_collection:
        layer_collection_set.add(layer_collection)

    # Add all of collection's objects when not hidden in an undesired way
    for obj in layer_collection.collection.objects:
        if not hidden_geo and obj.hide_viewport:
            continue

        if not hidden_geo and obj.hide_get():
            continue

        if not nonrender_geo and obj.hide_render:
            continue

        object_set.add(obj)

    # Recursively gather resources for child collections
    for collection in layer_collection.children:
        gather_collection_resources(collection, layer_collection_set, object_set, hidden_geo, nonrender_geo, True)

but I'm not sure if this hurts the workflow you intended or something since it basically only cares if the collection is visible or not.

jadshep commented 2 years ago

@General-101 Would something like this work?

def gather_collection_resources(layer_collection, layer_collection_set, object_set, hidden_geo, nonrender_geo, include_this_collection = False):
    """
        Recursively gathers the relevant collections and objects for export, starting from a root layer collection.
        "include_this_collection" should be false for the root collection, else restoring visibility will cause everything to become visible regardless of stored value.
    """

    # Don't include anything from collection if exclude
    if layer_collection.exclude:
        return

    # Don't include anything from collection if hidden in an undesired way
    if not hidden_geo and not layer_collection.is_visible:
        return

    if not nonrender_geo and layer_collection.collection.hide_render:
        return

    # Add collection to set of all included collections
    if include_this_collection:
        layer_collection_set.add(layer_collection)

    # Add all of collection's objects when not hidden in an undesired way
    for obj in layer_collection.collection.objects:
        if not hidden_geo and obj.hide_viewport:
            continue

        if not hidden_geo and obj.hide_get():
            continue

        if not nonrender_geo and obj.hide_render:
            continue

        object_set.add(obj)

    # Recursively gather resources for child collections
    for collection in layer_collection.children:
        gather_collection_resources(collection, layer_collection_set, object_set, hidden_geo, nonrender_geo, True)

This should filter collections the same way as objects with differentiation between visible/render.

General-101 commented 2 years ago

Aight yea that seems to do it. This should be solved now then.