Skip to content

Commit 6b1a39a

Browse files
committed
Basic obj loader supporting positions
1 parent 3ac5231 commit 6b1a39a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

demosys/scene/loaders/wavefront.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1+
import numpy
12
from .base import SceneLoader
3+
import pywavefront
4+
5+
from OpenGL import GL
6+
from OpenGL.arrays.vbo import VBO
7+
from demosys.opengl import VAO
8+
from demosys.scene import Mesh, Node
29

310

411
class ObjLoader(SceneLoader):
512
"""Loade obj files"""
613
file_extensions = ['.obj']
714

815
def __init__(self, file_path):
9-
self.path = path
1016
super().__init__(file_path)
1117

1218
def load(self, scene, file=None):
13-
print(scene, file)
19+
"""Deferred loading"""
20+
data = pywavefront.Wavefront(file)
21+
22+
for mesh in data.mesh_list:
23+
for mat in mesh.materials:
24+
vbo = VBO(numpy.array(mat.vertices, dtype=numpy.dtype(numpy.float32)))
25+
26+
vao = VAO("moo", mode=GL.GL_TRIANGLES)
27+
vao.add_array_buffer(GL.GL_FLOAT, vbo)
28+
vao.map_buffer(vbo, "in_uv", 2)
29+
vao.map_buffer(vbo, "in_normal", 3)
30+
vao.map_buffer(vbo, "in_position", 3)
31+
vao.build()
32+
33+
mesh = Mesh("moo", vao=vao)
34+
scene.meshes.append(mesh)
35+
node = Node(mesh=mesh)
36+
scene.root_nodes.append(node)
37+
1438
return scene

0 commit comments

Comments
 (0)