tkeskita / BVtkNodes

Create and execute VTK pipelines in Blender Node Editor
GNU General Public License v3.0
119 stars 20 forks source link

Refactoring of BVTKNodes object handling (core and updating) #45

Closed tkeskita closed 3 years ago

tkeskita commented 3 years ago

I'm starting to work on refactoring node/vtk obj update code. Two consequtive Multi Block Leaf nodes fail and there's room for clarifying code.

tkeskita commented 3 years ago

OK.. So this is now escalating to a full core refactoring, since updates are linked to how objects are handled in BVTKNodes. Therefore I've started to sketch an overall design spec, here's first draft:

Main targets of object handling in BVTKNodes:

Design items (note: List has been edited!):

Comments welcome! This is gonna take some time and some iterations..

NickGeneva commented 3 years ago

Some ideas from my end:

Housekeeping items:

Code refactoring:

tkeskita commented 3 years ago

Hi Nick, thanks for your comments!

Housekeeping items:

Good ideas for down the road. Housekeeping could be improved, yes.

Automatic testing I think is very limited in Blender without GUI, may not work well for our needs.

What do you mean by status shield?

More examples (json tree files) I'm planning to add at least for the stuff now shown in docs. I'd like to have there a compact set of typical examples of common node usages, which could be used for testing as well as user examples.

A performance improvement would be only update the downstream vtkobjects, i.e. in a tree, only the nodes following a modified one actually need to be updated. Seems to me that there should be no need to update the reading of the file is all your changing is the color map. This is of course unless the top most vtkobjs are being modified as the tree executes. This would likely require a graphical representation of the node structure in the cache so you can do a search from any modified nodes. Not sure right now.

I think this can be done, if the node status feature is successfully added. Update needs to be initiated at the final output node, but it only needs to update up to the highest upstream node which is out-of-date/modified.

I'm not sure if node_id can be removed as of right now. I think we need some unique identifier for each node.

I was thinking of trying to use the objects themselves (BVTK nodes and Blender nodes) as keys for the map dicts.

Thinking of the future, we should be mindful of designing for easy extensions for keyframing/baking animations etc. I have no idea how this would work. Just forward thinking.

Me neither :-( Having a deterministic update system is a start, I hope.

Adding additional support for info node may be good (debug beyond vtkAlgo objects).

Can you give example for this what you're thinking?

For some nodes (for example vtkDelaunay2D ) This works with two inputs but also supports a single input it seems, perhaps support for optional inputs should be added (different colored connection circle. Maybe this is just a bug with the delaunay2D node

I'm not sure I follow you here, can you point me to a Python VTK example? At least vtkStreamTracer already now takes two or three inputs..?

Perhaps having consistency checks between output/input connections would be good (e.g. a node should make sure its node before is giving a vtkAlgo object and not some PolyData) perhaps this can also be a tool tip or even color coated like blender texture nodes...

Example for this as well? I'm not very well familiar with many of the VTK filters available.. But definitely nodes should stop in error if they encounter unexpected input which they can't handle.

PS. There's so much that could be improved, let's try to bite one thing at a time :-) Now I'm most irritated by the update system so I'll try to fix that.

NickGeneva commented 3 years ago

Thats what I figured regarding CI, thought it would be cool... but I also don't think its worth it.

What do you mean by status shield?

Read me shields! I'm sure you've seen these little buttons are repos. There great for acting as a download button, showing the liscense and also the documentation. I can add them to the readme in a PR in the near future. This is the one generated from readthedocs for this repo:

I think this can be done, if the node status feature is successfully added. Update needs to be initiated at the final output node, but it only needs to update up to the highest upstream node which is out-of-date/modified.

Agreed, will need to monitor when a nodes been modified or not and then query that. This isn't wouldn't be a huge improvement but would be a nice feature... however I could see it potentially resulting in bugs if we aren't careful.

Regarding the info node

Well right now there's a set of properties the info node provides information on objects that have points, cells, etc. Perhaps another debug node that shows information on output class, properties, etc. would be a good addition. So this could be inserted anywhere (like after color ramps for example). Would be more for debugging purposes I think.

Regarding the vtkDelaunay2D/ optional inputs.

I'll have to look more into this if I encounter it, it could just be this node... I was thinking if an input isnt required indicate it somehow but standard blender ui doesnt do such things so maybe not a good idea.

Example for this as well? I'm not very well familiar with many of the VTK filters available.. But definitely nodes should stop in error if they encounter unexpected input which they can't handle.

For example, Glyphs note should take polydata and a source object, color mapper takes poly data and the texture. So you could denote these distinct input types with different colored dots like how blender does this with vectors/scalars/colors/etc. I can look more into this.

Also no worries, everyone is busy, just spit-balling ideas from what I've seen from a couple weeks of looking at the code.

tkeskita commented 3 years ago

Thanks for clarifications! Those are good ideas, and good to have them now listed here.

tkeskita commented 3 years ago

Modified design items in 2nd post. Hoping to eliminate caches altogether and keep links to VTK objects in nodes. Planning to move actions like initialization, updating and deletion of VTK object to node functions.

NickGeneva commented 3 years ago

Modified design items in 2nd post. Hoping to eliminate caches altogether and keep links to VTK objects in nodes. Planning to move actions like initialization, updating and deletion of VTK object to node functions.

I tried looking to this when redoing the cache code, but couldnt figure out a good way. The requirements of node properties being a bstruct and also dealing with RNA were hard to work with. However, while working on this new node I found you can define bpy.props.PointerProperty to classes. Not sure if that can be used.

Some additional items:

tkeskita commented 3 years ago

Thanks, I'm gonna see in a week or two if there's a problem.

Currently the special nodes are scattered around, put in places during development. Yes it's good idea to create a separate folder like special_nodes for them and reorganize them somehow (I don't have a clear picture how) at some point!

tkeskita commented 3 years ago

Thanks, I'm gonna see in a week or two if there's a problem.

Indeed it is a problem like you said @NickGeneva. I didn't get more luck with PointerProperty. Apparently it is just easiest to keep cache.py and use node_id there for mapping from node to VTK objects like currently.

Otherwise I'm making some progress on cleaning up the stuff related to node and VTK object initialization and updates. Seems promising so far! To be continued..

tkeskita commented 3 years ago

@NickGeneva about rearranging special nodes: Could that wait until I've merged #46? I'm now starting to modify special node code..

NickGeneva commented 3 years ago

@tkeskita No worries, I've added my new node into current file. See #54. Had to add some new items with the cache for this to work properly. Not sure if this causes you issues, if so let me know and we can work out merging.

Also yeah, the Blender RNA is a big pain and frustrating, I needed to make a global variable for this new node to function as well. Maybe we can generalize the cache so it can store more than just vtk objects... idk. But I think the local status and other items that can be stored in the node (through the built in props) is a major improvement.

Working on this new node gave me some additional naming ideas and implementation ideas for special nodes. But we can wait until merge.

tkeskita commented 3 years ago

I've now updated PR #46 so that vtkConeSource and Info nodes work as they should upon placement to node tree and updates. If you have time, please check the new core functionality and comment!

tkeskita commented 3 years ago

PR #46 is now merged to master! Half a year of work, hope you like it!