Parcourir la source

support for Directtools

David Rose il y a 24 ans
Parent
commit
ad981aaee2

+ 13 - 3
direct/src/directtools/DirectGeometry.py

@@ -24,7 +24,7 @@ class LineNodePath(NodePath):
 
         # Attach a geomNode to the parent and set self to be
         # the resulting node path
-        self.lineNode = GeomNode()
+        self.lineNode = GeomNode("lineNode")
         self.assign(parent.attachNewNode( self.lineNode ))
         if name:
             self.setName(name)
@@ -46,7 +46,12 @@ class LineNodePath(NodePath):
 
     def reset( self ):
         self.lineSegs.reset()
-        self.lineNode.clear()
+        try:
+            # Old-style graph
+            self.lineNode.clear()
+        except:
+            # New-style graph
+            self.lineNode.removeAllGeoms()
 
     def isEmpty( self ):
         return self.lineSegs.isEmpty()
@@ -210,5 +215,10 @@ def relHpr(nodePath, base, h, p, r):
 # Set direct drawing style for an object
 # Never light object or draw in wireframe
 def useDirectRenderStyle(nodePath):
-    nodePath.arc().setTransition(LightTransition.allOff())
+    try:
+        # Old-style scene graph
+        nodePath.arc().setTransition(LightTransition.allOff())
+    except:
+        # No new-style equivalent yet.
+        pass
     nodePath.setRenderModeFilled()

+ 24 - 5
direct/src/directtools/DirectLights.py

@@ -9,11 +9,20 @@ class DirectLight(NodePath):
         # Record light and name
         self.light = light
         self.name = light.getName()
-        # Attach node to self
+
+        # Upcast the light object to its node base pointer
         if isinstance(light, Spotlight):
-            self.assign(parent.attachNewNode(light.upcastToProjectionNode()))
+            node = light.upcastToProjectionNode()
         else:
-            self.assign(parent.attachNewNode(light.upcastToNamedNode()))
+            node = light.upcastToNamedNode()
+
+        # Attach node to self
+        try:
+            self.assign(parent.attachNewNode(none))
+        except:
+            # New scene graph doesn't have lights yet.
+            pass
+
     def getName(self):
         return self.name
     def getLight(self):
@@ -99,13 +108,23 @@ class DirectLights(NodePath):
 
     def allOn(self):
         """ Turn on all DIRECT lights """
-        render.arc().setTransition(self.lt)
+        try:
+            # Old-style scene graph
+            render.arc().setTransition(self.lt)
+        except:
+            # No new-style equivalent yet.
+            pass
         # Make sure there is a default material
         render.setMaterial(Material())
 
     def allOff(self):
         """ Turn off all DIRECT lights """
-        render.arc().clearTransition(LightTransition.getClassType())
+        try:
+            # Old-style scene graph
+            render.arc().clearTransition(LightTransition.getClassType())
+        except:
+            # No new-style equivalent yet.
+            pass
 
     def toggle(self):
         """ Toggles light attribute, but doesn't toggle individual lights """

+ 2 - 2
direct/src/directtools/DirectSelection.py

@@ -383,7 +383,7 @@ class DirectBoundingBox:
 class SelectionRay:
     def __init__(self, parent):
         # Create a collision node path attached to the given parent
-        self.rayCollisionNodePath = parent.attachNewNode( CollisionNode() )
+        self.rayCollisionNodePath = parent.attachNewNode( CollisionNode("ray") )
         # Don't pay the penalty of drawing this collision ray
         self.rayCollisionNodePath.hide()
         self.rayCollisionNode = self.rayCollisionNodePath.node()
@@ -400,7 +400,7 @@ class SelectionRay:
         # Current entry in collision queue
         self.cqIndex = 0
         # And a traverser to do the actual collision tests
-        self.ct = CollisionTraverser( RenderRelation.getClassType() )
+        self.ct = CollisionTraverser()
         # Let the traverser know about the queue and the collision node
         self.ct.addCollider(self.rayCollisionNode, self.cq )
         # Reference node path (for picking next)

+ 4 - 2
direct/src/directtools/DirectSession.py

@@ -865,8 +865,10 @@ class DisplayRegionContext:
         # one display region per camera, since we are defining a
         # display region on a per-camera basis.  See note in
         # DisplayRegionList.__init__()
-        numDrs = self.camNode.getNumDrs()
-        self.dr = self.camNode.getDr(0)
+        try:
+            self.dr = self.camNode.getDr(0)
+        except:
+            self.dr = self.camNode.getDisplayRegion(0)
         left = self.dr.getLeft()
         right = self.dr.getRight()
         bottom = self.dr.getBottom()

+ 5 - 2
direct/src/extensions/NodePath-extensions.py

@@ -5,8 +5,11 @@
     """
 
     def id(self):
-        """Returns the bottom node's this pointer as a unique id"""
-        return self.arc()
+        """Returns a unique id identifying the NodePath instance"""
+        # Nowadays, the NodePath itself serves as that unique id.
+        # This function is therefore deprecated and should be removed
+        # soon.
+        return self
 
     def getName(self):
         """Returns the name of the bottom node if it exists, or <noname>"""

+ 12 - 0
direct/src/ffi/FFIRename.py

@@ -98,15 +98,21 @@ pgraphClassRenameDictionary = {
     'ButtonNode'                : 'SpButtonNode',
     'ButtonThrower'             : 'SpButtonThrower',
     'Camera'                    : 'SpCamera',
+    'CardMaker'                 : 'SpCardMaker',
     'ChanConfig'                : 'SpChanConfig',
     'Character'                 : 'SpCharacter',
+    'CollisionNode'             : 'SpCollisionNode',
+    'CollisionTraverser'        : 'SpCollisionTraverser',
     'DataGraphTraverser'        : 'SpDataGraphTraverser',
     'DataNode'                  : 'SpDataNode',
     'DialNode'                  : 'SpDialNode',
     'DriveInterface'            : 'SpDriveInterface',
     'GeomNode'                  : 'SpGeomNode',
     'LODNode'                   : 'SpLODNode',
+    'LineSegs'                  : 'SpLineSegs',
     'LensNode'                  : 'SpLensNode',
+    'ModelNode'                 : 'SpModelNode',
+    'ModelRoot'                 : 'SpModelRoot',
     'ModelPool'                 : 'SpModelPool',
     'MouseAndKeyboard'          : 'SpMouseAndKeyboard',
     'MouseWatcher'              : 'SpMouseWatcher',
@@ -131,15 +137,21 @@ pgraphClassRenameDictionary = {
     'QpButtonNode'              : 'ButtonNode',
     'QpButtonThrower'           : 'ButtonThrower',
     'QpCamera'                  : 'Camera',
+    'QpCardMaker'               : 'CardMaker',
     'QpChanConfig'              : 'ChanConfig',
     'QpCharacter'               : 'Character',
+    'QpCollisionNode'           : 'CollisionNode',
+    'QpCollisionTraverser'      : 'CollisionTraverser',
     'QpDataGraphTraverser'      : 'DataGraphTraverser',
     'QpDataNode'                : 'DataNode',
     'QpDialNode'                : 'DialNode',
     'QpDriveInterface'          : 'DriveInterface',
     'QpGeomNode'                : 'GeomNode',
     'QpLODNode'                 : 'LODNode',
+    'QpLineSegs'                : 'LineSegs',
     'QpLensNode'                : 'LensNode',
+    'QpModelNode'               : 'ModelNode',
+    'QpModelRoot'               : 'ModelRoot',
     'QpModelPool'               : 'ModelPool',
     'QpMouseAndKeyboard'        : 'MouseAndKeyboard',
     'QpMouseWatcher'            : 'MouseWatcher',