Viewport for base.cam

I am trying to set up a viewport that all of my 3d rendering will go into, and have the rest of the main window for GUI. I can get the 3d viewport rendering, but the objects I have added to the scene also render in my main window.

# Standard imports

import sys
import math

# Panda imports

from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *

from pandac.PandaModules import TextNode

ClearColor = VBase4(0.0,0.0,0.0,1.0)
BgColor = VBase4(0.0,0.1,0.55,1.0)
Model="assets/eve"

class World(DirectObject):
	def __init__(self):
		base.setBackgroundColor(ClearColor)
		self.accept('escape',sys.exit)

		# Setup the main 'world' scene
		self.mWorld = NodePath("World")
		self.mWorld.reparentTo(render)

		#add some text
		self.textObject = OnscreenText("This is my Demo", pos = (0.95,-0.95), scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)

		#add button
		self.buttonObject = DirectButton(text = ("OK", "click!", "rolling over", "disabled"),scale=.05,command=self.setText)


		self.mVPDisplayRegion = base.win.makeDisplayRegion(0.70,0.95,0.70,0.95)
		self.mVPDisplayRegion.setClearColorActive(1)
		self.mVPDisplayRegion.setClearDepthActive(1)
		self.mVPDisplayRegion.setCamera(base.cam)
		self.mVPDisplayRegion.setClearColor(BgColor)


		self.mModel = loader.loadModel(Model)
		self.mModel.setScale(1.0,1.0,1.0)
		self.mModel.setPos(0,15,-2)
		self.mModel.reparentTo(self.mWorld)


		#callback function to set  text
	def setText():
		textObject.setText("Button Clicked")

w = World()

#run
run()

Can anybody lend some insight as to how I am supposed to keep the main scene from rendering?

The original DisplayRegion is still associated with base.cam. You just need to disassociate it, or disable the DisplayRegion. For this, you need to get a pointer to the DisplayRegion, which you can get through base.cam:

dr = base.cam.getDisplayRegion(0)
dr.setActive(False)

David

Thanks for the quick reply David, but I am getting this attribute error now

dr = base.cam.getDisplayRegion(0)
AttributeError: 'libpanda.NodePath' object has no attribute 'getDisplayRegion'

Try base.camNode instead of base.cam (or base.cam.node() which is the same thing)

Perfect! Thanks!

One more quick question,
Say I were to want to turn this viewport on and off, how would I go about doing such a thing?

EDIT: SetActive(bool)
got it… just couldn’t find it in the docs :slight_smile: