Git Product home page Git Product logo

Comments (41)

ly29 avatar ly29 commented on June 12, 2024 2

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.

zeffii avatar zeffii commented on June 12, 2024 2

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

image

#38

from sverchok.

ly29 avatar ly29 commented on June 12, 2024 1

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.

ly29 avatar ly29 commented on June 12, 2024 1

Function signature should be like below.

@node_script
def sn_make_cricket() -> (Vertices, Edges, Faces):

from sverchok.

zeffii avatar zeffii commented on June 12, 2024 1

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.

ly29 avatar ly29 commented on June 12, 2024 1

It has kind on moved on into other issues

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

Organized is a keyword. The default could be very similar but allowing different advanced options like strange options like plane does.

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

The @generator should probably not be in util.geom but in util.function

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

or util.decorators

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

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.

ly29 avatar ly29 commented on June 12, 2024

Yeah a lib for core functions makes sense. circle is a util, mesh etc is a core functionality

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

zeffii avatar zeffii commented on June 12, 2024

i'll find somethign else to do... but it won't be until later today at the earliest : /

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

I won't have time for that today either, need to do some other stuff.

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

Updated all nodes from vectorize to generator and also the cookbook.

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

zeffii avatar zeffii commented on June 12, 2024

i'll make a cricket :)

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

That is a slightly bigger challenges :)

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

https://www.dropbox.com/s/pe7f6ciza8vt8fq/cricket_remakeFIXR.blend?dl=0

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

Yeah that is nice. 👍

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

hmmm.. it's a little geometry heavy.

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

cool, that's clearer now

from sverchok.

nortikin avatar nortikin commented on June 12, 2024

why obj file?

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

simple standard format text format, easy to work with

from sverchok.

nortikin avatar nortikin commented on June 12, 2024

ok, lets use it. than inner svrx.obj.library

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

i like the idea of storing these as zipped files, .. but Google lately made a geometry compressor worth investigating :)

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

I am partial towards .gz file but .zip probably makes more sense.
https://docs.python.org/3/library/archiving.html

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

https://opensource.googleblog.com/2017/01/introducing-draco-compression-for-3d.html

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

Would be good to have that as export/import from blender if there isn't a plugin yet as well

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

ly29 avatar ly29 commented on June 12, 2024
@functools.lru_cache(maxsize=16)
def obj_to_pydata_lite(path)
....

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

that's a 5 magnitude smaller. ?

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

almost 7k times faster?..wtf..?

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

ly29 avatar ly29 commented on June 12, 2024

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.

ly29 avatar ly29 commented on June 12, 2024

https://docs.python.org/3.5/library/functools.html

from sverchok.

zeffii avatar zeffii commented on June 12, 2024

i might have to read that.

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

zeffii avatar zeffii commented on June 12, 2024

maybe offer cached_basic_obj_to_pydata and basic_obj_to_pydata

from sverchok.

ly29 avatar ly29 commented on June 12, 2024

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.

zeffii avatar zeffii commented on June 12, 2024

OK. :)

from sverchok.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.