-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4878 from rendetto/solid_section_node
Introducing "Solid Section" node
- Loading branch information
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Solid Section | ||
============= | ||
|
||
.. image:: https://user-images.githubusercontent.com/66558924/212058287-c0426edb-7f56-425d-8e7c-cc99ff8700c7.jpg | ||
|
||
Dependencies | ||
------------ | ||
|
||
This node requires `FreeCAD library <https://nortikin.github.io/sverchok/docs/data_structure/solids.html>`_ to work. | ||
|
||
|
||
Functionality | ||
------------- | ||
|
||
This node generates the intersection Curves and Points between different Shapes including Solids, Solid Faces, Solid Edges, NURBS Surfaces and NURBS Curves. | ||
|
||
The node can operate on pair of objects ("Shape A" intersects "Shape B") or on pair of lists of objects. | ||
|
||
Inputs | ||
------ | ||
|
||
This node has the following inputs: | ||
|
||
* **Shape A**. The first object to perform operation on. This input is | ||
mandatory and can accept a list of Shapes*. | ||
* **Shape B**. The second object to perform operation on. This input is | ||
mandatory and can accept a list of Shapes*. | ||
|
||
Curves (NURBS Curves and Solid Edges) cannot be mixed with other Shape types. | ||
For example [<NURBS_Curve>, <Solid_Edge>, <Solid>] is not a valid input list. | ||
|
||
Valid inputs are [<NURBS_Curve1>, <NURBS_Curve2>, <Solid_Edge>] or [<NURBS_Curve>, <Solid_Edge>] | ||
or [<NURBS_Surface1>, <Solid>, <NURBS_Surface2>] etc. | ||
|
||
Options | ||
------- | ||
|
||
This node has the following parameters: | ||
|
||
* **NURBS Output**. This parameter is available in the N panel only. If | ||
checked, the node will generate curves in NURBS representation. Otherwise, it | ||
will generate standard FreeCAD curves (Solid Edge curves). Unchecked by default. | ||
|
||
Outputs | ||
------- | ||
|
||
This node has the following outputs: | ||
|
||
* **Vertices**. The resulting intersection (puncture) Points or endpoints of the intersection Curves. | ||
* **Curves**. The resulting intersection Curves. | ||
|
||
Product variations of the Section operation: | ||
|
||
* Solid × Curve → Point (common case) or Curve (if the curve or part of the curve overlays with the solid) | ||
|
||
* Solid × Surface → Curve (common case) or Point (when both are only touching) | ||
|
||
* Curve × Surface → Point (common case) or Curve (if the curve or part of the curve overlays with the surface) | ||
|
||
* Solid × Solid → Curve (common case) or Point (when both are only touching) | ||
|
||
* Surface × Surface → Curve (common case) or Point (when both are only touching) | ||
|
||
* Curve × Curve → Point (common case) or Curve (if curves overlay at a certain segment) | ||
|
||
|
||
If no intersections are found the node will output empty lists. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
**Curve** × **Curve** → **Points**: | ||
|
||
.. image:: https://user-images.githubusercontent.com/66558924/212648237-1f4f052f-1a61-496c-a0db-27eebb8c9524.jpg | ||
|
||
|
||
|
||
**Curves** × **Surface** → **Points and Curve**: | ||
|
||
.. image:: https://user-images.githubusercontent.com/66558924/212650377-26c0af14-1b6d-4039-b655-7719ae4dee03.jpg | ||
|
||
|
||
**Surface** × **List of Surfaces** → **Curves**: | ||
|
||
.. image:: https://user-images.githubusercontent.com/66558924/212664158-65bc2f04-0376-4b8a-bbbf-05812fc4e76e.jpg | ||
|
||
|
||
**Surface** × **Solid** → **Curves**: | ||
|
||
.. image:: https://user-images.githubusercontent.com/66558924/212653198-d616f3ad-d533-4409-a2bf-2e65213f6939.jpg | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# This file is part of project Sverchok. It's copyrighted by the contributors | ||
# recorded in the version control history of the file, available from | ||
# its original location https://github.com/nortikin/sverchok/commit/master | ||
# | ||
# SPDX-License-Identifier: GPL3 | ||
# License-Filename: LICENSE | ||
|
||
import bpy | ||
from bpy.props import BoolProperty | ||
|
||
from sverchok.node_tree import SverchCustomTreeNode | ||
from sverchok.data_structure import (updateNode, map_recursive, zip_long_repeat, | ||
ensure_nesting_level, get_data_nesting_level) | ||
from sverchok.utils.curve.freecad import SvSolidEdgeCurve | ||
from sverchok.dependencies import FreeCAD | ||
|
||
if FreeCAD is not None: | ||
import Part | ||
|
||
class SvSolidSectionNode(SverchCustomTreeNode, bpy.types.Node): | ||
""" | ||
Triggers: Section | ||
Tooltip: Generate Intersection Curves and Points | ||
""" | ||
bl_idname = 'SvSolidSectionNode' | ||
bl_label = 'Solid Section' | ||
bl_icon = 'OUTLINER_OB_EMPTY' | ||
sv_icon = 'SV_SOLID_SECTION' | ||
sv_category = "Solid Operators" | ||
sv_dependencies = {'FreeCAD'} | ||
|
||
nurbs_output : BoolProperty( | ||
name = "NURBS Output", | ||
description = "Output curves in NURBS representation", | ||
default = False, | ||
update=updateNode) | ||
|
||
def draw_buttons_ext(self, context, layout): | ||
self.draw_buttons(context, layout) | ||
layout.prop(self, 'nurbs_output', toggle=True) | ||
|
||
def sv_init(self, context): | ||
self.inputs.new('SvSolidSocket', "Shape A") | ||
#"Shape" is a generic term covering all different topological types defined by Open CASCADE Technology (OCCT) | ||
self.inputs.new('SvSolidSocket', "Shape B") | ||
|
||
self.outputs.new('SvVerticesSocket', "Vertices") | ||
self.outputs.new('SvCurveSocket', "Curves") | ||
|
||
def make_section(self, shapes): | ||
base = shapes[0].copy() | ||
rest = shapes[1:] | ||
section = base.section(rest) | ||
return section | ||
|
||
def process(self): | ||
if not any(socket.is_linked for socket in self.outputs): | ||
return | ||
|
||
sections_out = [] | ||
|
||
shapes_a_in = self.inputs['Shape A'].sv_get() | ||
shapes_b_in = self.inputs['Shape B'].sv_get() | ||
level_a = get_data_nesting_level(shapes_a_in, data_types=(Part.Shape,)) | ||
level_b = get_data_nesting_level(shapes_b_in, data_types=(Part.Shape,)) | ||
shapes_a_in = ensure_nesting_level(shapes_a_in, 2, data_types=(Part.Shape,)) | ||
shapes_b_in = ensure_nesting_level(shapes_b_in, 2, data_types=(Part.Shape,)) | ||
level = max(level_a, level_b) | ||
|
||
for params in zip_long_repeat(shapes_a_in, shapes_b_in): | ||
new_sections = [] | ||
for shape_a, shape_b in zip_long_repeat(*params): | ||
result = self.make_section([shape_a, shape_b]) | ||
new_sections.append(result) | ||
sections_out.extend(new_sections) | ||
|
||
def get_verts(section): | ||
verts = [] | ||
for v in section.Vertexes: | ||
verts.append(v.Point[:]) | ||
return verts | ||
|
||
def get_edges(section): | ||
edges_curves = [] | ||
for e in section.Edges: | ||
try: | ||
curve = SvSolidEdgeCurve(e) | ||
if self.nurbs_output: | ||
curve = curve.to_nurbs() | ||
edges_curves.append(curve) | ||
except TypeError: | ||
pass | ||
return edges_curves | ||
|
||
verts_out = map_recursive(get_verts, sections_out, data_types=(Part.Shape,)) | ||
edges_out = map_recursive(get_edges, sections_out, data_types=(Part.Shape,)) | ||
|
||
self.outputs['Vertices'].sv_set(verts_out) | ||
self.outputs['Curves'].sv_set(edges_out) | ||
|
||
|
||
def register(): | ||
bpy.utils.register_class(SvSolidSectionNode) | ||
|
||
|
||
def unregister(): | ||
bpy.utils.unregister_class(SvSolidSectionNode) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.