MCPcopy Create free account
hub / github.com/BerkeleyAutomation/meshrender / _render

Method _render

meshrender/viewer.py:661–767  ·  view source on GitHub ↗

Render the scene into the framebuffer and flip.

(self)

Source from the content-addressed store, hash-verified

659
660
661 def _render(self):
662 """Render the scene into the framebuffer and flip.
663 """
664 scene = self.scene
665 camera = self._camera
666
667 camera.T_camera_world = self._trackball.T_camera_world
668
669 # Set viewport size
670 context = self.context
671 back_width, back_height = self._size
672
673 # Check for retina slash high-dpi displays (hack)
674 if hasattr(self.context, '_nscontext'):
675 view = self.context._nscontext.view()
676 bounds = view.convertRectToBacking_(view.bounds()).size
677 back_width, back_height = (int(bounds.width), int(bounds.height))
678
679 glViewport(0, 0, back_width, back_height)
680 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
681
682 glUseProgram(self._shader)
683
684 # Get Uniform Locations from Shader
685 v_id = glGetUniformLocation(self._shader, 'V')
686 p_id = glGetUniformLocation(self._shader, 'P')
687 m_id = glGetUniformLocation(self._shader, 'M')
688 matprop_id = glGetUniformLocation(self._shader, 'material_properties')
689 ambient_id = glGetUniformLocation(self._shader, 'ambient_light_info')
690 directional_id = glGetUniformLocation(self._shader, "directional_light_info")
691 n_directional_id = glGetUniformLocation(self._shader, "n_directional_lights")
692 point_id = glGetUniformLocation(self._shader, "point_light_info")
693 n_point_id = glGetUniformLocation(self._shader, "n_point_lights")
694 front_and_back_id = glGetUniformLocation(self._shader, "front_and_back")
695
696 # Bind bad normals id
697 glUniform1i(front_and_back_id, int(self._flags['two_sided_lighting']))
698
699 # Bind view matrix
700 glUniformMatrix4fv(v_id, 1, GL_TRUE, camera.V)
701 glUniformMatrix4fv(p_id, 1, GL_TRUE, camera.P)
702
703 # Bind ambient lighting
704 glUniform4fv(ambient_id, 1, np.hstack((scene.ambient_light.color,
705 scene.ambient_light.strength)))
706
707 # If using raymond lighting, don't use scene's directional or point lights
708 d_lights = scene.directional_lights
709 p_lights = scene.point_lights
710 if self._raymond_lighting:
711 d_lights = []
712 for dlight in SceneViewer._raymond_lights:
713 direc = dlight.direction
714 direc = camera.T_camera_world.matrix[:3,:3].dot(direc)
715 d_lights.append(DirectionalLight(
716 direction=direc,
717 color=dlight.color,
718 strength=dlight.strength

Callers 1

on_drawMethod · 0.95

Calls 1

DirectionalLightClass · 0.85

Tested by

no test coverage detected