clvrai / furniture

IKEA Furniture Assembly Environment for Long-Horizon Complex Manipulation Tasks
https://clvrai.com/furniture
MIT License
496 stars 56 forks source link

Changing camera pose #43

Open ozgraslan opened 2 years ago

ozgraslan commented 2 years ago

Hello,

I am trying to change the pose of the camera during simulation.
There are already implemented functions in furniture class: _set_camera_position for mujoco renderer and _set_camera_pose for unity renderer. When I tried to use _set_camera_pose, it did not change the camera pose. But _set_camera_position works using the mujoco renderer. I used following code. Am I missing something for the unity case?

import gym
import furniture
import numpy as np
from furniture import agent_names, background_names, furniture_names
import matplotlib.pyplot as plt

env_name = "IKEA{}-v0".format(agent_names[0])
furniture_name= furniture_names[0]
background_name = background_names[2]
unity = False 
camera_id = 0
new_pose = np.array([1,1,1, 1,0,0,0])
env = gym.make(env_name, furniture_name=furniture_name, background=background_name, 
                unity=unity, camera_ids = [camera_id])

env.reset()
old_rgb = env.render("rgb_array")[0]
if unity:
    env.env._set_camera_pose(camera_id, new_pose)
else:
    env.env._set_camera_position(camera_id, new_pose[:3])
    env.env.sim.model.cam_quat[camera_id] = new_pose[3:]
    env.env.sim.forward()
    env.env.sim.step()

new_rgb = env.render("rgb_array")[0]

fig = plt.figure()
fig.add_subplot(2, 1, 1)
plt.imshow(old_rgb)
fig.add_subplot(2, 1, 2)
plt.imshow(new_rgb)
plt.show()

Outputs: Mujoco:
mjc Unity:
unity