pyglet 2.1.12__py3-none-any.whl → 3.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyglet/__init__.py +67 -61
- pyglet/__init__.pyi +15 -8
- pyglet/app/__init__.py +22 -13
- pyglet/app/async_app.py +212 -0
- pyglet/app/base.py +2 -1
- pyglet/app/{xlib.py → linux.py} +3 -3
- pyglet/config/__init__.py +101 -0
- pyglet/config/gl/__init__.py +30 -0
- pyglet/config/gl/egl.py +120 -0
- pyglet/config/gl/macos.py +262 -0
- pyglet/config/gl/windows.py +267 -0
- pyglet/config/gl/x11.py +142 -0
- pyglet/customtypes.py +43 -2
- pyglet/display/__init__.py +8 -6
- pyglet/display/base.py +3 -63
- pyglet/display/cocoa.py +12 -17
- pyglet/display/emscripten.py +39 -0
- pyglet/display/headless.py +23 -30
- pyglet/display/wayland.py +157 -0
- pyglet/display/win32.py +4 -17
- pyglet/display/xlib.py +19 -27
- pyglet/display/xlib_vidmoderestore.py +2 -2
- pyglet/enums.py +183 -0
- pyglet/event.py +0 -1
- pyglet/experimental/geoshader_sprite.py +15 -13
- pyglet/experimental/hidraw.py +6 -15
- pyglet/experimental/multitexture_sprite.py +31 -19
- pyglet/experimental/particles.py +13 -35
- pyglet/font/__init__.py +251 -85
- pyglet/font/base.py +116 -61
- pyglet/font/dwrite/__init__.py +349 -204
- pyglet/font/dwrite/dwrite_lib.py +27 -5
- pyglet/font/fontconfig.py +14 -6
- pyglet/font/freetype.py +138 -87
- pyglet/font/freetype_lib.py +19 -0
- pyglet/font/group.py +179 -0
- pyglet/font/harfbuzz/__init__.py +3 -3
- pyglet/font/pyodide_js.py +310 -0
- pyglet/font/quartz.py +319 -126
- pyglet/font/ttf.py +45 -3
- pyglet/font/user.py +14 -19
- pyglet/font/win32.py +45 -21
- pyglet/graphics/__init__.py +8 -787
- pyglet/graphics/allocation.py +115 -1
- pyglet/graphics/api/__init__.py +77 -0
- pyglet/graphics/api/base.py +299 -0
- pyglet/graphics/api/gl/__init__.py +58 -0
- pyglet/graphics/api/gl/base.py +24 -0
- pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
- pyglet/graphics/api/gl/cocoa/context.py +76 -0
- pyglet/graphics/api/gl/context.py +391 -0
- pyglet/graphics/api/gl/default_shaders.py +0 -0
- pyglet/graphics/api/gl/draw.py +627 -0
- pyglet/graphics/api/gl/egl/__init__.py +0 -0
- pyglet/graphics/api/gl/egl/context.py +92 -0
- pyglet/graphics/api/gl/enums.py +76 -0
- pyglet/graphics/api/gl/framebuffer.py +315 -0
- pyglet/graphics/api/gl/gl.py +5463 -0
- pyglet/graphics/api/gl/gl_info.py +188 -0
- pyglet/graphics/api/gl/global_opengl.py +226 -0
- pyglet/{gl → graphics/api/gl}/lib.py +34 -18
- pyglet/graphics/api/gl/shader.py +1476 -0
- pyglet/graphics/api/gl/shapes.py +55 -0
- pyglet/graphics/api/gl/sprite.py +102 -0
- pyglet/graphics/api/gl/state.py +219 -0
- pyglet/graphics/api/gl/text.py +190 -0
- pyglet/graphics/api/gl/texture.py +1526 -0
- pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
- pyglet/graphics/api/gl/vertexdomain.py +751 -0
- pyglet/graphics/api/gl/win32/__init__.py +0 -0
- pyglet/graphics/api/gl/win32/context.py +108 -0
- pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
- pyglet/graphics/api/gl/xlib/__init__.py +0 -0
- pyglet/graphics/api/gl/xlib/context.py +174 -0
- pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
- pyglet/graphics/api/gl1/__init__.py +0 -0
- pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
- pyglet/graphics/api/gl2/__init__.py +0 -0
- pyglet/graphics/api/gl2/buffer.py +320 -0
- pyglet/graphics/api/gl2/draw.py +600 -0
- pyglet/graphics/api/gl2/global_opengl.py +122 -0
- pyglet/graphics/api/gl2/shader.py +200 -0
- pyglet/graphics/api/gl2/shapes.py +51 -0
- pyglet/graphics/api/gl2/sprite.py +79 -0
- pyglet/graphics/api/gl2/text.py +175 -0
- pyglet/graphics/api/gl2/vertexdomain.py +364 -0
- pyglet/graphics/api/webgl/__init__.py +233 -0
- pyglet/graphics/api/webgl/buffer.py +302 -0
- pyglet/graphics/api/webgl/context.py +234 -0
- pyglet/graphics/api/webgl/draw.py +590 -0
- pyglet/graphics/api/webgl/enums.py +76 -0
- pyglet/graphics/api/webgl/framebuffer.py +360 -0
- pyglet/graphics/api/webgl/gl.py +1537 -0
- pyglet/graphics/api/webgl/gl_info.py +130 -0
- pyglet/graphics/api/webgl/shader.py +1346 -0
- pyglet/graphics/api/webgl/shapes.py +92 -0
- pyglet/graphics/api/webgl/sprite.py +102 -0
- pyglet/graphics/api/webgl/state.py +227 -0
- pyglet/graphics/api/webgl/text.py +187 -0
- pyglet/graphics/api/webgl/texture.py +1227 -0
- pyglet/graphics/api/webgl/vertexarray.py +54 -0
- pyglet/graphics/api/webgl/vertexdomain.py +616 -0
- pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
- pyglet/{image → graphics}/atlas.py +33 -32
- pyglet/graphics/base.py +10 -0
- pyglet/graphics/buffer.py +245 -0
- pyglet/graphics/draw.py +578 -0
- pyglet/graphics/framebuffer.py +26 -0
- pyglet/graphics/instance.py +178 -69
- pyglet/graphics/shader.py +267 -1553
- pyglet/graphics/state.py +83 -0
- pyglet/graphics/texture.py +703 -0
- pyglet/graphics/vertexdomain.py +695 -538
- pyglet/gui/ninepatch.py +10 -10
- pyglet/gui/widgets.py +120 -10
- pyglet/image/__init__.py +20 -1973
- pyglet/image/animation.py +12 -12
- pyglet/image/base.py +730 -0
- pyglet/image/codecs/__init__.py +9 -0
- pyglet/image/codecs/bmp.py +53 -30
- pyglet/image/codecs/dds.py +53 -31
- pyglet/image/codecs/gdiplus.py +38 -14
- pyglet/image/codecs/gdkpixbuf2.py +0 -2
- pyglet/image/codecs/js_image.py +99 -0
- pyglet/image/codecs/ktx2.py +161 -0
- pyglet/image/codecs/pil.py +1 -1
- pyglet/image/codecs/png.py +1 -1
- pyglet/image/codecs/wic.py +11 -2
- pyglet/info.py +26 -24
- pyglet/input/__init__.py +8 -0
- pyglet/input/base.py +163 -105
- pyglet/input/controller.py +13 -19
- pyglet/input/controller_db.py +39 -24
- pyglet/input/emscripten/__init__.py +18 -0
- pyglet/input/emscripten/gamepad_js.py +397 -0
- pyglet/input/linux/__init__.py +11 -5
- pyglet/input/linux/evdev.py +10 -11
- pyglet/input/linux/x11_xinput.py +2 -2
- pyglet/input/linux/x11_xinput_tablet.py +1 -1
- pyglet/input/macos/__init__.py +7 -2
- pyglet/input/macos/darwin_gc.py +559 -0
- pyglet/input/win32/__init__.py +1 -1
- pyglet/input/win32/directinput.py +34 -29
- pyglet/input/win32/xinput.py +11 -61
- pyglet/lib.py +3 -3
- pyglet/libs/__init__.py +1 -1
- pyglet/{gl → libs/darwin}/agl.py +1 -1
- pyglet/libs/darwin/cocoapy/__init__.py +2 -2
- pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
- pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
- pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
- pyglet/libs/darwin/cocoapy/runtime.py +81 -45
- pyglet/libs/darwin/coreaudio.py +4 -4
- pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
- pyglet/libs/darwin/quartzkey.py +1 -3
- pyglet/libs/egl/__init__.py +2 -0
- pyglet/libs/egl/egl_lib.py +576 -0
- pyglet/libs/egl/eglext.py +51 -5
- pyglet/libs/linux/__init__.py +0 -0
- pyglet/libs/linux/egl/__init__.py +0 -0
- pyglet/libs/linux/egl/eglext.py +22 -0
- pyglet/libs/linux/glx/__init__.py +0 -0
- pyglet/{gl → libs/linux/glx}/glx.py +13 -14
- pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
- pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
- pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
- pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
- pyglet/libs/linux/wayland/__init__.py +0 -0
- pyglet/libs/linux/wayland/client.py +1068 -0
- pyglet/libs/linux/wayland/lib_wayland.py +207 -0
- pyglet/libs/linux/wayland/wayland_egl.py +38 -0
- pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
- pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
- pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
- pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
- pyglet/libs/linux/x11/xrandr.py +0 -0
- pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
- pyglet/libs/shared/__init__.py +0 -0
- pyglet/libs/shared/spirv/__init__.py +0 -0
- pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
- pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
- pyglet/libs/win32/__init__.py +27 -5
- pyglet/libs/win32/constants.py +59 -48
- pyglet/libs/win32/context_managers.py +20 -3
- pyglet/libs/win32/dinput.py +105 -88
- pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
- pyglet/libs/win32/types.py +58 -23
- pyglet/{gl → libs/win32}/wgl.py +32 -25
- pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
- pyglet/media/__init__.py +9 -10
- pyglet/media/codecs/__init__.py +12 -1
- pyglet/media/codecs/base.py +99 -96
- pyglet/media/codecs/ffmpeg.py +2 -2
- pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
- pyglet/media/codecs/webaudio_pyodide.py +111 -0
- pyglet/media/drivers/__init__.py +9 -4
- pyglet/media/drivers/base.py +4 -4
- pyglet/media/drivers/openal/__init__.py +1 -1
- pyglet/media/drivers/openal/adaptation.py +3 -3
- pyglet/media/drivers/pulse/__init__.py +1 -1
- pyglet/media/drivers/pulse/adaptation.py +3 -3
- pyglet/media/drivers/pyodide_js/__init__.py +8 -0
- pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
- pyglet/media/drivers/xaudio2/adaptation.py +3 -3
- pyglet/media/player.py +276 -193
- pyglet/media/player_worker_thread.py +1 -1
- pyglet/model/__init__.py +39 -29
- pyglet/model/codecs/base.py +4 -4
- pyglet/model/codecs/gltf.py +3 -3
- pyglet/model/codecs/obj.py +71 -43
- pyglet/resource.py +129 -78
- pyglet/shapes.py +147 -177
- pyglet/sprite.py +47 -164
- pyglet/text/__init__.py +44 -54
- pyglet/text/caret.py +12 -7
- pyglet/text/document.py +19 -17
- pyglet/text/formats/html.py +2 -2
- pyglet/text/formats/structured.py +10 -40
- pyglet/text/layout/__init__.py +20 -13
- pyglet/text/layout/base.py +176 -287
- pyglet/text/layout/incremental.py +9 -10
- pyglet/text/layout/scrolling.py +7 -95
- pyglet/window/__init__.py +183 -172
- pyglet/window/cocoa/__init__.py +62 -51
- pyglet/window/cocoa/pyglet_delegate.py +2 -25
- pyglet/window/cocoa/pyglet_view.py +9 -8
- pyglet/window/dialog/__init__.py +184 -0
- pyglet/window/dialog/base.py +99 -0
- pyglet/window/dialog/darwin.py +121 -0
- pyglet/window/dialog/linux.py +72 -0
- pyglet/window/dialog/windows.py +194 -0
- pyglet/window/emscripten/__init__.py +779 -0
- pyglet/window/headless/__init__.py +44 -28
- pyglet/window/key.py +2 -0
- pyglet/window/mouse.py +2 -2
- pyglet/window/wayland/__init__.py +377 -0
- pyglet/window/win32/__init__.py +101 -46
- pyglet/window/xlib/__init__.py +104 -66
- {pyglet-2.1.12.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
- pyglet-3.0.dev1.dist-info/RECORD +322 -0
- {pyglet-2.1.12.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
- pyglet/gl/__init__.py +0 -208
- pyglet/gl/base.py +0 -499
- pyglet/gl/cocoa.py +0 -309
- pyglet/gl/gl.py +0 -4625
- pyglet/gl/gl.pyi +0 -2320
- pyglet/gl/gl_compat.pyi +0 -3097
- pyglet/gl/gl_info.py +0 -190
- pyglet/gl/headless.py +0 -166
- pyglet/gl/wgl_info.py +0 -36
- pyglet/gl/wglext_nv.py +0 -1096
- pyglet/gl/win32.py +0 -268
- pyglet/gl/xlib.py +0 -295
- pyglet/image/buffer.py +0 -274
- pyglet/image/codecs/s3tc.py +0 -354
- pyglet/libs/x11/xrandr.py +0 -166
- pyglet-2.1.12.dist-info/RECORD +0 -234
- /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
- /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
- /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
- /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
- /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
- {pyglet-2.1.12.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
pyglet/model/__init__.py
CHANGED
|
@@ -32,7 +32,7 @@ from math import pi, sin, cos
|
|
|
32
32
|
from typing import TYPE_CHECKING
|
|
33
33
|
|
|
34
34
|
import pyglet
|
|
35
|
-
from pyglet import
|
|
35
|
+
from pyglet import graphics
|
|
36
36
|
from pyglet.math import Mat4
|
|
37
37
|
|
|
38
38
|
from .codecs import add_default_codecs as _add_default_codecs
|
|
@@ -41,11 +41,10 @@ from .codecs.base import Material, Scene, SimpleMaterial
|
|
|
41
41
|
|
|
42
42
|
if TYPE_CHECKING:
|
|
43
43
|
from typing import BinaryIO, TextIO
|
|
44
|
-
from pyglet.
|
|
44
|
+
from pyglet.graphics import Texture
|
|
45
45
|
from pyglet.graphics import Batch, Group
|
|
46
|
-
from pyglet.graphics
|
|
46
|
+
from pyglet.graphics import ShaderProgram
|
|
47
47
|
from pyglet.graphics.vertexdomain import VertexList
|
|
48
|
-
from pyglet.image import Texture
|
|
49
48
|
from pyglet.model.codecs import ModelDecoder
|
|
50
49
|
|
|
51
50
|
|
|
@@ -68,13 +67,19 @@ def load(filename: str, file: BinaryIO | TextIO | None = None, decoder: ModelDec
|
|
|
68
67
|
|
|
69
68
|
|
|
70
69
|
def get_default_shader() -> ShaderProgram:
|
|
71
|
-
return pyglet.
|
|
72
|
-
|
|
70
|
+
return pyglet.graphics.api.get_cached_shader(
|
|
71
|
+
"default_model_material",
|
|
72
|
+
(MaterialGroup.default_vert_src, 'vertex'),
|
|
73
|
+
(MaterialGroup.default_frag_src, 'fragment'),
|
|
74
|
+
)
|
|
73
75
|
|
|
74
76
|
|
|
75
77
|
def get_default_textured_shader() -> ShaderProgram:
|
|
76
|
-
return pyglet.
|
|
77
|
-
|
|
78
|
+
return pyglet.graphics.api.get_cached_shader(
|
|
79
|
+
"default_model_textured_material",
|
|
80
|
+
(TexturedMaterialGroup.default_vert_src, 'vertex'),
|
|
81
|
+
(TexturedMaterialGroup.default_frag_src, 'fragment'),
|
|
82
|
+
)
|
|
78
83
|
|
|
79
84
|
|
|
80
85
|
class Model:
|
|
@@ -123,7 +128,7 @@ class Model:
|
|
|
123
128
|
batch = graphics.Batch()
|
|
124
129
|
|
|
125
130
|
for group, vlist in zip(self.groups, self.vertex_lists):
|
|
126
|
-
self._batch.migrate(vlist,
|
|
131
|
+
self._batch.migrate(vlist, graphics.GeometryMode.TRIANGLES, group, batch)
|
|
127
132
|
|
|
128
133
|
self._batch = batch
|
|
129
134
|
|
|
@@ -204,24 +209,29 @@ class TexturedMaterialGroup(BaseMaterialGroup):
|
|
|
204
209
|
texture: Texture, order: int = 0, parent: Group | None = None):
|
|
205
210
|
super().__init__(material, program, order, parent)
|
|
206
211
|
self.texture = texture
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
212
|
+
self.set_texture(self.texture)
|
|
213
|
+
self.set_shader_program(program)
|
|
214
|
+
self.uniforms = {"model": self.matrix}
|
|
215
|
+
self.set_shader_uniforms(program, self.uniforms)
|
|
216
|
+
#
|
|
217
|
+
# def set_state(self) -> None:
|
|
218
|
+
# # gl.glActiveTexture(gl.GL_TEXTURE0)
|
|
219
|
+
# # gl.glBindTexture(self.texture.target, self.texture.id)
|
|
220
|
+
# # self.program.use()
|
|
221
|
+
# # self.program['model'] = self.matrix
|
|
222
|
+
# pass
|
|
223
|
+
#
|
|
224
|
+
# def __hash__(self) -> int:
|
|
225
|
+
# return hash((self.texture.target, self.texture.id, self.program, self.order, self.parent))
|
|
226
|
+
#
|
|
227
|
+
# def __eq__(self, other) -> bool:
|
|
228
|
+
# return (self.__class__ is other.__class__ and
|
|
229
|
+
# self.material == other.material and
|
|
230
|
+
# self.texture.target == other.texture.target and
|
|
231
|
+
# self.texture.id == other.texture.id and
|
|
232
|
+
# self.program == other.program and
|
|
233
|
+
# self.order == other.order and
|
|
234
|
+
# self.parent == other.parent)
|
|
225
235
|
|
|
226
236
|
|
|
227
237
|
class MaterialGroup(BaseMaterialGroup):
|
|
@@ -354,7 +364,7 @@ class Cube(Model):
|
|
|
354
364
|
7, 6, 4, 6, 5, 4, # back
|
|
355
365
|
3, 2, 0, 2, 1, 0] # front
|
|
356
366
|
|
|
357
|
-
return self._program.vertex_list_indexed(len(vertices) // 3,
|
|
367
|
+
return self._program.vertex_list_indexed(len(vertices) // 3, graphics.GeometryMode.TRIANGLES, indices,
|
|
358
368
|
batch=self._batch, group=self._group,
|
|
359
369
|
POSITION=('f', vertices),
|
|
360
370
|
NORMAL=('f', normals),
|
|
@@ -412,7 +422,7 @@ class Sphere(Model):
|
|
|
412
422
|
indices.extend([first, second, second + 1])
|
|
413
423
|
indices.extend([first, second + 1, first + 1])
|
|
414
424
|
|
|
415
|
-
return self._program.vertex_list_indexed(len(vertices) // 3,
|
|
425
|
+
return self._program.vertex_list_indexed(len(vertices) // 3, graphics.GeometryMode.TRIANGLES, indices,
|
|
416
426
|
batch=self._batch, group=self._group,
|
|
417
427
|
POSITION=('f', vertices),
|
|
418
428
|
NORMAL=('f', normals),
|
pyglet/model/codecs/base.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from abc import ABC
|
|
3
|
+
from abc import ABC
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
7
|
from typing import Sequence
|
|
8
8
|
from pyglet.model import Model
|
|
9
|
-
from pyglet.graphics import Batch, Group
|
|
9
|
+
from pyglet.graphics import Batch, Group, GeometryMode
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Scene(ABC):
|
|
@@ -75,7 +75,7 @@ class Attribute:
|
|
|
75
75
|
class Primitive:
|
|
76
76
|
"""Geometry to be rendered, with optional material."""
|
|
77
77
|
def __init__(self, attributes: list[Attribute], indices: Sequence[int] | None,
|
|
78
|
-
mode:
|
|
78
|
+
mode: GeometryMode, material: Material | None = None) -> None:
|
|
79
79
|
self.attributes = attributes
|
|
80
80
|
self.indices = indices
|
|
81
81
|
self.mode = mode
|
|
@@ -107,7 +107,7 @@ class SimpleMaterial(Material):
|
|
|
107
107
|
self.texture_name = texture_name
|
|
108
108
|
|
|
109
109
|
def __repr__(self):
|
|
110
|
-
return f"Material(name='{self.name}', texture='{self.texture_name}'"
|
|
110
|
+
return f"Material(name='{self.name}', texture='{self.texture_name}')"
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
class PBRMaterial(Material):
|
pyglet/model/codecs/gltf.py
CHANGED
|
@@ -8,9 +8,9 @@ from urllib.request import urlopen
|
|
|
8
8
|
|
|
9
9
|
import pyglet
|
|
10
10
|
|
|
11
|
-
from pyglet.gl import GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FLOAT, GL_DOUBLE
|
|
12
|
-
from pyglet.gl import GL_INT, GL_UNSIGNED_INT, GL_ELEMENT_ARRAY_BUFFER, GL_ARRAY_BUFFER
|
|
13
|
-
from pyglet.gl import GL_REPEAT
|
|
11
|
+
from pyglet.graphics.api.gl import GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FLOAT, GL_DOUBLE
|
|
12
|
+
from pyglet.graphics.api.gl import GL_INT, GL_UNSIGNED_INT, GL_ELEMENT_ARRAY_BUFFER, GL_ARRAY_BUFFER
|
|
13
|
+
from pyglet.graphics.api.gl import GL_REPEAT
|
|
14
14
|
|
|
15
15
|
from . import ModelDecodeException, ModelDecoder
|
|
16
16
|
from .base import Scene
|
pyglet/model/codecs/obj.py
CHANGED
|
@@ -4,27 +4,29 @@ import os
|
|
|
4
4
|
|
|
5
5
|
import pyglet
|
|
6
6
|
|
|
7
|
-
from pyglet.gl import GL_TRIANGLES
|
|
8
7
|
from pyglet.util import asstr
|
|
9
8
|
|
|
10
9
|
from . import ModelDecodeException, ModelDecoder
|
|
11
10
|
from .base import SimpleMaterial, Mesh, Primitive, Attribute, Node, Scene
|
|
12
|
-
from
|
|
13
|
-
from
|
|
11
|
+
from pyglet.model import Model, MaterialGroup, TexturedMaterialGroup
|
|
12
|
+
from pyglet.graphics import Batch, Group, GeometryMode
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
def _new_mesh(name, material):
|
|
17
16
|
# The three primitive types used in .obj files:
|
|
18
|
-
attributes = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
attributes = [
|
|
18
|
+
Attribute('POSITION', 'f', 'VEC3', 0, []),
|
|
19
|
+
Attribute('NORMAL', 'f', 'VEC3', 0, []),
|
|
20
|
+
Attribute('TEXCOORD_0', 'f', 'VEC3', 0, []),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
primitive = Primitive(attributes=attributes, indices=None, material=material, mode=GeometryMode.TRIANGLES)
|
|
22
24
|
mesh = Mesh(primitives=[primitive], name=name)
|
|
23
25
|
return mesh
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
def load_material_library(filename):
|
|
27
|
-
file = open(filename
|
|
29
|
+
file = open(filename)
|
|
28
30
|
|
|
29
31
|
name = None
|
|
30
32
|
diffuse = [1.0, 1.0, 1.0]
|
|
@@ -73,7 +75,7 @@ def load_material_library(filename):
|
|
|
73
75
|
texture_name = values[1]
|
|
74
76
|
|
|
75
77
|
except BaseException as ex:
|
|
76
|
-
raise ModelDecodeException('Parsing error in {
|
|
78
|
+
raise ModelDecodeException(f'Parsing error in {(filename, ex)}.')
|
|
77
79
|
|
|
78
80
|
file.close()
|
|
79
81
|
|
|
@@ -93,7 +95,7 @@ def parse_obj_file(filename, file=None) -> list[Mesh]:
|
|
|
93
95
|
|
|
94
96
|
try:
|
|
95
97
|
if file is None:
|
|
96
|
-
with open(filename
|
|
98
|
+
with open(filename) as f:
|
|
97
99
|
file_contents = f.read()
|
|
98
100
|
else:
|
|
99
101
|
file_contents = asstr(file.read())
|
|
@@ -132,7 +134,7 @@ def parse_obj_file(filename, file=None) -> list[Mesh]:
|
|
|
132
134
|
|
|
133
135
|
elif values[0] == 'mtllib':
|
|
134
136
|
material_abspath = os.path.join(location, values[1])
|
|
135
|
-
materials = load_material_library(filename=material_abspath)
|
|
137
|
+
materials = load_material_library(filename=material_abspath)
|
|
136
138
|
|
|
137
139
|
elif values[0] in ('usemtl', 'usemat'):
|
|
138
140
|
material = materials.get(values[1])
|
|
@@ -140,49 +142,75 @@ def parse_obj_file(filename, file=None) -> list[Mesh]:
|
|
|
140
142
|
mesh.primitives[0].material = material
|
|
141
143
|
|
|
142
144
|
elif values[0] == 'o':
|
|
143
|
-
mesh = _new_mesh(
|
|
145
|
+
mesh = _new_mesh(values[1], material=default_material)
|
|
144
146
|
meshes.append(mesh)
|
|
145
147
|
|
|
146
148
|
elif values[0] == 'f':
|
|
149
|
+
# --- FACES
|
|
150
|
+
|
|
147
151
|
if material is None:
|
|
148
152
|
material = SimpleMaterial()
|
|
149
153
|
if mesh is None:
|
|
150
154
|
mesh = _new_mesh(name='unknown', material=material)
|
|
151
155
|
meshes.append(mesh)
|
|
152
156
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
primitive = mesh.primitives[0]
|
|
158
|
+
|
|
159
|
+
pos_attr = primitive.attributes[0]
|
|
160
|
+
|
|
161
|
+
# optional normals and teture uvs
|
|
162
|
+
normal_attr = primitive.attributes[1] if len(primitive.attributes) > 1 else None
|
|
163
|
+
tex_uv_attr = primitive.attributes[2] if len(primitive.attributes) > 2 else None
|
|
164
|
+
|
|
165
|
+
face_vertices = []
|
|
166
|
+
for v in values[1:]:
|
|
167
|
+
parts = v.split('/')
|
|
168
|
+
|
|
169
|
+
# vertex index (should not be empty, raise error instead?)
|
|
170
|
+
v_i = int(parts[0]) if parts[0] else 0
|
|
171
|
+
|
|
172
|
+
# texcoord index (optional)
|
|
173
|
+
t_i = 0
|
|
174
|
+
if len(parts) >= 2 and parts[1]:
|
|
175
|
+
t_i = int(parts[1])
|
|
176
|
+
|
|
177
|
+
# normal index (optional)
|
|
178
|
+
n_i = 0
|
|
179
|
+
if len(parts) == 3 and parts[2]:
|
|
180
|
+
n_i = int(parts[2])
|
|
181
|
+
|
|
182
|
+
# handle negative indices
|
|
163
183
|
if v_i < 0:
|
|
164
|
-
v_i
|
|
184
|
+
v_i = len(vertices) + v_i
|
|
165
185
|
if t_i < 0:
|
|
166
|
-
t_i
|
|
186
|
+
t_i = len(tex_coords) + t_i
|
|
167
187
|
if n_i < 0:
|
|
168
|
-
n_i
|
|
169
|
-
|
|
170
|
-
mesh.primitives[0].attributes[0].array += vertices[v_i]
|
|
171
|
-
mesh.primitives[0].attributes[1].array += normals[n_i]
|
|
172
|
-
mesh.primitives[0].attributes[2].array += tex_coords[t_i]
|
|
188
|
+
n_i = len(normals) + n_i
|
|
173
189
|
|
|
174
|
-
|
|
175
|
-
mesh.primitives[0].attributes[0].array += v1 + vlast
|
|
176
|
-
mesh.primitives[0].attributes[1].array += n1 + nlast
|
|
177
|
-
mesh.primitives[0].attributes[2].array += t1 + tlast
|
|
190
|
+
face_vertices.append((v_i, t_i, n_i))
|
|
178
191
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
# For fan triangulation, remember first and latest vertices
|
|
193
|
+
for i in range(2, len(face_vertices)):
|
|
194
|
+
for idx in (0, i - 1, i):
|
|
195
|
+
v_i, t_i, n_i = face_vertices[idx]
|
|
196
|
+
|
|
197
|
+
pos_attr.array += vertices[v_i]
|
|
198
|
+
|
|
199
|
+
# normals (optional)
|
|
200
|
+
if normal_attr is not None:
|
|
201
|
+
if n_i != 0:
|
|
202
|
+
primitive.has_normals = True
|
|
203
|
+
normal_attr.array += normals[n_i]
|
|
204
|
+
else:
|
|
205
|
+
normal_attr.array += [0.0, 0.0, 1.0]
|
|
206
|
+
|
|
207
|
+
# texcoords (optional)
|
|
208
|
+
if tex_uv_attr is not None:
|
|
209
|
+
if t_i != 0:
|
|
210
|
+
primitive.has_tex_coords = True
|
|
211
|
+
tex_uv_attr.array += tex_coords[t_i]
|
|
212
|
+
else:
|
|
213
|
+
tex_uv_attr.array += [0.0, 0.0]
|
|
186
214
|
|
|
187
215
|
for mesh in meshes:
|
|
188
216
|
for primitive in mesh.primitives:
|
|
@@ -204,17 +232,17 @@ class OBJScene(Scene):
|
|
|
204
232
|
|
|
205
233
|
if material.texture_name:
|
|
206
234
|
program = pyglet.model.get_default_textured_shader()
|
|
207
|
-
texture = pyglet.resource.texture(material.texture_name)
|
|
235
|
+
texture = pyglet.resource.texture(material.texture_name, atlas=False)
|
|
208
236
|
matgroup = TexturedMaterialGroup(material, program, texture, parent=group)
|
|
209
237
|
else:
|
|
210
238
|
program = pyglet.model.get_default_shader()
|
|
211
239
|
matgroup = MaterialGroup(material, program, parent=group)
|
|
212
240
|
|
|
213
|
-
data = {a.name: (a.fmt, a.array) for a in mesh.primitives[0].attributes}
|
|
241
|
+
data = {a.name: (a.fmt, a.array) for a in mesh.primitives[0].attributes if a.name in program.attributes}
|
|
214
242
|
# Add additional material data:
|
|
215
243
|
data['COLOR_0'] = 'f', material.diffuse * count
|
|
216
244
|
|
|
217
|
-
vertex_lists.append(program.vertex_list(count,
|
|
245
|
+
vertex_lists.append(program.vertex_list(count, GeometryMode.TRIANGLES, batch, matgroup, **data))
|
|
218
246
|
groups.append(matgroup)
|
|
219
247
|
|
|
220
248
|
return [Model(vertex_lists=vertex_lists, groups=groups, batch=batch)]
|