Page Menu
Home
Search
Configure Global Search
Log In
Paste
P2291
generate_sample_data.py
Active
Public
Actions
Authored by
Campbell Barton (campbellbarton)
on Jul 27 2021, 8:36 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Tags
None
Subscribers
None
# This script generates sample data for benchmarking.
#
# - Uses spheres, duplicated and moved.
# - Joins & randomizes geometry (using a fixed seed)
# to avoid ordered in a way that could give misleading statistics.
#
# Example execution:
#
# ./bin/blender -b --python generate_sample_data.py
import
bpy
import
os
import
sys
# Generate an object that can be grabbed to force normals to be regenerated.
# (left selected for simple automated testing).
GENERATE_OBJECT_TO_TRANSFORM
=
True
OUT
=
"/d/perf_test_gen"
# Optionally pass in numbers to generate, se:
# ` -- 50` will only generate the 50th file.
argv
=
sys
.
argv
try
:
index
=
argv
.
index
(
"--"
)
+
1
except
ValueError
:
index
=
len
(
argv
)
argv
=
argv
[
index
:]
# Generate 200 files.
for
i
in
range
(
200
):
if
argv
and
str
(
i
)
not
in
argv
:
continue
segments
=
100
rings
=
100
total_copies
=
i
+
1
nr_expect
=
total_copies
*
(
segments
*
rings
)
filename
=
"{0:08_}"
.
format
(
nr_expect
)
+
".blend"
filepath
=
os
.
path
.
join
(
OUT
,
filename
)
print
(
filepath
)
if
os
.
path
.
exists
(
filepath
):
continue
bpy
.
ops
.
wm
.
read_homefile
(
load_ui
=
True
,
use_splash
=
False
,
use_factory_startup
=
True
,
use_empty
=
True
)
bpy
.
ops
.
object
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
mesh
.
primitive_uv_sphere_add
(
segments
=
segments
,
ring_count
=
rings
,
enter_editmode
=
False
)
for
i
in
range
(
total_copies
-
1
):
bpy
.
ops
.
object
.
duplicate_move_linked
(
OBJECT_OT_duplicate
=
{
"linked"
:
True
,
"mode"
:
'TRANSLATION'
},
TRANSFORM_OT_translate
=
{
"value"
:(
-
1
,
0
,
0
)}
)
bpy
.
ops
.
object
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
object
.
join
()
bpy
.
ops
.
object
.
editmode_toggle
()
bpy
.
ops
.
mesh
.
select_all
(
action
=
'SELECT'
)
bpy
.
ops
.
mesh
.
sort_elements
(
type
=
'RANDOMIZE'
,
elements
=
{
'VERT'
,
'EDGE'
,
'FACE'
})
bpy
.
ops
.
object
.
editmode_toggle
()
ob
=
bpy
.
context
.
active_object
nr
=
len
(
ob
.
data
.
polygons
)
assert
(
nr
==
nr_expect
)
if
GENERATE_OBJECT_TO_TRANSFORM
:
# Setup an object that transforms and modifies normals.
bpy
.
ops
.
object
.
modifier_add
(
type
=
'WAVE'
)
mod
=
ob
.
modifiers
[
0
]
bpy
.
ops
.
object
.
empty_add
()
ob_empty
=
bpy
.
context
.
active_object
mod
.
start_position_object
=
ob_empty
bpy
.
ops
.
wm
.
save_mainfile
(
filepath
=
filepath
)
Event Timeline
Campbell Barton (campbellbarton)
created this paste.
Jul 27 2021, 8:36 AM
Campbell Barton (campbellbarton)
mentioned this in
D11993: Mesh: optimize normal calculation
.
Campbell Barton (campbellbarton)
edited the content of this paste.
(Show Details)
Jul 27 2021, 8:59 AM
Campbell Barton (campbellbarton)
edited the content of this paste.
(Show Details)
Campbell Barton (campbellbarton)
edited the content of this paste.
(Show Details)
Log In to Comment