Browse Source

Changes to reflect new window code

Mark Mine 23 years ago
parent
commit
a96e5e4bd2

+ 5 - 6
direct/src/cluster/ClusterClient.py

@@ -156,7 +156,7 @@ class ClusterClientSync(ClusterClient):
                 server.sendSwapNow()
             self.notify.debug(
                 "------------------------------START swap----------")
-            base.win.swap()
+            base.graphicsEngine.flipFrame()
             self.notify.debug(
                 "------------------------------------------END swap")
         return Task.cont
@@ -335,12 +335,11 @@ def createClusterClient():
                 displayConfigs.append(cci)
     # Create Cluster Managers (opening connections to servers)
     # Are the servers going to be synced?
-    clusterSyncFlag = base.config.GetBool('cluster-sync', 0)
-    if clusterSyncFlag:
-        base.win.setSync(1)
-        return ClusterClientSync(displayConfigs, clusterSyncFlag)
+    if base.clusterSyncFlag:
+        base.graphicsEngine.setAutoFlip(0)
+        return ClusterClientSync(displayConfigs, base.clusterSyncFlag)
     else:
-        return ClusterClient(displayConfigs, clusterSyncFlag)
+        return ClusterClient(displayConfigs, base.clusterSyncFlag)
     
     
 class DummyClusterClient(DirectObject.DirectObject):

+ 1 - 1
direct/src/cluster/ClusterServer.py

@@ -166,7 +166,7 @@ class ClusterServer(DirectObject.DirectObject):
             pass
         elif (type == CLUSTER_SWAP_NOW):
             self.notify.debug('swapping')
-            base.win.swap()
+            base.graphicsEngine.flipFrame()
         else:
             self.notify.warning("Received unknown packet type:" % type)
         return type

+ 1 - 0
direct/src/directtools/DirectCameraControl.py

@@ -1,6 +1,7 @@
 from PandaObject import *
 from DirectUtil import *
 from DirectGeometry import *
+import Task
 
 CAM_MOVE_DURATION = 1.2
 COA_MARKER_SF = 0.0075

+ 1 - 0
direct/src/directtools/DirectManipulation.py

@@ -2,6 +2,7 @@ from PandaObject import *
 from DirectGlobals import *
 from DirectUtil import *
 from DirectGeometry import *
+import Task
 
 class DirectManipulationControl(PandaObject):
     def __init__(self):

+ 21 - 7
direct/src/directtools/DirectSelection.py

@@ -19,12 +19,10 @@ class DirectNodePath(NodePath):
         center = self.bbox.getCenter()
         # Create matrix to hold the offset between the nodepath
         # and its center of action (COA)
-        self.mCoa2Dnp = Mat4()
-        if direct.coaMode == COA_ORIGIN:
-            self.mCoa2Dnp.assign(Mat4.identMat())
-        else:
-            self.mCoa2Dnp.assign(Mat4.identMat())
+        self.mCoa2Dnp = Mat4(Mat4.identMat())
+        if direct.coaMode == COA_CENTER:
             self.mCoa2Dnp.setRow(3, Vec4(center[0], center[1], center[2], 1))
+            
         # Transform from nodePath to widget
         self.tDnp2Widget = TransformState.makeIdentity()
 
@@ -233,12 +231,28 @@ class DirectBoundingBox:
         # Record the node path
         self.nodePath = nodePath
         # Compute bounds, min, max, etc.
-        self.computeBounds()
+        self.computeTightBounds()
         # Generate the bounding box
         self.lines = self.createBBoxLines()
 
+    def computeTightBounds(self):
+        # Compute bounding box using tighter calcTightBounds function
+        # Need to clear out existing transform on node path
+        tMat = Mat4()
+        tMat.assign(self.nodePath.getMat())
+        self.nodePath.clearMat()
+        # Get bounds
+        self.min = Point3(0)
+        self.max = Point3(0)
+        self.nodePath.calcTightBounds(self.min,self.max)
+        # Calc center and radius
+        self.center = Point3((self.min + self.max)/2.0)
+        self.radius = Vec3(self.max - self.min).length()
+        # Restore transform
+        self.nodePath.setMat(tMat)
+        del tMat
+        
     def computeBounds(self):
-        #self.bounds = self.nodePath.getBounds()
         self.bounds = self.getBounds()
         if self.bounds.isEmpty() or self.bounds.isInfinite():
             self.center = Point3(0)

+ 117 - 130
direct/src/directtools/DirectSession.py

@@ -17,6 +17,7 @@ import SceneGraphExplorer
 import OnscreenText
 import types
 import string
+import Loader
 
 class DirectSession(PandaObject):
 
@@ -35,7 +36,7 @@ class DirectSession(PandaObject):
         self.drList = DisplayRegionList()
         self.iRayList = map(lambda x: x.iRay, self.drList)
         self.dr = self.drList[0]
-        self.camera = base.cameraList[0]
+        self.camera = base.camera
         self.trueCamera = self.camera
         self.iRay = self.dr.iRay
         self.coaMode = COA_ORIGIN
@@ -124,7 +125,8 @@ class DirectSession(PandaObject):
         
         # One run through the context task to init everything
         self.drList.updateContext()
-        self.drList.camUpdate('')
+        for dr in self.drList:
+            dr.camUpdate()
 
         self.actionEvents = [
             ['select', self.select],
@@ -183,7 +185,7 @@ class DirectSession(PandaObject):
         if self.clusterMode == 'client':
             self.cluster = createClusterClient()
         elif self.clusterMode == 'server':
-            self.cluster = ClusterServer(base.cameraList[0], base.camList[0])
+            self.cluster = ClusterServer(base.camera, base.cam)
         else:
             self.cluster = DummyClusterClient()
         __builtins__['cluster'] = self.cluster
@@ -768,133 +770,17 @@ class DirectSession(PandaObject):
         for iRay in self.iRayList:
             iRay.removeUnpickable(item)
 
-class DisplayRegionList(PandaObject):
-    def __init__(self):
-        self.displayRegionList = []
-        self.displayRegionLookup = {}
-        i = 0
-
-        # Things are funky if we are oobe
-        if (hasattr(base, 'oobeMode') and base.oobeMode):
-            # assume we only have one cam at this point
-            self.displayRegionList.append(DisplayRegionContext(base.win, base.cam, base.groupList[0]))
-        else:
-            for cameraGroup in base.cameraList:
-                # This is following the old way of setting up
-                # display regions.  A display region is set up for
-                # each camera node in the scene graph.  This was done
-                # so that only display regions in the scene graph are
-                # considered.  The right way to do this is to set up
-                # a display region for each real display region, and then
-                # keep track of which are currently active (e.g. use a flag)
-                # processing only them.
-                camList=cameraGroup.findAllMatches('**/+Camera')
-                for cameraIndex in range(camList.getNumPaths()):
-                    camera = camList[cameraIndex]
-                    if camera.getName()=='<noname>':
-                        camera.setName('Camera%d' % cameraIndex)
-                    group = base.groupList[cameraIndex]
-                    self.displayRegionList.append(
-                        DisplayRegionContext(base.win,
-                                             camera,group))
-                    if camera.getName()!='<noname>' or len(camera.getName())==0:
-                        self.displayRegionLookup[camera.getName()]=i
-                        i = i + 1
-
-        self.accept("CamChange",self.camUpdate)
-        self.accept("DIRECT-mouse1",self.mouseUpdate)
-        self.accept("DIRECT-mouse2",self.mouseUpdate)
-        self.accept("DIRECT-mouse3",self.mouseUpdate)
-        self.accept("DIRECT-mouse1Up",self.mouseUpdate)
-        self.accept("DIRECT-mouse2Up",self.mouseUpdate)
-        self.accept("DIRECT-mouse3Up",self.mouseUpdate)
-
-        #setting up array of camera nodes
-        cameraList = []
-        for dr in self.displayRegionList:
-            cameraList.append(dr.cam)
-
-    def __getitem__(self, index):
-        return self.displayRegionList[index]
-
-    def __len__(self):
-        return len(self.displayRegionList)
-
-    def updateContext(self):
-        self.contextTask(None)
-
-    def setNearFar(self, near, far):
-        for dr in self.displayRegionList:
-            dr.camLens.setNearFar(near, far)
-    
-    def setNear(self, near):
-        for dr in self.displayRegionList:
-            dr.camLens.setNear(near)
-    
-    def setFar(self, far):
-        for dr in self.displayRegionList:
-            dr.camLens.setFar(far)
-
-    def setFov(self, hfov, vfov):
-        for dr in self.displayRegionList:
-            dr.setFov(hfov, vfov)
-
-    def setHfov(self, fov):
-        for dr in self.displayRegionList:
-            dr.setHfov(fov)
-
-    def setVfov(self, fov):
-        for dr in self.displayRegionList:
-            dr.setVfov(fov)
-
-    def camUpdate(self, camName):
-        if self.displayRegionLookup.has_key(camName):
-            self.displayRegionList[self.displayRegionLookup[camName]].camUpdate()
-        else:
-            for dr in self.displayRegionList:
-                dr.camUpdate()
-
-    def mouseUpdate(self, modifiers = DIRECT_NO_MOD):
-        for dr in self.displayRegionList:
-            dr.mouseUpdate()
-        direct.dr = self.getCurrentDr()
-
-    def getCurrentDr(self):
-        for dr in self.displayRegionList:
-            if (dr.mouseX >= -1.0 and dr.mouseX <= 1.0 and
-                dr.mouseY >= -1.0 and dr.mouseY <= 1.0):
-                return dr
-        return self.displayRegionList[0]
-
-    def start(self):
-        # First shutdown any existing task
-        self.stop()
-        # Start a new context task
-        self.spawnContextTask()
-
-    def stop(self):
-        # Kill the existing context task
-        taskMgr.remove('DIRECTContextTask')
-
-    def spawnContextTask(self):
-        taskMgr.add(self.contextTask, 'DIRECTContextTask')
-
-    def removeContextTask(self):
-        taskMgr.remove('DIRECTContextTask')
-
-    def contextTask(self, state):
-        # Window Data
-        self.mouseUpdate()
-        # hack to test movement
-        return Task.cont
-
-class DisplayRegionContext:
-    def __init__(self, win, cam, group):
-        self.win = win
+class DisplayRegionContext(PandaObject):
+    regionCount = 0
+    def __init__(self, cam):
         self.cam = cam
         self.camNode = self.cam.node()
         self.camLens = self.camNode.getLens()
-        self.group = group
+        # set lens change callback
+        changeEvent = 'dr%d-change-event' % DisplayRegionContext.regionCount
+        DisplayRegionContext.regionCount += 1
+        self.camLens.setChangeEvent(changeEvent)
+        self.accept(changeEvent, self.camUpdate)
         self.iRay = SelectionRay(self.cam)
         self.nearVec = Vec3(0)
         self.mouseX = 0.0
@@ -923,7 +809,8 @@ class DisplayRegionContext:
         return self.__dict__[key]
 
     def setOrientation(self):
-        hpr = self.cam.getHpr(base.cameraList[self.group])
+        # MRM This assumes orientation is set on transform above cam
+        hpr = self.cam.getHpr()
         if hpr[2] < 135 and hpr[2]>45 or hpr[2]>225 and hpr[2]<315:
             self.isSideways = 1
         elif hpr[2] > -135 and hpr[2] < -45 or hpr[2] < -225 and hpr[2] > -315:
@@ -964,8 +851,6 @@ class DisplayRegionContext:
             
     def camUpdate(self):
         # Window Data
-        self.width = self.win.getWidth()
-        self.height = self.win.getHeight()
         self.near = self.camLens.getNear()
         self.far = self.camLens.getFar()
         self.fovH = self.camLens.getHfov()
@@ -996,6 +881,108 @@ class DisplayRegionContext:
                          self.near,
                          (self.nearHeight*0.5) * self.mouseY)
 
+class DisplayRegionList(PandaObject):
+    def __init__(self):
+        self.displayRegionList = []
+        i = 0
+        # Things are funky if we are oobe
+        if (hasattr(base, 'oobeMode') and base.oobeMode):
+            # assume we only have one cam at this point
+            drc = DisplayRegionContext(base.cam)
+            self.displayRegionList.append(drc)
+        else:
+            # MRM: Doesn't properly handle multiple camera groups anymore
+            # Assumes everything is under main camera
+            for cameraGroup in base.cameraList:
+                # This is following the old way of setting up
+                # display regions.  A display region is set up for
+                # each camera node in the scene graph.  This was done
+                # so that only display regions in the scene graph are
+                # considered.  The right way to do this is to set up
+                # a display region for each real display region, and then
+                # keep track of which are currently active (e.g. use a flag)
+                # processing only them.
+                for camIndex in range(len(base.camList)):
+                    cam = base.camList[camIndex]
+                    if cam.getName()=='<noname>':
+                        cam.setName('Camera%d' % camIndex)
+                    drc = DisplayRegionContext(cam)
+                    self.displayRegionList.append(drc)
+
+        self.accept("DIRECT-mouse1",self.mouseUpdate)
+        self.accept("DIRECT-mouse2",self.mouseUpdate)
+        self.accept("DIRECT-mouse3",self.mouseUpdate)
+        self.accept("DIRECT-mouse1Up",self.mouseUpdate)
+        self.accept("DIRECT-mouse2Up",self.mouseUpdate)
+        self.accept("DIRECT-mouse3Up",self.mouseUpdate)
+
+    def __getitem__(self, index):
+        return self.displayRegionList[index]
+
+    def __len__(self):
+        return len(self.displayRegionList)
+
+    def updateContext(self):
+        self.contextTask(None)
+
+    def setNearFar(self, near, far):
+        for dr in self.displayRegionList:
+            dr.camLens.setNearFar(near, far)
+    
+    def setNear(self, near):
+        for dr in self.displayRegionList:
+            dr.camLens.setNear(near)
+    
+    def setFar(self, far):
+        for dr in self.displayRegionList:
+            dr.camLens.setFar(far)
+
+    def setFov(self, hfov, vfov):
+        for dr in self.displayRegionList:
+            dr.setFov(hfov, vfov)
+
+    def setHfov(self, fov):
+        for dr in self.displayRegionList:
+            dr.setHfov(fov)
+
+    def setVfov(self, fov):
+        for dr in self.displayRegionList:
+            dr.setVfov(fov)
+
+    def mouseUpdate(self, modifiers = DIRECT_NO_MOD):
+        for dr in self.displayRegionList:
+            dr.mouseUpdate()
+        direct.dr = self.getCurrentDr()
+
+    def getCurrentDr(self):
+        for dr in self.displayRegionList:
+            if (dr.mouseX >= -1.0 and dr.mouseX <= 1.0 and
+                dr.mouseY >= -1.0 and dr.mouseY <= 1.0):
+                return dr
+        return self.displayRegionList[0]
+
+    def start(self):
+        # First shutdown any existing task
+        self.stop()
+        # Start a new context task
+        self.spawnContextTask()
+
+    def stop(self):
+        # Kill the existing context task
+        taskMgr.remove('DIRECTContextTask')
+
+    def spawnContextTask(self):
+        taskMgr.add(self.contextTask, 'DIRECTContextTask')
+
+    def removeContextTask(self):
+        taskMgr.remove('DIRECTContextTask')
+
+    def contextTask(self, state):
+        # Window Data
+        self.mouseUpdate()
+        # hack to test movement
+        return Task.cont
+
 # Create one
 __builtins__['direct'] = base.direct = DirectSession()
 

+ 24 - 14
direct/src/showbase/ShowBase.py

@@ -78,6 +78,14 @@ class ShowBase(DirectObject.DirectObject):
         fsmRedefine = self.config.GetBool('fsm-redefine', 0)
         State.FsmRedefine = fsmRedefine
 
+        # This is used for syncing multiple PCs in a distributed cluster
+        try:
+            # Has the cluster sync variable been set externally?
+            self.clusterSyncFlag = clusterSyncFlag
+        except NameError:
+            # Has the clusterSyncFlag been set via a config variable
+            self.clusterSyncFlag = base.config.GetBool('cluster-sync', 0)
+
         self.hidden = NodePath('hidden')
 
         # We need a graphics engine to manage the actual rendering.
@@ -110,8 +118,9 @@ class ShowBase(DirectObject.DirectObject):
         self.camList = []
         self.camNode = None
         self.camLens = None
-        self.groupList = []
-        self.camera = self.render.attachNewNode('camera')
+        #self.camera = self.render.attachNewNode('camera')
+        self.camera = None
+        self.cameraList = []
         self.camera2d = self.render2d.attachNewNode('camera2d')
 
         # Now that we've set up the window structures, assign an exitfunc.
@@ -566,21 +575,20 @@ class ShowBase(DirectObject.DirectObject):
         """
 
         for i in range(chanConfig.getNumGroups()):
-            cam = NodePath(chanConfig.getGroupNode(i)).find('**/+Camera')
-            lens = cam.node().getLens()
-
+            # Create a top level camera node for this group
+            camera = self.render.attachNewNode(chanConfig.getGroupNode(i))
+            self.cameraList.append(camera)
+            # Extract camera
+            cam = camera.find('**/+Camera')
+            self.camList.append(cam)
             # Enforce our expected aspect ratio, overriding whatever
             # nonsense ChanConfig put in there.
+            lens = cam.node().getLens()
             lens.setAspectRatio(self.aspectRatio)
-            
-            cam.reparentTo(self.camera)
-            self.camList.append(cam)
-            
-        # this is how we know which display region cameras belong to which
-        # camera group.  display region i belongs to group self.groupList[i]
-        for i in range(chanConfig.getNumDrs()):
-            self.groupList.append(chanConfig.getGroupMembership(i))
 
+        # Update main camera variables
+        if self.camera == None:
+            self.camera = self.cameraList[0]
         if self.cam == None:
             self.cam = self.camList[0]
             # If you need to get a handle to the camera node itself,
@@ -781,7 +789,9 @@ class ShowBase(DirectObject.DirectObject):
     def igloop(self, state):
         # Finally, render the frame.
         self.graphicsEngine.renderFrame()
-
+        if self.clusterSyncFlag:
+            base.graphicsEngine.syncFrame()
+    
         if self.mainWinMinimized:
             # If the main window is minimized, slow down the app a bit
             # by sleeping here in igloop so we don't use all available