2023年2月13日月曜日

How to resize my blender market assets.

import bpy, mathutils


armature_object = bpy.data.objects["VultureArmature"]

multiplier=3

# Set the scale to multiplier

armature_object.scale *= multiplier


# set mode to object

bpy.ops.object.mode_set(mode='OBJECT')


# select the armature

armature_object.select_set(True)


# set the active object to the armature

bpy.context.view_layer.objects.active = armature_object


# apply the scale transformation

bpy.ops.object.transform_apply(scale=True)


    

Emptyaction1 = bpy.data.actions["VultureIKEmpty_L_Action"]


for fcu in Emptyaction1.fcurves:

    if "location" in fcu.data_path:

        for keyframe in fcu.keyframe_points:        

            keyframe.co = (keyframe.co - mathutils.Vector((keyframe.co.x,0))) * multiplier + mathutils.Vector((keyframe.co.x,0)) 

            keyframe.interpolation='LINEAR'                

Emptyaction2 = bpy.data.actions["VultureIKEmpty_R_Action"]


for fcu in Emptyaction2.fcurves:

    if "location" in fcu.data_path:

        for keyframe in fcu.keyframe_points:        

            keyframe.co = (keyframe.co - mathutils.Vector((keyframe.co.x,0))) * multiplier + mathutils.Vector((keyframe.co.x,0))               

            keyframe.interpolation='LINEAR'             

action = bpy.data.actions["VultureArmatureAction"]


for fcu in action.fcurves:

    if "location" in fcu.data_path:

        for keyframe in fcu.keyframe_points:        

            keyframe.co = (keyframe.co - mathutils.Vector((keyframe.co.x,0))) * multiplier + mathutils.Vector((keyframe.co.x,0))      

            keyframe.interpolation='LINEAR'       

2023年2月2日木曜日

異なるメッシュをShapeKeyのデータにする

 





import bpy


# Select the two meshes

mesh_a = bpy.data.objects["Cube"]

mesh_b = bpy.data.objects["Cube.001"]


# Assign the shape keys of Mesh B to Mesh A

mesh_b.shape_key_add(name='Basis', from_mix=False)

mesh_a.shape_key_add(name='Basis', from_mix=False)

mesh_a.shape_key_add(name='Morph1', from_mix=False)

bpy.ops.object.editmode_toggle()


for i, vert_b in enumerate(mesh_b.data.vertices):

    mesh_a.data.shape_keys.key_blocks["Morph1"].data[i].co = vert_b.co



2023年1月31日火曜日

時計



 
時計を描くBlender Pythonスクリプトを書け。

以下は、BlenderのPythonスクリプトを使用して時計を作成する例です。これを修正または変更して、独自の画像を作成することができます。

import bpy
import math
from datetime import datetime

def create_clock():
    # Create a circle for the clock face
    bpy.ops.mesh.primitive_circle_add(radius=2, location=(0,0,0))
    
    # Get the current time
    current_time = datetime.now().time()
    hour = current_time.hour
    minute = current_time.minute
    second = current_time.second
    
    # Create the hour hand
    hour_angle = (hour / 12) * 360
    x = math.sin(math.radians(hour_angle)) * 1.5
    y = math.cos(math.radians(hour_angle)) * 1.5
    bpy.ops.mesh.primitive_cone_add(radius1=0.1, depth=1.5, location=(x, y, 0))
    
    # Create the minute hand
    minute_angle = (minute / 60) * 360
    x = math.sin(math.radians(minute_angle)) * 1.8
    y = math.cos(math.radians(minute_angle)) * 1.8
    bpy.ops.mesh.primitive_cylinder_add(radius=0.1, depth=1.8, location=(x, y, 0))
    
    # Create the second hand
    second_angle = (second / 60) * 360
    x = math.sin(math.radians(second_angle)) * 2
    y = math.cos(math.radians(second_angle)) * 2
    bpy.ops.mesh.primitive_cube_add(size=0.2, location=(x, y, 0))

create_clock()