Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
avvy
content-processor
Commits
fadb9273
Commit
fadb9273
authored
1 month ago
by
Vlad Gaydukov
Browse files
Options
Download
Email Patches
Plain Diff
AL-15501 - обновлен алгоритм рассчета ячеек
parent
8f36fb76
main
No related merge requests found
Pipeline
#18519
passed with stages
in 5 minutes and 56 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
blender/block_cells.py
+18
-6
blender/block_cells.py
blender/lod_execute.py
+33
-22
blender/lod_execute.py
with
51 additions
and
28 deletions
+51
-28
blender/block_cells.py
View file @
fadb9273
...
...
@@ -14,6 +14,10 @@ import numpy
import
uuid
import
math
from
celery.utils.log
import
get_task_logger
logger
=
get_task_logger
(
__name__
)
CELL_SIZE
=
10
NON_MANIFOLD_SHARE
=
0.001
# how many vertices should be manifold in order to consider it watertight
...
...
@@ -188,7 +192,7 @@ class BlockCellCreator:
def
_remove_duplicated_vertices
(
self
,
mesh
):
remove_duplicated_geometry
(
mesh
)
def
calculate_block_cells
(
self
,
mesh_obj
):
def
calculate_block_cells
(
self
,
mesh_obj
,
cells_cache
=
[]
):
bb_min
,
bb_max
=
self
.
bound_box_coords
(
mesh_obj
)
pos
=
(
bb_max
-
bb_min
)
/
2
...
...
@@ -227,9 +231,10 @@ class BlockCellCreator:
block_cells
=
self
.
cells_matrix_to_coord_list
(
start_position
=
bb_min
,
cells_contour
=
cells_contour
,
cell_size
=
self
.
cell_size
)
cell_size
=
self
.
cell_size
,
cells_cache
=
cells_cache
)
block_cells
=
self
.
_guarantee_at_least_one_cell
(
block_cells
,
pos
)
#
block_cells = self._guarantee_at_least_one_cell(block_cells, pos)
return
block_cells
...
...
@@ -260,8 +265,12 @@ class BlockCellCreator:
cells_contour
[
indexes_i
]
=
1
@
staticmethod
def
cells_matrix_to_coord_list
(
start_position
,
cells_contour
,
cell_size
):
block_cells
=
[]
def
cells_matrix_to_coord_list
(
start_position
,
cells_contour
,
cell_size
,
cells_cache
=
[]):
block_cells
=
{
"unique"
:
[],
"all"
:
[]
}
it
=
numpy
.
nditer
(
cells_contour
,
flags
=
[
'multi_index'
])
for
is_cell
in
it
:
...
...
@@ -270,8 +279,11 @@ class BlockCellCreator:
x
=
int
(
round
(
start_position
.
x
+
(
idx
*
cell_size
)))
z
=
-
int
(
round
(
start_position
.
y
+
(
idy
*
cell_size
)))
y
=
int
(
round
(
start_position
.
z
+
(
idz
*
cell_size
)))
cell
=
[
x
,
y
,
z
]
block_cells
.
append
([
x
,
y
,
z
])
block_cells
[
"all"
].
append
(
cell
)
if
cell
not
in
cells_cache
:
block_cells
[
"unique"
].
append
(
cell
)
return
block_cells
...
...
This diff is collapsed.
Click to expand it.
blender/lod_execute.py
View file @
fadb9273
import
bpy
,
os
,
sys
,
re
,
math
,
uuid
,
bmesh
import
blender.block_cells
as
bc
from
celery.utils.log
import
get_task_logger
logger
=
get_task_logger
(
__name__
)
sign
=
lambda
x
:
math
.
copysign
(
1
,
x
)
# two will work
...
...
@@ -52,7 +55,7 @@ def _import(infile):
# process_cells(infile)
print
(
"Importing %s "
%
(
ext
))
logger
.
info
(
"Importing %s "
%
(
ext
))
if
ext
.
startswith
(
"."
):
ext
=
ext
[
1
:]
...
...
@@ -70,18 +73,18 @@ def _import(infile):
axis_up
=
"Z"
)
elif
ext
==
'dae'
:
print
(
"Importing COLLADA"
)
logger
.
info
(
"Importing COLLADA"
)
# import a collada model
bpy
.
ops
.
wm
.
collada_import
(
filepath
=
infile
)
elif
ext
==
'fbx'
:
print
(
"Importing FBX"
)
logger
.
info
(
"Importing FBX"
)
# import a collada model
bpy
.
ops
.
import_scene
.
fbx
(
filepath
=
infile
)
elif
ext
in
[
'glb'
,
'gltf'
]:
print
(
"Importing GLTF"
)
logger
.
info
(
"Importing GLTF"
)
# import a collada model
bpy
.
ops
.
import_scene
.
gltf
(
filepath
=
infile
)
...
...
@@ -362,15 +365,17 @@ def process_mesh(infile, outfile):
remove_doubles
()
creator
=
bc
.
BlockCellCreator
(
cell_size
=
bc
.
CELL_SIZE
,
non_manifold_share
=
bc
.
NON_MANIFOLD_SHARE
,
divider_in_watertight
=
bc
.
DIVIDER_IN_WATERTIGHT
,
divider_in_nonwatertight
=
bc
.
DIVIDER_IN_NONWATERTIGHT
,
divider_out_watertight
=
bc
.
DIVIDER_OUT_WATERTIGHT
)
def
process
(
ob
,
level
,
counter
):
copy
=
copy_ob
(
ob
,
parent
,
counter
)
creator
=
bc
.
BlockCellCreator
(
cell_size
=
bc
.
CELL_SIZE
,
non_manifold_share
=
bc
.
NON_MANIFOLD_SHARE
,
divider_in_watertight
=
bc
.
DIVIDER_IN_WATERTIGHT
,
divider_in_nonwatertight
=
bc
.
DIVIDER_IN_NONWATERTIGHT
,
divider_out_watertight
=
bc
.
DIVIDER_OUT_WATERTIGHT
)
bpy
.
ops
.
object
.
select_all
(
action
=
'DESELECT'
)
_copy
=
copy_ob
(
ob
,
parent
)
...
...
@@ -386,9 +391,9 @@ def process_mesh(infile, outfile):
bpy
.
ops
.
object
.
select_all
(
action
=
'DESELECT'
)
copy
.
parent
=
None
if
counter
==
0
:
copy
[
"cells"
]
=
block_cells
copy
[
"cells"
]
=
block_cells
[
"unique"
]
ratio
=
calculate_ratio
(
copy
,
level
,
len
(
block_cells
))
ratio
=
calculate_ratio
(
copy
,
level
,
len
(
block_cells
[
"all"
]
or
1
))
if
ratio
==
None
:
return
copy
...
...
@@ -487,27 +492,33 @@ def process_view(infile, outfile, params):
pivot
=
params
.
get
(
'pivot'
,
0
)
apply
=
params
.
get
(
'apply'
,
True
)
creator
=
bc
.
BlockCellCreator
(
cell_size
=
bc
.
CELL_SIZE
,
non_manifold_share
=
bc
.
NON_MANIFOLD_SHARE
,
divider_in_watertight
=
bc
.
DIVIDER_IN_WATERTIGHT
,
divider_in_nonwatertight
=
bc
.
DIVIDER_IN_NONWATERTIGHT
,
divider_out_watertight
=
bc
.
DIVIDER_OUT_WATERTIGHT
)
_import
(
infile
)
apply_transform
()
remove_doubles
()
def
process
(
ob
,
root_parent
,
level
,
counter
):
def
recurse
(
ob
,
parent
,
root_parent
):
cells_cache
=
[]
def
recurse
(
ob
,
parent
,
root_parent
):
copy
=
copy_ob
(
ob
,
parent
,
counter
)
if
copy
.
type
==
"MESH"
:
creator
=
bc
.
BlockCellCreator
(
cell_size
=
bc
.
CELL_SIZE
,
non_manifold_share
=
bc
.
NON_MANIFOLD_SHARE
,
divider_in_watertight
=
bc
.
DIVIDER_IN_WATERTIGHT
,
divider_in_nonwatertight
=
bc
.
DIVIDER_IN_NONWATERTIGHT
,
divider_out_watertight
=
bc
.
DIVIDER_OUT_WATERTIGHT
)
block_cells
=
creator
.
calculate_block_cells
(
copy
)
block_cells
=
creator
.
calculate_block_cells
(
copy
,
cells_cache
)
cells_cache
.
extend
(
block_cells
[
"unique"
])
if
counter
==
0
:
copy
[
"cells"
]
=
block_cells
copy
.
data
[
"cells"
]
=
block_cells
copy
[
"cells"
]
=
block_cells
[
"unique"
]
copy
.
data
[
"cells"
]
=
block_cells
[
"unique"
]
ratio
=
calculate_ratio
(
copy
,
level
,
len
(
block_cells
))
ratio
=
calculate_ratio
(
copy
,
level
,
len
(
block_cells
[
"all"
]
or
1
))
if
ratio
==
None
:
return
copy
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help