def test_bbox(self): """Create a bounding box""" mesh = geometry.bbox(size=(1.0, 1.0, 1.0), name="test_bbox") self.assertEqual(mesh.name, "test_bbox") self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.POSITION), BufferInfo) # Use custom buffer/attribute names mesh = geometry.bbox(size=(1.0, 1.0, 1.0), name="test_bbox", attr_names=self.custom_attrs) self.assertIsInstance( mesh.get_buffer_by_name(self.custom_attrs.POSITION), BufferInfo)
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() global DEFAULT_BBOX_PROGRAM if DEFAULT_BBOX_PROGRAM is None: DEFAULT_BBOX_PROGRAM = programs.load( ProgramDescription(path='scene_default/bbox.glsl'), ) self.bbox_program = DEFAULT_BBOX_PROGRAM global DEFAULT_WIREFRAME_PROGRAM if DEFAULT_WIREFRAME_PROGRAM is None: DEFAULT_WIREFRAME_PROGRAM = programs.load( ProgramDescription(path='scene_default/wireframe.glsl'), ) self.wireframe_program = DEFAULT_WIREFRAME_PROGRAM self._matrix = matrix44.create_identity(dtype='f4')
def __init__(self, **kwargs) -> None: super().__init__(**kwargs) # load programs self.compute_shader = self.load_compute_shader("compute_shader.glsl", self.consts) self.render_program = self.load_program("points.glsl") self.render_program = self.load_program("balls.glsl") self.box_program = self.load_program("box.glsl") # set projection matrices projection_matrix = perspective(60, self.wnd.aspect_ratio, 0.1, 1000).astype("f4") self.camera_matrix = translation( (0, 0, -4 * self.BOX_SIZE)).astype("f4") self.render_program["m_projection"].write(projection_matrix.tobytes()) self.render_program["m_camera"].write(self.camera_matrix.tobytes()) # generate random positions and velocities pos_vel = self.generate_data() # generate N hsv colors _rgb_colors = np.array( (np.arange(self.N) / self.N, np.full(self.N, 0.7), np.full(self.N, 0.5))).T # convert to grb colors = hsv_to_rgb(_rgb_colors) # reshape into vec4; [h, s, v] -> [h, s, v, 0.] colors = np.c_[colors, np.ones(colors.shape[0])] # create two buffers to switch between self.buffer1 = self.ctx.buffer(pos_vel) self.buffer2 = self.ctx.buffer(reserve=pos_vel.nbytes) self.colors = self.ctx.buffer(colors.astype("f4")) # create a VAO with buffer 1 bound to it to render the balls # some number between 4 and 16 rings_sectors_count = max(4, int(16 - 0.0005 * self.N)) self.ball = sphere( radius=self.BALL_SIZE, rings=rings_sectors_count, sectors=rings_sectors_count, ) self.ball.buffer(self.buffer1, "3f 3f/i", ["ball_position", "ball_velocity"]) self.ball.buffer(self.colors, "4f/i", ["ball_color"]) # bind the buffers to 1 and 0 respectively self._toggle = False self.buffer1.bind_to_storage_buffer(self._toggle) self.buffer2.bind_to_storage_buffer(not self._toggle) # box vao self.box = bbox(size=(self.BOX_SIZE * 2, self.BOX_SIZE * 2, self.BOX_SIZE * 2)) self.box_program["m_projection"].write(projection_matrix.tobytes()) self.box_program["m_camera"].write(self.camera_matrix.tobytes())
def __init__(self, **kwargs): super().__init__(**kwargs) self.prog = self.load_program('scene_default/bbox.glsl') self.bbox = geometry.bbox() self.prog['color'].value = (1, 1, 1) self.prog['bb_min'].value = (-2, -2, -2) self.prog['bb_max'].value = (2, 2, 2) self.prog['m_model'].write(matrix44.create_from_translation([0.0, 0.0, -8.0], dtype='f4'))
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() if self.ctx.extra is None: self.ctx.extra = {} # Load bbox program and cache in the context self.bbox_program = self.ctx.extra.get("DEFAULT_BBOX_PROGRAM") if not self.bbox_program: self.bbox_program = programs.load( ProgramDescription(path="scene_default/bbox.glsl"), ) self.ctx.extra["DEFAULT_BBOX_PROGRAM"] = self.bbox_program # Load wireframe program and cache in the context self.wireframe_program = self.ctx.extra.get( "DEFAULT_WIREFRAME_PROGRAM") if not self.wireframe_program: self.wireframe_program = programs.load( ProgramDescription(path="scene_default/wireframe.glsl"), ) self.ctx.extra[ "DEFAULT_WIREFRAME_PROGRAM"] = self.wireframe_program self._matrix = matrix44.create_identity(dtype="f4")
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() self.bbox_program = programs.load( ProgramDescription(path='scene_default/bbox.glsl'), ) self._model_matrix = matrix44.create_identity()