nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.26k stars 233 forks source link

[Need Help] How to create Gyroid mesh? #5130

Closed kevinsmia1939 closed 5 months ago

kevinsmia1939 commented 5 months ago

Hi, I want to create a surface with sverchok in Blender. Specifically Gyroid. https://en.wikipedia.org/wiki/Gyroid

The implicit function of Gyroid can be express in Python as: np.sin(x) np.cos(y) + np.sin(y) np.cos(z) + np.sin(z) * np.cos(x)

But I don't know how to actually implement this in Sverchok. There are example tutorial with Grasshopper 3D: https://www.youtube.com/watch?v=mhYrVlvbN4k But since Sverchok is different, I don't know where to write the implicit equation and generate mesh from it.

Thanks for the help.

Blender 4.1.1 Sverchok bgl_replacement latest commit. OS: openSUSE Tumbleweed

Here is the example Python code to draw Gyroid with Matplotlib and marching cubes.

import numpy as np
from skimage import measure
import matplotlib.pyplot as plt

# implicit function
def gyroid(x, y, z):
    return np.sin(x) * np.cos(y) + np.sin(y) * np.cos(z) + np.sin(z) * np.cos(x)

xl = np.linspace(-np.pi, np.pi, 40)
X, Y, Z = np.meshgrid(xl, xl, xl)
F = gyroid(X, Y, Z)

verts, faces, normals, values = measure.marching_cubes(F, 0, spacing=[np.diff(xl)[0]]*3)
verts -= 3

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:, 1], faces, verts[:, 2],cmap='jet')

Screenshot_20240602_162747

portnov commented 5 months ago

You can implement such things pretty straightforward with Scalar Field Formula + Marching Cubes: Screenshot_20240602_215629 Note: "Scalar Field Formula" will use numpy by default, so you even don't have to bother about "np.".

kevinsmia1939 commented 5 months ago

You can implement such things pretty straightforward with Scalar Field Formula + Marching Cubes: Screenshot_20240602_215629 Note: "Scalar Field Formula" will use numpy by default, so you even don't have to bother about "np.".

Thank you so much it work! Instead of "bounds", it is called box on my node.