Exemplo n.º 1
0
    def handle_attr_socket(self):
        """
        this socket expects input dictionary wrapped. once.

            [  {attr: attr_vale, attr2: attr2_value } ]

        """

        if self.node_ui_show_attrs_socket and not self.inputs[
                'attrs'].hide and self.inputs['attrs'].is_linked:
            socket_acquired_attrs = self.inputs['attrs'].sv_get(
                default=[{
                    'activate': False
                }])

            if socket_acquired_attrs:
                try:
                    with hard_freeze(self) as node:
                        for k, new_value in socket_acquired_attrs[0].items():
                            print(f"setattr(node, {k}, {new_value})")
                            setattr(node, k, new_value)
                except Exception as err:
                    print('error inside socket_acquired_attrs: ', err)
                    self.id_data.unfreeze(
                        hard=True)  # ensure this thing is unfrozen
Exemplo n.º 2
0
    def process(self):

        if not self.object_names:
            return

        scene = bpy.context.scene
        data_objects = bpy.data.objects
        outputs = self.outputs

        edgs_out = []
        vers_out = []
        vers_out_grouped = []
        pols_out = []
        mtrx_out = []

        # iterate through references
        for obj in (data_objects.get(o.name) for o in self.object_names):

            edgs = []
            vers = []
            vers_grouped = []
            pols = []
            mtrx = []

            with hard_freeze(self) as _:

                mtrx = [list(m) for m in obj.matrix_world]
                if obj.type == 'EMPTY':
                    mtrx_out.append(mtrx)
                    continue
                try:
                    if obj.mode == 'EDIT' and obj.type == 'MESH':
                        # Mesh objects do not currently return what you see
                        # from 3dview while in edit mode when using obj.to_mesh.
                        me = obj.data
                        bm = bmesh.from_edit_mesh(me)
                        vers, edgs, pols = pydata_from_bmesh(bm)
                        del bm
                    else:
                        obj_data = obj.to_mesh(scene, self.modifiers,
                                               'PREVIEW')
                        if obj_data.polygons:
                            pols = [
                                list(p.vertices) for p in obj_data.polygons
                            ]
                        vers, vers_grouped = self.get_verts_and_vertgroups(
                            obj_data)
                        edgs = obj_data.edge_keys
                        bpy.data.meshes.remove(obj_data, do_unlink=True)
                except:
                    print('failure in process between frozen area', self.name)

            vers_out.append(vers)
            edgs_out.append(edgs)
            pols_out.append(pols)
            mtrx_out.append(mtrx)
            vers_out_grouped.append(vers_grouped)

        if vers_out and vers_out[0]:
            outputs['Vertices'].sv_set(vers_out)
            outputs['Edges'].sv_set(edgs_out)
            outputs['Polygons'].sv_set(pols_out)

            if 'Vers_grouped' in outputs and self.vergroups:
                outputs['Vers_grouped'].sv_set(vers_out_grouped)

        outputs['Matrixes'].sv_set(mtrx_out)
        outputs['Object'].sv_set(
            [data_objects.get(o.name) for o in self.object_names])
Exemplo n.º 3
0
    def process(self):

        if not self.object_names:
            return

        scene = bpy.context.scene
        data_objects = bpy.data.objects
        outputs = self.outputs

        edgs_out = []
        vers_out = []
        vers_out_grouped = []
        pols_out = []
        mtrx_out = []

        # iterate through references
        for obj in (data_objects.get(o.name) for o in self.object_names):

            edgs = []
            vers = []
            vers_grouped = []
            pols = []
            mtrx = []

            with hard_freeze(self) as _:

                mtrx = [list(m) for m in obj.matrix_world]
                if obj.type == "EMPTY":
                    mtrx_out.append(mtrx)
                    continue
                try:
                    if obj.mode == "EDIT" and obj.type == "MESH":
                        # Mesh objects do not currently return what you see
                        # from 3dview while in edit mode when using obj.to_mesh.
                        me = obj.data
                        bm = bmesh.from_edit_mesh(me)
                        vers, edgs, pols = pydata_from_bmesh(bm)
                        del bm
                    else:
                        obj_data = obj.to_mesh(scene, self.modifiers, "PREVIEW")
                        if obj_data.polygons:
                            pols = [list(p.vertices) for p in obj_data.polygons]
                        vers, vers_grouped = self.get_verts_and_vertgroups(obj_data)
                        edgs = obj_data.edge_keys
                        bpy.data.meshes.remove(obj_data, do_unlink=True)
                except:
                    print("failure in process between frozen area", self.name)

            vers_out.append(vers)
            edgs_out.append(edgs)
            pols_out.append(pols)
            mtrx_out.append(mtrx)
            vers_out_grouped.append(vers_grouped)

        if vers_out and vers_out[0]:
            outputs["Vertices"].sv_set(vers_out)
            outputs["Edges"].sv_set(edgs_out)
            outputs["Polygons"].sv_set(pols_out)

            if "Vers_grouped" in outputs and self.vergroups:
                outputs["Vers_grouped"].sv_set(vers_out_grouped)

        outputs["Matrixes"].sv_set(mtrx_out)
        outputs["Object"].sv_set([data_objects.get(o.name) for o in self.object_names])