예제 #1
0
파일: Set.py 프로젝트: Irmitya/zpy
def in_scene(context, object, value=True):
    # TODO: set this function to be able to remove an object from scene
    #       currently it ONLY uses the value for set at True

    if value:
        if Is.collection(object):
            scn = context.scene
            if not Get.collection_from_scene(object, scn.collection):
                scn.collection.children.link(object)
        elif not (Is.in_scene(context, object)
                  and Is.in_view(context, object)):
            Get.objects(context, link=True).link(object)
예제 #2
0
    def convert(self, context, obj):
        scn = context.scene
        Set.active_select(context, obj, isolate=True)

        coll_instanced = False  # Whether or not to instance collection in full macro

        head = self.head
        group = obj.name + '-Mannequin'

        coll = bpy.data.collections.get(group)
        if coll:
            # Regenerating mannequin
            coll_instanced = True

            for ob in coll.objects.values():
                if Is.mesh(ob) and ob.DazMannequin:
                    bpy.data.objects.remove(ob)
        else:
            coll = bpy.data.collections.new(group)
            scn.collection.children.link(coll)

        # "temporarily" unhide collection if hidden
        in_view = Is.in_view(context, coll)
        if not in_view:
            Set.visible(context, coll, view_layer=True)
        visible = Is.visible(context, coll)
        if not visible:
            Set.visible(context, coll)

        # Add mannequin objects for current mesh
        self.generate(context, obj, obj.parent, coll)

        if self.macro:
            has_mann = False
            for ob in coll.objects.values():
                if Is.mesh(ob):
                    Set.select(ob)
                    has_mann = True

            if has_mann:
                bpy.ops.object.data_transfer_mannequin_preset()
                # if obj.data.materials:
                # bpy.ops.object.data_transfer_materials()

            # Hide the collection and create an instancer of it
            # if coll:
            # # Set.visible(context, obj, value=False)
            # Set.visible(context, coll, value=False, view_layer=True)
            # if not coll_instanced:
            # inst = New.object(context, name=coll.name)
            # inst.instance_type = 'COLLECTION'
            # inst.instance_collection = coll
            # Set.empty_size(inst, 0)
            # return inst

            for ob in coll.objects.values():
                Set.select(ob, value=False)

        if not visible:
            Set.visible(context, coll, False)
        if not in_view:
            Set.visible(context, coll, False, view_layer=True)

        return obj