Exemplo n.º 1
0
def main():

    env = BasicEnvironment(houseId="0004d52d1aeeb8ae6de39d6bd993e992",
                           suncgDatasetRoot=TEST_SUNCG_DATA_DIR,
                           realtime=True)
    env.setAgentOrientation((60.0, 0.0, 0.0))
    env.setAgentPosition((42, -39, 1.0))

    env.renderWorld.showRoomLayout(showCeilings=False,
                                   showWalls=True,
                                   showFloors=True)

    viewer = Viewer(env.scene, interactive=False, showPosition=True)

    # Find agent and reparent camera to it
    agent = env.scene.scene.find('**/agents/agent*/+BulletRigidBodyNode')
    viewer.camera.reparentTo(agent)

    linearVelocity = np.zeros(3)
    angularVelocity = np.zeros(3)
    rotationStepCounter = -1
    rotationsStepDuration = 40
    try:
        while True:

            # Constant speed forward (Y-axis)
            linearVelocity = LVector3f(0.0, 1.0, 0.0)
            env.setAgentLinearVelocity(linearVelocity)

            # Randomly change angular velocity (rotation around Z-axis)
            if rotationStepCounter > rotationsStepDuration:
                # End of rotation
                rotationStepCounter = -1
                angularVelocity = np.zeros(3)
            elif rotationStepCounter >= 0:
                # During rotation
                rotationStepCounter += 1
            else:
                # No rotation, initiate at random
                if np.random.random() > 0.5:
                    angularVelocity = np.zeros(3)
                    angularVelocity[2] = np.random.uniform(low=-np.pi,
                                                           high=np.pi)
                    rotationStepCounter = 0
            env.setAgentAngularVelocity(angularVelocity)

            # Simulate
            env.step()

            viewer.step()

    except KeyboardInterrupt:
        pass

    viewer.destroy()

    return 0
Exemplo n.º 2
0
def main():
    env = BasicEnvironment(houseId="0004d52d1aeeb8ae6de39d6bd993e992",
                           suncgDatasetRoot=TEST_SUNCG_DATA_DIR,
                           realtime=True)

    # a, b = env.generateOccupancyMap()
    # plt.imshow(a, cmap='hot', interpolation='nearest')
    # plt.show(block=False)

    env.setAgentOrientation((60.0, 0.0, 0.0))
    env.setAgentPosition((42, -39, 1.2))
    env.renderWorld.showRoomLayout(showCeilings=False,
                                   showWalls=True,
                                   showFloors=True)

    viewer = Viewer(env.scene, interactive=False, showPosition=True, fov=50.)

    # Find agent and reparent camera to it
    agent = env.agentRbNp
    viewer.camera.reparentTo(agent)
    viewer.capture_video()

    # ai_world = AIWorld(env.scene.scene)
    # ai_char = AICharacter("seeker", agent, 60, 0.5, 5)
    # ai_world.addAiChar(ai_char)
    # ai_behaviors = ai_char.getAiBehaviors()
    # ai_behaviors.seek(Vec3(35, -39, 1.0))
    #
    # def update_ai_world(task):
    #     ai_world.update()
    #     return task.cont

    # taskMgr.add(update_ai_world, "AIUpdate")
    #
    # while True:
    #
    #     viewer.step()
    #     env.step()

    renderer = Panda3dSemanticsRenderer(env.scene,
                                        TEST_SUNCG_DATA_DIR,
                                        mode='offscreen',
                                        segment_by_instance=True)
    renderer.cameras[0].reparentTo(agent)
    renderer.showRoomLayout(showCeilings=False)
    images = []

    linearVelocity = np.zeros(3)
    angularVelocity = np.zeros(3)
    rotationStepCounter = -1
    rotationsStepDuration = 40
    try:
        while True:

            # Constant speed forward (Y-axis)
            linearVelocity = LVector3f(0.0, 1.0, 0.0)
            env.setAgentLinearVelocity(linearVelocity)

            # Randomly change angular velocity (rotation around Z-axis)
            if rotationStepCounter > rotationsStepDuration:
                # End of rotation
                rotationStepCounter = -1
                angularVelocity = np.zeros(3)
            elif rotationStepCounter >= 0:
                # During rotation
                rotationStepCounter += 1
            else:
                # No rotation, initiate at random
                if np.random.random() > 0.5:
                    angularVelocity = np.zeros(3)
                    angularVelocity[2] = np.random.uniform(low=-np.pi,
                                                           high=np.pi)
                    rotationStepCounter = 0
            env.setAgentAngularVelocity(angularVelocity)

            # Simulate
            env.step()
            viewer.step()

            image = renderer.getRgbaImages()['agent-0']
            images.append(image)

            if viewer.stop:
                postprocess_images(images, env.scene, renderer)
                sys.exit(0)

    except KeyboardInterrupt:
        postprocess_images(images, env.scene, renderer)
        pass

    viewer.destroy()

    return 0