Extensions:2.4/Py/Nodes/Cookbook/Vector

提供: wiki
移動先: 案内検索

Back to index

Ideas

  • Add your idea here.

Recipes

Invert Vector

This script inverts the given vector.

from Blender import Node

class InvertVectorNode(Node.Scripted):
    def __init__(self, sockets):
        sockets.input = [Node.Socket('Vector', val = 3*[1.0])]
        sockets.output = [Node.Socket('Vector', val = 3*[1.0])]

    def __call__(self):
        self.output.Vector = map(lambda x: -x, self.input.Vector)

__node__ = InvertVectorNode

Merge Vector

Merges 3 values into a vector.

from Blender import Node

class MergeVector(Node.Scripted):
	def __init__(self, sockets):
		vec = Node.Socket('Vector', val = [1.0, 1.0, 1.0])
		valx = Node.Socket('X', val=1.0, min=-10e6, max=10e6)
		valy = Node.Socket('Y', val=1.0, min=-10e6, max=10e6)
		valz = Node.Socket('Z', val=1.0, min=-10e6, max=10e6)
		
		sockets.output = [vec]
		sockets.input = [valx, valy, valz]
		
	def __call__(self):
		ovec = [0.0, 0.0, 0.0]
		
		ovec[0] = self.input.X
		ovec[1] = self.input.Y
		ovec[2] = self.input.Z
		
		self.output.Vector = ovec
		
__node__ = MergeVector

Quantizes Vector

Quantizes a vector by a value.

from Blender import Node

class QuantizeVector(Node.Scripted):
	def __init__(self, sockets):
		vec = Node.Socket('Vector', val = [1.0, 1.0, 1.0])
		val = Node.Socket('Quantize', val=1.0, min=0.001, max=100.0)
		sockets.input = [vec, val]
		sockets.output = [vec]
		
	def __call__(self):
		ovec = list(self.input.Vector)
		oqval = self.input.Quantize
		ovec[0] = ((ovec[0]/oqval)-(ovec[0]%oqval))*oqval
		ovec[1] = ((ovec[1]/oqval)-(ovec[1]%oqval))*oqval
		ovec[2] = ((ovec[2]/oqval)-(ovec[2]%oqval))*oqval
		self.output.Vector = ovec
		
__node__ = QuantizeVector

Scale Vector

Multiplies a vector by a value.

from Blender import Node

class ScaleVector(Node.Scripted):
	def __init__(self, sockets):
		vec = Node.Socket('Vector', val = [1.0, 1.0, 1.0])
		val = Node.Socket('Value', val=1.0, min=-10e6, max=10e6)
		sockets.input = [vec, val]
		sockets.output = [vec]
		
	def __call__(self):
		ovec = list(self.input.Vector)
		oval = self.input.Value
		ovec[0] *= oval
		ovec[1] *= oval
		ovec[2] *= oval
		self.output.Vector = ovec
		
__node__ = ScaleVector

Split Vector

Splits a vector into 3 values

from Blender import Node

class SplitVector(Node.Scripted):
	def __init__(self, sockets):
		vec = Node.Socket('Vector', val = [1.0, 1.0, 1.0])
		valx = Node.Socket('X', val=1.0, min=-10e6, max=10e6)
		valy = Node.Socket('Y', val=1.0, min=-10e6, max=10e6)
		valz = Node.Socket('Z', val=1.0, min=-10e6, max=10e6)
		sockets.input = [vec]
		sockets.output = [valx, valy, valz]
		
	def __call__(self):
		ovec = list(self.input.Vector)
		self.output.X = ovec[0]
		self.output.Y = ovec[1]
		self.output.Z = ovec[2]
		
__node__ = SplitVector

Vector to RGB

This script converts given vector to RGB.

from Blender import Node

class VectorToRGBNode(Node.Scripted):
    def __init__(self, sockets):
        sockets.input = [Node.Socket('Vector', val = 3*[1.0])]
        sockets.output = [Node.Socket('Color', val = 4*[1.0])]

    def __call__(self):
        self.output.Color = list(self.input.Vector) + [1.0]

__node__ = VectorToRGBNode