def draw(self, renderer, draw_pass): '''Render a color and depth texture pair.''' if self._first_image: return draw = ((draw_pass == self.OPAQUE_DRAW_PASS and self.opaque_texture) or (draw_pass == self.TRANSPARENT_DRAW_PASS and not self.opaque_texture)) if not draw: return r = renderer r.disable_shader_capabilities(r.SHADER_LIGHTING | r.SHADER_STEREO_360 | # Avoid geometry shift r.SHADER_DEPTH_CUE | r.SHADER_SHADOW | r.SHADER_MULTISHADOW | r.SHADER_CLIP_PLANES) r.enable_capabilities |= r.SHADER_ALPHA_DEPTH # If the desired field of view of the texture does not match the camera field of view # then adjust projection size. Also if the apect ratio of the target framebuffer and # the aspect ratio of the texture don't match adjust the projection size. w, h = r.render_size() vw, vh = self.size if vw * h > vh * w: # Video aspect is wider than window aspect. Fit height, clip width. sx = (vw / vh) / (w / h) sy = 1 else: # Video aspect is narrower than window aspect. Fit width, clip height. sx = 1 sy = (w / h) / (vw / vh) cur_proj = r.current_projection_matrix proj = ((sx, 0, 0, 0), (0, sy, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) r.set_projection_matrix(proj) from chimerax.geometry import place p0 = place.identity() cur_view = r.current_view_matrix r.set_view_matrix(p0) r.set_model_matrix(p0) r.enable_blending(False) Model.draw(self, r, draw_pass) # Restore view and projection matrices since drawings are not supposed to change these. r.set_projection_matrix(cur_proj) r.set_view_matrix(cur_view) r.enable_capabilities &= ~r.SHADER_ALPHA_DEPTH r.disable_shader_capabilities(0)
def draw(self, renderer, draw_pass): '''Render a color and depth texture pair.''' if self._first_image: return if not getattr(renderer, 'mix_video', True): return draw = ((draw_pass == self.OPAQUE_DRAW_PASS and self.opaque_texture) or (draw_pass == self.TRANSPARENT_DRAW_PASS and not self.opaque_texture)) if not draw: return r = renderer r.disable_shader_capabilities(r.SHADER_LIGHTING | r.SHADER_STEREO_360 | # Avoid geometry shift r.SHADER_DEPTH_CUE | r.SHADER_SHADOW | r.SHADER_MULTISHADOW | r.SHADER_CLIP_PLANES) r.enable_capabilities |= r.SHADER_DEPTH_TEXTURE # If the desired field of view of the texture does not match the camera field of view # then adjust projection size. Also if the apect ratio of the target framebuffer and # the aspect ratio of the texture don't match adjust the projection size. w, h = r.render_size() fx = self._render_field_of_view rsfx, rsfy = self._realsense_color_field_of_view from math import atan, radians rw = atan(radians(fx / 2)) rh = rw * h / w rsw, rsh = atan(radians(rsfx / 2)), atan(radians(rsfy / 2)) sx, sy = rsw / rw, rsh / rh cur_proj = r.current_projection_matrix r.set_projection_matrix( ((sx, 0, 0, 0), (0, sy, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))) from chimerax.geometry import place p0 = place.identity() cur_view = r.current_view_matrix r.set_view_matrix(p0) r.set_model_matrix(p0) t = self._depth_texture t.bind_texture(r.depth_texture_unit) frm = 2**16 / 1000 # Realsense full range in meters (~65). c = self.session.main_view.camera from chimerax.vive.vr import SteamVRCamera if isinstance(c, SteamVRCamera): # Scale factor from RealSense depth texture 0-1 range # (~65 meters) to scene units (typically Angstroms). depth_scale = frm / c.scene_scale else: depth_scale = self._depth_scale * frm from math import tan, radians cxfov, cyfov = self._realsense_color_field_of_view dxfov, dyfov = self._realsense_depth_field_of_view dxscale = tan(radians(0.5 * cxfov)) / tan(radians(0.5 * dxfov)) dyscale = tan(radians(0.5 * cyfov)) / tan(radians(0.5 * dyfov)) r.set_depth_texture_parameters(dxscale, dyscale, depth_scale) # if r.frame_number % 200 == 1: # print ('depth params', dxscale, dyscale, depth_scale) Model.draw(self, r, draw_pass) # Restore view and projection matrices since drawings are not supposed to change these. r.set_projection_matrix(cur_proj) r.set_view_matrix(cur_view) r.enable_capabilities &= ~r.SHADER_DEPTH_TEXTURE r.disable_shader_capabilities(0)
def draw(self, renderer, draw_pass): self._update_graphics(renderer) Model.draw(self, renderer, draw_pass)