-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXportMesh.py
65 lines (38 loc) · 1.27 KB
/
XportMesh.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# XportMesh.py
import json
if 'includeScript' not in locals():
def includeScript(path, cwd=''):
exec (open(cwd + path, 'r').read(), globals())
# includes
includeScript('getMeshData.py', '/Users/laserstorm/MayaUsefulScripts/')
includeScript('exportText.py', '/Users/laserstorm/MayaUsefulScripts/')
includeScript('getFileLocation.py', '/Users/laserstorm/MayaUsefulScripts/')
def exportJson(dic, pretty=False):
if pretty:
exportText(json.dumps(dic, indent=2), getFileLocation(0, '.json'))
else:
exportText(json.dumps(dic), getFileLocation(0, '.json'))
def meshToData(m):
# mesh data
meshData = getMeshData( m )
# add the transform
meshData['transform'] = cmds.xform(m, q=1, m=1, worldSpace=True )
# # flatten arrays
# meshData['position'] = [ p[i] for p in meshData['position'] for i in range(3) ]
# meshData['normal'] = [ n[i] for n in meshData['normal'] for i in range(3) ]
# meshData['uv'] = [ u[i] for u in meshData['uv'] for i in range(2) ]
# meshData['itemSize'] = {
# 'position' : 3,
# 'normal' : 3,
# 'uv' : 2
# }
return meshData
selected = cmds.ls(sl=1, fl=1)
scene = {
'mesh' : []
}
for i in selected:
# print i
scene['mesh'].append( meshToData(i) )
exportJson(scene, True)
cmds.select(selected, r=1)