2023年4月10日月曜日

x^2+y^2+z^2 = zion_distance

 


blender python で frame 毎に 進む距離を

x^2+y^2+z^2 = zion_distance 

と定義して Pythonスクリプト



Blender Pythonで、

各フレームでオブジェクトを移動する距離を

zion_distanceで定義し、

その距離だけオブジェクトを移動するスクリプト




import bpy

from mathutils import Vector


# 初期位置を取得

start_pos = bpy.context.active_object.location

# 初期フレームを取得

start_frame = bpy.context.scene.frame_current


def move_object():

    # 現在のフレームを取得

    current_frame = bpy.context.scene.frame_current

    # オブジェクトを移動する距離を計算

    zion_distance = (current_frame - start_frame)**2

    # 移動ベクトルを作成

    move_vector = Vector((zion_distance, zion_distance, zion_distance))

    # オブジェクトを移動

    bpy.context.active_object.location = start_pos + move_vector


# フレームを進める

for frame in range(start_frame, bpy.context.scene.frame_end+1):

    bpy.context.scene.frame_set(frame)

    move_object()


Blender Pythonでx^2+y^2+z^2 = r^2の球体を、

フレーム0から600で拡大するスクリプト


-30 y から 線路レールへの リアルボール テスト

動いた




 import bpy

from mathutils import Vector


# Set sphere radius

sphere_radius = 1


# Set target location

target_location = Vector((-30, 0, 0))


# Set initial location and movement direction for sphere

initial_location = Vector((0, 0, 0))

movement_direction = (target_location - initial_location).normalized()


# Create sphere and set location

bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius)

sphere = bpy.context.object

sphere.name = "Sphere"

sphere.location = initial_location


# Animate sphere

num_frames = 1000

movement_speed = 0.1

for frame in range(num_frames):

    distance = (target_location - sphere.location).length

    if distance > 0.01:

        direction = movement_direction

        sphere.location += direction * min(movement_speed, distance)

        sphere.keyframe_insert(data_path="location", frame=frame+1)





2023年4月9日日曜日

円柱 複数改造

 


import bpy

import math


zion_collection_name = "光時計たくさん"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)



import bpy

import math

zion_collection_name = "土台"

# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)

電車列車から見える 円柱 複数も

光時計 たくさん



import bpy

import math


zion_collection_name = "光時計たくさん"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)



import bpy

import math

zion_collection_name = "土台"

# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)





円錐 りんごの木

import bpy

import math

from mathutils import Vector

from math import radians


# Create collection

zion_collection_name = "cone"

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)


# Set target location

target_location = Vector((-600, 0, 30)) # heiko idou taksa


# Set initial location

initial_locations = [Vector((0, 0, 30))]


# Set cone properties

cone_radius = 60

cone_depth = 60


# Calculate speeds based on initial distances

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create cone objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, radius2=0, depth=cone_depth)

    cone = bpy.context.object

    cone.location = initial_location

    cone.name = "cone"


    # Rotate cone by 180 degrees around the x-axis

    cone.rotation_euler.rotate_axis('X', radians(0))


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - cone.location).length

        if distance > 0.01:

            direction = (target_location - cone.location).normalized()

            cone.location += direction * min(speeds[i], distance)

            cone.keyframe_insert(data_path="location", frame=frame)


# Set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)


2023年4月8日土曜日

円錐平行 移動 線路も 移動で 座標系の 動きを再現の一歩

逆さ円錐 動く 再生でも 位置修正中




import bpy

from mathutils import Vector


# 設定可能な変数

zion_object_name = "逆さ円錐 600上昇"  # 円錐オブジェクトの名前

radius = 60  # 円錐の半径

height = 60  # 円錐の高さ

distance_per_frame = 0.1  # 円錐の移動距離

animation_frames = 1000  # アニメーションの再生時間(フレーム数)

wait_frames = 40  # アニメーション再生完了後の待機時間(フレーム数)

zion_stop =600 * 0.1

zion_saibyouga = 30


# 円錐を作成する

def create_cone():

    bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)

    cone = bpy.context.object

    cone.name = zion_object_name

    cone.location = Vector((0, 0, 0))  # 初期位置を設定する


 


# アニメーションのキーフレームを設定する

for i in range(animation_frames):

    frame = i + 1


    # キーフレームごとの円錐の位置を設定する

    zion_pos = Vector((0, 0, (i+1)*distance_per_frame))

    cone.location = zion_pos


    # キーフレームを設定する

    cone.keyframe_insert(data_path="location", frame=frame)


# アニメーション再生後の待機時間を設定する

for i in range(wait_frames):

    frame = animation_frames + i + 1

    cone.keyframe_insert(data_path="location", frame=frame, index=-1)


改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...