Skip to content

Instantly share code, notes, and snippets.

@darshanhegde
Created October 27, 2020 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darshanhegde/a18cfed8188d73f518f663678dc537a2 to your computer and use it in GitHub Desktop.
Save darshanhegde/a18cfed8188d73f518f663678dc537a2 to your computer and use it in GitHub Desktop.
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