Hello,
I would like to implement a service call that renders the viewport and returns the image. The problem here is that capture_next_frame_rp_resource or capture_next_frame_rp_resource_callback are nonblocking but to return the image to the caller I have to wait for completion.
Here is my current code:
import ctypes
import numpy
import threading
event = None
imageData = None
def callback(capsule, length, width, height, textureFormat):
print(textureFormat)
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
pointer = ctypes.pythonapi.PyCapsule_GetPointer(capsule, None)
ap = ctypes.cast(pointer, ctypes.POINTER(ctypes.c_long * width * height))
a = numpy.frombuffer(ap.contents)
imageData = numpy.asarray(a)
event.set()
print("Rendering done")
event = threading.Event()
renderer = omni.renderer_capture.acquire_renderer_capture_interface()
viewport = omni.kit.viewport.acquire_viewport_interface()
viewportWindow = viewport.get_viewport_window()
viewportWindow.set_active_camera("/Stage/Cameras/Interactive")
viewport_ldr_rp = viewportWindow.get_drawable_ldr_resource()
renderer.capture_next_frame_rp_resource_callback(callback, viewport_ldr_rp)
#thread1 = threading.Thread(target=renderer.capture_next_frame_rp_resource_callback, args=(callback, viewport_ldr_rp))
#thread1.start()
print("Wait for rendering...")
event.wait(timeout = 10)
print("Done")
OK… my python skills are very limited (25 years of c#), so this is a complete miracle to me:
“Done” (after the wait for the event) is printed BEFORE “Rendering done”… so the event is not signaled (the execution is halted for the 10 seconds). Even starting the rending on another thread (commented lines) does not change anything… what am I doing wrong? Can someone help?
Thanks
Carl