Easy modeling with Blender and Python

Preface

Blender is free and has so many features that it's often said to be a first-time killer ~~ It's a great software for modeling! However, I don't know what to do to model using many functions suddenly ...

Therefore!

This time, I will model using only one function.

that is…

** "I can write Python" ** feature! This time I'm going to do various things with this. ~~ I'm crazy ~~

Environmental setting

I will explain it briefly here. image.png

It's easy, isn't it?

Ah installation is here. https://www.blender.org/

Then I will make various things from here

The one that comes out when you start the PlayStation 2

Some people may wonder what it is ... image.png It's like this

import bpy
import random

for i in range(30):
    for j in range(30):
        bpy.ops.mesh.primitive_cube_add(location=(i-15,j-15,0),scale=(1,1,random.randint(1,10)))

I feel like this image.png

Certain 〇 ring

image.png Let's make donuts like the one above

import bpy
import math

for i in range(8):
    bpy.ops.mesh.primitive_uv_sphere_add(location=(2*math.cos(math.pi*i/4),2*math.sin(math.pi*i/4),0))

Substituting cos and sin for the x and y coordinates of location = (x coordinate, y coordinate, z coordinate). In short, it means that eight spheres are arranged at equal intervals on the circumference. With this, a certain ring is completed. image.png

Graph (line)

Now let's make a graph.

import bpy
import math

for i in range(180):
    bpy.ops.mesh.primitive_cube_add(location=(i,10*(math.pow(math.log(0.05*i+1)+math.sin(math.pi*i/30),3))*math.cos(math.pi*i/90),10*(math.pow(math.log(0.05*i+1)+math.sin(math.pi*i/30),3))*math.sin(math.pi*i/90)))


This time, the polar form of $ 10 \ times log_e (0.05 \ times x + 1) + \ sin ({x \ pi/30}) $ is decomposed into the vertical axis component and the horizontal axis component to create a graph with θ as a parameter. We now have

By the way, the graph looks like this. image.png Overall view and view from each axis

Have you seen this source code somewhere? ~~ I don't like kid like you ~~

Graph (plane)

Now let's make this a flat surface.

import bpy
import math

for i in range(30):
    for j in range(20):
        bpy.ops.mesh.primitive_cube_add(location=(i,20-j+10*(math.pow(math.log(0.05*i+1)+math.sin(math.pi*i/30),3))*math.cos(math.pi*i/90),j+10*(math.pow(math.log(0.05*i+1)+math.sin(math.pi*i/30),3))*math.sin(math.pi*i/90)))

The horizontal axis of the above formula is arranged at equal intervals, and the vertical axis is slightly spaced between cubes. The graph looks like this.

image.png

At the end

This time I wrote various easy modeling methods in Python. It can be used for many other things, so please give it a try!

Recommended Posts

Easy modeling with Blender and Python
Easy web scraping with Python and Ruby
Operate Blender with Python
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Easy folder synchronization with Python
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
python with pyenv and venv
Works with Python and R
Easy partial download of mp4 with python and youtube-dl!
Easy to use Nifty Cloud API with botocore and python
Shining life with Python and OpenCV
Robot running with Arduino and python
[Python] Easy parallel processing with Joblib
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Easy Slackbot with Docker and Errbot
Scraping with Python, Selenium and Chromedriver
Run mruby with Python or Blender
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
Easy Python + OpenCV programming with Canopy
[GUI with Python] PyQt5-Drag and drop-
Easy email sending with haste python3
Reading and writing NetCDF with Python
Bayesian optimization very easy with Python
I played with PyQt5 and Python3
Easy data visualization with Python seaborn.
Reading and writing CSV with Python
Multiple integrals with Python and Sympy
Easy parallel execution with python subprocess
Coexistence of Python2 and 3 with CircleCI (1.0)
Get started with Python in Blender
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Easy deep learning web app with NNC and Python + Flask
Play with Statistical Modeling: Quantify J-League Team Strength with Stan and Python
Communicate between Elixir and Python with gRPC
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
Easy keyword extraction with TermExtract for Python
Monitor Mojo outages with Python and Skype
[Python] Super easy test with assert statement
FM modulation and demodulation with Python Part 3
[Automation] Manipulate mouse and keyboard with Python
Passwordless authentication with RDS and IAM (Python)
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
POST variously with Python and receive with Flask
Capturing images with Pupil, python and OpenCV
A memo with Python2.7 and Python3 on CentOS
Easy introduction of speech recognition with Python
Use PIL and Pillow with Cygwin Python
Create and decrypt Caesar cipher with python
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Reading and writing JSON files with Python