from .node_container_common import * from bpy.types import Node from .base_definitions import MantisNode def TellClasses(): return [ # Primitives CirclePrimitive, ] #*#-------------------------------#++#-------------------------------#*# # P R I M I T I V E S #*#-------------------------------#++#-------------------------------#*# class CirclePrimitive: '''A node representing float input''' def __init__(self, signature, base_tree): self.base_tree=base_tree self.executed = False self.signature = signature self.inputs = { "Name" : NodeSocket(is_input = True, name = "Name", node = self), "Radius" : NodeSocket(is_input = True, name = "Radius", node = self), "Number of Points" : NodeSocket(is_input = True, name = "Number of Points", node = self), } self.outputs = { "Circle" : NodeSocket(is_input = False, name = "Circle", node=self), } self.parameters = { "Name":None, "Radius":None, "Number of Points":None, "Circle":None, } self.node_type = "UTILITY" def evaluate_input(self, input_name): return evaluate_input(self, input_name) def bGetObject(self): from bpy import data # first try Curve, then try Mesh bObject = data.curves.get(self.evaluate_input("Name")) if not bObject: bObject = data.meshes.get(self.evaluate_input("Name")) return bObject def bExecute(self, bContext = None,): # Get the datablock data = self.bGetObject() import bpy if not data: data = bpy.data.meshes.new( self.evaluate_input("Name") ) # make the circle import bmesh; bm = bmesh.new() bmesh.ops.create_circle( # lazy but easy bm, cap_ends=False, radius=max(self.evaluate_input("Radius"), 0.0001), segments=min( max( self.evaluate_input("Number of Points"), 3), 1024), ) # this is rotated 90 degrees, we need Y-up instead of Z-up from mathutils import Matrix from math import pi for v in bm.verts: v.co = Matrix.Rotation(pi/2, 4, 'X') @ v.co # done with this, push it to the data and free the bmesh. bm.to_mesh(data); bm.free() def __repr__(self): return self.signature.__repr__() def fill_parameters(self): fill_parameters(self)