** * Blender version is 2.80 **
Some modeling in Blender can be catastrophically reduced in time using Python scripts. The work of arranging a large number of objects is the best. I will show you an example.
Arrange primitives (simple figures).
If you split the window and press Shift + F11
with the cursor on one side, it will be as follows.
Press "New" to create a new script.
Copy the following text.
import bpy
#reset objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
max = 20
for i in range(0,max):
for j in range(0,max):
bpy.ops.mesh.primitive_cone_add(
radius1=.7,
location=(i,j,0)
)
Click "Run Script" or enter ʻAlt + P`, and the following picture will be created.
You can specify the repeat width by playing with the value of max
. If it's about 20
, I think it's okay with most computers, but if it's 100
, it may freeze for a few minutes. radius1
specifies the radius of the bottom, and 0.7
specifies a value close to $ \ frac {1} {\ sqrt {2}} $ so that the bottoms of each other barely touch each other. To do.
import bpy
import math
#reset objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
max = 20
for i in range(0,max):
for j in range(0,max):
height = 2+math.sin(i+j)
bpy.ops.mesh.primitive_cone_add(
radius1=.7,
location=(i,j,height/2),
depth = height)
Add variation to the height of the cone. Use trigonometric functions to change the height periodically. Since the height of the bottom does not match unless half of the height is specified by depth
to the z position, depth = height
and location = (i, j, height / 2)
are used. I will.
import bpy
#reset objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
max = 5
for i in range(-max,max):
for j in range(-max,max):
for k in range(-max,max):
bpy.ops.mesh.primitive_cone_add(
location=(i*4,j*4,k*4)
)
Feel the universe. The range of iterations is from 0
<max
to -max
<max
for the convenience of future calculations.
import bpy
import numpy
#reset objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
max = 5
for i in range(-max,max):
for j in range(-max,max):
for k in range(-max,max):
bpy.ops.mesh.primitive_cone_add(
location=(i*4,j*4,k*4),
rotation=numpy.random.rand(3)*3,
)
A random number is specified for rotation
. This is beautiful with this.
import bpy
import math
#reset objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(True)
max = 5
for i in range(-max,max):
for j in range(-max,max):
for k in range(-max,max):
dist = math.sqrt(i*i+j*j)
zx = math.atan2(j,i)
zy = -math.pi/2-math.atan2(k,dist)
bpy.ops.mesh.primitive_cone_add(
location=(i*8,j*8,k*8),
depth=dist*2,
rotation=(0,zy,zx)
)
All cones are centered.
$ \ tan ^ {-1} (\ frac {j} {i}) $ for longitude, $ \ tan ^ {-1} (\ frac {k} {\ sqrt {i ^ 2 + j ^ 2}}) The latitude is calculated by $. The depth
is also adjusted to create a feeling of being toward the center.
Since it is boring if it is only primitives, I will copy and arrange arbitrary objects. We will do it by arranging and selecting the one that will be the copy source, and copying it earnestly.
This is,
Like this.
import bpy
import numpy
for i in range(0,500):
bpy.ops.object.duplicate()
bpy.context.object.location = numpy.random.rand(3)*40-20
bpy.context.object.rotation_euler = numpy.random.rand(3)*3
If you want to make further changes to the figure, you can prepare fbx, obj, or ply in advance and import a large amount of them. Just before We have generated a large number of human body models, so let's import them all at once and arrange them. It is necessary to prepare a large number of files in a specific folder in advance and prepare them so that they can be processed collectively by serial number.
Is it Neo Exdes?
import bpy
import numpy
#Enter the file path (up to just before the serial number) here
dir = r'~~~'
for i in range(0,500):
#Specify the serial number and extension (obj with this code)
path = dir + str(i) + '.obj'
bpy.ops.import_scene.obj(filepath=path)
for i in range(0,500):
bpy.data.objects[i].location = numpy.random.rand(3)*20-10
Recommended Posts