def testDebugHouseWithRender(self):
        renderer = None
        physics = None
        viewer = None

        try:
            scene = SunCgSceneLoader.loadHouseFromJson(
                "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR)

            renderer = Panda3dRenderer(scene,
                                       shadowing=False,
                                       mode='offscreen')
            renderer.showRoomLayout(showCeilings=False)

            physics = Panda3dBulletPhysics(
                scene, suncgDatasetRoot=TEST_SUNCG_DATA_DIR, debug=True)

            viewer = Viewer(scene, interactive=False)
            viewer.disableMouse()

            mat = np.array([
                0.999992, 0.00394238, 0, 0, -0.00295702, 0.750104, -0.661314,
                0, -0.00260737, 0.661308, 0.75011, 0, 43.621, -55.7499,
                12.9722, 1
            ])

            mat = LMatrix4f(*mat.ravel())
            viewer.cam.setMat(mat)
            for _ in range(20):
                viewer.step()
            time.sleep(1.0)

        finally:
            self.hulkSmash(renderer, physics, viewer)
    def testStep(self):

        scene = SunCgSceneLoader.loadHouseFromJson("0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR)

        modelLightsInfo = SunCgModelLights(os.path.join(TEST_SUNCG_DATA_DIR, 'metadata', 'suncgModelLights.json'))
        renderer = Panda3dRenderer(scene, shadowing=True, mode='offscreen', modelLightsInfo=modelLightsInfo)
        renderer.showRoomLayout(showCeilings=False)

        mat = np.array([0.999992, 0.00394238, 0, 0,
                        -0.00295702, 0.750104, -0.661314, 0,
                        -0.00260737, 0.661308, 0.75011, 0,
                        43.621, -55.7499, 12.9722, 1])
        scene.agents[0].setMat(LMatrix4f(*mat.ravel()))

        renderer.step(dt=0.1)
        image = renderer.getRgbImages()['agent-0']
        depth = renderer.getDepthImages(mode='distance')['agent-0']
        self.assertTrue(np.min(depth) >= renderer.zNear)
        self.assertTrue(np.max(depth) <= renderer.zFar)

        fig = plt.figure(figsize=(16, 8))
        plt.axis("off")
        ax = plt.subplot(121)
        ax.imshow(image)
        ax = plt.subplot(122)
        ax.imshow(depth / np.max(depth), cmap='binary')
        plt.show(block=False)
        time.sleep(1.0)
        plt.close(fig)

        renderer.destroy()
Exemple #3
0
    def __init__(self, houseId, suncgDatasetRoot=None, size=(256, 256), debug=False, depth=False, realtime=False, dt=0.1, cameraTransform=None):

        self.__dict__.update(houseId=houseId, suncgDatasetRoot=suncgDatasetRoot, size=size,
                             debug=debug, depth=depth, realtime=realtime, dt=dt, cameraTransform=cameraTransform)

        self.scene = SunCgSceneLoader.loadHouseFromJson(houseId, suncgDatasetRoot)

        agentRadius = 0.1
        agentHeight = 1.6
        if self.cameraTransform is None:
            self.cameraTransform = TransformState.makePos(LVector3f(0.0, 0.0, agentHeight/2.0 - agentRadius))
        self.renderWorld = Panda3dRenderer(self.scene, size, shadowing=False, depth=depth, cameraTransform=self.cameraTransform)

        self.physicWorld = Panda3dBulletPhysics(self.scene, suncgDatasetRoot, debug=debug, objectMode='box', 
                                                agentRadius=agentRadius, agentHeight=agentHeight, agentMass=60.0, agentMode='capsule')

        self.clock = ClockObject.getGlobalClock()
        
        self.worlds = {
            "physics": self.physicWorld,
            "render": self.renderWorld,
        }

        self.agent = self.scene.agents[0]
        self.agentRbNp = self.agent.find('**/+BulletRigidBodyNode')

        self.labeledNavMap = None
        self.occupancyMapCoord = None
Exemple #4
0
    def testObjectWithViewer(self):

        scene = Scene()

        modelId = '83'
        modelFilename = os.path.join(TEST_SUNCG_DATA_DIR, "object",
                                     str(modelId),
                                     str(modelId) + ".egg")
        assert os.path.exists(modelFilename)
        model = loadModel(modelFilename)
        model.setName('model-' + str(modelId))
        model.show(BitMask32.allOn())

        objectsNp = scene.scene.attachNewNode('objects')
        objNp = objectsNp.attachNewNode('object-' + str(modelId))
        model.reparentTo(objNp)

        # Calculate the center of this object
        minBounds, maxBounds = model.getTightBounds()
        centerPos = minBounds + (maxBounds - minBounds) / 2.0

        # Add offset transform to make position relative to the center
        model.setTransform(TransformState.makePos(-centerPos))

        renderer = None
        viewer = None

        try:
            renderer = Panda3dRenderer(scene, shadowing=False)

            viewer = Viewer(scene, interactive=False)
            viewer.disableMouse()

            viewer.cam.setTransform(
                TransformState.makePos(LVecBase3(5.0, 0.0, 0.0)))
            viewer.cam.lookAt(model)

            for _ in range(20):
                viewer.step()
            time.sleep(1.0)

        finally:
            if renderer is not None:
                renderer.destroy()
            if viewer is not None:
                viewer.destroy()
                viewer.graphicsEngine.removeAllWindows()
Exemple #5
0
    def testDebugObjectWithRender(self):

        scene = Scene()

        modelId = '83'
        modelFilename = os.path.join(TEST_SUNCG_DATA_DIR, "object",
                                     str(modelId),
                                     str(modelId) + ".egg")
        assert os.path.exists(modelFilename)
        model = loadModel(modelFilename)
        model.setName('model-' + str(modelId))
        model.hide()

        objectsNp = scene.scene.attachNewNode('objects')
        objNp = objectsNp.attachNewNode('object-' + str(modelId))
        model.reparentTo(objNp)

        # Calculate the center of this object
        minBounds, maxBounds = model.getTightBounds()
        centerPos = minBounds + (maxBounds - minBounds) / 2.0

        # Add offset transform to make position relative to the center
        model.setTransform(TransformState.makePos(-centerPos))

        renderer = None
        physics = None
        viewer = None

        try:
            renderer = Panda3dRenderer(scene, shadowing=False)
            physics = Panda3dBulletPhysics(scene, debug=True)

            viewer = Viewer(scene, interactive=False)
            viewer.disableMouse()

            viewer.cam.setTransform(
                TransformState.makePos(LVecBase3(5.0, 0.0, 0.0)))
            viewer.cam.lookAt(model)

            for _ in range(20):
                viewer.step()
            time.sleep(1.0)

        finally:
            self.hulkSmash(renderer, physics, viewer)