示例#1
0
 def __init__(
     self,
     context_identifier: Any,
     opengl_resource_pack: OpenGLResourcePack,
     level: "BaseLevel",
     draw_floor=True,
     draw_box=False,
 ):
     OpenGLResourcePackManager.__init__(self, opengl_resource_pack)
     ContextManager.__init__(self, context_identifier)
     self._level = level
     self._camera_location: CameraLocationType = (0, 150, 0)
     # yaw (-180 to 180), pitch (-90 to 90)
     self._camera_rotation: CameraRotationType = (0, 90)
     self._dimension: Dimension = "overworld"
     self._render_distance = 5
     self._garbage_distance = 10
     self._draw_box = draw_box
     self._draw_floor = draw_floor
     self._selection = GreenRenderSelectionGroup(
         context_identifier, self.resource_pack, self.level.selection_bounds
     )
     self._selection_displacement = displacement_matrix(
         *self.level.selection_bounds.min.astype(int)
     )
     self._chunk_manager = ChunkManager(self.context_identifier, self.resource_pack)
     self._chunk_generator = ChunkGenerator(self)
    def _create_geometry(self):
        self._setup()
        self._create_geometry_()

        self.transformation_matrix = displacement_matrix(*self.min - self.min % 16)

        self.change_verts()
        self._volume = numpy.product(self.max - self.min)
        self._rebuild = False
示例#3
0
    def transformation_matrix(self) -> numpy.ndarray:
        """The world to projection matrix."""
        # camera translation
        if self._transformation_matrix is None:
            self._transformation_matrix = numpy.matmul(
                self.projection_matrix(),
                numpy.matmul(
                    self.rotation_matrix(*self.camera_rotation),
                    displacement_matrix(*-numpy.array(self.camera_location)),
                ),
            )

        return self._transformation_matrix
 def active_transform(self, location_scale_rotation: TransformType):
     """Set the transform for the active object.
     Has no effect if there is no active object.
     :param location_scale_rotation: The location, scale and rotation
     :return:
     """
     if self._active_level is not None:
         location, scale, rotation = location_scale_rotation
         self._transforms[self._active_level] = (location, scale, rotation)
         self._transformation_matrices[self._active_level] = numpy.matmul(
             transform_matrix(scale, rotation, location),
             displacement_matrix(
                 *self._world_translation[self._active_level]),
         )
示例#5
0
 def active_transform(self, location_scale_rotation: TransformType):
     """Set the transform for the active object.
     Has no effect if there is no active object.
     :param location_scale_rotation: The location, scale and rotation
     :return:
     """
     if self._active_level_index is not None:
         location, scale, rotation = location_scale_rotation
         self._transforms[self._active_level_index] = (location, scale, rotation)
         self._is_mirrored[self._active_level_index] = bool(
             sum(1 for s in scale if s < 0) % 2
         )
         self._transformation_matrices[self._active_level_index] = numpy.matmul(
             transform_matrix(scale, rotation, location),
             displacement_matrix(*self._world_translation[self._active_level_index]),
         )
         self._set_camera_location()
示例#6
0
 def append(
     self,
     level: BaseLevel,
     dimension: Dimension,
     location: LocationType,
     scale: ScaleType,
     rotation: RotationType,
 ):
     """Append a level to the list and activate it."""
     # TODO: update this to support multiple levels
     self.clear()
     render_level = RenderLevel(
         self.context_identifier,
         self._resource_pack,
         level,
         draw_box=True,
         limit_bounds=True,
     )
     render_level.dimension = dimension
     # the level objects to be drawn
     self.register(render_level)
     # the transforms (tuple) applied by the user
     self._transforms.append((location, scale, rotation))
     self._is_mirrored.append(bool(sum(1 for s in scale if s < 0) % 2))
     self._world_translation.append(
         (
             -(
                 (
                     level.bounds(dimension).min_array
                     + level.bounds(dimension).max_array
                 )
                 // 2
             ).astype(int)
         ).tolist()
     )
     # the matrix of the transform applied by the user
     self._transformation_matrices.append(
         numpy.matmul(
             transform_matrix(scale, rotation, location),
             displacement_matrix(*self._world_translation[-1]),
         )
     )
     if self._active_level_index is None:
         self._active_level_index = 0
     else:
         self._active_level_index += 1
示例#7
0
 def __init__(
     self,
     context_identifier: Any,
     resource_pack: OpenGLResourcePack,
     structure: Structure,
 ):
     OpenGLResourcePackManager.__init__(self, resource_pack)
     ContextManager.__init__(self, context_identifier)
     self._structure = structure
     self._sub_structures = []
     self._selection = GreenRenderSelectionGroup(context_identifier,
                                                 self.resource_pack,
                                                 structure.selection)
     self._selection_transform = displacement_matrix(
         *((self._structure.selection.min - self._structure.selection.max) /
           2).astype(int))
     self._create_geometry()  # TODO: move this to a different thread
示例#8
0
    def __init__(
        self,
        rx: int,
        rz: int,
        region_size: int,
        context_identifier: str,
        resource_pack: OpenGLResourcePack,
    ):
        """A group of RenderChunks to minimise the number of draw calls"""
        super().__init__(context_identifier,
                         resource_pack.get_atlas_id(context_identifier))
        self.rx = rx
        self.rz = rz
        self._chunks: Dict[Tuple[int, int], RenderChunk] = {}
        self._merged_chunk_locations: Dict[Tuple[int, int],
                                           Tuple[int, int, int, int]] = {}
        self._manual_chunks: Dict[Tuple[int, int], RenderChunk] = {}

        self.region_transform = displacement_matrix(rx * region_size * 16, 0,
                                                    rz * region_size * 16)
示例#9
0
 def __init__(
     self,
     context_identifier: Any,
     structure: Structure,
     resource_pack: minecraft_model_reader.JavaRPHandler,
     texture: Any,
     texture_bounds: Dict[Any, Tuple[float, float, float, float]],
     translator: PyMCTranslate.Version,
 ):
     super().__init__(context_identifier, resource_pack, texture,
                      texture_bounds, translator)
     self._structure = structure
     self._sub_structures = []
     self._selection = GreenRenderSelectionGroup(context_identifier,
                                                 texture_bounds, texture,
                                                 structure.selection)
     self._selection_transform = displacement_matrix(
         *((self._structure.selection.min - self._structure.selection.max) /
           2).astype(int))
     self._create_geometry()  # TODO: move this to a different thread
示例#10
0
    def __init__(
        self,
        rx: int,
        rz: int,
        region_size: int,
        context_identifier: str,
        resource_pack: OpenGLResourcePack,
    ):
        """A group of RenderChunks to minimise the number of draw calls"""
        super().__init__(context_identifier,
                         resource_pack.get_atlas_id(context_identifier))
        self.rx = rx
        self.rz = rz
        self._chunks: Dict[Tuple[int, int], RenderChunk] = {}
        self._merged_chunk_locations: MergedChunkLocationsType = {}
        self._manual_chunks: Dict[Tuple[int, int], RenderChunk] = {}

        # Merging is done on a new thread which can't modify the opengl state.
        # This stores the created data and the main thread loads it when drawing.
        self._temp_data = None

        self.region_transform = displacement_matrix(rx * region_size * 16, 0,
                                                    rz * region_size * 16)
 def append(
     self,
     level: BaseLevel,
     dimension: Dimension,
     location: LocationType,
     scale: ScaleType,
     rotation: RotationType,
 ):
     """Append a level to the list and activate it."""
     # TODO: update this to support multiple levels
     self.clear()
     render_level = RenderLevel(
         self.context_identifier,
         self._resource_pack,
         level,
         draw_floor=False,
         draw_box=True,
     )
     render_level.dimension = dimension
     # the level objects to be drawn
     self._levels.append(render_level)
     # the transforms (tuple) applied by the user
     self._transforms.append((location, scale, rotation))
     self._world_translation.append(
         (-((level.selection_bounds.min + level.selection_bounds.max) //
            2).astype(int)).tolist())
     # the matrix of the transform applied by the user
     self._transformation_matrices.append(
         numpy.matmul(
             transform_matrix(scale, rotation, location),
             displacement_matrix(*self._world_translation[-1]),
         ))
     if self._active_level is None:
         self._active_level = 0
     else:
         self._active_level += 1
示例#12
0
 def draw(self, transformation_matrix: numpy.ndarray):
     super().draw(
         numpy.matmul(transformation_matrix,
                      displacement_matrix(*self._camera_location)))