Created
October 27, 2020 02:54
-
-
Save darshanhegde/a18cfed8188d73f518f663678dc537a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
import random | |
import time | |
import pybullet as pb | |
import pybullet_data | |
def main(): | |
pysics_client = pb.connect(pb.GUI) | |
pb.setAdditionalSearchPath(pybullet_data.getDataPath()) | |
plane_id = pb.loadURDF('plane.urdf') | |
shoes_paths = glob.glob("/home/darshanhegde/source/models/google_research_scans/toys/*") | |
for i in range(10): | |
shoes_path = random.choice(shoes_paths) | |
visual_shape_id = pb.createVisualShape(shapeType=pb.GEOM_MESH, | |
fileName=os.path.join(shoes_path, "meshes/model.obj"), | |
rgbaColor=None, | |
meshScale=[1.0, 1.0, 1.0]) | |
collision_shape_id = pb.createCollisionShape(shapeType=pb.GEOM_MESH, | |
fileName=os.path.join(shoes_path, "meshes/model.obj"), | |
meshScale=[1.0, 1.0, 1.0]) | |
multi_body_id = pb.createMultiBody(baseMass=1.0, | |
baseCollisionShapeIndex=collision_shape_id, | |
baseVisualShapeIndex=visual_shape_id, | |
basePosition=[0, 0, 1 + i * 0.15], | |
baseOrientation=pb.getQuaternionFromEuler([0, 0, 0])) | |
texture_id = pb.loadTexture(os.path.join(shoes_path, "meshes/model.png")) | |
pb.changeVisualShape(multi_body_id, -1, textureUniqueId=texture_id) | |
pb.setGravity(0, 0, -9.8) | |
pb.setRealTimeSimulation(1) | |
for i in range (100): | |
pb.stepSimulation() | |
time.sleep(1./5.) | |
view_matrix = pb.computeViewMatrix(cameraEyePosition=[0, 0, 3], | |
cameraTargetPosition=[0, 0, 0], | |
cameraUpVector=[0, 1, 0]) | |
projection_matrix = pb.computeProjectionMatrixFOV(fov=45.0, aspect=1.0, | |
nearVal=0.1, farVal=3.1) | |
width, height, rgb_img, depth_img, seg_img = pb.getCameraImage(width=512, height=512, | |
viewMatrix=view_matrix, | |
projectionMatrix=projection_matrix) | |
time.sleep(15.) | |
pb.disconnect() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment