Skip to content

Commit

Permalink
glTF draco compression support (#209)
Browse files Browse the repository at this point in the history
* glTF draco compression support

* Read dracu data the extension's own bufferview

* Alert user when dracopy is not installed

* Bump version
  • Loading branch information
einarf authored Dec 6, 2024
1 parent c6531c0 commit 81da3db
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 131 deletions.
31 changes: 2 additions & 29 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,20 @@ __pycache__/
*.dll

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Sphinx documentation
Expand All @@ -43,26 +30,12 @@ docs/_build/
# IDEs
.vscode
.idea/
.spyproject/

# Environments
.env
.venv
.venv35
.venv36
.venv37
.venv38
env/
venv/
ENV/
env.bak/
venv.bak/
.venv*

# Misc local
/test.py
.mypy_cache
/random_fun/
imgui.ini
.DS_Store
/temp/
video_rec.py
/tmp/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.1.0

* Support for daco compressed meshes in glTF2 files

## 3.0.3

* Fixed a potential division by zero issue in timers
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __getattr__(cls: Any, name: Any) -> MagicMock:
author = "Einar Forselv"

# The short X.Y version
version = "3.0.3"
version = "3.1.0"
# The full version, including alpha/beta/rc tags
release = version

Expand Down
33 changes: 22 additions & 11 deletions examples/gltf_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import moderngl
from base import CameraWindow

import moderngl_window as mglw
from moderngl_window.scene.camera import KeyboardCamera


class CubeModel(CameraWindow):
class GLTFTest(CameraWindow):
"""
In oder for this example to work you need to clone the gltf
model samples repository and ensure resource_dir is set correctly:
Expand All @@ -19,11 +18,16 @@ class CubeModel(CameraWindow):
window_size = 1280, 720
aspect_ratio = None
resource_dir = Path(__file__, "../../../glTF-Sample-Models/2.0").resolve()
# resource_dir = Path(__file__, "../../tmp/issue_with_draco").resolve()

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.wnd.mouse_exclusivity = True

# self.scene = self.load_scene(
# "0147_858530.6583696686_-5537397.529199226_3036197.2162786936.glb", kind="gltf"
# )

# --- glTF-Sample-Models ---
# self.scene = self.load_scene("2CylinderEngine/glTF-Binary/2CylinderEngine.glb")
# self.scene = self.load_scene("CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf")
Expand Down Expand Up @@ -61,6 +65,12 @@ def __init__(self, **kwargs):
# self.scene = self.load_scene("VertexColorTest/glTF/VertexColorTest.gltf")
# self.scene = self.load_scene("WaterBottle/glTF/WaterBottle.gltf")

# --- Draco compressed ---
# self.scene = self.load_scene("Box/glTF-Draco/Box.gltf")
# self.scene = self.load_scene("Buggy/glTF-Draco/Buggy.gltf")
# self.scene = self.load_scene("2CylinderEngine/glTF-Draco/2CylinderEngine.gltf")
# self.scene = self.load_scene("CesiumMilkTruck/glTF-Draco/CesiumMilkTruck.gltf")

self.camera = KeyboardCamera(
self.wnd.keys,
fov=75.0,
Expand All @@ -75,34 +85,35 @@ def __init__(self, **kwargs):
# if self.scene.diagonal_size > 0:
# self.camera.velocity = self.scene.diagonal_size / 5.0

self.camera.position = (
self.scene.get_center()
+ glm.vec3(0.0, 0.0, self.scene.diagonal_size / 1.75)
)

def on_render(self, time: float, frame_time: float):
"""Render the scene"""
self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

# Move camera in on the z axis slightly by default
translation = glm.translate(glm.vec3(0, 0, -1.5))
camera_matrix = self.camera.matrix * translation

self.scene.draw(
projection_matrix=self.camera.projection.matrix,
camera_matrix=camera_matrix,
camera_matrix=self.camera.matrix,
time=time,
)

# Draw bounding boxes
# # Draw bounding boxes
# self.scene.draw_bbox(
# projection_matrix=self.camera.projection.matrix,
# camera_matrix=camera_matrix,
# camera_matrix=self.camera.matrix,
# children=True,
# color=(0.75, 0.75, 0.75),
# )

# self.scene.draw_wireframe(
# projection_matrix=self.camera.projection.matrix,
# camera_matrix=camera_matrix,
# camera_matrix=self.camera.matrix,
# color=(1, 1, 1, 1),
# )


if __name__ == "__main__":
mglw.run_window_config(CubeModel)
GLTFTest.run()
2 changes: 1 addition & 1 deletion moderngl_window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from moderngl_window.utils.keymaps import AZERTY, QWERTY, KeyMap, KeyMapFactory # noqa
from moderngl_window.utils.module_loading import import_string

__version__ = "3.0.3"
__version__ = "3.1.0"

IGNORE_DIRS = [
"__pycache__",
Expand Down
Loading

0 comments on commit 81da3db

Please sign in to comment.