Открыть боковую панель
nikitronn
sverchok
Коммиты
e55f753b
Коммит
e55f753b
создал
Май 23, 2021
по автору
Ilya Portnov
Просмотр файлов
Voronoi on mesh / solid update.
Make it possible to specify spacing / inset per cell.
владелец
2c309df7
Изменения
3
Скрыть пробелы
Построчно
Рядом
nodes/spatial/voronoi_on_mesh.py
Просмотр файла @
e55f753b
...
...
@@ -24,7 +24,7 @@ import bmesh
from
mathutils
import
Vector
from
sverchok.node_tree
import
SverchCustomTreeNode
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
throttle_and_update_node
,
ensure_nesting_level
,
get_data_nesting_level
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
throttle_and_update_node
,
ensure_nesting_level
,
get_data_nesting_level
,
ensure_min_nesting
from
sverchok.utils.sv_bmesh_utils
import
recalc_normals
from
sverchok.utils.sv_mesh_utils
import
mesh_join
from
sverchok.utils.voronoi3d
import
voronoi_on_mesh
...
...
@@ -131,7 +131,7 @@ class SvVoronoiOnMeshNode(bpy.types.Node, SverchCustomTreeNode):
sites_in
=
ensure_nesting_level
(
sites_in
,
4
)
faces_in
=
ensure_nesting_level
(
faces_in
,
4
)
#thickness_in = ensure_nesting_level(thickness_in, 2)
spacing_in
=
ensure_nesting
_level
(
spacing_in
,
2
)
spacing_in
=
ensure_
min_
nesting
(
spacing_in
,
2
)
nested_output
=
input_level
>
3
...
...
nodes/spatial/voronoi_on_solid.py
Просмотр файла @
e55f753b
...
...
@@ -25,10 +25,10 @@ import bmesh
from
mathutils
import
Vector
from
sverchok.node_tree
import
SverchCustomTreeNode
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
throttle_and_update_node
,
ensure_nesting_level
,
get_data_nesting_level
from
sverchok.data_structure
import
updateNode
,
zip_long_repeat
,
throttle_and_update_node
,
ensure_nesting_level
,
get_data_nesting_level
,
ensure_min_nesting
,
repeat_last_for_length
from
sverchok.utils.sv_bmesh_utils
import
recalc_normals
from
sverchok.utils.voronoi3d
import
voronoi_on_solid
from
sverchok.utils.geom
import
scale_relative
,
center
from
sverchok.utils.geom
import
scale_relative
,
center
,
diameter
from
sverchok.utils.solid
import
BMESH
,
svmesh_to_solid
,
SvSolidTopology
,
SvGeneralFuse
from
sverchok.utils.surface.freecad
import
SvSolidFaceSurface
from
sverchok.utils.dummy_nodes
import
add_dummy
...
...
@@ -107,6 +107,23 @@ class SvVoronoiOnSolidNode(bpy.types.Node, SverchCustomTreeNode):
layout
.
prop
(
self
,
'scale_center'
)
layout
.
prop
(
self
,
'accuracy'
)
def
scale_cells
(
self
,
verts
,
sites
,
insets
,
precision
):
if
all
(
i
==
0.0
for
i
in
insets
):
return
verts
verts_out
=
[]
for
vs
,
site
,
inset
in
zip
(
verts
,
sites
,
insets
):
if
inset
>=
1.0
:
continue
if
self
.
scale_center
==
'SITE'
:
c
=
site
else
:
c
=
center
(
vs
)
vs1
=
scale_relative
(
vs
,
c
,
1.0
-
inset
)
if
diameter
(
vs1
,
axis
=
None
)
<=
precision
:
continue
verts_out
.
append
(
vs1
)
return
verts_out
def
process
(
self
):
if
not
any
(
socket
.
is_linked
for
socket
in
self
.
outputs
):
...
...
@@ -119,7 +136,7 @@ class SvVoronoiOnSolidNode(bpy.types.Node, SverchCustomTreeNode):
solid_in
=
ensure_nesting_level
(
solid_in
,
2
,
data_types
=
(
Part
.
Shape
,))
input_level
=
get_data_nesting_level
(
sites_in
)
sites_in
=
ensure_nesting_level
(
sites_in
,
4
)
inset_in
=
ensure_nesting
_level
(
inset_in
,
2
)
inset_in
=
ensure_
min_
nesting
(
inset_in
,
2
)
nested_output
=
input_level
>
3
need_inner
=
self
.
outputs
[
'InnerSolid'
].
is_linked
...
...
@@ -136,13 +153,11 @@ class SvVoronoiOnSolidNode(bpy.types.Node, SverchCustomTreeNode):
verts
,
edges
,
faces
=
voronoi_on_solid
(
solid
,
sites
,
do_clip
=
True
,
clipping
=
None
)
if
inset
!=
0.0
:
scale
=
1.0
-
inset
if
self
.
scale_center
==
'SITE'
:
verts
=
[
scale_relative
(
vs
,
site
,
scale
)
for
vs
,
site
in
zip
(
verts
,
sites
)]
else
:
verts
=
[
scale_relative
(
vs
,
center
(
vs
),
scale
)
for
vs
,
site
in
zip
(
verts
,
sites
)]
if
isinstance
(
inset
,
list
):
inset
=
repeat_last_for_length
(
inset
,
len
(
sites
))
else
:
inset
=
[
inset
for
i
in
range
(
len
(
sites
))]
verts
=
self
.
scale_cells
(
verts
,
sites
,
inset
,
precision
)
fragments
=
[
svmesh_to_solid
(
vs
,
fs
,
precision
,
method
=
BMESH
,
remove_splitter
=
False
)
for
vs
,
fs
in
zip
(
verts
,
faces
)]
if
self
.
mode
==
'SURFACE'
:
...
...
utils/voronoi3d.py
Просмотр файла @
e55f753b
...
...
@@ -25,6 +25,7 @@ import bmesh
from
mathutils
import
Vector
from
mathutils.bvhtree
import
BVHTree
from
sverchok.data_structure
import
repeat_last_for_length
from
sverchok.utils.sv_mesh_utils
import
mask_vertices
,
polygons_to_edges
,
point_inside_mesh
from
sverchok.utils.sv_bmesh_utils
import
bmesh_from_pydata
,
pydata_from_bmesh
,
bmesh_clip
from
sverchok.utils.geom
import
calc_bounds
,
bounding_sphere
,
PlaneEquation
...
...
@@ -248,7 +249,7 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, fill=T
result
[
site2_idx
].
append
(
plane
)
return
result
def
cut_cell
(
verts
,
faces
,
planes
,
site
):
def
cut_cell
(
verts
,
faces
,
planes
,
site
,
spacing
):
src_mesh
=
bmesh_from_pydata
(
verts
,
[],
faces
,
normal_update
=
True
)
n_cuts
=
0
for
plane
in
planes
:
...
...
@@ -297,8 +298,12 @@ def voronoi_on_mesh_bmesh(verts, faces, n_orig_sites, sites, spacing=0.0, fill=T
voronoi
=
Voronoi
(
np
.
array
(
sites
))
ridges_per_site
=
get_ridges_per_site
(
voronoi
)
if
isinstance
(
spacing
,
list
):
spacing
=
repeat_last_for_length
(
spacing
,
len
(
sites
))
else
:
spacing
=
[
spacing
for
i
in
range
(
len
(
sites
))]
for
site_idx
in
range
(
len
(
sites
)):
cell
=
cut_cell
(
verts
,
faces
,
ridges_per_site
[
site_idx
],
sites
[
site_idx
])
cell
=
cut_cell
(
verts
,
faces
,
ridges_per_site
[
site_idx
],
sites
[
site_idx
]
,
spacing
[
site_idx
]
)
if
cell
is
not
None
:
new_verts
,
new_edges
,
new_faces
=
cell
if
new_verts
:
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать