コード例 #1
0
ファイル: canvas.py プロジェクト: feifeiq/Amulet-Map-Editor
    def __init__(self, parent: wx.Window, world: 'World'):
        super().__init__(parent)
        self._last_mouse_x = 0
        self._last_mouse_y = 0
        self._mouse_delta_x = 0
        self._mouse_delta_y = 0
        self._mouse_lock = False
        self._mouse_moved = False

        # load the resource packs
        os.makedirs('resource_packs', exist_ok=True)
        if not os.path.isfile('resource_packs/readme.txt'):
            with open('resource_packs/readme.txt', 'w') as f:
                f.write('Put the Java resource pack you want loaded in here.')

        self._texture_bounds: Optional[Dict[Any, Tuple[float, float, float, float]]] = None
        self._resource_pack: Optional[minecraft_model_reader.JavaRPHandler] = None

        self._load_resource_pack(
            minecraft_model_reader.JavaRP(os.path.join(os.path.dirname(__file__), '..', 'amulet_resource_pack')),
            minecraft_model_reader.java_vanilla_latest,
            *[minecraft_model_reader.JavaRP(rp) for rp in os.listdir('resource_packs') if os.path.isdir(rp)],
            minecraft_model_reader.java_vanilla_fix
        )

        self._resource_pack_translator = world.world_wrapper.translation_manager.get_version('java', (1, 15, 2))

        self._render_world = RenderWorld(
            self.context_identifier,
            world,
            self._resource_pack,
            self._gl_texture_atlas,
            self._texture_bounds,
            self._resource_pack_translator
        )

        self._camera: List[float] = [0.0, 100.0, 0.0, 45.0, 45.0]
        self._projection = [70.0, 4 / 3, 0.1, 1000.0]
        self._camera_move_speed = 2
        self._camera_rotate_speed = 2
        self._select_distance = 10
        self._select_distance2 = 10
        self._select_mode = MODE_NORMAL

        self._selection_group = RenderSelectionGroup(
            self.context_identifier,
            self._texture_bounds,
            self._gl_texture_atlas
        )
        self._structure: Optional[RenderStructure] = None
        self._structure_locations: List[numpy.ndarray] = []

        self._draw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._on_draw, self._draw_timer)

        self._gc_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._gc, self._gc_timer)

        self._rebuild_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._rebuild, self._rebuild_timer)
コード例 #2
0
    def setup(self) -> Generator[OperationYieldType, None, None]:
        """Set up objects that take a while to set up."""
        yield 0.1, "Downloading vanilla resource pack"
        gen = get_java_vanilla_latest_iter()
        try:
            while True:
                yield next(gen) * 0.4 + 0.1
        except StopIteration as e:
            latest_pack = e.value
        yield 0.5, "Loading resource packs"
        fix_pack = get_java_vanilla_fix()
        amulet_pack = minecraft_model_reader.JavaRP(
            os.path.join(os.path.dirname(__file__), "..",
                         "amulet_resource_pack"))
        user_packs = [
            minecraft_model_reader.JavaRP(rp)
            for rp in os.listdir("resource_packs") if os.path.isdir(rp)
        ]

        self._resource_pack = minecraft_model_reader.JavaRPHandler(
            (amulet_pack, latest_pack, *user_packs, fix_pack), load=False)
        for i in self._resource_pack.reload():
            yield i / 4 + 0.5

        yield 0.75, "Creating texture atlas"
        for i in self._create_atlas():
            yield i / 4 + 0.75

        yield 1.0, "Setting up renderer"

        self._resource_pack_translator = self.world.translation_manager.get_version(
            "java", (999, 0, 0))

        self._render_world = RenderWorld(
            self.context_identifier,
            self.world,
            self._resource_pack,
            self._gl_texture_atlas,
            self._texture_bounds,
            self._resource_pack_translator,
        )

        self._selection_group = EditProgramRenderSelectionGroup(
            self, self.context_identifier, self._texture_bounds,
            self._gl_texture_atlas)

        self._structure: StructureGroup = StructureGroup(
            self.context_identifier,
            self.world.palette,
            self._resource_pack,
            self._gl_texture_atlas,
            self._texture_bounds,
            self._resource_pack_translator,
        )

        self._bind_base_events()
コード例 #3
0
    def __init__(self, world_panel: 'EditExtension', world: 'World'):
        self._keys_pressed = set()
        attribs = (glcanvas.WX_GL_CORE_PROFILE, glcanvas.WX_GL_RGBA,
                   glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24)
        super().__init__(world_panel,
                         -1,
                         size=world_panel.GetClientSize(),
                         attribList=attribs)
        self._context = glcanvas.GLContext(self)  # setup the OpenGL context
        self.SetCurrent(self._context)
        self.context_identifier = str(
            uuid.uuid4())  # create a UUID for the context. Used to get shaders
        self._gl_texture_atlas = glGenTextures(
            1)  # Create the atlas texture location
        self._setup_opengl()  # set some OpenGL states

        # load the resource packs
        os.makedirs('resource_packs', exist_ok=True)
        if not os.path.isfile('resource_packs/readme.txt'):
            with open('resource_packs/readme.txt', 'w') as f:
                f.write('Put the Java resource pack you want loaded in here.')

        self._texture_bounds: Optional[Dict[Any, Tuple[float, float, float,
                                                       float]]] = None
        self._resource_pack: Optional[
            minecraft_model_reader.JavaRPHandler] = None

        self._load_resource_pack(
            minecraft_model_reader.JavaRP(
                os.path.join(os.path.dirname(__file__),
                             'amulet_resource_pack')),
            minecraft_model_reader.java_vanilla_latest, *[
                minecraft_model_reader.JavaRP(rp)
                for rp in os.listdir('resource_packs') if os.path.isdir(rp)
            ], minecraft_model_reader.java_vanilla_fix)

        self._resource_pack_translator = world.world_wrapper.translation_manager.get_version(
            'java', (1, 15, 2))

        self._render_world = RenderWorld(self.context_identifier, world,
                                         self._resource_pack,
                                         self._gl_texture_atlas,
                                         self._texture_bounds,
                                         self._resource_pack_translator)

        self._transformation_matrix: Optional[numpy.ndarray] = None
        self._collision_locations_cache: Optional[numpy.ndarray] = None
        self._camera = [0, 150, 0, 90, 0]
        self._projection = [70.0, 4 / 3, 0.1, 1000.0]
        self._camera_move_speed = 2
        self._camera_rotate_speed = 2
        self._select_distance = 10
        self._select_mode = 0  # 0 is normal box select, 1 is selection place
        self._select_style = 1  # 0 is select at fixed distance, 1 is select closest non-air
        self._selection_box = RenderSelection(self.context_identifier,
                                              self._texture_bounds)
        self._selection_box2 = RenderSelection(self.context_identifier,
                                               self._texture_bounds)
        self._structure: Optional[RenderStructure] = None
        self._structure_locations: List[numpy.ndarray] = []

        self._draw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._on_draw, self._draw_timer)

        self._input_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._process_inputs, self._input_timer)

        self._gc_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._gc, self._gc_timer)

        world_panel.Bind(wx.EVT_SIZE, self._on_resize)
コード例 #4
0
    def __init__(self, parent: wx.Window, world: 'World'):
        super().__init__(parent)
        glClearColor(*self.background_colour, 1.0)
        self.Hide()

        self._bound_events: Set[wx.PyEventBinder] = set()

        self._world = weakref.ref(world)
        self._mouse_delta_x = 0
        self._mouse_delta_y = 0
        self._mouse_lock = False

        # load the resource packs
        os.makedirs('resource_packs', exist_ok=True)
        if not os.path.isfile('resource_packs/readme.txt'):
            with open('resource_packs/readme.txt', 'w') as f:
                f.write('Put the Java resource pack you want loaded in here.')

        self._texture_bounds: Optional[Dict[Any, Tuple[float, float, float,
                                                       float]]] = None
        self._resource_pack: Optional[
            minecraft_model_reader.JavaRPHandler] = None

        self._load_resource_pack(
            minecraft_model_reader.JavaRP(
                os.path.join(os.path.dirname(__file__), '..',
                             'amulet_resource_pack')),
            minecraft_model_reader.java_vanilla_latest, *[
                minecraft_model_reader.JavaRP(rp)
                for rp in os.listdir('resource_packs') if os.path.isdir(rp)
            ], minecraft_model_reader.java_vanilla_fix)

        self._resource_pack_translator = world.world_wrapper.translation_manager.get_version(
            'java', (999, 0, 0))

        self._render_world = RenderWorld(self.context_identifier, world,
                                         self._resource_pack,
                                         self._gl_texture_atlas,
                                         self._texture_bounds,
                                         self._resource_pack_translator)

        self._camera_location: CameraLocationType = (0.0, 100.0, 0.0)
        self._camera_rotation: CameraRotationType = (45.0, 45.0)
        self._camera_move_speed = 2
        self._camera_rotate_speed = 2
        self._select_distance = 10
        self._select_distance2 = 10

        self._selection_moved = True  # has the selection point moved and does the box need rebuilding
        self._selection_location: BlockCoordinates = (0, 0, 0)

        self._draw_selection = True
        self._selection_group = EditProgramRenderSelectionGroup(
            self, self.context_identifier, self._texture_bounds,
            self._gl_texture_atlas)

        self._draw_structure = False
        self._structure: Optional[RenderStructure] = None
        self._structure_locations: List[numpy.ndarray] = [
        ]  # TODO rewrite this

        self._draw_timer = wx.Timer(self)
        self._gc_timer = wx.Timer(self)
        self._rebuild_timer = wx.Timer(self)
        self._bind_base_events()
コード例 #5
0
import minecraft_model_reader
try:
    from amulet.api.block import Block
except:
    from minecraft_model_reader.api.block import Block

vanilla_1_13_2 = minecraft_model_reader.JavaRP(
    './../test_packs/Vanilla 1.13.2')

resource_pack = minecraft_model_reader.JavaRPHandler([vanilla_1_13_2])

air: Block = Block(namespace='minecraft', base_name='air')
stone: Block = Block(namespace='minecraft', base_name='stone')
fire: Block = Block(namespace='minecraft',
                    base_name='fire',
                    properties={
                        "age": "0",
                        "east": "true",
                        "north": "true",
                        "south": "false",
                        "up": "false",
                        "west": "false"
                    })

air_model = resource_pack.get_model(air)
stone_model = resource_pack.get_model(stone)
fire_model = resource_pack.get_model(fire)

print('Read successfully')