コード例 #1
0
def record_animation(supervisor: Supervisor,
                     file_path: Path) -> Iterator[None]:
    file_path.parent.mkdir(parents=True, exist_ok=True)
    print("Saving animation to {}".format(file_path))
    supervisor.animationStartRecording(str(file_path))
    yield
    supervisor.animationStopRecording()
コード例 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--duration',
                        type=float,
                        default=10,
                        help='Duration of the animation in seconds')
    parser.add_argument('--output',
                        default='../../animation/index.html',
                        help='Path at which the animation will be saved')
    args = parser.parse_args()

    robot = Supervisor()
    timestep = int(robot.getBasicTimeStep())
    receiver = robot.getDevice('receiver')
    receiver.enable(timestep)

    robot.step(timestep)
    robot.animationStartRecording(args.output)

    step_i = 0
    done = False
    n_steps = (1000 * args.duration) / robot.getBasicTimeStep()
    while not done and robot.step(timestep) != -1 and step_i < n_steps:
        step_i += 1
        if receiver.getQueueLength() > 0:
            if receiver.getData().decode('utf-8') == 'done':
                done = True
            receiver.nextPacket()

    robot.animationStopRecording()
    for _ in range(10):
        robot.step(timestep)
    print('The animation is saved')
    robot.simulationQuit(0)
コード例 #3
0
robotName = robot.getField('name').getSFString()

# Get target paths.
scenePath = os.path.join(userGuidePath, 'scenes', robotName)
targetHTMLFile = os.path.join(scenePath, robotName + '.html')
targetAnimationFile = os.path.join(scenePath, robotName + '.json')
targetMetaFile = os.path.join(scenePath, robotName + '.meta.json')
targetX3DFile = os.path.join(scenePath, robotName + '.x3d')

# Store the scene.
if os.path.exists(scenePath):
    shutil.rmtree(scenePath)
if not os.path.exists(scenePath):
    os.makedirs(scenePath)
supervisor.animationStartRecording(targetHTMLFile)
supervisor.animationStopRecording()
supervisor.step(timeStep)
supervisor.step(timeStep)

# Remove useless files.
os.remove(targetHTMLFile)
os.remove(targetAnimationFile)
for fl in glob.glob(
        os.path.join(scenePath, 'textures', 'cubic',
                     'noon_cloudy_mountains*.jpg')):
    os.remove(fl)

# Simplified JSON file.
# - keep only the interested robot.
assert os.path.exists(targetMetaFile), 'The meta file does not exists. ' \
    'Please run Webots with the "--enable-x3d-meta-file-export" argument.'