Skip to content

Commit

Permalink
glTF draco compression support
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Dec 6, 2024
1 parent c6531c0 commit 9b242ea
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 123 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/
33 changes: 21 additions & 12 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,17 +18,22 @@ 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")
# self.scene = self.load_scene("CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb")
# self.scene = self.load_scene("CesiumMilkTruck/glTF/CesiumMilkTruck.gltf")
self.scene = self.load_scene("Sponza/glTF/Sponza.gltf")
# self.scene = self.load_scene("Sponza/glTF/Sponza.gltf")
# self.scene = self.load_scene("Lantern/glTF-Binary/Lantern.glb")
# self.scene = self.load_scene("Buggy/glTF-Binary/Buggy.glb")
# self.scene = self.load_scene("VC/glTF-Binary/VC.glb")
Expand Down Expand Up @@ -61,6 +65,10 @@ 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.camera = KeyboardCamera(
self.wnd.keys,
fov=75.0,
Expand All @@ -75,34 +83,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 / 2.0)
)

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()
Loading

0 comments on commit 9b242ea

Please sign in to comment.