Use blender python
・ Non-information system ・ I have never messed with the 3D model ・ Of course, blender is almost the first time
It's easy because you can do this!
Make a 3D version of the above "Sierpinski Gasket"
I think that the screen of blender is divided into several, but you can execute it interactively by selecting "python console" from the switching among them.
However, there are many things that cannot be done with this, so if you select "Text Editor" as a recommendation, you will see something like the one below! Press the "New" button below here. That's all you need to do.
There are various notations, but it's basically easy. Let's take a look at the whole thing first.
import bpy
from math import sqrt
def duplicate_object_rename(arg_objectname='Default', arg_dupname='', position=(0,0,0)):
for ob in bpy.context.scene.objects:
ob.select=False
selectob=bpy.context.scene.objects[arg_objectname]
#bpy.context.scene.objects.active = selectob
selectob.select=True
bpy.ops.object.duplicate_move(
OBJECT_OT_duplicate=None, TRANSFORM_OT_translate=None)
# move object
bpy.ops.transform.translate(value=position)
selectob.select=False
if len(arg_dupname) > 0:
duplicated_objectname=arg_objectname + ".001"
duplicatedob=bpy.data.objects[duplicated_objectname]
duplicatedob.name=arg_dupname
return
scale = 0.01
bpy.ops.mesh.primitive_cone_add(vertices=3,radius1=1*scale,depth=sqrt(2)*scale,location=(scale*sqrt(3)*(.5+.5*1+1),scale*1.5*(1+3*1)/3,scale*sqrt(2)/2),rotation=(0,0,0))
duplicate_object_rename(arg_objectname='Cone', arg_dupname='Duplicate1',position=(scale*sqrt(3),0,0))
duplicate_object_rename(arg_objectname='Cone', arg_dupname='Duplicate2',position=(scale*sqrt(3)/2,scale*1.5,0))
duplicate_object_rename(arg_objectname='Cone', arg_dupname='Duplicate3',position=(scale*sqrt(3)/2,scale*1/2,scale*sqrt(2)))
bpy.ops.object.select_by_type(type = 'MESH')
bpy.ops.object.join()
namehead = 'Duplicate'
for i in range(1,7):
namebufprev = namehead + str(i)
namebuf = namehead + str(i+1)
duplicate_object_rename(arg_objectname=namebufprev, arg_dupname=namebuf,position=(scale*sqrt(3)*2*2**(i-1),0,0))
duplicate_object_rename(arg_objectname=namebufprev, arg_dupname='buf2',position=(scale*sqrt(3)*2**(i-1),scale*3*2**(i-1),0))
duplicate_object_rename(arg_objectname=namebufprev, arg_dupname='buf3',position=(scale*sqrt(3)*2**(i-1),scale*2**(i-1),scale*2*sqrt(2)*2**(i-1)))
bpy.ops.object.select_by_type(type = 'MESH'))
bpy.ops.object.join()
bpy.ops.object.origin_set(type = 'ORIGIN_GEOMETRY', center = 'MEDIAN')
I will explain in order
import bpy
from math import sqrt
I'm importing a module called bpy here, which is a blender function. These are installed from the beginning without using pip, so let's import without thinking about anything. Other basic modules are included from the beginning. Here, I'm importing math because I had to take the square root to find the position of the center of gravity of the triangle. It does not include pandas etc. You can do it if you want to install it yourself, but we won't cover it here.
And how do you do it? I think it will be a story, but in fact the answer is already prepared. When I play with blender, the code pops up, and this is the method corresponding to that operation. For example
bpy.ops.mesh.primitive_cone_add(vertices=3,radius1=1*scale,depth=sqrt(2)*scale,location=(scale*sqrt(3)*(.5+.5*1+1),scale*1.5*(1+3*1)/3,scale*sqrt(2)/2),rotation=(0,0,0))
But this is equivalent to the cone of a primitive shape. You can understand it only by the pop-up, so I will try to make it partially by myself → I think that it will be a flow of automation. Therefore, those who can freely manipulate blender will not be so difficult, and those who do not will be caught in the operation rather than the coding.
This is almost no substitute for ordinary python. To put it bluntly, it's hard to tell what's wrong with debugging, so be patient. It consumes memory unexpectedly, so if you don't write it well, the operation tends to be slow. Even though I am using a proper PC this time, it is not output immediately, but it is output after one beat.
After that, just output fbx and plunge into unity, but before that, be careful When using vci, it seems that if the number of subitems is too large, it will suddenly become heavy, and in my environment, if I put in 800, it will be a mess. And the number of objects in fractals increases rapidly just by touching the floor. (This time it's on the 7th floor, but if you don't put it together, the virtual cast will drop ...) So it's better to put the created objects together at the end. To put together
bpy.ops.object.select_by_type(type = 'MESH')
bpy.ops.object.join()
Etc. would be convenient. Even if the size is heavy, the operation is not so slow because it is heavy to load, but the operation becomes heavy when the number of objects is large, and in some cases the seed online upload is rejected. The error message at that time was "chunk size is too large".
I brought it to the VR world with this
If you learn how to do it
Like this
Because this is
This article is almost like this second decoction You're doing a 3D version of Koch's snowflake here. https://qiita.com/hoji1107/items/99b2b669225d05990b5b I studied while modifying this code.
Click here for an explanation of the fractal itself https://ja.wikipedia.org/wiki/%E3%83%95%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%AB
Is the English version better for Sierpinski Gasket? https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle
Recommended Posts