Привяжите BaseMesh к буровой установке с помощью автоматических весов. не работаетPython

Программы на Python
Ответить
Anonymous
 Привяжите BaseMesh к буровой установке с помощью автоматических весов. не работает

Сообщение Anonymous »

Я использую блендер 3.6.
Цель — смоделировать анимацию бега/ходьбы загруженного BaseMesh в виде obj-файла через Python.
Вот мой код на Python:

Код: Выделить всё

import bpy
import math

def import_basemesh(filepath):
# Import the BaseMesh OBJ file
bpy.ops.import_scene.obj(filepath=filepath)
basemesh = bpy.context.selected_objects[0]
basemesh.name = "BaseMesh"
return basemesh

def create_rig():
# Create an armature
bpy.ops.object.armature_add(enter_editmode=True, location=(0, 0, 0))
armature = bpy.context.object
armature.name = "Rig"
armature.show_in_front = True

# Add bones in Edit Mode
bones = armature.data.edit_bones

# Rename default bone to "Spine"
bones["Bone"].head = (0, 0, 18)
bones["Bone"].tail =(0, 0, 11)
bones["Bone"].name = "Spine"

# Add head bone
head_bone = bones.new("Head")
head_bone.head = (0, 0, 20)
head_bone.tail = (0, 0, 18)
head_bone.parent = bones["Spine"]

# Add left leg bone
left_leg_bone = bones.new("Left_Leg")
left_leg_bone.head = (0, 0, 11)
left_leg_bone.tail = (0, -2, 1)
left_leg_bone.parent = bones["Spine"]

# Add right leg bone
right_leg_bone = bones.new("Right_Leg")
right_leg_bone.head = (0, 0, 11)
right_leg_bone.tail = (0, 2, 1)
right_leg_bone.parent = bones["Spine"]

# Add left arm bone
left_arm_bone = bones.new("Left_Arm")
left_arm_bone.head = (0, 0, 18)
left_arm_bone.tail = (0, -6, 9)
left_arm_bone.parent = bones["Spine"]

# Add right arm bone
right_arm_bone = bones.new("Right_Arm")
right_arm_bone.head = (0, 0, 18)
right_arm_bone.tail = (0, 6, 9)
right_arm_bone.parent = bones["Spine"]

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

def rig_basemesh(basemesh, armature):
"""
Parent the BaseMesh to the rig with automatic weights.
"""
# Select the BaseMesh and the Armature
bpy.ops.object.mode_set(mode='OBJECT')
bpy.context.view_layer.objects.active = armature
bpy.ops.object.select_all(action='DESELECT')
basemesh.select_set(True)
armature.select_set(True)

# Set Parent to Armature with Automatic Weights
bpy.ops.object.parent_set(type='ARMATURE_AUTO')

print(f"Parented '{basemesh.name}' to '{armature.name}' with Automatic Weights.")

def rotate_basemesh(basemesh, angle_degrees):
"""
Rotates the BaseMesh around the Z-axis by a given angle (in degrees).
"""
import math

# Convert degrees to radians
angle_radians = math.radians(angle_degrees)

# Apply rotation
basemesh.rotation_euler[2] += angle_radians  # Z-axis rotation (XY plane)

print(f"Rotated '{basemesh.name}' by {angle_degrees} degrees counterclockwise on the XY plane.")

def animate_running(armature):
"""
Create a running animation for the rig's bones.
"""
# Ensure animation data exists
if not armature.animation_data:
armature.animation_data_create()

# Switch to Pose Mode
bpy.context.view_layer.objects.active = armature
bpy.ops.object.mode_set(mode='POSE')
pose_bones = armature.pose.bones

# Verify the bones exist
required_bones = ["Left_Leg", "Right_Leg", "Left_Arm", "Right_Arm"]
missing_bones = [bone for bone in required_bones if bone not in pose_bones]
if missing_bones:
print(f"ERROR: Missing bones:  {missing_bones}")
return

print("Available bones in armature:")
for bone in pose_bones:
print(bone.name)

# Set animation frame range
frame_start = 1
frame_end = 200
bpy.context.scene.frame_start = frame_start
bpy.context.scene.frame_end = frame_end

# Insert keyframes for each bone
print("Inserting keyframes for running animation...")
try:
while frame_start

Подробнее здесь: [url]https://stackoverflow.com/questions/79289826/parent-the-basemesh-to-the-rig-with-automatic-weights-not-working[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»