예제 #1
0
 def process(self):
     obj = bpy.data.objects[self.object_ref]
     obj.data.update()
     Ve, We, Owe = self.inputs[:] + self.outputs[:]
     if not obj.vertex_groups:
         obj.vertex_groups.new(name="Sv_VGroup")
     if self.vertex_group not in obj.vertex_groups:
         return
     ovgs = obj.vertex_groups.get(self.vertex_group)
     Vi = [i.index for i in obj.data.vertices]
     if Ve.is_linked:
         verts = Ve.sv_get()[0]
     else:
         verts = Vi
     if We.is_linked:
         if self.clear:
             ovgs.add(Vi, self.fade_speed, "SUBTRACT")
         wei = We.sv_get()[0]
         verts, wei = second_as_first_cycle(verts, wei)
         for i, i2 in zip(verts, wei):
             ovgs.add([i], i2, "REPLACE")
     elif Owe.is_linked:
         out = []
         for i in verts:
             try:
                 out.append(ovgs.weight(i))
             except Exception:
                 out.append(0.0)
         Owe.sv_set([out])
예제 #2
0
 def process(self):
     objm = bpy.data.objects[self.object_ref].data
     objm.update()
     if not objm.vertex_colors:
         objm.vertex_colors.new(name='Sv_VColor')
     if self.vertex_color not in objm.vertex_colors:
         return
     ovgs = objm.vertex_colors.get(self.vertex_color)
     Ind, Col = self.inputs
     if Col.is_linked:
         sm, colors = self.mode, Col.sv_get()[0]
         idxs = Ind.sv_get()[0] if Ind.is_linked else [i.index for i in getattr(objm,sm)]
         idxs, colors = second_as_first_cycle(idxs, colors)
         bm = bmesh.new()
         bm.from_mesh(objm)
         if self.clear:
             for i in ovgs.data:
                 i.color = self.clear_c
         if sm == 'vertices':
             bv = bm.verts[:]
             for i, i2 in zip(idxs, colors):
                 for i in bv[i].link_loops:
                     ovgs.data[i.index].color = i2
         elif sm == 'polygons':
             bf = bm.faces[:]
             for i, i2 in zip(idxs, colors):
                 for i in bf[i].loops:
                     ovgs.data[i.index].color = i2
         bm.free()
예제 #3
0
 def process(self):
     Objs, Ve, We = self.inputs
     Owe = self.outputs[0]
     outobs = []
     for obj in self.inputs['Object'].sv_get():
         if not obj.vertex_groups:
             obj.vertex_groups.new(name=self.group_name)
         if self.group_name not in obj.vertex_groups:
             return
         ovgs = obj.vertex_groups.get(self.group_name)
         Vi = [i.index for i in obj.data.vertices]
         if Ve.is_linked:
             verts = Ve.sv_get()[0]
         else:
             verts = Vi
         if We.is_linked:
             if self.clear:
                 ovgs.add(Vi, self.fade_speed, "SUBTRACT")
             wei = second_as_first_cycle(verts, We.sv_get()[0])
             for i, i2 in zip(verts, wei):
                 ovgs.add([i], i2, "REPLACE")
         obj.data.update()
         if Owe.is_linked:
             out = []
             for i in verts:
                 try:
                     out.append(ovgs.weight(i))
                 except Exception:
                     out.append(0.0)  # ovgs.weight() error if vertex not in vgroup
             outobs.append(out)
     Owe.sv_set(outobs)
예제 #4
0
 def process(self):
     obj = bpy.data.objects[self.object_ref]
     obj.data.update()
     Ve, We, Owe = self.inputs[:] + self.outputs[:]
     if not obj.vertex_groups:
         obj.vertex_groups.new(name='Sv_VGroup')
     if self.vertex_group not in obj.vertex_groups:
         return
     ovgs = obj.vertex_groups.get(self.vertex_group)
     Vi = [i.index for i in obj.data.vertices]
     if Ve.is_linked:
         verts = Ve.sv_get()[0]
     else:
         verts = Vi
     if We.is_linked:
         if self.clear:
             ovgs.add(Vi, self.fade_speed, "SUBTRACT")
         wei = We.sv_get()[0]
         verts, wei = second_as_first_cycle(verts, wei)
         for i, i2 in zip(verts, wei):
             ovgs.add([i], i2, "REPLACE")
     elif Owe.is_linked:
         out = []
         for i in verts:
             try:
                 out.append(ovgs.weight(i))
             except Exception:
                 out.append(0.0)
         Owe.sv_set([out])
예제 #5
0
파일: weights.py 프로젝트: rfswarm/sverchok
    def process(self):
        obj = bpy.data.objects[self.object_ref]
        obj.data.update()
        if not obj.vertex_groups:
            obj.vertex_groups.new(name='Sv_VGroup')
        if self.vertex_group not in obj.vertex_groups:
            return
        ovgs = obj.vertex_groups.get(self.vertex_group)
        vind = [i.index for i in obj.data.vertices]
        if self.inputs['VertIND'].is_linked:
            verts = self.inputs['VertIND'].sv_get()[0]
        else:
            verts = vind

        if self.inputs['Weights'].is_linked:
            wei = self.inputs['Weights'].sv_get()[0]
            verts, wei = second_as_first_cycle(verts, wei)
            if self.clear:
                ovgs.add(vind, self.fade_speed, "SUBTRACT")
            g = 0
            while g != len(verts):
                ovgs.add([verts[g]], wei[g], "REPLACE")
                g = g+1

        elif self.outputs['OutWeights'].is_linked:
            out = []
            for i in verts:
                try:
                    out.append(ovgs.weight(i))
                except Exception:
                    out.append(0.0)
            self.outputs['OutWeights'].sv_set([out])
예제 #6
0
 def process(self):
     o, p, md = self.inputs
     S, P, N, I = self.outputs
     Out, point, sm1, sm2 = [], p.sv_get()[0], self.mode, self.mode2
     obj, max_dist = second_as_first_cycle(o.sv_get(), md.sv_get()[0])
     for i, i2 in zip(obj, max_dist):
         if sm1:
             Out.append([
                 i.closest_point_on_mesh(
                     i.matrix_local.inverted() * Vector(p), i2)
                 for p in point
             ])
         else:
             Out.append([i.closest_point_on_mesh(p, i2) for p in point])
     if P.is_linked:
         if sm2:
             out = []
             for i, i2 in zip(obj, Out):
                 out.append([(i.matrix_world * i3[1])[:] for i3 in i2])
             P.sv_set(out)
         else:
             P.sv_set([[i2[1][:] for i2 in o] for o in Out])
     if S.is_linked:
         S.sv_set([[i2[0] for i2 in o] for o in Out])
     if N.is_linked:
         N.sv_set([[i2[2][:] for i2 in o] for o in Out])
     if I.is_linked:
         I.sv_set([[i2[3] for i2 in o] for o in Out])
예제 #7
0
 def process(self):
     o,p,md = self.inputs
     S,P,N,I = self.outputs
     Out,point,sm1,sm2 = [],p.sv_get()[0],self.mode,self.mode2
     obj = o.sv_get()
     max_dist = second_as_first_cycle(obj, md.sv_get()[0])
     for i,i2 in zip(obj,max_dist):
         if sm1:
             Out.append([i.closest_point_on_mesh(i.matrix_local.inverted()*Vector(p), i2) for p in point])
         else:
             Out.append([i.closest_point_on_mesh(p, i2) for p in point])
     if P.is_linked:
         if sm2:
             out =[]
             for i,i2 in zip(obj,Out):
                 out.append([(i.matrix_world*i3[1])[:] for i3 in i2])
             P.sv_set(out)
         else:
             P.sv_set([[i2[1][:] for i2 in o] for o in Out])
     if S.is_linked:
         S.sv_set([[i2[0] for i2 in o] for o in Out])
     if N.is_linked:
         N.sv_set([[i2[2][:] for i2 in o] for o in Out])
     if I.is_linked:
         I.sv_set([[i2[3] for i2 in o] for o in Out])
예제 #8
0
 def process(self):
     Objs, Ve, We = self.inputs
     Owe = self.outputs[0]
     out = []
     for obj in self.inputs['Object'].sv_get():
         if not obj.vertex_groups:
             obj.vertex_groups.new(name=self.group_name)
         if self.group_name not in obj.vertex_groups:
             return
         ovgs = obj.vertex_groups.get(self.group_name)
         Vi = [i.index for i in obj.data.vertices]
         if Ve.is_linked:
             verts = Ve.sv_get()[0]
         else:
             verts = Vi
         if We.is_linked:
             if self.clear:
                 ovgs.add(Vi, self.fade_speed, "SUBTRACT")
             wei = We.sv_get()[0]
             verts, wei = second_as_first_cycle(verts, wei)
             for i, i2 in zip(verts, wei):
                 ovgs.add([i], i2, "REPLACE")
         obj.data.update()
         if Owe.is_linked:
             try:
                 out.append([ovgs.weight(i) for i in verts])
             except Exception:
                 out.append([0.0 for i in verts])
     Owe.sv_set(out)
예제 #9
0
 def process(self):
     objm = bpy.data.objects[self.object_ref].data
     objm.update()
     if not objm.vertex_colors:
         objm.vertex_colors.new(name='Sv_VColor')
     if self.vertex_color not in objm.vertex_colors:
         return
     ovgs = objm.vertex_colors.get(self.vertex_color)
     Ind, Col = self.inputs
     if Col.is_linked:
         sm, colors = self.mode, Col.sv_get()[0]
         idxs = Ind.sv_get()[0] if Ind.is_linked else [
             i.index for i in getattr(objm, sm)
         ]
         idxs, colors = second_as_first_cycle(idxs, colors)
         bm = bmesh.new()
         bm.from_mesh(objm)
         if self.clear:
             for i in ovgs.data:
                 i.color = self.clear_c
         if sm == 'vertices':
             bv = bm.verts[:]
             for i, i2 in zip(idxs, colors):
                 for i in bv[i].link_loops:
                     ovgs.data[i.index].color = i2
         elif sm == 'polygons':
             bf = bm.faces[:]
             for i, i2 in zip(idxs, colors):
                 for i in bf[i].loops:
                     ovgs.data[i.index].color = i2
         bm.free()
예제 #10
0
파일: weights.py 프로젝트: rfswarm/sverchok
    def process(self):
        obj = bpy.data.objects[self.object_ref]
        obj.data.update()
        if not obj.vertex_groups:
            obj.vertex_groups.new(name="Sv_VGroup")
        if self.vertex_group not in obj.vertex_groups:
            return
        ovgs = obj.vertex_groups.get(self.vertex_group)
        vind = [i.index for i in obj.data.vertices]
        if self.inputs["VertIND"].is_linked:
            verts = self.inputs["VertIND"].sv_get()[0]
        else:
            verts = vind

        if self.inputs["Weights"].is_linked:
            wei = self.inputs["Weights"].sv_get()[0]
            verts, wei = second_as_first_cycle(verts, wei)
            if self.clear:
                ovgs.add(vind, self.fade_speed, "SUBTRACT")
            g = 0
            while g != len(verts):
                ovgs.add([verts[g]], wei[g], "REPLACE")
                g = g + 1

        elif self.outputs["OutWeights"].is_linked:
            out = []
            for i in verts:
                try:
                    out.append(ovgs.weight(i))
                except Exception:
                    out.append(0.0)
            self.outputs["OutWeights"].sv_set([out])
예제 #11
0
 def process(self):
     objm = bpy.data.objects[self.object_ref].data
     objm.update()
     if not objm.vertex_colors:
         objm.vertex_colors.new(name='Sv_VColor')
     if self.vertex_color not in objm.vertex_colors:
         return
     ovgs = objm.vertex_colors.get(self.vertex_color)
     if self.inputs['Color'].is_linked:
         colors = self.inputs['Color'].sv_get()[0]
         bm = bmesh.new()
         bm.from_mesh(objm)
         if self.clear:
             for i in ovgs.data:
                 i.color = self.clear_c
         if self.mode == 'VERT':
             if self.inputs['Index'].is_linked:
                 idxs = self.inputs['Index'].sv_get()[0]
             else:
                 idxs = [i.index for i in objm.vertices]
             idxs, colors = second_as_first_cycle(idxs, colors)
             g = 0
             bm.verts.ensure_lookup_table()
             while g < len(idxs):
                 for i in bm.verts[idxs[g]].link_loops:
                     ovgs.data[i.index].color = colors[g]
                 g = g + 1
         elif self.mode == 'POLY':
             if self.inputs['Index'].is_linked:
                 idxs = self.inputs['Index'].sv_get()[0]
             else:
                 idxs = [i.index for i in objm.polygons]
             idxs, colors = second_as_first_cycle(idxs, colors)
             g = 0
             bm.faces.ensure_lookup_table()
             while g < len(idxs):
                 for i in bm.faces[idxs[g]].loops:
                     ovgs.data[i.index].color = colors[g]
                 g = g + 1
         bm.free()
예제 #12
0
파일: colors.py 프로젝트: Kosvor/sverchok
 def process(self):
     objm = bpy.data.objects[self.object_ref].data
     objm.update()
     if not objm.vertex_colors:
         objm.vertex_colors.new(name='Sv_VColor')
     if self.vertex_color not in objm.vertex_colors:
         return
     ovgs = objm.vertex_colors.get(self.vertex_color)
     if self.inputs['Color'].is_linked:
         colors = self.inputs['Color'].sv_get()[0]
         bm = bmesh.new()
         bm.from_mesh(objm)
         if self.clear:
             for i in ovgs.data:
                 i.color = self.clear_c
         if self.mode == 'VERT':
             if self.inputs['Index'].is_linked:
                 idxs = self.inputs['Index'].sv_get()[0]
             else:
                 idxs = [i.index for i in objm.vertices]
             idxs, colors = second_as_first_cycle(idxs, colors)
             g = 0
             bm.verts.ensure_lookup_table()
             while g < len(idxs):
                 for i in bm.verts[idxs[g]].link_loops:
                     ovgs.data[i.index].color = colors[g]
                 g = g+1
         elif self.mode == 'POLY':
             if self.inputs['Index'].is_linked:
                 idxs = self.inputs['Index'].sv_get()[0]
             else:
                 idxs = [i.index for i in objm.polygons]
             idxs, colors = second_as_first_cycle(idxs, colors)
             g = 0
             bm.faces.ensure_lookup_table()
             while g < len(idxs):
                 for i in bm.faces[idxs[g]].loops:
                     ovgs.data[i.index].color = colors[g]
                 g = g+1
         bm.free()
예제 #13
0
 def process(self):
     objs = self.inputs['Objects'].sv_get()
     if isinstance(objs[0], list):
         objs = objs[0]
     Prop = self.formula
     if self.inputs['values'].is_linked:
         v = self.inputs['values'].sv_get()
         if isinstance(v[0], list):
             v = v[0]
         objs, v = second_as_first_cycle(objs, v)
         exec("for i, i2 in zip(objs, v):\n    i."+Prop+"= i2")
     elif self.outputs['outvalues'].is_linked:
         self.outputs['outvalues'].sv_set(eval("[i."+Prop+" for i in objs]"))
     else:
         exec("for i in objs:\n    i."+Prop)
예제 #14
0
 def process(self):
     objs = self.inputs['Objects'].sv_get()
     if isinstance(objs[0], list):
         objs = objs[0]
     Prop = self.formula
     if self.inputs['values'].is_linked:
         v = self.inputs['values'].sv_get()
         if isinstance(v[0], list):
             v = v[0]
         objs, v = second_as_first_cycle(objs, v)
         exec("for i, i2 in zip(objs, v):\n    i." + Prop + "= i2")
     elif self.outputs['outvalues'].is_linked:
         self.outputs['outvalues'].sv_set(
             eval("[i." + Prop + " for i in objs]"))
     else:
         exec("for i in objs:\n    i." + Prop)
예제 #15
0
 def process(self):
     O, V = self.inputs
     Ov = self.outputs[0]
     objs = O.sv_get()
     if isinstance(objs[0], list):
         objs = objs[0]
     Prop = self.formula
     if V.is_linked:
         v = V.sv_get()
         if isinstance(v[0], list):
             v = v[0]
         objs, v = second_as_first_cycle(objs, v)
         exec("for i, i2 in zip(objs, v):\n    i." + Prop + "= i2")
     elif Ov.is_linked:
         Ov.sv_set(eval("[i." + Prop + " for i in objs]"))
     else:
         exec("for i in objs:\n    i." + Prop)
예제 #16
0
 def process(self):
     O, V = self.inputs
     Ov = self.outputs[0]
     objs = O.sv_get()
     if isinstance(objs[0], list):
         objs = objs[0]
     Prop = self.formula
     if V.is_linked:
         v = V.sv_get()
         if isinstance(v[0], list):
             v = v[0]
         objs, v = second_as_first_cycle(objs, v)
         exec("for i, i2 in zip(objs, v):\n    i."+Prop+"= i2")
     elif Ov.is_linked:
         Ov.sv_set(eval("[i."+Prop+" for i in objs]"))
     else:
         exec("for i in objs:\n    i."+Prop)
예제 #17
0
    def process(self):
        Location = []
        Normal = []
        Index = []
        point = self.inputs['point'].sv_get()[0]
        max_dist = self.inputs['max_dist'].sv_get()[0]
        obj = self.inputs['Objects'].sv_get()
        obj, max_dist = second_as_first_cycle(obj, max_dist)

        g = 0
        while g < len(obj):
            OB = obj[g]
            if self.mode:
                pnt = [OB.closest_point_on_mesh(OB.matrix_local.inverted()*Vector(p), max_dist[g]) for p in point]
            else:
                pnt = [OB.closest_point_on_mesh(p, max_dist[g]) for p in point]
            Location.append([(OB.matrix_world*i2[0])[:] for i2 in pnt])
            Normal.append([i2[1][:] for i2 in pnt])
            Index.append([i2[2] for i2 in pnt])
            g = g+1

        self.outputs['Point_on_mesh'].sv_set(Location)
        self.outputs['Normal_on_mesh'].sv_set(Normal)
        self.outputs['FaceINDEX'].sv_set(Index)
예제 #18
0
    def process(self):
        if self.use_foreach:
            self.process_foreach()
            return
        objm = bpy.data.objects[self.object_ref].data
        objm.update()
        if not objm.vertex_colors:
            objm.vertex_colors.new(name='Sv_VColor')
        if self.vertex_color not in objm.vertex_colors:
            return
        ovgs = objm.vertex_colors.get(self.vertex_color)
        Ind, Col = self.inputs
        if Col.is_linked:
            sm, colors = self.mode, Col.sv_get()[0]
            idxs = Ind.sv_get()[0] if Ind.is_linked else [i.index for i in getattr(objm,sm)]
            idxs, colors = second_as_first_cycle(idxs, colors)
            bm = bmesh.new()
            bm.from_mesh(objm)
            if self.clear:
                clear_c = self.clear_c[:]
                for i in range(len(ovgs.data)):
                    ovgs.data[i].color = clear_c
            if sm == 'vertices':
                bv = bm.verts
                bm.verts.ensure_lookup_table()
                for i, col in zip(idxs, colors):
                    for l in bv[i].link_loops:
                        ovgs.data[l.index].color = col
            elif sm == 'polygons':
                #bf = bm.faces[:]
                bm.faces.ensure_lookup_table()
                for i, i2 in zip(idxs, colors):
                    for loop in bm.faces[i].loops:
                        ovgs.data[loop.index].color = i2
            elif sm == 'loops':
                for idx, color in zip(idxs, colors):
                    ovgs.data[idx].color = color
            bm.free()
        if self.outputs["OutColor"].is_linked:
            out = []
            sm= self.mode
            bm = bmesh.new()
            bm.from_mesh(objm)
            if sm == 'vertices':
                #output one color per vertex
                for v in bm.verts[:]:
                    c = ovgs.data[v.link_loops[0].index].color
                    out.append(list(c))

            elif sm == 'polygons':
                #output one color per face
                for f in bm.faces[:]:
                    c = ovgs.data[f.loops[0].index].color
                    out.append(list(c))
            elif sm == 'loops':
                for i in range(len(ovgs.data)):
                    c = ovgs.data[i].color
                    out.append(c[:])

            self.outputs["OutColor"].sv_set([out])
            bm.free()
예제 #19
0
    def process(self):
        if self.use_foreach:
            self.process_foreach()
            return
        objm = bpy.data.objects[self.object_ref].data
        objm.update()
        if not objm.vertex_colors:
            objm.vertex_colors.new(name='Sv_VColor')
        if self.vertex_color not in objm.vertex_colors:
            return
        ovgs = objm.vertex_colors.get(self.vertex_color)
        Ind, Col = self.inputs
        if Col.is_linked:
            sm, colors = self.mode, Col.sv_get()[0]
            idxs = Ind.sv_get()[0] if Ind.is_linked else [
                i.index for i in getattr(objm, sm)
            ]
            colors = second_as_first_cycle(idxs, colors)
            bm = bmesh.new()
            bm.from_mesh(objm)
            if self.clear:
                clear_c = self.clear_c[:]
                for i in range(len(ovgs.data)):
                    ovgs.data[i].color = clear_c
            if sm == 'vertices':
                bv = bm.verts
                bm.verts.ensure_lookup_table()
                for i, col in zip(idxs, colors):
                    for l in bv[i].link_loops:
                        ovgs.data[l.index].color = col
            elif sm == 'polygons':
                #bf = bm.faces[:]
                bm.faces.ensure_lookup_table()
                for i, i2 in zip(idxs, colors):
                    for loop in bm.faces[i].loops:
                        ovgs.data[loop.index].color = i2
            elif sm == 'loops':
                for idx, color in zip(idxs, colors):
                    ovgs.data[idx].color = color
            bm.free()
        if self.outputs["OutColor"].is_linked:
            out = []
            sm = self.mode
            bm = bmesh.new()
            bm.from_mesh(objm)
            if sm == 'vertices':
                #output one color per vertex
                for v in bm.verts[:]:
                    c = ovgs.data[v.link_loops[0].index].color
                    out.append(list(c))

            elif sm == 'polygons':
                #output one color per face
                for f in bm.faces[:]:
                    c = ovgs.data[f.loops[0].index].color
                    out.append(list(c))
            elif sm == 'loops':
                for i in range(len(ovgs.data)):
                    c = ovgs.data[i].color
                    out.append(c[:])

            self.outputs["OutColor"].sv_set([out])
            bm.free()