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
Marching_cubes with pymcubes, skimage and sverchok #1549
Comments
multi schwarz ( i think it is called so...) with just a function call.
notice the isovalue used ( do not use high values). script here |
it can do metaballs? :) |
maybe, i will try to add a set of multi spheres,... |
"""
in bounds s d=10 n=2
in iso_val s d=8.0 n=2
in samples s d=100 n=2
in factor s d=0.9 n=2
out vertices v
out triangles s
"""
import numpy as np
import sys
mcubes_path = r"/usr/local/lib/python3.5/dist-packages" #it depend on your OS but just paste the path where is scipy
if not mcubes_path in sys.path:
sys.path.append(mcubes_path)
import mcubes
import math
# Create the volume
def f(x, y, z):
return ((x-factor)*(x-factor)+y*y+z*z-1)*((x+factor)*(x+factor)+y*y+z*z-1)-0.3
# Extract the 16-isosurface
verts, tri = mcubes.marching_cubes_func(
(-bounds, -bounds, -bounds), (bounds, bounds, bounds), # Bounds
samples, samples, samples, # Number of samples in each dimension
f, # Implicit function
iso_val) # Isosurface value
vertices, triangles = verts.tolist(), tri.tolist() This only create two spheres but it can be developed a multi spheres version. |
Scikit image module has also marching cubes functions http://scikit-image.org/docs/dev/auto_examples/edges/plot_marching_cubes.html |
i'd like to see an example of multi verts for metaballs. very cool stuff. |
i will do later if i can. |
hm, will try at home just essentially needed stuff |
ok thank you. I'm looking for the multi metaballs example. struct PythonToCFunc
{
PyObject* func;
PythonToCFunc(PyObject* func) {this->func = func;}
double operator()(double x, double y, double z)
{
PyObject* res = PyObject_CallFunction(func, "(d,d,d)", x, y, z); // py::extract<double>(func(x,y,z));
if(res == NULL)
return 0.0;
double result = PyFloat_AsDouble(res);
Py_DECREF(res);
return result;
}
}; https://github.com/pmneila/PyMCubes/blob/master/mcubes/src/pywrapper.cpp#L8 |
anyone know a reason the script would fail to load mcubes on Windows? |
can it remesh Particles into something meshy?
|
@scorpion451 i don't know. But where is
? in my mcubes folder i have three files:
really i don't know @enzyme69: i'm testing the lib for now. |
@scorpion451 i suspect the problem could also be a mismatch between python 3.5 and your 3.6 |
TorusIso"""
in bounds s d=10 n=2
in iso_val s d=8.0 n=2
in samples s d=100 n=2
in r_i s d=5.0 n=2
in r_o s d=1.0 n=2
out vertices v
out triangles s
"""
import numpy as np
import sys
mcubes_path = r"/usr/local/lib/python3.5/dist-packages" #it depend on your OS but just paste the path where is mcubes
if not mcubes_path in sys.path:
sys.path.append(mcubes_path)
import mcubes
import math
# Create the volume
def f(x, y, z):
# (sqrt(x*x+y*y)-3)^2+z*z-1 formula from MathMod
res=(math.sqrt(x*x+y*y)-r_i)**2+z*z-r_o
return res
# Extract the 16-isosurface
verts, tri = mcubes.marching_cubes_func(
(-bounds, -bounds, -bounds), (bounds, bounds, bounds), # Bounds
samples, samples, samples, # Number of samples in each dimension
f, # Implicit function
iso_val) # Isosurface value
vertices, triangles = [verts.tolist()], [tri.tolist()] https://github.com/kalwalt/sverchok_nodes_collection/blob/master/scripts/pymcubes/torus_iso.py |
Testing the scikit marching_cubes function: """
in sp s d=0.0 n=2
in iso_val s d=0.0 n=2
in step s d=1 n=2
in a s d=6 n=2
in b s d=10 n=2
in c s d=16 n=2
out vertices v
out faces s
"""
import numpy as np
import sys
scikit_path = r"/usr/local/lib/python3.5/dist-packages" # it depend on your OS but just paste the path where is scikit
if not scikit_path in sys.path:
sys.path.append(scikit_path)
from skimage import measure
from skimage.draw import ellipsoid
# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(a, b, c, levelset=True)
ellip_double = np.concatenate((ellip_base[:-1, ...],
ellip_base[2:, ...]), axis=0)
# Use marching cubes to obtain the surface mesh of these ellipsoids
verts, faces, normals, values = measure.marching_cubes(
ellip_double, level=iso_val,spacing=(sp, sp, sp), step_size=step)
vertices, faces = [verts.tolist()], [faces.tolist()]
|
@kalwalt double checked, and I do have mcubes in my C:\Program Files\Python36\Lib\site-packages folder, with
I just updated Python, so I'm going to try rolling back to 3.5.2, see if that makes any difference. |
Okay, so now that I've got it working and played with it for a while: |
@scorpion451 Happy, that you got it working!
This is sure possible. Probably given the Bounding Box of the mesh you can calculate the distance of every vertex from the center of the BB, so finding the values for the marching cubes algorithm. This is a feature that would fine have with Sverchok. but for now we can only develop some script or macro, because pymcubes can't be installed in blender python. I suggest also to try the scikit-image module as mentioned in a previous post in this issue. For now I'm testing the two modules to see what is more convenient to use. |
Unexpected error: <class 'ImportError'>
on line: 2
Traceback (most recent call last):
File "/home/ololo/.config/blender/2.78/scripts/addons/sverchok/nodes/generator/script1_lite.py", line 348, in process_script
exec(self.script_str, locals(), locals())
File "<string>", line 16, in <module>
ImportError: No module named 'mcubes._mcubes' mcubes_path = r"/usr/lib/python3.6/site-packages/" #it depend on your OS but just paste the path where is scipy
if not mcubes_path in sys.path:
sys.path.append(mcubes_path)
import mcubes the same 3.6 |
@nortikin i think should match the python versions. Blender use python 3.5 (at least 2.78a) your system python installed is as i can see 3.6. |
the same 3.6 problem, i see |
if you can you should install python 3.5 on your system and after the |
Traceback (most recent call last):
File "/home/ololo/.config/blender/2.78/scripts/addons/sverchok/nodes/generator/script1_lite.py", line 348, in process_script
exec(self.script_str, locals(), locals())
File "<string>", line 16, in <module>
ImportError: No module named 'mcubes._mcubes' have now 3.5 |
how to point blender on locan python? |
@nortikin now how is your |
@kalwalt r"/usr/lib/python3.5/site-packages/mcubes/" |
from ._mcubes import marching_cubes, marching_cubes_func |
try: -r"/usr/lib/python3.5/site-packages/"
+r"/usr/lib/python3.5/site-packages" |
stick a plate of glass ontop of that and you got a coffee table. |
try also; # instead of multiplying
v = Z * u
# try yo add
v = Z + u |
Cool stuff, if I also send normals / colors or others attributes per vertex, how can I use them in sverchok / blender ? |
Hi @paulofalcao, no pymcubes can't send normals or other vertex informations. Polyvox lib has this feature but the python bindings unfortunately not. I would update the bindings to the latest but Polyvox, the original lib in C++, is heavily templated and i don't feel very comfortable with.
i think you can do what you want with it. You can apply other nodes, baking in the scene and use all the modifiers and other blender tools. |
Thanks, that's what I was trying to do with a simple example like this: """
in bounds s d=10 n=2
in iso_val s d=0.0 n=2
in samples s d=100 n=2
in sphere_size s d=5.0 n=2
out vertices v
out triangles s
out normals v
out colors v
"""
import numpy as np
import sys
mcubes_path = r"/usr/local/lib/python3.6/site-packages/PyMCubes-0.0.6-py3.6-macosx-10.11-x86_64.egg" # it depend on your OS but just paste the path where is mcubes
if not mcubes_path in sys.path:
sys.path.append(mcubes_path)
import mcubes
import math
# Signed Distance Function
def sdf(x, y, z):
x = x + math.sin(y*2.0)*1.0
res = math.sqrt(x*x + y*y + z*z) - sphere_size
return res
def norm(p):
e = 0.001
v = sdf(p[0],p[1],p[2])
return np.linalg.norm([v-sdf(p[0]+e,p[1],p[2]),
v-sdf(p[0],p[1]+e,p[2]),
v-sdf(p[0],p[1],p[2]+e)])
def cor(p):
return [math.sin(p[0]*0.5)+0.5,
math.sin(p[1]*0.7)+0.5,
math.sin(p[2]*0.9)+0.5]
# Extract the 16-isosurface
verts, tri = mcubes.marching_cubes_func(
(-bounds, -bounds, -bounds), (bounds, bounds, bounds), # Bounds
samples, samples, samples, # Number of samples in each dimension
sdf, # Signed Distance Function
iso_val) # Isosurface value
vertices = [verts.tolist()]
triangles = [tri.tolist()]
normals = map(norm,vertices)
colors = map(cor,vertices) |
@paulofalcao great! but colors and normals i think won't works as it is now. Anyway you could plug into a viewer bmesh and a vertex color new to display the color information onto the mesh. But i will show you tomorrow, maybe opening another issue thread, as i have no time now |
@kalwalt, OK thanks. I was just playing around with these stuff :) |
consulted with pymcubes developer, i had blender 32 bit, system 64 bit, so it was not working ))) |
Did you tried with blender 64 bit? |
yes, it importing ok |
I would not mind a coffee shop with such futuristic furniture!
I think this 3D voxel mesher is what I need to meditate soon.
I always want it since Cycles can do volumetric.
|
also.. i can't get mcubes installed if you want answers, paste / copy (not screenshot) the output of a working SNLite piped into a Debug node, and SNLite that doesn't work and by "doesn't work" i mean, it doesn't display anything for VDMK. also show the whole Error messages, but maybe not the parts of the message that repeat, or have already been printed earlier. |
also.. disconnect the VDMK2 when you connect the |
@zeffii Yes, I think the issue was: data list was empty: [[]] --> this gives "int not iterable" error. By adjusting parameter, etc, I finally got something. False alarm. something to do with this: verts, tri = mcubes.marching_cubes(v, 0) --> empty list I wish you can play with this "marching cube" stuff, interesting~ |
hi @enzyme69 glad that you work with it ! pay attention to the iso values. As i remember it is very sensible. Sorry for my long delay here. I have no time to work or experimenting with sverchok and programming in general... |
What would be cool is a way to read or export Cycles Volumetric back into
Sverchok. Maybe OSL can help with this?
--
…------------------------------------------------------------
- Jimmy Gunawan
http://blendersushi.blogspot.com.au
http://mayaspiral.blogspot.com.au
http://houdoodles.blogspot.com.au
http://puppetar.blogspot.com.au
|
import mcubes command generating the following error: Traceback (most recent call last): Any help would be appreciated! |
@akalyan3 You need to ensure that the module is callable from inside Blender or Script node. Have you downloaded the PyMCubes module and install it into your computer and testing it using Python outside Blender? Ensuring also the Python version is good. Then once it's good, you can call it using the lines mentioned above by @kalwalt
|
@enzyme69 Thanks for that. That resolved the issue. But I ran into another one :P I'm trying to export a Schwarz. |
Pymcubes is a python module with a marching cubes algorithm. In the simple example that i provide it simply plot a sphere. You can set the bounds, the number of samples in each dimension, and the iso surface level. The sphere is defined by the function
f
; of course you can use what function you desire.You must install the module in the python 3 location and then import it with the sys importing statement.
change your path accordingly.
to install pymcubes i used pip:
pip3 install pymcubes
it requires also pycollada and cython.
you can take the script also here
The text was updated successfully, but these errors were encountered: