Files
bullet3/examples/pybullet/examples/video_sync_mp4.py
Erwin Coumans 1e8f39b492 improve premake4 build in case X11 headers are missing
improve video_sync_mp4.py example
allow to create a heightfield from file or programmatically in C++ robotics api. Example:

{
		b3RobotSimulatorCreateCollisionShapeArgs shapeArgs;
		shapeArgs.m_shapeType = GEOM_HEIGHTFIELD;
		bool useFile = true;
		if (useFile)
		{
			shapeArgs.m_fileName = "D:/dev/bullet3/data/heightmaps/gimp_overlay_out.png";
			shapeArgs.m_meshScale.setValue(.05, .05, 1);
		}
		else
		{
			shapeArgs.m_numHeightfieldColumns = 256;
			shapeArgs.m_numHeightfieldRows = 256;
			shapeArgs.m_meshScale.setValue(.05, .05, 1);
			shapeArgs.m_heightfieldData.resize(shapeArgs.m_numHeightfieldRows * shapeArgs.m_numHeightfieldColumns);
			double heightPerturbationRange = 0.05;
			for (int j = 0; j<int(shapeArgs.m_numHeightfieldColumns / 2); j++)
			{
				for (int i = 0; i < (int(shapeArgs.m_numHeightfieldRows / 2)); i++)
				{
					double height = ((double)rand() / (RAND_MAX)) * heightPerturbationRange;
					shapeArgs.m_heightfieldData[2 * i + 2 * j * shapeArgs.m_numHeightfieldRows] = height;
					shapeArgs.m_heightfieldData[2 * i + 1 + 2 * j * shapeArgs.m_numHeightfieldRows] = height;
					shapeArgs.m_heightfieldData[2 * i + (2 * j + 1) * shapeArgs.m_numHeightfieldRows] = height;
					shapeArgs.m_heightfieldData[2 * i + 1 + (2 * j + 1) * shapeArgs.m_numHeightfieldRows] = height;
				}
			}
		}
		int shape = sim->createCollisionShape(shapeArgs.m_shapeType, shapeArgs);
		b3RobotSimulatorCreateMultiBodyArgs bodyArgs;
		bodyArgs.m_baseCollisionShapeIndex = shape;
		int groundId = sim->createMultiBody(bodyArgs);
		int texId = sim->loadTexture(shapeArgs.m_fileName);
		b3RobotSimulatorChangeVisualShapeArgs args;
		args.m_objectUniqueId = groundId;
		args.m_linkIndex = -1;
		args.m_textureUniqueId = texId;
		sim->changeVisualShape(args);
	}
2020-07-24 18:09:13 -07:00

33 lines
1.0 KiB
Python

import pybullet as p
import time
import pybullet_data
#Once the video is recorded, you can extract all individual frames using ffmpeg
#mkdir frames
#ffmpeg -i test.mp4 "frames/out-%03d.png"
#by default, PyBullet runs at 240Hz
p.connect(p.GUI, options="--width=1920 --height=1080 --mp4=\"test.mp4\" --mp4fps=240")
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.configureDebugVisualizer(p.COV_ENABLE_GUI,0)
p.configureDebugVisualizer(p.COV_ENABLE_SINGLE_STEP_RENDERING,1)
p.loadURDF("plane.urdf")
#in 3 seconds, the object travels about 0.5*g*t^2 meter ~ 45 meter.
r2d2 = p.loadURDF("r2d2.urdf",[0,0,45])
#disable linear damping
p.changeDynamics(r2d2,-1, linearDamping=0)
p.setGravity(0,0,-10)
for i in range (3*240):
txt = "frame "+str(i)
item = p.addUserDebugText(txt, [0,1,0])
p.stepSimulation()
#synchronize the visualizer (rendering frames for the video mp4) with stepSimulation
p.configureDebugVisualizer(p.COV_ENABLE_SINGLE_STEP_RENDERING,1)
#print("r2d2 vel=", p.getBaseVelocity(r2d2)[0][2])
p.removeUserDebugItem(item)
p.disconnect()