Skip to content

Commit

Permalink
Added 3D world viewer (#86)
Browse files Browse the repository at this point in the history
* Fixed get_game_version call

* Open the level after getting it if not already open.

* Fixed typo

* Expose View3D to other plugins

* Added chunk builder stub file

* Added View3D layout and button

* Expanded Optional

* Added error chunk and null chunk geometry

* Renamed WidgetLevelGeometry to LevelGeometry

* Renamed GlData to CanvasGlData

* Added debug logging and comments

* Renamed WidgetChunkData to ChunkData

* Fixed LibraryUID hashing and equality.

* Split up default layout plugin

* Renamed package

* Implemented missing widget population

If a layout is added before a required widget is added it will be displayed as a missing widget.
Once the widget is added it can be populated.
Likewise when plugins are disabled.

* Added main window destruction

When the plugin is disabled, the window will be destroyed.

* Reformatted

* Removed Drawable ABC

* Renamed modules

* Added prototype renderer

* Removed multisample

* Updated stub file

* Reformatted

* Fixed issues starting and stopping threads

The stop method is called twice without being started for some reason.

* Drop chunk meshing to idle priority

This should make it lag a little less.
Releasing the GIL will also improve this.

* Reduced thread count

I may increase this again but they are all locked by the GIL currently.

* Remove duplicate code

* Renamed OpenGLResourcePackHandle

* Remove RPC

* Moved the texture out of the chunk

If each chunk stores the texture, we need to re-bind the texture for each draw making it slower.
When the resource pack changes we just unload all chunks like Minecraft does.

* Set texture location once

* Refactored chunk mesh module

* Reformatted

* Update references

* Added first chunk mesher

* Refactored and improved chunk meshing

Moved performant code to C++ so it does not need the GIL.
__init__ is now extension

* Moved C++ chunk meshing code

Moved pure C++ meshing code to its own file.

* Removed Amulet:: prefix

* Refactored chunk mesher

Added neighbour chunk component inputs. This is needed to determine culling at chunk edges.
Merged the chunk mesher into one function.
Converted storage to raw pointers.

* Modified python function signature

* Refactored chunk mesher

Switched to a transparency array. This makes the code a bit simpler and reduces the number of calls to get_block_mesh which should make it a bit faster.

* Fixed mesher call

* Fixed stride bug

* Fixed transparency issues

Draw the blocks with translucency after the opaque blocks.

* Implemented vertical culling

* Pencilled in neighbour chunk getting

This causes a deadlock currently.

* Implemented getting neighbour chunks

* Implemented neighbour chunk culling

* Implemented block shading

* Updated widget titles

* Reformatted

* Bumped amulet dependency

* Moved tests

* Added tests init py

* Added a dummy test

* Added missing import
  • Loading branch information
gentlegiantJGC authored Oct 27, 2024
1 parent 38d8ac2 commit 39e8a0f
Show file tree
Hide file tree
Showing 68 changed files with 1,796 additions and 1,584 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ requires = [
"versioneer",
"pybind11 ~= 2.12",
"amulet_nbt ~= 4.0a2",
"amulet_core == 2.0a7"
"amulet_core == 2.0a8"
]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ install_requires =
pyopengl~=3.0
packaging
amulet_nbt~=4.0a2
amulet_core==2.0a7
amulet_core==2.0a8
amulet_runtime_final~=1.1
Pillow

Expand Down
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,15 @@ def finalize_options(self) -> None:
libraries=[AmuletNBTLib, AmuletCoreLib],
ext_modules=[
Extension(
name="builtin_plugins.amulet_team_3d_viewer._view_3d._chunk_builder",
sources=[
"src/builtin_plugins/amulet_team_3d_viewer/_view_3d/_chunk_builder.cpp",
"src/builtin_plugins/amulet_team_3d_viewer/_view_3d/_chunk_builder.py.cpp",
],
name="builtin_plugins.amulet_team_3d_viewer._view_3d.__init__",
sources=glob.glob(
os.path.join(
glob.escape("src/builtin_plugins/amulet_team_3d_viewer/_view_3d"),
"**",
"*.cpp",
),
recursive=True,
),
include_dirs=[
pybind11.get_include(),
amulet_nbt.get_include(),
Expand Down
5 changes: 3 additions & 2 deletions src/amulet_editor/application/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ def trace_calls(frame: FrameType, event: str, arg: Any) -> TraceFunction:
else:
log.debug("Loading level.")
with DisplayException(f"Failed loading level at path {level_path}"):
_level.level = get_level(level_path)
_level.level = level = get_level(level_path)
level.open()

rpc.init_rpc(is_broker)
# rpc.init_rpc(is_broker)

log.debug("Entering main loop.")
exit_code = app.exec()
Expand Down
4 changes: 2 additions & 2 deletions src/amulet_editor/application/_splash/_splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
################################################################################
## Form generated from reading UI file '_splash.ui'
##
## Created by: Qt User Interface Compiler version 6.7.0
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down Expand Up @@ -44,4 +44,4 @@ def changeEvent(self, event: QEvent) -> None:
self._localise()

def _localise(self) -> None:
self.setWindowTitle(QCoreApplication.translate("Splash", "Form", None))
self.setWindowTitle(QCoreApplication.translate("Splash", "Amulet Editor", None))
2 changes: 1 addition & 1 deletion src/amulet_editor/application/_splash/_splash.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
<string>Amulet Editor</string>
</property>
<layout class="QVBoxLayout" name="_layout" stretch="1,0">
<item>
Expand Down
9 changes: 9 additions & 0 deletions src/amulet_editor/models/plugin/_uid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import re
from typing import Any

from packaging.version import Version
from runtime_final import final
Expand All @@ -20,6 +21,14 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return f"{self._identifier} {self._version}"

def __hash__(self) -> int:
return hash((self._identifier, self._version))

def __eq__(self, other: Any) -> bool:
if not isinstance(other, LibraryUID):
return NotImplemented
return self._identifier == other._identifier and self._version == other._version

@property
def identifier(self) -> str:
"""The package name. This is the name used when importing the package. Eg "my_name_my_plugin_v1". This must be a valid python identifier."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
################################################################################
## Form generated from reading UI file '_traceback_dialog.ui'
##
## Created by: Qt User Interface Compiler version 6.7.0
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
39 changes: 37 additions & 2 deletions src/builtin_plugins/amulet_team_3d_viewer/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
from amulet_editor.models.localisation import ATranslator
from amulet_editor.models.plugin import PluginV1

import tablericons
import amulet_team_locale
from amulet_team_main_window import register_widget, unregister_widget
from amulet_team_main_window import (
register_widget,
unregister_widget,
register_layout,
unregister_layout,
WidgetConfig,
WidgetStackConfig,
WindowConfig,
LayoutConfig,
ButtonProxy,
create_layout_button,
)

import amulet_team_3d_viewer
from ._view_3d import View3D
Expand All @@ -19,9 +31,12 @@
# Qt only weekly references this. We must hold a strong reference to stop it getting garbage collected
_translator: Optional[ATranslator] = None

View3DID = "68817e4c-32e3-43f8-ac61-9d7352c6329d"
view_3d_button: ButtonProxy | None = None


def load_plugin() -> None:
global _translator
global _translator, view_3d_button
if get_level() is not None:
_translator = ATranslator()
_locale_changed()
Expand All @@ -30,6 +45,23 @@ def load_plugin() -> None:

register_widget(View3D)

register_layout(
View3DID,
LayoutConfig(
WindowConfig(
None,
None,
WidgetStackConfig((WidgetConfig(View3D.__qualname__),)),
),
(),
),
)

# Set up the 3D View button
view_3d_button = create_layout_button(View3DID)
view_3d_button.set_icon(tablericons.three_d_cube_sphere)
view_3d_button.set_name("3D Editor")


def _locale_changed() -> None:
assert _translator is not None
Expand All @@ -41,6 +73,9 @@ def _locale_changed() -> None:


def unload_plugin() -> None:
if view_3d_button is not None:
view_3d_button.delete()
unregister_layout(View3DID)
with suppress(ValueError):
unregister_widget(View3D)
if _translator is not None:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

from amulet_team_3d_viewer._view_3d._widget import View3D

from . import _chunk_mesher_lod0, _resource_pack_base

__all__ = ["View3D"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <pybind11/pybind11.h>
namespace py = pybind11;

void init_resource_pack_base(py::module);
void init_chunk_mesher(py::module);

static bool init_run = false;

void init_view_3d(py::module m)
{
if (init_run) {
return;
}
init_run = true;

// This is normally added after initilsation but we need it to pass to subpackages.
// This may cause issues with frozen installs.
//m.attr("__path__") = py::module::import("importlib.util").attr("find_spec")("amulet_team_3d_viewer._view_3d").attr("submodule_search_locations");

init_resource_pack_base(m);
init_chunk_mesher(m);

m.attr("View3D") = py::module::import("amulet_team_3d_viewer._view_3d._widget").attr("View3D");
}

PYBIND11_MODULE(__init__, m) { init_view_3d(m); }
PYBIND11_MODULE(_view_3d, m) { init_view_3d(m); }
Loading

0 comments on commit 39e8a0f

Please sign in to comment.