Открыть боковую панель
Городецкий Никита Сергеевич
sverchok
Коммиты
3e54d5a0
Коммит
3e54d5a0
создал
Дек 30, 2024
по автору
satabol
Просмотр файлов
- add socket Voronoi Sites Matrix
- move old version of Voronoi on Mesh MK4 into old nodes
владелец
1a603c67
Изменения
6
Развернуть все
Скрыть пробелы
Построчно
Рядом
index.yaml
Просмотр файла @
3e54d5a0
...
@@ -320,7 +320,7 @@
...
@@ -320,7 +320,7 @@
-
SvExVoronoi3DNode
-
SvExVoronoi3DNode
-
SvExVoronoiSphereNode
-
SvExVoronoiSphereNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnMeshNodeMK
4
-
SvVoronoiOnMeshNodeMK
5
-
SvVoronoiOnSolidNodeMK2
-
SvVoronoiOnSolidNodeMK2
-
---
-
---
-
SvLloyd2dNode
-
SvLloyd2dNode
...
...
menus/full_by_data_type.yaml
Просмотр файла @
3e54d5a0
...
@@ -519,7 +519,7 @@
...
@@ -519,7 +519,7 @@
-
SvExVoronoi3DNode
-
SvExVoronoi3DNode
-
SvExVoronoiSphereNode
-
SvExVoronoiSphereNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnMeshNodeMK
4
-
SvVoronoiOnMeshNodeMK
5
-
SvVoronoiOnSolidNodeMK2
-
SvVoronoiOnSolidNodeMK2
-
---
-
---
-
SvLloyd2dNode
-
SvLloyd2dNode
...
...
menus/full_nortikin.yaml
Просмотр файла @
3e54d5a0
...
@@ -388,7 +388,7 @@
...
@@ -388,7 +388,7 @@
-
SvExVoronoi3DNode
-
SvExVoronoi3DNode
-
SvExVoronoiSphereNode
-
SvExVoronoiSphereNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnSurfaceNode
-
SvVoronoiOnMeshNodeMK
4
-
SvVoronoiOnMeshNodeMK
5
-
SvVoronoiOnSolidNodeMK2
-
SvVoronoiOnSolidNodeMK2
-
---
-
---
-
SvLloyd2dNode
-
SvLloyd2dNode
...
...
nodes/spatial/voronoi_on_mesh.py
Просмотр файла @
3e54d5a0
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
import
bpy
import
bpy
from
bpy.props
import
FloatProperty
,
EnumProperty
,
BoolProperty
,
IntProperty
from
bpy.props
import
FloatProperty
,
EnumProperty
,
BoolProperty
,
IntProperty
from
mathutils
import
Matrix
from
sverchok.node_tree
import
SverchCustomTreeNode
from
sverchok.node_tree
import
SverchCustomTreeNode
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
ensure_nesting_level
,
get_data_nesting_level
,
ensure_min_nesting
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
ensure_nesting_level
,
get_data_nesting_level
,
ensure_min_nesting
...
@@ -28,12 +29,12 @@ from sverchok.utils.voronoi3d import voronoi_on_mesh
...
@@ -28,12 +29,12 @@ from sverchok.utils.voronoi3d import voronoi_on_mesh
import
numpy
as
np
import
numpy
as
np
class
SvVoronoiOnMeshNodeMK
4
(
SverchCustomTreeNode
,
bpy
.
types
.
Node
):
class
SvVoronoiOnMeshNodeMK
5
(
SverchCustomTreeNode
,
bpy
.
types
.
Node
):
"""
"""
Triggers: Voronoi Mesh
Triggers: Voronoi Mesh
Tooltip: Generate Voronoi diagram on the surface of a mesh object
Tooltip: Generate Voronoi diagram on the surface of a mesh object
"""
"""
bl_idname
=
'SvVoronoiOnMeshNodeMK
4
'
bl_idname
=
'SvVoronoiOnMeshNodeMK
5
'
bl_label
=
'Voronoi on Mesh'
bl_label
=
'Voronoi on Mesh'
bl_icon
=
'OUTLINER_OB_EMPTY'
bl_icon
=
'OUTLINER_OB_EMPTY'
sv_icon
=
'SV_VORONOI'
sv_icon
=
'SV_VORONOI'
...
@@ -70,9 +71,9 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -70,9 +71,9 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
update
=
update_sockets
)
# type: ignore
update
=
update_sockets
)
# type: ignore
join_modes
=
[
join_modes
=
[
(
'FLAT'
,
"S
eparate All Meshes
"
,
"Post processing: Separate the result meshes into individual meshes"
,
custom_icon
(
"SV_VOM_SEPARATE_ALL_MESHES"
)
,
0
),
(
'FLAT'
,
"S
plit
"
,
"Post processing: Separate the result meshes into individual meshes"
,
'SNAP_VERTEX'
,
0
),
(
'SEPARATE'
,
"Keep
Source Meshes
"
,
"Post processing: Keep parts of the source meshes as source meshes."
,
custom_icon
(
"SV_VOM_KEEP_SOURCE_MESHES"
)
,
1
),
(
'SEPARATE'
,
"Keep"
,
"Post processing: Keep parts of the source meshes as source meshes."
,
'SYNTAX_ON'
,
1
),
(
'JOIN'
,
"
Join All Meshes
"
,
"Post processing: Join all results meshes into a single mesh"
,
custom_icon
(
"SV_VOM_JOIN_ALL_MESHES"
)
,
2
)
(
'JOIN'
,
"
Merge
"
,
"Post processing: Join all results meshes into a single mesh"
,
'STICKY_UVS_LOC'
,
2
)
]
]
join_mode
:
EnumProperty
(
join_mode
:
EnumProperty
(
...
@@ -147,6 +148,7 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -147,6 +148,7 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
self
.
inputs
.
new
(
'SvVerticesSocket'
,
'voronoi_sites'
).
label
=
'Voronoi Sites'
self
.
inputs
.
new
(
'SvVerticesSocket'
,
'voronoi_sites'
).
label
=
'Voronoi Sites'
self
.
inputs
.
new
(
'SvStringsSocket'
,
'voronoi_sites_mask'
).
label
=
"Mask of Voronoi Sites"
self
.
inputs
.
new
(
'SvStringsSocket'
,
'voronoi_sites_mask'
).
label
=
"Mask of Voronoi Sites"
self
.
inputs
.
new
(
'SvStringsSocket'
,
'spacing'
).
prop_name
=
'spacing'
self
.
inputs
.
new
(
'SvStringsSocket'
,
'spacing'
).
prop_name
=
'spacing'
self
.
inputs
.
new
(
'SvMatrixSocket'
,
'voronoi_matrix_sites'
).
label
=
'Voronoi Sites Matrix'
self
.
inputs
[
'voronoi_sites_mask'
].
custom_draw
=
'draw_voronoi_sites_mask_in_socket'
self
.
inputs
[
'voronoi_sites_mask'
].
custom_draw
=
'draw_voronoi_sites_mask_in_socket'
...
@@ -183,6 +185,9 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -183,6 +185,9 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
verts_in
=
self
.
inputs
[
'vertices'
].
sv_get
(
deepcopy
=
False
)
verts_in
=
self
.
inputs
[
'vertices'
].
sv_get
(
deepcopy
=
False
)
faces_in
=
self
.
inputs
[
'polygons'
].
sv_get
(
deepcopy
=
False
)
faces_in
=
self
.
inputs
[
'polygons'
].
sv_get
(
deepcopy
=
False
)
sites_in
=
self
.
inputs
[
'voronoi_sites'
].
sv_get
(
deepcopy
=
False
)
sites_in
=
self
.
inputs
[
'voronoi_sites'
].
sv_get
(
deepcopy
=
False
)
voronoi_matrix_sites_in
=
self
.
inputs
[
'voronoi_matrix_sites'
].
sv_get
(
default
=
[
Matrix
().
Identity
(
4
)],
deepcopy
=
False
)
if
(
get_data_nesting_level
(
voronoi_matrix_sites_in
,
search_first_data
=
True
)
!=
2
):
voronoi_matrix_sites_in
=
ensure_nesting_level
(
voronoi_matrix_sites_in
,
2
)
mask_in
=
self
.
inputs
[
'voronoi_sites_mask'
]
#.sv_get(deepcopy=False)
mask_in
=
self
.
inputs
[
'voronoi_sites_mask'
]
#.sv_get(deepcopy=False)
if
mask_in
.
is_linked
==
False
:
if
mask_in
.
is_linked
==
False
:
...
@@ -209,7 +214,7 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -209,7 +214,7 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
sites_idx_out
=
[]
sites_idx_out
=
[]
sites_verts_out
=
[]
sites_verts_out
=
[]
for
verts
,
faces
,
sites
,
spacing
,
mask
in
zip_long_repeat
(
verts_in
,
faces_in
,
sites_in
,
spacing_in
,
mask_in
):
for
verts
,
faces
,
sites
,
spacing
,
mask
,
sites_matrixes
in
zip_long_repeat
(
verts_in
,
faces_in
,
sites_in
,
spacing_in
,
mask_in
,
voronoi_matrix_sites_in
):
# if mask is zero or not connected then do not mask any. Except of inversion,
# if mask is zero or not connected then do not mask any. Except of inversion,
if
not
mask
:
if
not
mask
:
np_mask
=
np
.
ones
(
len
(
sites
),
dtype
=
bool
)
np_mask
=
np
.
ones
(
len
(
sites
),
dtype
=
bool
)
...
@@ -245,7 +250,8 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -245,7 +250,8 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
mode
=
self
.
mode
,
mode
=
self
.
mode
,
normal_update
=
self
.
normals
,
normal_update
=
self
.
normals
,
precision
=
precision
,
precision
=
precision
,
mask
=
mask
mask
=
mask
,
sites_matrixes
=
sites_matrixes
)
)
# collect sites_idx and used_sites_verts independently of self.join_mode
# collect sites_idx and used_sites_verts independently of self.join_mode
...
@@ -274,5 +280,5 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
...
@@ -274,5 +280,5 @@ class SvVoronoiOnMeshNodeMK4(SverchCustomTreeNode, bpy.types.Node):
self
.
outputs
[
'sites_idx'
].
sv_set
(
sites_idx_out
)
self
.
outputs
[
'sites_idx'
].
sv_set
(
sites_idx_out
)
self
.
outputs
[
'sites_verts'
].
sv_set
(
sites_verts_out
)
self
.
outputs
[
'sites_verts'
].
sv_set
(
sites_verts_out
)
classes
=
[
SvVoronoiOnMeshNodeMK
4
]
classes
=
[
SvVoronoiOnMeshNodeMK
5
]
register
,
unregister
=
bpy
.
utils
.
register_classes_factory
(
classes
)
register
,
unregister
=
bpy
.
utils
.
register_classes_factory
(
classes
)
\ No newline at end of file
old_nodes/voronoi_on_mesh_mk4.py
0 → 100644
Просмотр файла @
3e54d5a0
Это отличие свёрнуто
Нажмите, чтобы развернуть
utils/voronoi3d.py
Просмотр файла @
3e54d5a0
...
@@ -24,7 +24,7 @@ import datetime
...
@@ -24,7 +24,7 @@ import datetime
import
bpy
import
bpy
import
bmesh
import
bmesh
import
random
import
random
from
mathutils
import
Vector
from
mathutils
import
Vector
,
Matrix
from
mathutils.bvhtree
import
BVHTree
from
mathutils.bvhtree
import
BVHTree
from
sverchok.data_structure
import
repeat_last_for_length
from
sverchok.data_structure
import
repeat_last_for_length
...
@@ -237,7 +237,7 @@ def calc_bvh_projections(bvh, sites):
...
@@ -237,7 +237,7 @@ def calc_bvh_projections(bvh, sites):
return
np
.
array
(
projections
)
return
np
.
array
(
projections
)
# see additional info https://github.com/nortikin/sverchok/pull/4948
# see additional info https://github.com/nortikin/sverchok/pull/4948
def
voronoi_on_mesh_bmesh
(
verts
,
faces
,
n_orig_sites
,
sites
,
spacing
=
0.0
,
mode
=
'VOLUME'
,
normal_update
=
False
,
precision
=
1e-8
,
mask
=
[]):
def
voronoi_on_mesh_bmesh
(
verts
,
faces
,
n_orig_sites
,
sites
,
spacing
=
0.0
,
mode
=
'VOLUME'
,
normal_update
=
False
,
precision
=
1e-8
,
mask
=
[]
,
sites_matrixes
=
None
):
def
get_sites_delaunay_params
(
delaunay
,
n_orig_sites
):
def
get_sites_delaunay_params
(
delaunay
,
n_orig_sites
):
result
=
defaultdict
(
list
)
result
=
defaultdict
(
list
)
...
@@ -272,7 +272,7 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
...
@@ -272,7 +272,7 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
num_bisect
=
0
# general count of bisect for full cutting process
num_bisect
=
0
# general count of bisect for full cutting process
num_unpredicted_erased
=
0
# if optimisation can not find a skip bisect case (with using bounding box) then counter incremented
num_unpredicted_erased
=
0
# if optimisation can not find a skip bisect case (with using bounding box) then counter incremented
def
cut_cell
(
start_mesh
,
sites_delaunay_params
,
site_idx
,
spacing
,
center_of_mass
,
bbox_aligned
):
def
cut_cell
(
start_mesh
,
site_matrix
,
sites_delaunay_params
,
site_idx
,
spacing
,
center_of_mass
,
bbox_aligned
):
nonlocal
num_bisect
,
num_unpredicted_erased
nonlocal
num_bisect
,
num_unpredicted_erased
src_mesh
=
None
src_mesh
=
None
# Check ridges for sites before bisect. If no ridges then no bisect and no mesh in result
# Check ridges for sites before bisect. If no ridges then no bisect and no mesh in result
...
@@ -327,6 +327,9 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
...
@@ -327,6 +327,9 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
lst_ridges_to_bisect
.
sort
()
# less dist gets more points to cut off (with negative dists to. Negative dist is a negative side of bisect plane)
lst_ridges_to_bisect
.
sort
()
# less dist gets more points to cut off (with negative dists to. Negative dist is a negative side of bisect plane)
src_mesh
=
start_mesh
.
copy
()
# do not need create src_mesh until here.
src_mesh
=
start_mesh
.
copy
()
# do not need create src_mesh until here.
if
site_matrix
is
not
None
:
src_mesh
.
transform
(
site_matrix
)
pass
# A main bisection process of site_idx
# A main bisection process of site_idx
for
i
in
range
(
len
(
lst_ridges_to_bisect
)):
for
i
in
range
(
len
(
lst_ridges_to_bisect
)):
...
@@ -455,7 +458,10 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
...
@@ -455,7 +458,10 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, mode='
start_mesh
=
bmesh_from_pydata
(
verts
,
[],
faces
,
normal_update
=
False
)
start_mesh
=
bmesh_from_pydata
(
verts
,
[],
faces
,
normal_update
=
False
)
for
site_idx
in
range
(
len
(
sites
)):
for
site_idx
in
range
(
len
(
sites
)):
if
(
mask
[
site_idx
]):
if
(
mask
[
site_idx
]):
cell
=
cut_cell
(
start_mesh
,
sites_delaunay_params
,
site_idx
,
spacing
[
site_idx
],
center_of_mass
,
bbox_aligned
)
sites_matrix_idx
=
None
if
sites_matrixes
is
not
None
and
site_idx
<=
len
(
sites_matrixes
)
-
1
:
sites_matrix_idx
=
sites_matrixes
[
site_idx
]
cell
=
cut_cell
(
start_mesh
,
sites_matrix_idx
,
sites_delaunay_params
,
site_idx
,
spacing
[
site_idx
],
center_of_mass
,
bbox_aligned
)
if
cell
is
not
None
:
if
cell
is
not
None
:
new_verts
,
new_edges
,
new_faces
=
cell
new_verts
,
new_edges
,
new_faces
=
cell
if
new_verts
:
if
new_verts
:
...
@@ -489,7 +495,8 @@ def voronoi_on_mesh(verts, faces, sites, thickness,
...
@@ -489,7 +495,8 @@ def voronoi_on_mesh(verts, faces, sites, thickness,
clip_inner
=
True
,
clip_outer
=
True
,
do_clip
=
True
,
clip_inner
=
True
,
clip_outer
=
True
,
do_clip
=
True
,
clipping
=
1.0
,
mode
=
'REGIONS'
,
normal_update
=
False
,
clipping
=
1.0
,
mode
=
'REGIONS'
,
normal_update
=
False
,
precision
=
1e-8
,
precision
=
1e-8
,
mask
=
[]
mask
=
[],
sites_matrixes
=
None
):
):
bvh
=
BVHTree
.
FromPolygons
(
verts
,
faces
)
bvh
=
BVHTree
.
FromPolygons
(
verts
,
faces
)
...
@@ -521,7 +528,7 @@ def voronoi_on_mesh(verts, faces, sites, thickness,
...
@@ -521,7 +528,7 @@ def voronoi_on_mesh(verts, faces, sites, thickness,
all_points
=
[
site
for
site
in
sites
if
site
]
all_points
=
[
site
for
site
in
sites
if
site
]
verts
,
edges
,
faces
,
used_sites_idx
,
used_sites_verts
=
voronoi_on_mesh_bmesh
(
verts
,
faces
,
len
(
sites
),
all_points
,
verts
,
edges
,
faces
,
used_sites_idx
,
used_sites_verts
=
voronoi_on_mesh_bmesh
(
verts
,
faces
,
len
(
sites
),
all_points
,
spacing
=
spacing
,
mode
=
mode
,
normal_update
=
normal_update
,
spacing
=
spacing
,
mode
=
mode
,
normal_update
=
normal_update
,
precision
=
precision
,
mask
=
mask
)
precision
=
precision
,
mask
=
mask
,
sites_matrixes
=
sites_matrixes
)
return
verts
,
edges
,
faces
,
used_sites_idx
,
used_sites_verts
return
verts
,
edges
,
faces
,
used_sites_idx
,
used_sites_verts
def
project_solid_normals
(
shell
,
pts
,
thickness
,
add_plus
=
True
,
add_minus
=
True
,
predicate_plus
=
None
,
predicate_minus
=
None
):
def
project_solid_normals
(
shell
,
pts
,
thickness
,
add_plus
=
True
,
add_minus
=
True
,
predicate_plus
=
None
,
predicate_minus
=
None
):
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать