WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Using viz.window.screenCapture in a loop? (https://forum.worldviz.com/showthread.php?t=6322)

jericson 08-14-2020 05:08 AM

Using viz.window.screenCapture in a loop?
 
Hello, I'm having trouble using viz.window.screenCapture() to grab images before and after a list of objects have been removed from a scene. This short example is analogous to what I'm trying to do:

Code:

def showDebugBall(x,y,z,size=1):
       
        ball = viz.add('ball.wrl')
        ball.setQuat(0,0,0,1)
        ball.setPosition(x,y,z)
        ball.setScale(size,size,size)

        smallball = viz.add('ball.wrl')
        smallball.setQuat(0,0,0,1)
        smallball.setParent(ball)
        smallball.setPosition(x,y,z)
        smallball.setScale(0.5*size,0.5*size,0.5*size)
       
        return ball

objects = []
n = 12
for i in range(n):
        aball = showDebugBall(0,2,i)
        objects.append(aball)

viz.window.screenCapture("images/Before.png")

for obj in objects:
        obj.remove()
       
viz.window.screenCapture("images/After.png")

If I run this code as is, the Before and After images show only a ground and sky plane, but no objects.

If I comment out the loop that removes the objs and also comment out the "After.png" screenCapture line, I get a "Before.png" that includes the objects, as expected.

It looks like there's a note about viz.window.screenCapture in the documentation: "Note: The image is not generated immediately. Vizard must wait until the next frame is rendered before it can capture the image." But I'm not sure how to modify the code based on this info.

Jeff 08-14-2020 06:57 AM

Here's an example using a task function that should capture an object before and after removing it:

Code:

import viz
import viztask

viz.go()

dojo = viz.addChild('dojo.osgb')
ball = viz.addChild('beachball.osgb', pos=[0,1.8,2])

def screenCaptureTask():
        viz.window.screenCapture('Before.png')
        yield viztask.waitFrame(1)
        ball.remove()
        viz.window.screenCapture('After.png')

viztask.schedule( screenCaptureTask() )



All times are GMT -7. The time now is 10:17 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC