Takunojiのプログラミング・プレイグラウンド(遊び場)

Javaプログラミングを基本にして、ゲーム作成に必要なことの調査結果、やったら面白そうなことなどを記載します。プログラミングのススメ的なことも記載します。プログラミングで楽しく遊ぶために色々と記載して行きます。

Blender Python Add-on 〜チュートリアル2-2〜

前回は、アドオンのチュートリアルを始めました。(Your Second Add-on)
今回は、Your Second Add-onの2回目をやります。
→次のスクリプトの写経です。

Addon Tutorial — Blender 2.78.0 e8299c8 - API documentation

今回のスクリプトは、選択したオブジェクトをカーソルの位置までに
オブジェクトを作成して並べるスクリプトでした。

f:id:Takunoji:20180407173736p:plain

f:id:Takunoji:20180407173747p:plain

そして、スクリプト ダウンロードはこちら

import bpy
from bpy import context

# よく使うものを変数に取り出します。
# this scene => in this 3dview
scene = context.scene
# cursor position of circle which red and white stripe
cursor = scene.cursor_location
# object of selected
obj = scene.objects.active

# 選択しているオブジェクトからカーソルの位置まで5個作成
total = 5

for i in range(total):
obj_new = obj.copy()
scene.objects.link(obj_new)
# Now place the objection between the cursor
# and the active object based on "i"
factor = i / total
obj_new.location = (obj.location * factor) + (cursor * (1.0 - factor))

以上、ちょっと計算が入るスクリプトでした。
次回は、アドオンとして作成します。