To give you a more of a look into what I'm doing, heres a single 1/5 key out of the json file
Code: Select all
{"1.2839901447296143": {"0": {"joint_positions": -0.2660407240964722}, "1": {"joint_positions": 0.5304539359064856}, "2": {"joint_positions": -0.44852838864481787}, "3": {"joint_positions": -0.14016010671763662}, "4": {"joint_positions": 0.5558784919638431}, "5": {"joint_positions": 0.463813963178519}, "6": {"joint_positions": 0.1232185850913412}, "7": {"joint_positions": 0.5509734074329725}, "8": {"joint_positions": -0.5095558255751145}, "9": {"joint_positions": 0.08173290868566063}, "10": {"joint_positions": 0.3949344400183078}
The script that tries to replicate this is very simple
Code: Select all
import pybullet as p
import time
import json
# Connect to the PyBullet physics server
p.connect(p.GUI)
p.setRealTimeSimulation(0)
# Load the humanoid model
skeleton = p.loadURDF("skeleton.urdf", useFixedBase=False)
p.setTimeStep(0.01)
# add a ground plane
plane_id = p.createCollisionShape(p.GEOM_PLANE)
ground = p.createMultiBody(baseCollisionShapeIndex=plane_id, basePosition=[0, 0, 0])
# enable collisions between the humanoid model and the ground plane
p.setCollisionFilterPair(skeleton, ground, -1, -1, 1)
# set the gravity
p.setGravity(0, 0, -9.8)
# load the joint angles from json file
with open("joint_angles.json", "r") as file:
joint_angles = json.load(file)
# Initialize a dictionary to store the current joint angles
current_joint_angles = {joint_num: 0 for joint_num in range(p.getNumJoints(skeleton))}
# Get the start time
start_time = time.time() +
offset = [0, 0, 1]
position, orientation = p.getBasePositionAndOrientation(skeleton)
new_position = [position[i] + offset[i] for i in range(3)]
p.resetBasePositionAndOrientation(skeleton, new_position, orientation)
n = 1
# Get the list of all time frames
time_frames = list(joint_angles.keys())
# Iterate through the time frames and set the joint angls
for i, keyframe_time in enumerate(time_frames):
keyframe_time = float(keyframe_time)
current_time = time.time() - start_time
time_to_sleep = keyframe_time - current_time
while time_to_sleep > 0:
time_to_sleep = keyframe_time - current_time
# Sleep for the calculated amount of time
time.sleep(time_to_sleep)
# Get the joint angles for this time frame
for joint_num, joint_data in joint_angles[str(keyframe_time)].items():
joint_positions = joint_data['joint_positions']
p.setJointMotorControl2(bodyIndex=0, jointIndex=int(joint_num), controlMode=p.POSITION_CONTROL, targetPosition=joint_positions)
# Step the simulation
p.stepSimulation()
print(time.time() - start_time)
p.disconnect()
TLDR:
Give me your experience in replicating animations preferably in python (C++ scares me).