Ver Fonte

Small extensions for the mirror demo

Add extra parameters for buffer size and clear color
Add sample code at the bottom to display usage of mirror demo

Closes: #195
fireclawthefox há 8 anos atrás
pai
commit
936ef1953c
1 ficheiros alterados com 26 adições e 4 exclusões
  1. 26 4
      direct/src/showbase/MirrorDemo.py

+ 26 - 4
direct/src/showbase/MirrorDemo.py

@@ -24,7 +24,8 @@ __all__ = ['setupMirror', 'showFrustum']
 from panda3d.core import *
 from direct.task import Task
 
-def setupMirror(name, width, height, rootCamera = None):
+def setupMirror(name, width, height, rootCamera = None,
+                bufferSize = 256, clearColor = None):
     # The return value is a NodePath that contains a rectangle that
     # reflects render.  You can reparent, reposition, and rotate it
     # anywhere you like.
@@ -49,9 +50,12 @@ def setupMirror(name, width, height, rootCamera = None):
     # Now create an offscreen buffer for rendering the mirror's point
     # of view.  The parameters here control the resolution of the
     # texture.
-    buffer = base.win.makeTextureBuffer(name, 256, 256)
-    #buffer.setClearColor(base.win.getClearColor())
-    buffer.setClearColor(VBase4(0, 0, 1, 1))
+    buffer = base.win.makeTextureBuffer(name, bufferSize, bufferSize)
+    if clearColor is None:
+        buffer.setClearColor(base.win.getClearColor())
+        #buffer.setClearColor(VBase4(0, 0, 1, 1))
+    else:
+        buffer.setClearColor(clearColor)
 
     # Set up a display region on this buffer, and create a camera.
     dr = buffer.makeDisplayRegion()
@@ -132,3 +136,21 @@ def showFrustum(np):
     geomNode.addGeom(lens.makeGeometry())
     cameraNP.attachNewNode(geomNode)
 
+if __name__ == "__main__":
+    from direct.showbase.ShowBase import ShowBase
+    base = ShowBase()
+
+    panda = loader.loadModel("panda")
+    panda.setH(180)
+    panda.setPos(0, 10, -2.5)
+    panda.setScale(0.5)
+    panda.reparentTo(render)
+
+    myMirror = setupMirror("mirror", 10, 10, bufferSize=1024, clearColor=(0, 0, 1, 1))
+    myMirror.setPos(0, 15, 2.5)
+    myMirror.setH(180)
+
+    # Uncomment this to show the frustum of the camera in the mirror
+    #showFrustum(render)
+
+    base.run()