-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCalInspector.py
More file actions
49 lines (41 loc) · 1.39 KB
/
CalInspector.py
File metadata and controls
49 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import imvu
import hashlib
import logging
import mmap
import cal3d
logger = logging.getLogger("imvu." + __name__)
class Cal3dException(Exception):
pass
def __mmap_to_string(b):
if isinstance(b, mmap.mmap):
b = b.read(b.size())
return b
def getMaterialInfo(materialBuffer):
materialBuffer = __mmap_to_string(materialBuffer)
cachekey = hashlib.md5(materialBuffer).hexdigest()
material = cal3d.loadCoreMaterialFromBuffer(materialBuffer)
if not material:
raise Cal3dException, cal3d.getLastErrorText()
materialInfo = {}
materialInfo['maps'] = {}
for m in material.maps:
materialInfo['maps'][m.type] = m.filename
return materialInfo
def getMeshInfo(meshBuffer):
meshBuffer = __mmap_to_string(meshBuffer)
mesh = cal3d.loadCoreMeshFromBuffer(meshBuffer)
if not mesh:
raise Cal3dException, cal3d.getLastErrorText()
result = {}
for i, submesh in enumerate(mesh.submeshes):
result[i] = {}
result[i]['materialId'] = submesh.coreMaterialThreadId
result[i]['faceCount'] = len(submesh.triangles)
result[i]['vertexCount'] = len(submesh.vertices)
return result
def getSkeletonInfo(skeletonBuffer):
skeletonBuffer = __mmap_to_string(skeletonBuffer)
skel = cal3d.loadCoreSkeletonFromBuffer(skeletonBuffer)
if not skel:
raise Cal3dException, cal3d.getLastErrorText()
return skel