ctm.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. Copyright (c) 2011 Juan Mellado
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. /*
  20. References:
  21. - "OpenCTM: The Open Compressed Triangle Mesh file format" by Marcus Geelnard
  22. http://openctm.sourceforge.net/
  23. */
  24. var CTM = CTM || {};
  25. // browserify support
  26. if ( typeof module === 'object' ) {
  27. module.exports = CTM;
  28. }
  29. CTM.CompressionMethod = {
  30. RAW: 0x00574152,
  31. MG1: 0x0031474d,
  32. MG2: 0x0032474d
  33. };
  34. CTM.Flags = {
  35. NORMALS: 0x00000001
  36. };
  37. CTM.File = function(stream) {
  38. this.load(stream);
  39. };
  40. CTM.File.prototype.load = function(stream) {
  41. this.header = new CTM.FileHeader(stream);
  42. this.body = new CTM.FileBody(this.header);
  43. this.getReader().read(stream, this.body);
  44. };
  45. CTM.File.prototype.getReader = function() {
  46. var reader;
  47. switch (this.header.compressionMethod){
  48. case CTM.CompressionMethod.RAW:
  49. reader = new CTM.ReaderRAW();
  50. break;
  51. case CTM.CompressionMethod.MG1:
  52. reader = new CTM.ReaderMG1();
  53. break;
  54. case CTM.CompressionMethod.MG2:
  55. reader = new CTM.ReaderMG2();
  56. break;
  57. }
  58. return reader;
  59. };
  60. CTM.FileHeader = function(stream) {
  61. stream.readInt32(); //magic "OCTM"
  62. this.fileFormat = stream.readInt32();
  63. this.compressionMethod = stream.readInt32();
  64. this.vertexCount = stream.readInt32();
  65. this.triangleCount = stream.readInt32();
  66. this.uvMapCount = stream.readInt32();
  67. this.attrMapCount = stream.readInt32();
  68. this.flags = stream.readInt32();
  69. this.comment = stream.readString();
  70. };
  71. CTM.FileHeader.prototype.hasNormals = function() {
  72. return this.flags & CTM.Flags.NORMALS;
  73. };
  74. CTM.FileBody = function(header) {
  75. var i = header.triangleCount * 3,
  76. v = header.vertexCount * 3,
  77. n = header.hasNormals() ? header.vertexCount * 3 : 0,
  78. u = header.vertexCount * 2,
  79. a = header.vertexCount * 4,
  80. j = 0;
  81. var data = new ArrayBuffer(
  82. (i + v + n + (u * header.uvMapCount) + (a * header.attrMapCount) ) * 4);
  83. this.indices = new Uint32Array(data, 0, i);
  84. this.vertices = new Float32Array(data, i * 4, v);
  85. if ( header.hasNormals() ) {
  86. this.normals = new Float32Array(data, (i + v) * 4, n);
  87. }
  88. if (header.uvMapCount) {
  89. this.uvMaps = [];
  90. for (j = 0; j < header.uvMapCount; ++ j) {
  91. this.uvMaps[j] = { uv: new Float32Array(data,
  92. (i + v + n + (j * u) ) * 4, u) };
  93. }
  94. }
  95. if (header.attrMapCount) {
  96. this.attrMaps = [];
  97. for (j = 0; j < header.attrMapCount; ++ j) {
  98. this.attrMaps[j] = { attr: new Float32Array(data,
  99. (i + v + n + (u * header.uvMapCount) + (j * a) ) * 4, a) };
  100. }
  101. }
  102. };
  103. CTM.FileMG2Header = function(stream) {
  104. stream.readInt32(); //magic "MG2H"
  105. this.vertexPrecision = stream.readFloat32();
  106. this.normalPrecision = stream.readFloat32();
  107. this.lowerBoundx = stream.readFloat32();
  108. this.lowerBoundy = stream.readFloat32();
  109. this.lowerBoundz = stream.readFloat32();
  110. this.higherBoundx = stream.readFloat32();
  111. this.higherBoundy = stream.readFloat32();
  112. this.higherBoundz = stream.readFloat32();
  113. this.divx = stream.readInt32();
  114. this.divy = stream.readInt32();
  115. this.divz = stream.readInt32();
  116. this.sizex = (this.higherBoundx - this.lowerBoundx) / this.divx;
  117. this.sizey = (this.higherBoundy - this.lowerBoundy) / this.divy;
  118. this.sizez = (this.higherBoundz - this.lowerBoundz) / this.divz;
  119. };
  120. CTM.ReaderRAW = function() {
  121. };
  122. CTM.ReaderRAW.prototype.read = function(stream, body) {
  123. this.readIndices(stream, body.indices);
  124. this.readVertices(stream, body.vertices);
  125. if (body.normals) {
  126. this.readNormals(stream, body.normals);
  127. }
  128. if (body.uvMaps) {
  129. this.readUVMaps(stream, body.uvMaps);
  130. }
  131. if (body.attrMaps) {
  132. this.readAttrMaps(stream, body.attrMaps);
  133. }
  134. };
  135. CTM.ReaderRAW.prototype.readIndices = function(stream, indices) {
  136. stream.readInt32(); //magic "INDX"
  137. stream.readArrayInt32(indices);
  138. };
  139. CTM.ReaderRAW.prototype.readVertices = function(stream, vertices) {
  140. stream.readInt32(); //magic "VERT"
  141. stream.readArrayFloat32(vertices);
  142. };
  143. CTM.ReaderRAW.prototype.readNormals = function(stream, normals) {
  144. stream.readInt32(); //magic "NORM"
  145. stream.readArrayFloat32(normals);
  146. };
  147. CTM.ReaderRAW.prototype.readUVMaps = function(stream, uvMaps) {
  148. var i = 0;
  149. for (; i < uvMaps.length; ++ i) {
  150. stream.readInt32(); //magic "TEXC"
  151. uvMaps[i].name = stream.readString();
  152. uvMaps[i].filename = stream.readString();
  153. stream.readArrayFloat32(uvMaps[i].uv);
  154. }
  155. };
  156. CTM.ReaderRAW.prototype.readAttrMaps = function(stream, attrMaps) {
  157. var i = 0;
  158. for (; i < attrMaps.length; ++ i) {
  159. stream.readInt32(); //magic "ATTR"
  160. attrMaps[i].name = stream.readString();
  161. stream.readArrayFloat32(attrMaps[i].attr);
  162. }
  163. };
  164. CTM.ReaderMG1 = function() {
  165. };
  166. CTM.ReaderMG1.prototype.read = function(stream, body) {
  167. this.readIndices(stream, body.indices);
  168. this.readVertices(stream, body.vertices);
  169. if (body.normals) {
  170. this.readNormals(stream, body.normals);
  171. }
  172. if (body.uvMaps) {
  173. this.readUVMaps(stream, body.uvMaps);
  174. }
  175. if (body.attrMaps) {
  176. this.readAttrMaps(stream, body.attrMaps);
  177. }
  178. };
  179. CTM.ReaderMG1.prototype.readIndices = function(stream, indices) {
  180. stream.readInt32(); //magic "INDX"
  181. stream.readInt32(); //packed size
  182. var interleaved = new CTM.InterleavedStream(indices, 3);
  183. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  184. CTM.restoreIndices(indices, indices.length);
  185. };
  186. CTM.ReaderMG1.prototype.readVertices = function(stream, vertices) {
  187. stream.readInt32(); //magic "VERT"
  188. stream.readInt32(); //packed size
  189. var interleaved = new CTM.InterleavedStream(vertices, 1);
  190. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  191. };
  192. CTM.ReaderMG1.prototype.readNormals = function(stream, normals) {
  193. stream.readInt32(); //magic "NORM"
  194. stream.readInt32(); //packed size
  195. var interleaved = new CTM.InterleavedStream(normals, 3);
  196. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  197. };
  198. CTM.ReaderMG1.prototype.readUVMaps = function(stream, uvMaps) {
  199. var i = 0;
  200. for (; i < uvMaps.length; ++ i) {
  201. stream.readInt32(); //magic "TEXC"
  202. uvMaps[i].name = stream.readString();
  203. uvMaps[i].filename = stream.readString();
  204. stream.readInt32(); //packed size
  205. var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2);
  206. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  207. }
  208. };
  209. CTM.ReaderMG1.prototype.readAttrMaps = function(stream, attrMaps) {
  210. var i = 0;
  211. for (; i < attrMaps.length; ++ i) {
  212. stream.readInt32(); //magic "ATTR"
  213. attrMaps[i].name = stream.readString();
  214. stream.readInt32(); //packed size
  215. var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4);
  216. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  217. }
  218. };
  219. CTM.ReaderMG2 = function() {
  220. };
  221. CTM.ReaderMG2.prototype.read = function(stream, body) {
  222. this.MG2Header = new CTM.FileMG2Header(stream);
  223. this.readVertices(stream, body.vertices);
  224. this.readIndices(stream, body.indices);
  225. if (body.normals) {
  226. this.readNormals(stream, body);
  227. }
  228. if (body.uvMaps) {
  229. this.readUVMaps(stream, body.uvMaps);
  230. }
  231. if (body.attrMaps) {
  232. this.readAttrMaps(stream, body.attrMaps);
  233. }
  234. };
  235. CTM.ReaderMG2.prototype.readVertices = function(stream, vertices) {
  236. stream.readInt32(); //magic "VERT"
  237. stream.readInt32(); //packed size
  238. var interleaved = new CTM.InterleavedStream(vertices, 3);
  239. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  240. var gridIndices = this.readGridIndices(stream, vertices);
  241. CTM.restoreVertices(vertices, this.MG2Header, gridIndices, this.MG2Header.vertexPrecision);
  242. };
  243. CTM.ReaderMG2.prototype.readGridIndices = function(stream, vertices) {
  244. stream.readInt32(); //magic "GIDX"
  245. stream.readInt32(); //packed size
  246. var gridIndices = new Uint32Array(vertices.length / 3);
  247. var interleaved = new CTM.InterleavedStream(gridIndices, 1);
  248. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  249. CTM.restoreGridIndices(gridIndices, gridIndices.length);
  250. return gridIndices;
  251. };
  252. CTM.ReaderMG2.prototype.readIndices = function(stream, indices) {
  253. stream.readInt32(); //magic "INDX"
  254. stream.readInt32(); //packed size
  255. var interleaved = new CTM.InterleavedStream(indices, 3);
  256. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  257. CTM.restoreIndices(indices, indices.length);
  258. };
  259. CTM.ReaderMG2.prototype.readNormals = function(stream, body) {
  260. stream.readInt32(); //magic "NORM"
  261. stream.readInt32(); //packed size
  262. var interleaved = new CTM.InterleavedStream(body.normals, 3);
  263. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  264. var smooth = CTM.calcSmoothNormals(body.indices, body.vertices);
  265. CTM.restoreNormals(body.normals, smooth, this.MG2Header.normalPrecision);
  266. };
  267. CTM.ReaderMG2.prototype.readUVMaps = function(stream, uvMaps) {
  268. var i = 0;
  269. for (; i < uvMaps.length; ++ i) {
  270. stream.readInt32(); //magic "TEXC"
  271. uvMaps[i].name = stream.readString();
  272. uvMaps[i].filename = stream.readString();
  273. var precision = stream.readFloat32();
  274. stream.readInt32(); //packed size
  275. var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2);
  276. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  277. CTM.restoreMap(uvMaps[i].uv, 2, precision);
  278. }
  279. };
  280. CTM.ReaderMG2.prototype.readAttrMaps = function(stream, attrMaps) {
  281. var i = 0;
  282. for (; i < attrMaps.length; ++ i) {
  283. stream.readInt32(); //magic "ATTR"
  284. attrMaps[i].name = stream.readString();
  285. var precision = stream.readFloat32();
  286. stream.readInt32(); //packed size
  287. var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4);
  288. LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
  289. CTM.restoreMap(attrMaps[i].attr, 4, precision);
  290. }
  291. };
  292. CTM.restoreIndices = function(indices, len) {
  293. var i = 3;
  294. if (len > 0) {
  295. indices[2] += indices[0];
  296. indices[1] += indices[0];
  297. }
  298. for (; i < len; i += 3) {
  299. indices[i] += indices[i - 3];
  300. if (indices[i] === indices[i - 3]) {
  301. indices[i + 1] += indices[i - 2];
  302. }else {
  303. indices[i + 1] += indices[i];
  304. }
  305. indices[i + 2] += indices[i];
  306. }
  307. };
  308. CTM.restoreGridIndices = function(gridIndices, len) {
  309. var i = 1;
  310. for (; i < len; ++ i) {
  311. gridIndices[i] += gridIndices[i - 1];
  312. }
  313. };
  314. CTM.restoreVertices = function(vertices, grid, gridIndices, precision) {
  315. var gridIdx, delta, x, y, z,
  316. intVertices = new Uint32Array(vertices.buffer, vertices.byteOffset, vertices.length),
  317. ydiv = grid.divx, zdiv = ydiv * grid.divy,
  318. prevGridIdx = 0x7fffffff, prevDelta = 0,
  319. i = 0, j = 0, len = gridIndices.length;
  320. for (; i < len; j += 3) {
  321. x = gridIdx = gridIndices[i ++];
  322. z = ~~(x / zdiv);
  323. x -= ~~(z * zdiv);
  324. y = ~~(x / ydiv);
  325. x -= ~~(y * ydiv);
  326. delta = intVertices[j];
  327. if (gridIdx === prevGridIdx) {
  328. delta += prevDelta;
  329. }
  330. vertices[j] = grid.lowerBoundx +
  331. x * grid.sizex + precision * delta;
  332. vertices[j + 1] = grid.lowerBoundy +
  333. y * grid.sizey + precision * intVertices[j + 1];
  334. vertices[j + 2] = grid.lowerBoundz +
  335. z * grid.sizez + precision * intVertices[j + 2];
  336. prevGridIdx = gridIdx;
  337. prevDelta = delta;
  338. }
  339. };
  340. CTM.restoreNormals = function(normals, smooth, precision) {
  341. var ro, phi, theta, sinPhi,
  342. nx, ny, nz, by, bz, len,
  343. intNormals = new Uint32Array(normals.buffer, normals.byteOffset, normals.length),
  344. i = 0, k = normals.length,
  345. PI_DIV_2 = 3.141592653589793238462643 * 0.5;
  346. for (; i < k; i += 3) {
  347. ro = intNormals[i] * precision;
  348. phi = intNormals[i + 1];
  349. if (phi === 0) {
  350. normals[i] = smooth[i] * ro;
  351. normals[i + 1] = smooth[i + 1] * ro;
  352. normals[i + 2] = smooth[i + 2] * ro;
  353. }else {
  354. if (phi <= 4) {
  355. theta = (intNormals[i + 2] - 2) * PI_DIV_2;
  356. }else {
  357. theta = ( (intNormals[i + 2] * 4 / phi) - 2) * PI_DIV_2;
  358. }
  359. phi *= precision * PI_DIV_2;
  360. sinPhi = ro * Math.sin(phi);
  361. nx = sinPhi * Math.cos(theta);
  362. ny = sinPhi * Math.sin(theta);
  363. nz = ro * Math.cos(phi);
  364. bz = smooth[i + 1];
  365. by = smooth[i] - smooth[i + 2];
  366. len = Math.sqrt(2 * bz * bz + by * by);
  367. if (len > 1e-20) {
  368. by /= len;
  369. bz /= len;
  370. }
  371. normals[i] = smooth[i] * nz +
  372. (smooth[i + 1] * bz - smooth[i + 2] * by) * ny - bz * nx;
  373. normals[i + 1] = smooth[i + 1] * nz -
  374. (smooth[i + 2] + smooth[i] ) * bz * ny + by * nx;
  375. normals[i + 2] = smooth[i + 2] * nz +
  376. (smooth[i] * by + smooth[i + 1] * bz) * ny + bz * nx;
  377. }
  378. }
  379. };
  380. CTM.restoreMap = function(map, count, precision) {
  381. var delta, value,
  382. intMap = new Uint32Array(map.buffer, map.byteOffset, map.length),
  383. i = 0, j, len = map.length;
  384. for (; i < count; ++ i) {
  385. delta = 0;
  386. for (j = i; j < len; j += count) {
  387. value = intMap[j];
  388. delta += value & 1 ? -( (value + 1) >> 1) : value >> 1;
  389. map[j] = delta * precision;
  390. }
  391. }
  392. };
  393. CTM.calcSmoothNormals = function(indices, vertices) {
  394. var smooth = new Float32Array(vertices.length),
  395. indx, indy, indz, nx, ny, nz,
  396. v1x, v1y, v1z, v2x, v2y, v2z, len,
  397. i, k;
  398. for (i = 0, k = indices.length; i < k;) {
  399. indx = indices[i ++] * 3;
  400. indy = indices[i ++] * 3;
  401. indz = indices[i ++] * 3;
  402. v1x = vertices[indy] - vertices[indx];
  403. v2x = vertices[indz] - vertices[indx];
  404. v1y = vertices[indy + 1] - vertices[indx + 1];
  405. v2y = vertices[indz + 1] - vertices[indx + 1];
  406. v1z = vertices[indy + 2] - vertices[indx + 2];
  407. v2z = vertices[indz + 2] - vertices[indx + 2];
  408. nx = v1y * v2z - v1z * v2y;
  409. ny = v1z * v2x - v1x * v2z;
  410. nz = v1x * v2y - v1y * v2x;
  411. len = Math.sqrt(nx * nx + ny * ny + nz * nz);
  412. if (len > 1e-10) {
  413. nx /= len;
  414. ny /= len;
  415. nz /= len;
  416. }
  417. smooth[indx] += nx;
  418. smooth[indx + 1] += ny;
  419. smooth[indx + 2] += nz;
  420. smooth[indy] += nx;
  421. smooth[indy + 1] += ny;
  422. smooth[indy + 2] += nz;
  423. smooth[indz] += nx;
  424. smooth[indz + 1] += ny;
  425. smooth[indz + 2] += nz;
  426. }
  427. for (i = 0, k = smooth.length; i < k; i += 3) {
  428. len = Math.sqrt(smooth[i] * smooth[i] +
  429. smooth[i + 1] * smooth[i + 1] +
  430. smooth[i + 2] * smooth[i + 2]);
  431. if (len > 1e-10) {
  432. smooth[i] /= len;
  433. smooth[i + 1] /= len;
  434. smooth[i + 2] /= len;
  435. }
  436. }
  437. return smooth;
  438. };
  439. CTM.isLittleEndian = (function() {
  440. var buffer = new ArrayBuffer(2),
  441. bytes = new Uint8Array(buffer),
  442. ints = new Uint16Array(buffer);
  443. bytes[0] = 1;
  444. return ints[0] === 1;
  445. }());
  446. CTM.InterleavedStream = function(data, count) {
  447. this.data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
  448. this.offset = CTM.isLittleEndian ? 3 : 0;
  449. this.count = count * 4;
  450. this.len = this.data.length;
  451. };
  452. CTM.InterleavedStream.prototype.writeByte = function(value) {
  453. this.data[this.offset] = value;
  454. this.offset += this.count;
  455. if (this.offset >= this.len) {
  456. this.offset -= this.len - 4;
  457. if (this.offset >= this.count) {
  458. this.offset -= this.count + (CTM.isLittleEndian ? 1 : -1);
  459. }
  460. }
  461. };
  462. CTM.Stream = function(data) {
  463. this.data = data;
  464. this.offset = 0;
  465. };
  466. CTM.Stream.prototype.TWO_POW_MINUS23 = Math.pow(2, -23);
  467. CTM.Stream.prototype.TWO_POW_MINUS126 = Math.pow(2, -126);
  468. CTM.Stream.prototype.readByte = function() {
  469. return this.data[this.offset ++] & 0xff;
  470. };
  471. CTM.Stream.prototype.readInt32 = function() {
  472. var i = this.readByte();
  473. i |= this.readByte() << 8;
  474. i |= this.readByte() << 16;
  475. return i | (this.readByte() << 24);
  476. };
  477. CTM.Stream.prototype.readFloat32 = function() {
  478. var m = this.readByte();
  479. m += this.readByte() << 8;
  480. var b1 = this.readByte();
  481. var b2 = this.readByte();
  482. m += (b1 & 0x7f) << 16;
  483. var e = ( (b2 & 0x7f) << 1) | ( (b1 & 0x80) >>> 7);
  484. var s = b2 & 0x80 ? -1 : 1;
  485. if (e === 255) {
  486. return m !== 0 ? NaN : s * Infinity;
  487. }
  488. if (e > 0) {
  489. return s * (1 + (m * this.TWO_POW_MINUS23) ) * Math.pow(2, e - 127);
  490. }
  491. if (m !== 0) {
  492. return s * m * this.TWO_POW_MINUS126;
  493. }
  494. return s * 0;
  495. };
  496. CTM.Stream.prototype.readString = function() {
  497. var len = this.readInt32();
  498. this.offset += len;
  499. return String.fromCharCode.apply(null, this.data.subarray(this.offset - len, this.offset));
  500. };
  501. CTM.Stream.prototype.readArrayInt32 = function(array) {
  502. var i = 0, len = array.length;
  503. while (i < len) {
  504. array[i ++] = this.readInt32();
  505. }
  506. return array;
  507. };
  508. CTM.Stream.prototype.readArrayFloat32 = function(array) {
  509. var i = 0, len = array.length;
  510. while (i < len) {
  511. array[i ++] = this.readFloat32();
  512. }
  513. return array;
  514. };