mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-12 13:39:04 +08:00
First version of draco wrapper for python
This commit is contained in:
parent
e06d8f217f
commit
9afc0d3177
1
maya/.gitignore
vendored
Normal file
1
maya/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
BIN
maya/bunny.drc
Normal file
BIN
maya/bunny.drc
Normal file
Binary file not shown.
60
maya/draco.py
Normal file
60
maya/draco.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
'''
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
from draco import Draco
|
||||||
|
|
||||||
|
drc = Draco()
|
||||||
|
mesh = drc.decode('path-to-file.drc')
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("==== FACES ====")
|
||||||
|
print(mesh.faces_num)
|
||||||
|
print(mesh.faces[0:10])
|
||||||
|
print("")
|
||||||
|
print("==== VERTICES ====")
|
||||||
|
print(mesh.vertices_num)
|
||||||
|
print(mesh.vertices[0:10])
|
||||||
|
print("==== NORMALS ====")
|
||||||
|
print(mesh.normals_num)
|
||||||
|
print(mesh.normals[0:10])
|
||||||
|
'''
|
||||||
|
|
||||||
|
import os
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
class Drc2PyMesh(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("faces_num", ctypes.c_uint),
|
||||||
|
("faces", ctypes.POINTER(ctypes.c_uint)),
|
||||||
|
("vertices_num", ctypes.c_uint),
|
||||||
|
("vertices", ctypes.POINTER(ctypes.c_float)),
|
||||||
|
("normals_num", ctypes.c_uint),
|
||||||
|
("normals", ctypes.POINTER(ctypes.c_float))
|
||||||
|
]
|
||||||
|
|
||||||
|
# TODO: Add integration for UNIX
|
||||||
|
class Draco:
|
||||||
|
def __init__(self):
|
||||||
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
lib_path = os.path.join(dir_path, 'dracodec_maya')
|
||||||
|
self.drc_lib = ctypes.CDLL(lib_path)
|
||||||
|
self.drc_decode = self.drc_lib.drc2py_decode
|
||||||
|
self.drc_decode.argtype = [ ctypes.POINTER(ctypes.c_char), ctypes.c_uint, ctypes.POINTER(ctypes.POINTER(Drc2PyMesh)) ]
|
||||||
|
|
||||||
|
def decode(self, file_path):
|
||||||
|
file = None
|
||||||
|
bytes = None
|
||||||
|
try:
|
||||||
|
file = open(file_path, 'rb')
|
||||||
|
bytes = file.read()
|
||||||
|
except IOError as err:
|
||||||
|
print('[ERROR] Failure opening file: ' + repr(err))
|
||||||
|
return None
|
||||||
|
finally:
|
||||||
|
if file: file.close()
|
||||||
|
|
||||||
|
size = len(bytes)
|
||||||
|
mesh_ptr = ctypes.POINTER(Drc2PyMesh)()
|
||||||
|
self.drc_decode(bytes, size, ctypes.byref(mesh_ptr))
|
||||||
|
mesh = mesh_ptr.contents
|
||||||
|
return mesh;
|
14
maya/draco_example.py
Normal file
14
maya/draco_example.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from draco import Draco
|
||||||
|
|
||||||
|
drc = Draco()
|
||||||
|
mesh = drc.decode('bunny.drc')
|
||||||
|
|
||||||
|
print("\n==== FACES ====")
|
||||||
|
print(mesh.faces_num)
|
||||||
|
print(mesh.faces[0:10])
|
||||||
|
print("\n==== VERTICES ====")
|
||||||
|
print(mesh.vertices_num)
|
||||||
|
print(mesh.vertices[0:10])
|
||||||
|
print("\n==== NORMALS ====")
|
||||||
|
print(mesh.normals_num)
|
||||||
|
# print(mesh.normals[0:10]) This mesh has no normals
|
BIN
maya/dracodec_maya.dll
Normal file
BIN
maya/dracodec_maya.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user