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 testAgent(self): physics = None viewer = None try: scene = Scene() physics = Panda3dBulletPhysics(scene, debug=True) agent = scene.agents[0].find('**/+BulletRigidBodyNode') agent.setPos(LVector3f(0, 0, 1.0)) agent.node().setLinearVelocity(LVector3f(1, 0, 0)) agent.node().setAngularVelocity(LVector3f(0, 0, 1)) agent.node().setActive(True) viewer = Viewer(scene, interactive=False) viewer.disableMouse() mat = np.array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, -10, 0, 1]) mat = LMatrix4f(*mat.ravel()) viewer.cam.setMat(mat) for _ in range(50): viewer.step() time.sleep(1.0) finally: self.hulkSmash(None, physics, viewer)
def testDebugHouseWithViewer(self): try: scene = SunCgSceneLoader.loadHouseFromJson( "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR) 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: physics.destroy() viewer.destroy() viewer.graphicsEngine.removeAllWindows()
def testStep(self): try: scene = SunCgSceneLoader.loadHouseFromJson( "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR) #NOTE: show initial models loaded into the scene for model in scene.scene.findAllMatches('**/+ModelNode'): model.show() viewer = Viewer(scene, shadowing=True) # Configure the camera #NOTE: in Panda3D, the X axis points to the right, the Y axis is forward, and Z is up 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: viewer.destroy()
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
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 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()
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)
def main(): env = BasicEnvironment(houseId="0004d52d1aeeb8ae6de39d6bd993e992", suncgDatasetRoot=TEST_SUNCG_DATA_DIR, realtime=True) env.renderWorld.showRoomLayout(showCeilings=False, showWalls=True, showFloors=True) viewer = Viewer(env.scene, interactive=True, showPosition=True) viewer.cam.setPos((42, -39, 1.1)) viewer.cam.setHpr(60.0, 0.0, 0.0) viewer.run() viewer.destroy() viewer.graphicsEngine.removeAllWindows() return 0
def testRenderHouse(self): scene = SunCgSceneLoader.loadHouseFromJson( "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR) samplingRate = 16000.0 hrtf = CipicHRTF(os.path.join(TEST_DATA_DIR, 'hrtf', 'cipic_hrir.mat'), samplingRate) acoustics = EvertAcoustics(scene, hrtf, samplingRate, maximumOrder=2, debug=True) acoustics.step(0.0) # Hide ceilings for nodePath in scene.scene.findAllMatches( '**/layouts/*/acoustics/*c'): nodePath.hide(BitMask32.allOn()) viewer = Viewer(scene, interactive=False) # Configure the camera # NOTE: in Panda3D, the X axis points to the right, the Y axis is # forward, and Z is up 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): acoustics.step(dt=0.1) viewer.step() time.sleep(1.0) acoustics.destroy() viewer.destroy() viewer.graphicsEngine.removeAllWindows()
def testRenderHouseWithAcousticsPath(self): scene = SunCgSceneLoader.loadHouseFromJson( "0004d52d1aeeb8ae6de39d6bd993e992", TEST_SUNCG_DATA_DIR) agentNp = scene.agents[0] agentNp.setPos(LVecBase3f(45, -42.5, 1.6)) agentNp.setHpr(45, 0, 0) # Define a sound source sourceSize = 0.25 modelId = 'source-0' modelFilename = os.path.join(TEST_DATA_DIR, 'models', 'sphere.egg') objectsNp = scene.scene.attachNewNode('objects') objectsNp.setTag('acoustics-mode', 'source') objectNp = objectsNp.attachNewNode('object-' + modelId) model = loadModel(modelFilename) model.setName('model-' + modelId) model.setTransform(TransformState.makeScale(sourceSize)) model.reparentTo(objectNp) objectNp.setPos(LVecBase3f(39, -40.5, 1.5)) samplingRate = 16000.0 hrtf = CipicHRTF(os.path.join(TEST_DATA_DIR, 'hrtf', 'cipic_hrir.mat'), samplingRate) acoustics = EvertAcoustics(scene, hrtf, samplingRate, maximumOrder=2, debug=True) # Attach sound to object filename = os.path.join(TEST_DATA_DIR, 'audio', 'toilet.ogg') sound = EvertAudioSound(filename) acoustics.attachSoundToObject(sound, objectNp) sound.play() acoustics.step(0.0) # Hide ceilings for nodePath in scene.scene.findAllMatches( '**/layouts/*/acoustics/*c'): nodePath.hide(BitMask32.allOn()) viewer = Viewer(scene, interactive=False) # Configure the camera # NOTE: in Panda3D, the X axis points to the right, the Y axis is forward, and Z is up center = agentNp.getNetTransform().getPos() mat = np.array([[1.0, 0.0, 0.0, 0.0], [0.0, 0.0, -1.0, 0.0], [0.0, 1.0, 0.0, 0.0], [center.x, center.y, 20, 1]]) mat = LMatrix4f(*mat.ravel()) viewer.cam.setMat(mat) for _ in range(20): viewer.step() time.sleep(1.0) viewer.destroy() viewer.graphicsEngine.removeAllWindows() # Calculate and show impulse responses impulse = acoustics.calculateImpulseResponse(objectNp.getName(), agentNp.getName()) fig = plt.figure() plt.plot(impulse.impulse[0], color='b', label='Left channel') plt.plot(impulse.impulse[1], color='g', label='Right channel') plt.legend() plt.show(block=False) time.sleep(1.0) plt.close(fig) acoustics.destroy()
def testRenderSimpleCubeRoom(self): samplingRate = 16000.0 scene = Scene() hrtf = CipicHRTF(os.path.join(TEST_DATA_DIR, 'hrtf', 'cipic_hrir.mat'), samplingRate) viewer = Viewer(scene, interactive=False) # Define a simple cube (10 x 10 x 10 m) as room geometry roomSize = 10.0 modelId = 'room-0' modelFilename = os.path.join(TEST_DATA_DIR, 'models', 'cube.egg') layoutNp = scene.scene.attachNewNode('layouts') objectNp = layoutNp.attachNewNode('object-' + modelId) objectNp.setTag('acoustics-mode', 'obstacle') model = loadModel(modelFilename) model.setName('model-' + modelId) model.setTransform(TransformState.makeScale(roomSize)) model.setRenderModeWireframe() model.reparentTo(objectNp) objectNp.setPos(LVecBase3f(0.0, 0.0, 0.0)) # Define a sound source sourceSize = 0.25 modelId = 'source-0' modelFilename = os.path.join(TEST_DATA_DIR, 'models', 'sphere.egg') objectsNp = scene.scene.attachNewNode('objects') objectNp = objectsNp.attachNewNode('object-' + modelId) objectNp.setTag('acoustics-mode', 'source') model = loadModel(modelFilename) model.setName('model-' + modelId) model.setTransform(TransformState.makeScale(sourceSize)) model.reparentTo(objectNp) objectNp.setPos(LVecBase3f(0.0, 0.0, 0.0)) acoustics = EvertAcoustics(scene, hrtf, samplingRate, maximumOrder=3, materialAbsorption=False, frequencyDependent=False, debug=True) # Attach sound to object filename = os.path.join(TEST_DATA_DIR, 'audio', 'toilet.ogg') sound = EvertAudioSound(filename) acoustics.attachSoundToObject(sound, objectNp) acoustics.step(0.1) center = acoustics.world.getCenter() self.assertTrue( np.allclose(acoustics.world.getMaxLength() / 1000.0, roomSize)) self.assertTrue( np.allclose([center.x, center.y, center.z], [0.0, 0.0, 0.0])) self.assertTrue(acoustics.world.numElements() == 12) self.assertTrue(acoustics.world.numConvexElements() == 12) # Configure the camera # NOTE: in Panda3D, the X axis points to the right, the Y axis is forward, and Z is up mat = np.array([ 0.999992, 0.00394238, 0, 0, -0.00295702, 0.750104, -0.661314, 0, -0.00260737, 0.661308, 0.75011, 0, 0.0, -25.0, 22, 1 ]) mat = LMatrix4f(*mat.ravel()) viewer.cam.setMat(mat) agentNp = scene.agents[0] agentNp.setPos( LVecBase3f(0.25 * roomSize, -0.25 * roomSize, 0.3 * roomSize)) for _ in range(10): viewer.step() time.sleep(1.0) agentNp.setPos( LVecBase3f(0.35 * roomSize, -0.35 * roomSize, 0.4 * roomSize)) for _ in range(10): viewer.step() time.sleep(1.0) agentNp.setPos( LVecBase3f(-0.25 * roomSize, 0.25 * roomSize, -0.3 * roomSize)) for _ in range(10): viewer.step() time.sleep(1.0) # Calculate and show impulse responses impulse = acoustics.calculateImpulseResponse(objectNp.getName(), agentNp.getName()) fig = plt.figure() plt.plot(impulse.impulse[0], color='b', label='Left channel') plt.plot(impulse.impulse[1], color='g', label='Right channel') plt.legend() plt.show(block=False) time.sleep(1.0) plt.close(fig) acoustics.destroy() viewer.destroy() viewer.graphicsEngine.removeAllWindows()
def main(): # Create scene and remove any default agents scene = SunCgSceneLoader.loadHouseFromJson( houseId="0004d52d1aeeb8ae6de39d6bd993e992", datasetRoot=SUNCG_DATA_DIR) scene.scene.find('**/agents').node().removeAllChildren() scene.agents = [] # Create multiple agents agents = [] for i in range(3): agentRadius = 0.15 agent = Agent(scene, 'agent-%d' % (i), agentRadius) agents.append(agent) # NOTE: specify to move the camera slightly outside the model (not to render the interior of the model) cameraTransform = TransformState.makePos( LVector3f(0.0, 1.1 * agentRadius, 0.0)) # Initialize rendering and physics renderer = RgbRenderer(scene, size=(128, 128), fov=70.0, cameraTransform=cameraTransform) renderer.showRoomLayout(showCeilings=False, showWalls=True, showFloors=True) physics = Panda3dBulletPhysics(scene, SUNCG_DATA_DIR, objectMode='box', agentRadius=agentRadius, agentMode='sphere') # Configure the camera viewer = Viewer(scene, interactive=False, showPosition=False, cameraMask=renderer.cameraMask) transform = TransformState.makePosHpr(LVecBase3f(44.01, -43.95, 22.97), LVecBase3f(0.0, -81.04, 0.0)) viewer.cam.setTransform(transform) # Initialize the agent agents[0].setPosition((45, -42.5, 1.6)) agents[1].setPosition((42.5, -39, 1.6)) agents[2].setPosition((42.5, -41.5, 1.6)) # Initialize figure that will show the point-of-view of each agent plt.ion() fig = plt.figure(figsize=(12, 4), facecolor='white') ims = [] for i in range(len(agents)): ax = fig.add_subplot(1, len(agents), i + 1) ax.set_title(agents[i].agentId) ax.axis('off') rgbImage = np.zeros(renderer.size + (3, ), dtype=np.uint8) im = ax.imshow(rgbImage) ims.append(im) plt.tight_layout() plt.show() # Main loop clock = ClockObject.getGlobalClock() try: while True: # Update physics dt = clock.getDt() physics.step(dt) # Update viewer viewer.step() for i, agent in enumerate(agents): # Get the current RGB rgbImage = renderer.getRgbImage(agent.agentId, channelOrder="RGB") # Get the current observation for the agent observation = { "position": agent.getPosition(), "orientation": agent.getOrientation(), "rgb-image": rgbImage } agent.step(observation) ims[i].set_data(rgbImage) fig.canvas.draw() plt.pause(0.0001) except KeyboardInterrupt: pass viewer.destroy() renderer.destroy() return 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