gcwmb / render_hand.py
twanghcmut's picture
Upload folder using huggingface_hub
7622175 verified
import os
from isaacsim import SimulationApp
import math
simulation_app = SimulationApp({"headless": True})
import omni.replicator.core as rep
HAND_USD = os.path.abspath("/workspace/IsaacLab/right_arm_only.usd")
target_pos = (0.0, -0.25, 0.35) # Tọa độ tĩnh của khúc giữa cánh tay phải
radius = 1.0 # Bán kính quỹ đạo (Camera cách tay 1 mét)
cam_positions = []
# Tính toán 72 vị trí của Camera nằm trên một vòng tròn quanh cánh tay
for i in range(72):
angle = math.radians(i * 5)
cx = target_pos[0] + radius * math.cos(angle)
cy = target_pos[1] + radius * math.sin(angle)
cz = target_pos[2] + 0.1 # Nâng camera cao hơn tâm một chút
cam_positions.append((cx, cy, cz))
# ==========================================
with rep.new_layer():
# Ánh sáng (Giữ nguyên)
rep.create.light(light_type="dome", intensity=1200)
rep.create.light(light_type="distant", intensity=3000, rotation=(315, 45, 0), color=(1.0, 0.95, 0.9))
rep.create.light(light_type="distant", intensity=1000, rotation=(45, -45, 0), color=(0.9, 0.95, 1.0))
# 1. Load model tay (Để nó ĐỨNG YÊN TẠI CHỖ, không xoay nữa)
hand = rep.create.from_usd(HAND_USD)
# 2. Khởi tạo Camera với tiêu cự 45mm chuẩn mắt người
camera = rep.create.camera(focal_length=24.0)
render_product = rep.create.render_product(camera, (1024, 1024))
# 3. Kích hoạt trigger chạy 72 frame
with rep.trigger.on_frame(max_execs=72):
# MA THUẬT Ở ĐÂY: Áp dụng mảng vị trí vòng tròn cho Camera
with camera:
rep.modify.pose(
position=rep.distribution.sequence(cam_positions),
look_at=target_pos # Camera luôn khóa mục tiêu nhìn thẳng vào cánh tay
)
# 4. Xuất ảnh
output_dir = os.path.abspath("fourier_hand_renders")
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir=output_dir, rgb=True)
writer.attach([render_product])
# Chạy ngầm
rep.orchestrator.run()
while rep.orchestrator.get_is_started():
simulation_app.update()
simulation_app.close()