Exemple #1
0
    def testRenderWithModelLights(self):

        filename = os.path.join(TEST_SUNCG_DATA_DIR, 'metadata',
                                'suncgModelLights.json')
        info = SunCgModelLights(filename)

        scene = Scene()

        modelId = 's__1296'
        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))

        # Add lights to model
        for lightNp in info.getLightsForModel(modelId):
            lightNp.node().setShadowCaster(True, 512, 512)
            lightNp.reparentTo(model)
            scene.scene.setLight(lightNp)

        viewer = None

        try:
            viewer = Viewer(scene, interactive=False, shadowing=True)

            viewer.cam.setTransform(
                TransformState.makePos(LVector3f(0.5, 0.5, 3.0)))
            viewer.cam.lookAt(lightNp)

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

        finally:
            if viewer is not None:
                viewer.destroy()
                viewer.graphicsEngine.removeAllWindows()
    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 testLoadFromJson(self):
        filename = os.path.join(TEST_SUNCG_DATA_DIR, 'metadata', 'suncgModelLights.json')
        info = SunCgModelLights(filename)

        lights = info.getLightsForModel(modelId='s__1296')
        self.assertTrue(len(lights) == 2)

        lights = info.getLightsForModel(modelId='83')
        self.assertTrue(len(lights) == 0)

        lights = info.getLightsForModel(modelId='377')
        self.assertTrue(len(lights) == 1)

        lights = info.getLightsForModel(modelId='178')
        self.assertTrue(len(lights) == 1)