Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solid Nodes and Extra-Nodes #3377

Merged
merged 24 commits into from Jul 6, 2020
Merged

Solid Nodes and Extra-Nodes #3377

merged 24 commits into from Jul 6, 2020

Conversation

vicdoval
Copy link
Collaborator

@vicdoval vicdoval commented Jun 28, 2020

image
This PR adds two features:

Extra nodes: The ability to add nodes with external dependencies.
A new tab has been added to the sverchok preferences to handle the dependencies
image

In case of missing dependencies the nodes wont be loaded and they wont appear on the menu.
If a file is loaded with nodes that require dependencies not found a Dummy node will be created on the Fly
image
The dependent nodes have to be added to the dummy_nodes_dict in utils/dummy_nodes
I followed the strategy of the old_nodes loading but generating the dummy_nodes when needed
Also if a json is loaded with nodes that require dependencies not found they will be replaced by a Dummy node

Solid Nodes: A set of nodes dependent on FreeCad to perform operations with solids (BRep)
Inspired in https://blenderartists.org/t/freecad-sverchok-subd-to-nurbs/1218702
Using FreeCAD as Python module a set of nodes to deal with solids

Installation
A python 3.7 FreeCad is needed. a windows version can be found here https://github.com/sgrogan/FreeCAD/releases/tag/PY3.7-win
Then the path to the FreeCad bin folder has to be placed in the Extra-Nodes ->FreeCad-> TextField and click on Set Path

image

Solids are heavier than meshes but perform better boolean operations (even with co-planar faces)
The module also offers variable radius Fillet
image

Chamfer with different angles:
image
image

And more to came (import/export to STL and BRep, center of mass, solid to NURBS...)

  • Code changes complete.
  • Code documentation complete.
  • Documentation for users complete (or not required, if user never sees these changes).
  • Manual testing done.
  • Unit-tests implemented.
  • Ready for merge.

@zeffii
Copy link
Collaborator

zeffii commented Jun 28, 2020

oh lol. i see you have Mesh to Solid already. i'm blind.

@portnov
Copy link
Collaborator

portnov commented Jun 28, 2020

Well. We have to decide something... We discussed this in portnov/sverchok-extra#15
If there will be "Extra nodes" subsystem in Sverchok, do we need Sverchok-Extra at all?

@vicdoval
Copy link
Collaborator Author

@portnov I took part some of the code from sverchok-extra to make this PR work, Sverchok-extra is a extra step, the easiest, but another step. I think moving sv-extra to extra-nodes will encourage the users to install the dependencies and to use the nodes ...

@vicdoval
Copy link
Collaborator Author

Solid Edges node outputs Curve objects:
image

@portnov
Copy link
Collaborator

portnov commented Jun 29, 2020

  1. Do I correctly understand that the path that I have to set up in preferences is the path to FreeCAD.so / FreeCAD.dll ? This is not too clear. I suggest to write it in the tooltip or in special label nearby. Also I suggest to add examples of typical paths on different platforms there.
  2. Why separate Set button is required?
  3. When I put /usr/lib/freecad-python3/lib/ there, I have
FreeCAD 0.18.4, Libs: 0.18.4R
No modules found in /usr/lib/freecad-python3/Mod
During initialization the error No module named 'freecad' occurred

However the nodes seem to work. What is going on? :)

  1. If I try to do "Mesh to Solid", and then do something with that Solid (Fillet, for example, or Champfer), I have
Traceback (most recent call last):
  File "/home/portnov/.config/blender/2.82/scripts/addons_contrib/sverchok/core/update_system.py", line 383, in do_update_general
    node.process()
  File "/home/portnov/.config/blender/2.82/scripts/addons_contrib/sverchok/nodes/solid/fillet_solid.py", line 62, in process
    solid_o = solid.makeFillet(r_s, r_e, selected_edges)
Part.OCCError: BRep_API: command not done

The same node works if I pass primitive like "Box (Solid)" into it.

@vicdoval
Copy link
Collaborator Author

Do I correctly understand that the path that I have to set up in preferences is the path to FreeCAD.so / FreeCAD.dll ? This is not too clear. I suggest to write it in the tooltip or in special label nearby. Also I suggest to add examples of typical paths on different platforms there.

The path has to be to the folder where FreeCadApp.dll (and the FreeCadBase.exe..) is placed... In my case is something like E:\programas\conda-0.18.3\bin (it is a portable Windows version of FreeCad downloaded from the provided link)

Why separate Set button is required?

The Set button saves a file in python\lib\site-packages called freecad_path.pth with the supplied path so it stays permanently on the system... maybe it could be set every time you open blender.. I thought this solution was cleaner but I'm open to suggestions

However the nodes seem to work. What is going on? :)

Probably you already had a path in your system to the right version of FreeCAD

About the 4th point: The FreeCAD api report is a bit obscure..., the Fillet and Chamfer nodes will fail if the Radius/Distance is to high to perform the operation without errors, reducing the value should make it work. maybe I should add a try/except to raise a more clear explanation

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

looks like the vdmk3 might need an alternative, for solids to avoid that chevron shading artifact in the fillet, but if each surface that is currently outlined by an edge is ultimately just one "polygon", then things become tricky.

@vicdoval
Copy link
Collaborator Author

Solid Faces node outputs surface objects and curves with the outer curves of each face:
image

@vicdoval
Copy link
Collaborator Author

vicdoval commented Jun 30, 2020

@zeffi i was thinking about this... in grashopper some nodes have a draw method that works like a inner viewer draw... now that we have Surfaces, Curves and Solids maybe could try something similar...
As you see in this images there could be a cleaner way to represent the Solid objects image
image

The faces are tesselated but only the "real" edges are represented....

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

"Solid Viewer" as a separate node maybe, an opportunity to go beyond my silly experiments.

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

coooool.

image

image

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

should the Solids get their own separate menu? even if it's only a really minor menu system.

- input
- operators
- convert
- output

@vicdoval
Copy link
Collaborator Author

@zeffi you mean taking it out of the general menu or keep it there and also making another smaller menu?

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

yes, to do this justice i think a separate menu has merit. Especially for the new users, who will be able to see what is available from the FreeCAD module in a nice menu/submenu form

whats happening here?
image

https://gist.github.com/f2406acbfa3b721d9926d6b912065f54

@vicdoval
Copy link
Collaborator Author

whats happening here?

It was me messing with curves... now is fixed
image

I understand you mean keeping in main + new menu?

The question that pops up is: A freeCad module menu or a Solids Menu? Once FreeCad is inside Sv we could import more than Solids... (BIM, Fem analysis, Surface, Mesh tools [there is a mesh boolean operator])... how do you imagine it?

@zeffii
Copy link
Collaborator

zeffii commented Jun 30, 2020

how do you imagine it?

well, in the overarching case that you paint, maybe a freeCAD menu would indeed make sense.

In that case I would vote to not mix those nodes in the Sverchok menu at all. but let's see.

@portnov
Copy link
Collaborator

portnov commented Jun 30, 2020

@vicdoval

The Set button saves a file in python\lib\site-packages called freecad_path.pth with the supplied path so it stays permanently on the system... maybe it could be set every time you open blender.. I thought this solution was cleaner but I'm open to suggestions

Does this mean I have to press this button each time I run blender?

Wouldn't it be enough to just save the path in sverchok settings and initialize sys.path accordingly at registration?

@portnov
Copy link
Collaborator

portnov commented Jun 30, 2020

Screenshot_20200630_210958

2020-06-30 21:09:10,122 [ERROR] sverchok.core.update_system: Node Chamfer Solid had exception: BRep_API: command not done
Traceback (most recent call last):
  File "/home/portnov/.config/blender/2.82/scripts/addons_contrib/sverchok/core/update_system.py", line 383, in do_update_general
    node.process()
  File "/home/portnov/.config/blender/2.82/scripts/addons_contrib/sverchok/nodes/solid/chamfer_solid.py", line 63, in process
    solid_o = solid.makeChamfer(d_a, d_b, selected_edges)
Part.OCCError: BRep_API: command not done

@portnov
Copy link
Collaborator

portnov commented Jun 30, 2020

  1. "Solid faces" node. Is it possible to have additional output similar to "Outer Wire", but with curves in UV coordinates of each surface? I just don't know if Freecad provides such.

@portnov
Copy link
Collaborator

portnov commented Jun 30, 2020

  1. Dummy nodes. Do we really need separate classes for them? Maybe that "dummy" functionality could be incorporated in the nodes themselves?
from sverchok.dependencies import FreeCAD

class SvSomeNode:
    def is_dummy(self):
        return (FreeCAD is None)
    
    def draw(...):
        if self.is_dummy(): layout.label(text="This is a dummy node")
        else: draw actual UI

    def process(self):
        if self.is_dummy(): raise Exception("This is a dummy node")

?

@portnov
Copy link
Collaborator

portnov commented Jun 30, 2020

https://github.com/microelly2/NodeEditor huh.

@vicdoval vicdoval merged commit 09574c9 into nortikin:master Jul 6, 2020
@portnov
Copy link
Collaborator

portnov commented Jul 6, 2020

👍

@zeffii
Copy link
Collaborator

zeffii commented Jul 6, 2020

🎉

now to make some coool stuff with it.

@nortikin
Copy link
Owner

nortikin commented Jul 6, 2020

https://vk.com/wall-35076122_11309
short installation instructions on linux and windows:

Linux:
sudo apt install libfreecad-python3-0.18
/usr/lib/freecad-python3/lib/
Windows:
https://github.com/sgrogan/FreeCAD/releases/tag/PY3.7-win
E:\programs\conda-0.18.3\bin

@portnov portnov added the Solids label Sep 1, 2020
@rastart
Copy link
Collaborator

rastart commented Sep 13, 2020

Hello everyone!
I'm the author of the blender artist post: https://blenderartists.org/t/freecad-sverchok-subd-to-nurbs/1218702
I'm starting to study this implementation and I rewrited my original sv project node.
Here node features:

  • it takes a freecad project file and output the solids from it
  • it writes a mesh from blender overwriting the given name

I see that is possible to slice the solid list and make operation on it, but It would be nice to add a node to select parts by name, I have to try…

freecad_project_to_sverchok

If could be of some use here the node code:
SvFCproject.zip

@portnov
Copy link
Collaborator

portnov commented Sep 13, 2020

I would suggest

  • Split reading and writing into different nodes;
  • For reading node, add "Read List" button, which would read list of objects from FreeCAD's file and populate a dropdown list (or a list with checkboxes, so that the user can select several objects)
  • Probably, support "SvFilePath" socket for file path.

@rastart
Copy link
Collaborator

rastart commented Sep 20, 2020

I would suggest

  • Split reading and writing into different nodes;
  • For reading node, add "Read List" button, which would read list of objects from FreeCAD's file and populate a dropdown list (or a list with checkboxes, so that the user can select several objects)
  • Probably, support "SvFilePath" socket for file path.

FCStdNodes

Hello! working in progress... Slowly learning Sverchok framework...
FCStd node splitted:

"read node"
It can import from multiple files but I didn't find a way to populate a dropdown list of the parts to select, so I added a field to filter by name, just writing parts name separated by comma and no spaces ( split(',')... )

"write node" ( mesh/solid modes)
I still have to code multiple file writing in write node.
I tried to write a solid input from the "mesh to solid" node, it works!
The parts writed from blender are overwrited by name in the FCStd file.
The solid write mode support multiple solids and it will add an index on the base name, on changes it will delete all parts with base name before write them again. This system could be quite dangerous... It's just a way to experiment with blender/CAD workflow.

FCStd_nodes.zip

@nortikin
Copy link
Owner

I would suggest

  • Split reading and writing into different nodes;
  • For reading node, add "Read List" button, which would read list of objects from FreeCAD's file and populate a dropdown list (or a list with checkboxes, so that the user can select several objects)
  • Probably, support "SvFilePath" socket for file path.

FCStdNodes

Hello! working in progress... Slowly learning Sverchok framework...
FCStd node splitted:

"read node"
It can import from multiple files but I didn't find a way to populate a dropdown list of the parts to select, so I added a field to filter by name, just writing parts name separated by comma and no spaces ( split(',')... )

"write node" ( mesh/solid modes)
I still have to code multiple file writing in write node.
I tried to write a solid input from the "mesh to solid" node, it works!
The parts writed from blender are overwrited by name in the FCStd file.
The solid write mode support multiple solids and it will add an index on the base name, on changes it will delete all parts with base name before write them again. This system could be quite dangerous... It's just a way to experiment with blender/CAD workflow.

FCStd_nodes.zip

image
would it be here or where?

@rastart
Copy link
Collaborator

rastart commented Sep 21, 2020

Yes, I think Exchange would be perfect

@rastart
Copy link
Collaborator

rastart commented Oct 25, 2020

hello! I fixed some issues related to file array and filter by name( now use .label prop in freecad instead of .name... I noticed that if you rename something in freecad it changes only the label)

FCStd_nodes_25_10_2020.zip

@vicdoval
Copy link
Collaborator Author

@rastart wouldn't you like to make a pull request? (https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZF9C0YMKuns9sLDzK6zoiV)

@nortikin
Copy link
Owner

@rastart @vicdoval
agree, git / github is must-have skill.

@rastart
Copy link
Collaborator

rastart commented Oct 26, 2020

Ok, I should have pull the request!

@rastart
Copy link
Collaborator

rastart commented Oct 27, 2020

Hello, I'm evaluating a convenient method to pass filter labels to read node.
I added a string input and it works fine ( I scripted a node to pass a simple string )
There are already some nodes in Sverchok to pass simple text line? maybe also in list format? (like 'list input' in number cat)
I could also try to make a node with an enum function to generate a dropdown list to select like Portnov pointed:

  • For reading node, add "Read List" button, which would read list of objects from FreeCAD's file and populate a dropdown list (or a list with checkboxes, so that the user can select several objects)

but in huge assembly would be a mess. Have you some feedbacks about it?
maybe a variant of SvExecNodeMod?
"dynamic_strings: bpy.props.CollectionProperty(type=SvExecNodeDynaStringItem)"

@portnov
Copy link
Collaborator

portnov commented Oct 27, 2020

class SvShowFcstdNamesOp(bpy.types.Operator):
    bl_idname = "node.sv_show_fcstd_names"
    bl_label = "Show contents"
    bl_options = {'INTERNAL', 'REGISTER'}
    bl_property = "option"

    def get_items(self, context): ...

    option : EnumProperty(items = get_items)
    idtree : StringProperty()
    idname : StringProperty()


    def execute(self, context):
        tree = bpy.data.node_groups[self.idtree]
        node = tree.nodes[self.idname]
        node.name_filter = self.option
        return {'FINISHED'}

    def invoke(self, context, event):
        context.space_data.cursor_location_from_region(event.mouse_region_x, event.mouse_region_y)
        wm = context.window_manager
        wm.invoke_search_popup(self)
        return {'FINISHED'}

...

def draw_buttons():
    wrapper_tracked_ui_draw_op(layout, SvShowFcstdNamesOp.bl_idname, icon=...)

This will show drop-down menu similar to one that appears by Alt-Space.

@rastart
Copy link
Collaborator

rastart commented Oct 27, 2020

Meanwhile I made up this... works nice!

Thanx for the dropdown code, I'll try to implement it in the next days

@rastart
Copy link
Collaborator

rastart commented Oct 30, 2020

This will show drop-down menu similar to one that appears by Alt-Space.
Working!

@DuncanLithgow
Copy link

I've referenced this discussion at https://wiki.osarch.org/index.php?title=Sverchok if anyone wants to expand the text that would be great. Or at least check that what I've written makes sense.

@rastart
Copy link
Collaborator

rastart commented Nov 29, 2020

added read sketch node!
The sketch geometry is converted in polylines by freecad 'discretize' function and passed to verts/edge data.
Added a resample function with a parameter 'max_points' that set the max number of point in relation to the max length in the sketch geometry.

Until now I just tested the nodes with random operations and I didnt experiment critical issues, mainly write node need some attention to avoid recursive overloading if the same freecad file is involved in read/write operation.
From here I'm going to make some little design project to experiment in freecad/sverchok using what we have done until now,
I'm thinking about some simple design involving mechanical, procedural and some direct blender modeling features all togheter.

fcnodes_sketch

@portnov
Copy link
Collaborator

portnov commented Nov 30, 2020

Can you output curves as sverchok.utils.curve.core.SvCurve instances? you probably will have to write special class for that, or maybe one of classes from sverchok.utils.curve.freecad will suffice.

@rastart
Copy link
Collaborator

rastart commented Dec 10, 2020

Can you output curves as sverchok.utils.curve.core.SvCurve instances? you probably will have to write special class for that, or maybe one of classes from sverchok.utils.curve.freecad will suffice.

Fc_sketch_to_curve

OK! sverchok.utils.curve.core.SvCurve instances worked to translate freecad line, circle and arc.
Still to translate conics to sv curves: maybe this won't be so easy...

@rastart
Copy link
Collaborator

rastart commented Dec 11, 2020

spreadsheet node preview... read/write mode
https://youtu.be/9DJoRjS3kD8

@rastart
Copy link
Collaborator

rastart commented Dec 30, 2020

I just updated the freecad exchange nodes.
Mainly:

READ NODE -> add some sort logic (ex. to read just the body final shape without import all features shape)
WRITE NODE -> no changes
SKETCH NODE -> it apply to the sketch geometry the transform matrix of the sketch placement and the parent body placement
SPREADSHEET NODE -> no changes

Screenshot (202)

I don't think I'm going to add more features so If you have some reviews from now I'll work just on refactoring!
Let me know!

Meanwhile I'll keep making design experiments with these nodes...

@rastart
Copy link
Collaborator

rastart commented Jan 30, 2021

Can you output curves as sverchok.utils.curve.core.SvCurve instances? you probably will have to write special class for that, or maybe one of classes from sverchok.utils.curve.freecad will suffice.

for curves other than segments and circles I manged like that:
freecad_sketch_curve.toNurbs() -> SvNurbsCurve.build( SvNurbsMaths.FREECAD, freecad_sketch_curve.Degree ecc...

It seems to work fine:
fc_sketch_node

@58911031
Copy link

freecad link disabled could you give me the link again please

@nortikin
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants