-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_tests.py
158 lines (145 loc) · 3.78 KB
/
_tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import sys, json
import traceback, logging, logging.handlers
import time
from struct import *
import struct
print 'glb test 0.1'
print 'writes a simple glb file with a triangle'
jsonobj ={
"accessors":{
"accessor_21":{
"bufferView":"bufferView_29",
"byteOffset":0,
"byteStride":0,
"componentType":5123,
"count":3,
"type":"SCALAR"
},
"accessor_23":{
"bufferView":"bufferView_30",
"byteOffset":0,
"byteStride":12,
"componentType":5126,
"count":3,
"max":[ 0.5, 0.5, 0.5 ],
"min":[ -0.5, -0.5, -0.5 ],
"type":"VEC3"
},
"accessor_25":{
"bufferView":"bufferView_30",
"byteOffset":36,
"byteStride":12,
"componentType":5126,
"count":3,
"max":[ 1, 1, 1 ],
"min":[ -1, -1, -1 ],
"type":"VEC3"
}
},
"animations":{
},
"asset":{
"generator":"collada2gltf@774bd4fe67703fbf60f9c02f3ba79632f246e9b6",
"premultipliedAlpha":True,
"profile":{
"api":"WebGL",
"version":"1.0.2"
},
"version":"1.0"
},
"bufferViews":{
"bufferView_29":{
"buffer":"binary_glTF",
"byteLength":6,
"byteOffset":0,
"target":34963
},
"bufferView_30":{
"buffer":"binary_glTF",
"byteLength":72,
"byteOffset":6,
"target":34962
}
},
"buffers":{
"binary_glTF":{
"type":"arraybuffer",
"byteLength":13790,
"uri":"data:,"
}
},
"meshes":{
"Geometry-mesh002":{
"name":"Mesh",
"primitives":[
{
"attributes":{
"NORMAL":"accessor_25",
"POSITION":"accessor_23",
# "TEXCOORD_0":"accessor_27"
},
"indices":"accessor_21",
# "material":"Effect-Texture",
"mode":4
}
]
}
},
"nodes":{
"Geometry-mesh002Node":{
"children":[
],
"matrix":[
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
],
"meshes":[
"Geometry-mesh002"
],
"name":"Mesh"
},
"node_3":{
"children":[
"Geometry-mesh002Node"
],
"matrix":[
1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0,0 , 0, 0, 1
],
"name":"Y_UP_Transform"
}
},
"scene":"defaultScene",
"scenes":{
"defaultScene":{
"nodes":[
"node_3"
]
}
},
"extensionsUsed":[
"KHR_binary_glTF"
]
}
jsonstr = json.dumps(jsonobj)
print jsonstr
with open('c:/tests/x3d2/x3d2/src/assets/test_e.glb', 'wb+') as f:
# head
f.write('glTF')
f.write(struct.pack('i',1))
jsonlength=sys.getsizeof(jsonstr)
length =20+jsonlength+78
f.write(struct.pack('i',length)) #filelength
f.write(struct.pack('i',jsonlength)) #contentlength
f.write(struct.pack('i',0)) #contentformat
# json
f.write( jsonstr)
# geometry data
indices = [0,1,2]
positions = [0.0,0.0,0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0]
normals = [0.0,0.0,1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]
for b in indices:
f.write(struct.pack('h', int(b)))
for b in positions:
f.write(struct.pack('f', float(b)))
for b in normals:
f.write(struct.pack('f', float(b)))