mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Added compression support to wavefront loader.
Removed massive generated C file.
This commit is contained in:
parent
6138402b01
commit
d1599eb511
12938
punyverse/_model.c
12938
punyverse/_model.c
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,20 @@ from punyverse.texture import load_texture
|
|||
include "_cyopengl.pxi"
|
||||
from uuid import uuid4
|
||||
import os
|
||||
import gzip
|
||||
import bz2
|
||||
import zipfile
|
||||
|
||||
def zip_open(file):
|
||||
zip = zipfile.ZipFile(file)
|
||||
return zip.open(zip.namelist()[0])
|
||||
|
||||
openers = {
|
||||
'gz': gzip.open,
|
||||
'bz2': bz2.BZ2File,
|
||||
'zip': zip_open,
|
||||
}
|
||||
|
||||
|
||||
cdef enum:
|
||||
FACE_TRIANGLES
|
||||
|
@ -178,8 +192,8 @@ cdef class WavefrontObject(object):
|
|||
|
||||
group.faces.append(Face(type, vindices, nindices, tindices, face_vertices, face_normals, face_textures))
|
||||
|
||||
cdef void material(self, list words):
|
||||
self.perform_io(os.path.join(self.root, words[1]))
|
||||
cdef bint material(self, list words) except False:
|
||||
return self.perform_io(os.path.join(self.root, words[1]))
|
||||
|
||||
cdef void use_material(self, list words):
|
||||
mat = words[1]
|
||||
|
@ -199,24 +213,16 @@ cdef class WavefrontObject(object):
|
|||
self.groups.append(group)
|
||||
self.current_group = group
|
||||
|
||||
cdef inline void perform_io(self, unicode file):
|
||||
mbcsfile = file.encode('mbcs')
|
||||
cdef char* fname = mbcsfile
|
||||
|
||||
cdef FILE* cfile
|
||||
cfile = fopen(fname, 'rb')
|
||||
if cfile == NULL:
|
||||
raise IOError(2, "No such file or directory: '%s'" % file)
|
||||
|
||||
cdef size_t bufsize = 2048
|
||||
cdef char *buf = <char*>malloc(bufsize)
|
||||
cdef ssize_t read
|
||||
cdef char *type
|
||||
cdef inline bint perform_io(self, unicode file) except False:
|
||||
cdef const char *type
|
||||
cdef list words
|
||||
cdef int hash, length
|
||||
|
||||
while fgets(buf, bufsize, cfile):
|
||||
if buf[0] in (0, 10, 13, 35):
|
||||
ext = os.path.splitext(file)[1].lstrip('.')
|
||||
reader = openers.get(ext, open)(file)
|
||||
with reader:
|
||||
for buf in reader:
|
||||
if not buf or buf.startswith(('\r', '\n', '#')):
|
||||
continue # Empty or comment
|
||||
words = buf.split()
|
||||
type = words[0]
|
||||
|
@ -254,8 +260,7 @@ cdef class WavefrontObject(object):
|
|||
self.new_material(words)
|
||||
elif strcmp(type, b'map_Kd') == 0:
|
||||
self.material_texture(words)
|
||||
free(buf)
|
||||
fclose(cfile)
|
||||
return True
|
||||
|
||||
model_base = None
|
||||
|
||||
|
|
Loading…
Reference in a new issue