I am looking to render scenes on the display region whose size is of my image(flags to do so have been set)
however, there is no scene rendered on the region. SetClearColor function works and changes the color of the display region but nothing rendered from the camera view
code:
self.img_width, self.img_height = self.get_image_dimensions(example_image_path) # Find all cameras and create render buffers self.render_buffers = {} self.cameras = self.find_all_cameras() for camera_path in self.cameras: buffer = self.create_render_buffer(camera_path) self.render_buffers[camera_path.getName()] = buffer # Add the task to render to textures self.taskMgr.add(self.render_to_textures, "render_to_textures") self.accept("v", self.bufferViewer.toggleEnable) self.bufferViewer.setPosition("llcorner") self.bufferViewer.setCardSize(1.0, 0.0) def find_all_cameras(self): cameras = [] for camera_path in self.render.findAllMatches("**/*"): node = camera_path.node() if isinstance(node, Camera): print(node.getLens().getNear()) print(node.getLens().getFov() ) camera_name = camera_path.getName() if camera_name.startswith("Camera_"): cameras.append(camera_path) node.active= False break return cameras def create_render_buffer(self, camera_path): #camera_path.hprInterval(1.5, (360, 360, 360)).loop() """Create a render buffer for each camera.""" #texture = Texture() #texture.set_format(Texture.F_rgb8) # Ensure the texture format is RGBA # Ensure the texture stores data in RAM #texture.set_compression(Texture.CM_off) # Turn off compression #texture.set_keep_ram_image(True) # Ensure RAM image is kept # Create a buffer to render into buffer = self.win.make_texture_buffer(camera_path.getName(), self.img_width, self.img_height) #buffer.add_render_texture(texture, GraphicsOutput.RTMCopyRam) # Create a display region and assign the camera to it dr = buffer.get_display_region(0)#self.win.get_display_region(0) #buffer.get_display_region(0) #self.win.setClearColor((0,1,0,1)) buffer.setClearColor((1,0,1,0.5)) print(dr) dr.set_camera(camera_path) print( camera_path.getPos(self.render) ) #camera_path.lookAt(self.render) #camera_path.hprInterval(3.5, (360,720, 1850)).loop() smiley = self.loader.loadModel("smiley") smiley.reparentTo(self.render) smiley.setScale(1500) smiley.hprInterval(1.5, (360, 360, 360)).loop() smiley.setTwoSided(True) #self.oobe() print(self.render.getPos(camera_path)) print(camera_path) return buffer
def save_screenshot_from_buffer(self, buffer, filename): """Save screenshot directly from the buffer.""" screenshot = PNMImage() # Get the screenshot from the buffer if buffer.get_screenshot(screenshot): # Save the screenshot to a file screenshot.write(filename) #print(f"Screenshot saved to {filename}") else: print("Failed to capture screenshot.") def convert_pnm_to_png(self, pnm_path, png_path): """Convert PNM image to PNG.""" with Image.open(pnm_path) as img: img.save(png_path) print(f"Converted PNM image to PNG: {png_path}") def render_to_textures(self, task): # Force a render frame to ensure textures are populated self.graphics_engine.render_frame() self.graphics_engine.render_frame() self.graphics_engine.render_frame() for name, buffer in self.render_buffers.items(): #texture = buffer.get_texture() # Save the screenshot from the buffer directly screenshot_filename = join(self.output_folder, f"{name}_screenshot.png") self.save_screenshot_from_buffer(buffer, screenshot_filename) # Continue rendering every frame return Task.done
All i get is grey background. the camera’S are loaded from the .bam file of my scene graph.
tried different debugs but nothing avails.
Potentially there is some issue in the create_render_buffers but unsure what…
Thank you and much appreciated