Comments (41)
As discussed in other places the generator pattern for functions was slightly awkward and not entirely logical leaving us with two choice, either amend the type system or redo the decorator allowing it to be used directly
import bmesh
from svrx.util.geom import vectorize
from svrx.util.mesh import rxdata_from_bm
@vectorize
def make_icosphere(subdiv, diam):
bm = bmesh.new()
bmesh.ops.create_icosphere(bm, subdivisions=subdiv, diameter=diam, calc_uvs=False)
return rxdata_from_bm(bm)
@node_script
def sn_icosphere(subdiv: Int = 2, diam: Float = 1.0) -> ([Vertices], [Edges], [Faces]):
return list(make_icosphere(min(subdiv, 5), diam))
Rethinking that a little bit made me come up with the following which auto wraps inputs allowing the functions to be tested in the blender python console. It also allows variable matching, the fact that the decorated function is exposed directly to the system allows further settings, like variable match type to be, potentially, controllable from the system.
import bmesh
from svrx.util.geom import generator
from svrx.util.mesh import rxdata_from_bm
@node_script
@generator
def sn_icosphere(subdiv: Int(min=0, max=5) = 3, diam: Float = 1.0) -> ([Vertices], [Edges], [Faces]):
bm = bmesh.new()
bmesh.ops.create_icosphere(bm, subdivisions=min(subdiv, 5), diameter=diam, calc_uvs=False)
return rxdata_from_bm(bm)
Todo:
- Allow only certain parameters to be wrapped
- Provide match function override at run time
from sverchok.
edited
import os
from svrx.util.mesh import rxdata_from_pydata
def simple_obj_loader(path):
verts, edges, faces = [], [] ,[]
add_vert = verts.append
add_face = faces.append
with open(path) as ofile:
for line in ofile:
if line.startswith('v'):
add_vert([float(i) for i in line[2:].strip().split(' ')])
if line.startswith('f'):
add_face([int(i)-1 for i in line[2:].strip().split(' ')])
return verts, edges, faces
@node_script
def sn_make_cricket() -> (Vertices, Edges, Faces):
mesh_objects_path = r"C:\Users\zeffi\Desktop\GITHUB\DEEP\svrx\util\mesh_objects"
obj_path = os.path.join(mesh_objects_path, "cricket.obj")
verts, _, faces = simple_obj_loader(obj_path)
return rxdata_from_pydata(verts, faces=faces)
haha
from sverchok.
Suzanne is also of limited use inside of the system but since it is basically free to add it I went there.
Still cannot get over how small the nodes have become. Almost all the fluff is gone, dealing with input, checking for outputs etc, parsing lists.
from sverchok.
Function signature should be like below.
@node_script
def sn_make_cricket() -> (Vertices, Edges, Faces):
from sverchok.
ok, that should look like this now:
from svrx.util.mesh import rxdata_from_pydata
from svrx.util.importers import named_mesh_path, obj_to_pydata_lite
@node_script
def sn_make_cricket() -> (Vertices, Edges, Faces):
obj_path = named_mesh_path("cricket.obj") # returns the library path + object name
verts, _, faces = obj_to_pydata_lite(obj_path) # accepts full valid path
return rxdata_from_pydata(verts, faces=faces)
from sverchok.
It has kind on moved on into other issues
from sverchok.
Organized is a keyword. The default could be very similar but allowing different advanced options like strange options like plane does.
from sverchok.
The @generator
should probably not be in util.geom
but in util.function
from sverchok.
or util.decorators
from sverchok.
maybe move the util.geom
to libs.geom
if it's content is only mesh producing functions ( that was the original intent of sverchok.utils.geom
) it seems to have slightly morphed.
from sverchok.
Yeah a lib for core functions makes sense. circle
is a util
, mesh etc is a core functionality
from sverchok.
Actually should probably do both a name review and project layout review.
nodes.classes -> nodes.classes.files
from nodes.node_base import node_func -> from nodes import node_func
etc.
Ensure consistent node namning, like
SvRxNode{Module}{Name}
SvRxNodeNumberMath
from sverchok.
i'll find somethign else to do... but it won't be until later today at the earliest : /
from sverchok.
I won't have time for that today either, need to do some other stuff.
from sverchok.
Updated all nodes from vectorize to generator and also the cookbook.
from sverchok.
The best generator function
@node_func(bl_idname='SvRxNodeBmeshGenerate', multi_label="Bmesh Gen", id=0)
def create_monkey() -> BMesh:
bm = bmesh.new()
bmesh.ops.create_monkey(bm)
return bm
from sverchok.
i'll make a cricket
:)
from sverchok.
That is a slightly bigger challenges :)
from sverchok.
https://www.dropbox.com/s/pe7f6ciza8vt8fq/cricket_remakeFIXR.blend?dl=0
from sverchok.
Yeah that is nice. 👍
from sverchok.
hmmm.. it's a little geometry heavy.
from sverchok.
cool, that's clearer now
from sverchok.
why obj file?
from sverchok.
simple standard format text format, easy to work with
from sverchok.
ok, lets use it. than inner svrx.obj.library
from sverchok.
i like the idea of storing these as zipped files, .. but Google lately made a geometry compressor worth investigating :)
from sverchok.
I am partial towards .gz
file but .zip
probably makes more sense.
https://docs.python.org/3/library/archiving.html
from sverchok.
https://opensource.googleblog.com/2017/01/introducing-draco-compression-for-3d.html
from sverchok.
Would be good to have that as export/import from blender if there isn't a plugin yet as well
from sverchok.
Stupid performance test, sticking a lru cache on it.
def test():
import time
obj_path = named_mesh_path("cricket.obj")
start = time.perf_counter()
obj_to_pydata_lite(obj_path)
stop = time.perf_counter()
print(stop-start)
start = time.perf_counter()
obj_to_pydata_lite(obj_path)
stop = time.perf_counter()
print(stop-start)
start = time.perf_counter()
obj_to_pydata_lite.__wrapped__(obj_path)
stop = time.perf_counter()
print(stop-start)
>>> svrx.util.importers.test()
0.014265173333313896 # first access to cache, cache miss, loading object
2.1333333393158682e-06 # second access
0.013622613333325262 # direct access using __wrapped__
from sverchok.
@functools.lru_cache(maxsize=16)
def obj_to_pydata_lite(path)
....
from sverchok.
that's a 5 magnitude smaller. ?
from sverchok.
almost 7k times faster?..wtf..?
from sverchok.
Yes, it turns the function into a dictionary lookup basically.
>>> svrx.util.importers.test()
1.49E-02 # cache miss and load
1.71E-06 # cached
1.34E-02 # raw access
from sverchok.
Something like this happens:
def func(path):
if path in _cache:
return _cache[path]
else:
res = inner_func(path)
_cachep[path] = res
return res
from sverchok.
https://docs.python.org/3.5/library/functools.html
from sverchok.
i might have to read that.
from sverchok.
It might be annoying if one changes the geometry, should put a note in there about how to work around in the docstring
from sverchok.
maybe offer cached_basic_obj_to_pydata
and basic_obj_to_pydata
from sverchok.
The other way around, long name for the uncommon case, uncached_basic_obj_to_pydata
and basic_obj_to_pydata
.
def uncached_obj_to_pydata_lite(path):
return obj_to_pydata_lite.__wrapped__(path)
from sverchok.
OK. :)
from sverchok.
Related Issues (20)
- Documentation HOT 8
- Int and Float socket can be limited HOT 2
- Mesh - rxdata_from_pydata HOT 28
- BMesh nodes HOT 10
- Dynamic Socket Issues HOT 3
- API to simplify mesh creation HOT 3
- The great namning debacle HOT 18
- Node wishlist HOT 48
- stethoscope v2 HOT 44
- startup error message HOT 1
- Timings HOT 74
- .foreach mesh out HOT 15
- torus np scriptnode HOT 39
- Rx Bridges (remakes of real bridges) HOT 1
- Texture script node HOT 52
- Index Viewer HOT 70
- Linspace and arrange HOT 16
- Some refactoring going on HOT 5
- OpenGL viwers HOT 39
- vectorization concept HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sverchok.