Skip to content

Commit

Permalink
Merge pull request #4807 from nortikin/curvature_comb
Browse files Browse the repository at this point in the history
Viewer Draw Curve node: Curvature comb
  • Loading branch information
portnov authored Dec 10, 2022
2 parents f745673 + 5353f0e commit 1688dc0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
16 changes: 15 additions & 1 deletion docs/nodes/viz/viewer_draw_curve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ The parameters of the node are (in this order):
.. image:: https://user-images.githubusercontent.com/14288520/190176111-16a43da1-2fd4-4b1c-bf74-78712bcd6a3f.png
:target: https://user-images.githubusercontent.com/14288520/190176111-16a43da1-2fd4-4b1c-bf74-78712bcd6a3f.png

-------------

* **Display Curvature Comb**, **Comb Color**, **Comb Line Width**. Control
display of curve's curvature comb. Curvature comb is not shown by default.
* **Scale**. This parameter is available only when **Display Curvature Comb**
parameter is enabled. This defines the scaling applied to curve normals used
to display the curvature comb. The default value of 1.0 means that normals
length will be equal to curve's curvature in corresponding points.

Operators
---------

Expand All @@ -102,6 +111,11 @@ Example of Usage
.. image:: https://user-images.githubusercontent.com/14288520/190133906-61748350-414f-4d3e-8e71-2bd6be30597c.png
:target: https://user-images.githubusercontent.com/14288520/190133906-61748350-414f-4d3e-8e71-2bd6be30597c.png

Example of curvature comb display:

.. image:: https://user-images.githubusercontent.com/284644/206860681-a70d93af-a72b-4dcb-bf36-3678135b835a.png
:target: https://user-images.githubusercontent.com/284644/206860681-a70d93af-a72b-4dcb-bf36-3678135b835a.png

* Generator-> :doc:`Line </nodes/generator/line_mk4>`
* Transform-> :doc:`Randomize </nodes/transforms/randomize>`
* Curves->NURBS-> :doc:`Approximate NURBS Curve </nodes/curve/approximate_nurbs_curve>`
* Curves->NURBS-> :doc:`Approximate NURBS Curve </nodes/curve/approximate_nurbs_curve>`
33 changes: 32 additions & 1 deletion nodes/viz/viewer_draw_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import bpy
from mathutils import Matrix, Vector
from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty, FloatVectorProperty
from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty, FloatVectorProperty, FloatProperty
import bgl
import gpu
from gpu_extras.batch import batch_for_shader
Expand Down Expand Up @@ -57,6 +57,9 @@ def draw_curves(context, args):
if node.draw_nodes and item.node_points is not None:
draw_points(v_shader, item.node_points, node.nodes_size, node.nodes_color)

if node.draw_comb and item.comb_edges is not None:
draw_edges(e_shader, item.comb_points, item.comb_edges, node.comb_width, node.comb_color)

if node.draw_verts:
draw_points(v_shader, item.points, node.verts_size, node.verts_color)

Expand Down Expand Up @@ -170,6 +173,26 @@ class SvCurveViewerDrawNode(SverchCustomTreeNode, bpy.types.Node):
min = 1, default = 3,
update = updateNode)

draw_comb: BoolProperty(
update=updateNode, name='Display curvature comb', default=False)

comb_color: FloatVectorProperty(
name = "Comb Color",
default = (1.0, 0.9, 0.1, 0.5),
size = 4, min = 0.0, max = 1.0,
subtype = 'COLOR',
update = updateNode)

comb_width : IntProperty(
name = "Comb Line Width",
min = 1, default = 1,
update = updateNode)

comb_scale : FloatProperty(
name = "Comb Scale",
min = 0.0, default = 1.0,
update = updateNode)

def draw_buttons(self, context, layout):
layout.prop(self, "activate", icon="HIDE_" + ("OFF" if self.activate else "ON"))

Expand Down Expand Up @@ -200,6 +223,14 @@ def draw_buttons(self, context, layout):
row.prop(self, 'nodes_color', text="")
row.prop(self, 'nodes_size', text="px")

row = grid.row(align=True)
row.prop(self, 'draw_comb', text="", icon='EVENT_C')
row.prop(self, 'comb_color', text="")
row.prop(self, 'comb_width', text="px")

if self.draw_comb:
grid.prop(self, 'comb_scale', text='Scale')

row = layout.row(align=True)
row.scale_y = 4.0 if self.prefs_over_sized_buttons else 1
self.wrapper_tracked_ui_draw_op(row, SvBakeCurveOp.bl_idname, icon='OUTLINER_OB_MESH', text="B A K E")
Expand Down
18 changes: 16 additions & 2 deletions utils/curve/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def __init__(self, node, curve, resolution):
self.curve = curve
self.resolution = resolution

if node.draw_line or node.draw_verts:
if node.draw_line or node.draw_verts or node.draw_comb:
t_min, t_max = curve.get_u_bounds()
ts = np.linspace(t_min, t_max, num=resolution)
n = len(ts)
self.points = curve.evaluate_array(ts).tolist()

if node.draw_line:
n = len(ts)
self.edges = [(i,i+1) for i in range(n-1)]

if (node.draw_control_polygon or node.draw_control_points) and hasattr(curve, 'get_control_points'):
Expand All @@ -53,6 +53,20 @@ def __init__(self, node, curve, resolution):
else:
self.node_points = None

if node.draw_comb:
n = len(self.points)
normals = curve.main_normal_array(ts, normalize=True)
curvatures = curve.curvature_array(ts)[np.newaxis].T
comb_normals = node.comb_scale * curvatures * normals
comb_points = self.points - comb_normals
self.comb_points = np.concatenate((self.points, comb_points)).tolist()
comb_normal_edges = [(i, i+n) for i in range(n-1)]
comb_tangent_edges = [(i, i+1) for i in range(n, 2*n-1)]
self.comb_edges = comb_normal_edges + comb_tangent_edges
else:
self.comb_points = None
self.comb_edges = None

def bake(self, object_name):
me = bpy.data.meshes.new(object_name)
me.from_pydata(self.points, self.edges, [])
Expand Down
1 change: 1 addition & 0 deletions utils/surface/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(self):
self.draw_control_polygon = False
self.draw_control_points = False
self.draw_nodes = False
self.draw_comb = False

def __init__(self, node, surface, resolution_u, resolution_v):
self.node = node
Expand Down

0 comments on commit 1688dc0

Please sign in to comment.