Skip to content

Commit 62117f5

Browse files
authored
Add custom render callback to Python visualizer (#14)
1 parent 12897dc commit 62117f5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

python/cli/visualization/visualizer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ class VisualizerArgs:
215215
# Recording
216216
recordPath = None # Record the window to video file given by path
217217

218+
# Callbacks
219+
customRenderCallback = None # Used to render custom OpenGL objects in user code
220+
218221
class Recorder:
219222
def __init__(self, recordPath, resolution):
220223
import subprocess
@@ -245,6 +248,8 @@ def __init__(self, args=VisualizerArgs()):
245248
self.outputQueue = []
246249
self.outputQueueMutex = Lock()
247250
self.clock = pygame.time.Clock()
251+
self.projectionMatrix = None
252+
self.viewMatrix = None
248253

249254
# Window
250255
self.fullScreen = args.fullScreen
@@ -371,9 +376,13 @@ def __render(self, cameraPose, width, height, image=None, colorFormat=None):
371376
top = 25.0 * self.cameraControls2D.zoom / self.aspectRatio
372377
projectionMatrix = getOrthographicProjectionMatrixOpenGL(left, right, bottom, top, -1000.0, 1000.0)
373378

379+
self.projectionMatrix = projectionMatrix
380+
self.viewMatrix = viewMatrix
381+
374382
self.map.render(cameraPose.getPosition(), viewMatrix, projectionMatrix)
375383
if self.showGrid: self.grid.render(viewMatrix, projectionMatrix)
376384
if self.showPoseTrail: self.poseTrail.render(viewMatrix, projectionMatrix)
385+
if self.args.customRenderCallback: self.args.customRenderCallback()
377386

378387
if self.cameraMode in [CameraMode.THIRD_PERSON, CameraMode.TOP_VIEW]:
379388
modelMatrix = cameraPose.getCameraToWorldMatrix()
@@ -539,6 +548,12 @@ def run(self):
539548

540549
self.__close()
541550

551+
def getProjectionMatrix(self):
552+
return self.projectionMatrix
553+
554+
def getViewMatrix(self):
555+
return self.viewMatrix
556+
542557
def printHelp(self):
543558
print("Control using the keyboard:")
544559
print("* Q: Quit")

0 commit comments

Comments
 (0)