Browse Source

Add Lattice Primitive

Note: while this is enough to get us off the ground with
a lattice deformer, we still need to update it a bit...
 - Live Updates aren't working yet but they should
 - i want to be able to use Integers or at least Drivers on the
     interpolation type, since it is very relevant for rigging
 - this is obviously useless without the Deformer
 - attaching this to an xForm works, but deforms probably
     dont work with that xForm
Joseph Brandenburg 4 months ago
parent
commit
2275e735ab
5 changed files with 106 additions and 2 deletions
  1. 1 0
      __init__.py
  2. 30 1
      primitives_containers.py
  3. 16 1
      primitives_definitions.py
  4. 27 0
      primitives_sockets.py
  5. 32 0
      socket_definitions.py

+ 1 - 0
__init__.py

@@ -120,6 +120,7 @@ driver_category = [
     ]
 geometry_category = [
         NodeItem("GeometryCirclePrimitive"),
+        NodeItem("GeometryLattice"),
     ]
 utility_category = [
         NodeItem("MathStaticInt"),

+ 30 - 1
primitives_containers.py

@@ -5,6 +5,7 @@ def TellClasses():
     return [
              # Primitives
              CirclePrimitive,
+             GeometryLattice,
             ]
 
 #*#-------------------------------#++#-------------------------------#*#
@@ -22,7 +23,6 @@ class PrimitiveNode(MantisNode):
         super().reset_execution()
         self.prepared=True
 
-
 class CirclePrimitive(PrimitiveNode):
     '''A node representing a Circle Primitive mesh'''
 
@@ -71,3 +71,32 @@ class CirclePrimitive(PrimitiveNode):
         # done with this, push it to the data and free the bmesh.
         bm.to_mesh(data); bm.free()
         self.executed = True
+
+from .primitives_sockets import LatticeSockets
+class GeometryLattice(PrimitiveNode):
+    '''A node representing a Circle Primitive mesh'''
+
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree, LatticeSockets)
+        self.init_parameters(additional_parameters= {})
+        self.prepared = False
+
+    def reset_execution(self):
+        super().reset_execution()
+        self.prepared=False
+        self.executed=False
+
+    def bGetObject(self):
+        from bpy import data
+        bObject = data.lattices.get(self.evaluate_input("Name"))
+        return bObject
+        
+    def bPrepare(self, bContext = None,):
+        # Get the datablock
+        data = self.bGetObject()
+        import bpy
+        if not data:
+            data = bpy.data.lattices.new( self.evaluate_input("Name") )
+        props_sockets = self.gen_property_socket_map()
+        evaluate_sockets(self, data, props_sockets)
+        self.prepared = True; self.executed = True

+ 16 - 1
primitives_definitions.py

@@ -1,10 +1,11 @@
 import bpy
-from bpy.types import NodeTree, Node, NodeSocket
+from bpy.types import Node
 from .base_definitions import MantisUINode
 
 def TellClasses():
     return [
              GeometryCirclePrimitive,
+             GeometryLattice,
            ]
 
 def default_traverse(self,socket):
@@ -26,6 +27,20 @@ class GeometryCirclePrimitive(Node, MantisUINode):
         self.outputs.new('GeometrySocket', "Circle")
         self.initialized = True
 
+from .primitives_sockets import LatticeSockets
+class GeometryLattice(Node, MantisUINode):
+    '''A node representing a lattice geometry'''
+    bl_idname = "GeometryLattice"
+    bl_label = "Lattice"
+    bl_icon = "NODE"
+    initialized : bpy.props.BoolProperty(default = False)
+    mantis_node_class_name=bl_idname
+    
+    def init(self, context):
+        self.init_sockets(LatticeSockets)
+        self.initialized = True
+
+
 for cls in TellClasses():
     cls.mantis_node_library='.primitives_containers'
     cls.set_mantis_class()

+ 27 - 0
primitives_sockets.py

@@ -0,0 +1,27 @@
+from .base_definitions import MantisSocketTemplate as SockTemplate
+from dataclasses import replace
+
+
+LatticeSockets = [
+    Name := SockTemplate(name="Name", blender_property="name", default_value='Lattice',
+            is_input=True, bl_idname="StringSocket"),
+    ResolutionU := SockTemplate(name = "Resolution U", bl_idname="UnsignedIntSocket",
+            blender_property="points_u", is_input=True, default_value=2),
+    ResolutionV := SockTemplate(name = "Resolution V", bl_idname="UnsignedIntSocket",
+            blender_property="points_v", is_input=True, default_value=2),
+    ResolutionW := SockTemplate(name = "Resolution W", bl_idname="UnsignedIntSocket",
+            blender_property="points_w", is_input=True, default_value=2),
+    InterpolationTypeU := SockTemplate(name = "Interpolation Type U",
+            bl_idname="EnumLatticeInterpolationTypeSocket",
+            blender_property="interpolation_type_u",
+            is_input=True, default_value='KEY_BSPLINE'),
+    InterpolationTypeV := SockTemplate(name = "Interpolation Type V",
+            bl_idname="EnumLatticeInterpolationTypeSocket",
+            blender_property="interpolation_type_v",
+            is_input=True, default_value='KEY_BSPLINE'),
+    InterpolationTypeW := SockTemplate(name = "Interpolation Type W",
+            bl_idname="EnumLatticeInterpolationTypeSocket",
+            blender_property="interpolation_type_w",
+            is_input=True, default_value='KEY_BSPLINE'),
+    GeometryOutput := SockTemplate(name="Lattice Geometry", bl_idname="GeometrySocket")
+]

+ 32 - 0
socket_definitions.py

@@ -189,6 +189,7 @@ def TellClasses() -> List[MantisSocket]:
              KeyframeSocket,
              EnumKeyframeInterpolationTypeSocket,
              EnumKeyframeBezierHandleTypeSocket,
+             EnumLatticeInterpolationTypeSocket,
              eFCrvExtrapolationMode,
              
              # Math
@@ -2302,6 +2303,37 @@ class eFCrvExtrapolationMode(MantisSocket):
         return self.color_simple
 
 
+EnumLatticeInterpolationType = (('KEY_LINEAR',   'Linear', 'Linear Interpolation.'),
+                                ('KEY_CARDINAL', "Cardinal", "Cardinal Interpolation."),
+                                ('KEY_CATMULL_ROM', "Catmull Rom", "Catmull Rom Interpolation."),
+                                ('KEY_BSPLINE', "B-Spline", "B Spline Interpolation."),)
+
+
+class EnumLatticeInterpolationTypeSocket(MantisSocket):
+    '''Lattice Interpolation Type'''
+    bl_idname = 'EnumLatticeInterpolationTypeSocket'
+    bl_label = "Lattice Interpolation Type"
+    
+    default_value :bpy.props.EnumProperty(
+        name="",
+        description="Interpolation Type",
+        items=EnumLatticeInterpolationType,
+        default='KEY_BSPLINE',
+        update = update_socket,)
+    
+    color_simple = cString
+    color : bpy.props.FloatVectorProperty(default=cString, size=4)
+    input : bpy.props.BoolProperty(default =False, update = update_socket)
+    def draw(self, context, layout, node, text):
+        ChooseDraw(self, context, layout, node, text)
+    def draw_color(self, context, node):
+        return self.color
+    @classmethod
+    def draw_color_simple(self):
+        return self.color_simple
+
+
+
 enumFloatOperations = (('ADD', 'Add', 'Add'),
                       ('SUBTRACT', "Subtract", "Subtract"),
                       ('MULTIPLY', "Multiply", "Multiply"),