diff --git a/project_directory/db.sqlite3 b/project_directory/db.sqlite3
index 517581f..dd65a57 100644
Binary files a/project_directory/db.sqlite3 and b/project_directory/db.sqlite3 differ
diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/bunny.ctm b/project_directory/three_d_viewer/templates/three_d_viewer/bunny.ctm
new file mode 100644
index 0000000..be2b5ce
Binary files /dev/null and b/project_directory/three_d_viewer/templates/three_d_viewer/bunny.ctm differ
diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/ctm.js b/project_directory/three_d_viewer/templates/three_d_viewer/ctm.js
new file mode 100755
index 0000000..9ca085d
--- /dev/null
+++ b/project_directory/three_d_viewer/templates/three_d_viewer/ctm.js
@@ -0,0 +1,626 @@
+
+var CTM = CTM || {};
+
+CTM.CompressionMethod = {
+ RAW: 0x00574152,
+ MG1: 0x0031474d,
+ MG2: 0x0032474d
+};
+
+CTM.Flags = {
+ NORMALS: 0x00000001
+};
+
+CTM.File = function(stream){
+ this.load(stream);
+};
+
+CTM.File.prototype.load = function(stream){
+ this.header = new CTM.FileHeader(stream);
+
+ this.body = new CTM.FileBody(this.header);
+
+ this.getReader().read(stream, this.body);
+};
+
+CTM.File.prototype.getReader = function(){
+ var reader;
+
+ switch(this.header.compressionMethod){
+ case CTM.CompressionMethod.RAW:
+ reader = new CTM.ReaderRAW();
+ break;
+ case CTM.CompressionMethod.MG1:
+ reader = new CTM.ReaderMG1();
+ break;
+ case CTM.CompressionMethod.MG2:
+ reader = new CTM.ReaderMG2();
+ break;
+ }
+
+ return reader;
+};
+
+CTM.FileHeader = function(stream){
+ stream.readInt32(); //magic "OCTM"
+ this.fileFormat = stream.readInt32();
+ this.compressionMethod = stream.readInt32();
+ this.vertexCount = stream.readInt32();
+ this.triangleCount = stream.readInt32();
+ this.uvMapCount = stream.readInt32();
+ this.attrMapCount = stream.readInt32();
+ this.flags = stream.readInt32();
+ this.comment = stream.readString();
+};
+
+CTM.FileHeader.prototype.hasNormals = function(){
+ return this.flags & CTM.Flags.NORMALS;
+};
+
+CTM.FileBody = function(header){
+ var i = header.triangleCount * 3,
+ v = header.vertexCount * 3,
+ n = header.hasNormals()? header.vertexCount * 3: 0,
+ u = header.vertexCount * 2,
+ a = header.vertexCount * 4,
+ j = 0;
+
+ var data = new ArrayBuffer(
+ (i + v + n + (u * header.uvMapCount) + (a * header.attrMapCount) ) * 4);
+
+ this.indices = new Uint32Array(data, 0, i);
+
+ this.vertices = new Float32Array(data, i * 4, v);
+
+ if ( header.hasNormals() ){
+ this.normals = new Float32Array(data, (i + v) * 4, n);
+ }
+
+ if (header.uvMapCount){
+ this.uvMaps = [];
+ for (j = 0; j < header.uvMapCount; ++ j){
+ this.uvMaps[j] = {uv: new Float32Array(data,
+ (i + v + n + (j * u) ) * 4, u) };
+ }
+ }
+
+ if (header.attrMapCount){
+ this.attrMaps = [];
+ for (j = 0; j < header.attrMapCount; ++ j){
+ this.attrMaps[j] = {attr: new Float32Array(data,
+ (i + v + n + (u * header.uvMapCount) + (j * a) ) * 4, a) };
+ }
+ }
+};
+
+CTM.FileMG2Header = function(stream){
+ stream.readInt32(); //magic "MG2H"
+ this.vertexPrecision = stream.readFloat32();
+ this.normalPrecision = stream.readFloat32();
+ this.lowerBoundx = stream.readFloat32();
+ this.lowerBoundy = stream.readFloat32();
+ this.lowerBoundz = stream.readFloat32();
+ this.higherBoundx = stream.readFloat32();
+ this.higherBoundy = stream.readFloat32();
+ this.higherBoundz = stream.readFloat32();
+ this.divx = stream.readInt32();
+ this.divy = stream.readInt32();
+ this.divz = stream.readInt32();
+
+ this.sizex = (this.higherBoundx - this.lowerBoundx) / this.divx;
+ this.sizey = (this.higherBoundy - this.lowerBoundy) / this.divy;
+ this.sizez = (this.higherBoundz - this.lowerBoundz) / this.divz;
+};
+
+CTM.ReaderRAW = function(){
+};
+
+CTM.ReaderRAW.prototype.read = function(stream, body){
+ this.readIndices(stream, body.indices);
+ this.readVertices(stream, body.vertices);
+
+ if (body.normals){
+ this.readNormals(stream, body.normals);
+ }
+ if (body.uvMaps){
+ this.readUVMaps(stream, body.uvMaps);
+ }
+ if (body.attrMaps){
+ this.readAttrMaps(stream, body.attrMaps);
+ }
+};
+
+CTM.ReaderRAW.prototype.readIndices = function(stream, indices){
+ stream.readInt32(); //magic "INDX"
+ stream.readArrayInt32(indices);
+};
+
+CTM.ReaderRAW.prototype.readVertices = function(stream, vertices){
+ stream.readInt32(); //magic "VERT"
+ stream.readArrayFloat32(vertices);
+};
+
+CTM.ReaderRAW.prototype.readNormals = function(stream, normals){
+ stream.readInt32(); //magic "NORM"
+ stream.readArrayFloat32(normals);
+};
+
+CTM.ReaderRAW.prototype.readUVMaps = function(stream, uvMaps){
+ var i = 0;
+ for (; i < uvMaps.length; ++ i){
+ stream.readInt32(); //magic "TEXC"
+
+ uvMaps[i].name = stream.readString();
+ uvMaps[i].filename = stream.readString();
+ stream.readArrayFloat32(uvMaps[i].uv);
+ }
+};
+
+CTM.ReaderRAW.prototype.readAttrMaps = function(stream, attrMaps){
+ var i = 0;
+ for (; i < attrMaps.length; ++ i){
+ stream.readInt32(); //magic "ATTR"
+
+ attrMaps[i].name = stream.readString();
+ stream.readArrayFloat32(attrMaps[i].attr);
+ }
+};
+
+CTM.ReaderMG1 = function(){
+};
+
+CTM.ReaderMG1.prototype.read = function(stream, body){
+ this.readIndices(stream, body.indices);
+ this.readVertices(stream, body.vertices);
+
+ if (body.normals){
+ this.readNormals(stream, body.normals);
+ }
+ if (body.uvMaps){
+ this.readUVMaps(stream, body.uvMaps);
+ }
+ if (body.attrMaps){
+ this.readAttrMaps(stream, body.attrMaps);
+ }
+};
+
+CTM.ReaderMG1.prototype.readIndices = function(stream, indices){
+ stream.readInt32(); //magic "INDX"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(indices, 3);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ CTM.restoreIndices(indices, indices.length);
+};
+
+CTM.ReaderMG1.prototype.readVertices = function(stream, vertices){
+ stream.readInt32(); //magic "VERT"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(vertices, 1);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+};
+
+CTM.ReaderMG1.prototype.readNormals = function(stream, normals){
+ stream.readInt32(); //magic "NORM"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(normals, 3);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+};
+
+CTM.ReaderMG1.prototype.readUVMaps = function(stream, uvMaps){
+ var i = 0;
+ for (; i < uvMaps.length; ++ i){
+ stream.readInt32(); //magic "TEXC"
+
+ uvMaps[i].name = stream.readString();
+ uvMaps[i].filename = stream.readString();
+
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+ }
+};
+
+CTM.ReaderMG1.prototype.readAttrMaps = function(stream, attrMaps){
+ var i = 0;
+ for (; i < attrMaps.length; ++ i){
+ stream.readInt32(); //magic "ATTR"
+
+ attrMaps[i].name = stream.readString();
+
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+ }
+};
+
+CTM.ReaderMG2 = function(){
+};
+
+CTM.ReaderMG2.prototype.read = function(stream, body){
+ this.MG2Header = new CTM.FileMG2Header(stream);
+
+ this.readVertices(stream, body.vertices);
+ this.readIndices(stream, body.indices);
+
+ if (body.normals){
+ this.readNormals(stream, body);
+ }
+ if (body.uvMaps){
+ this.readUVMaps(stream, body.uvMaps);
+ }
+ if (body.attrMaps){
+ this.readAttrMaps(stream, body.attrMaps);
+ }
+};
+
+CTM.ReaderMG2.prototype.readVertices = function(stream, vertices){
+ stream.readInt32(); //magic "VERT"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(vertices, 3);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ var gridIndices = this.readGridIndices(stream, vertices);
+
+ CTM.restoreVertices(vertices, this.MG2Header, gridIndices, this.MG2Header.vertexPrecision);
+};
+
+CTM.ReaderMG2.prototype.readGridIndices = function(stream, vertices){
+ stream.readInt32(); //magic "GIDX"
+ stream.readInt32(); //packed size
+
+ var gridIndices = new Uint32Array(vertices.length / 3);
+
+ var interleaved = new CTM.InterleavedStream(gridIndices, 1);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ CTM.restoreGridIndices(gridIndices, gridIndices.length);
+
+ return gridIndices;
+};
+
+CTM.ReaderMG2.prototype.readIndices = function(stream, indices){
+ stream.readInt32(); //magic "INDX"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(indices, 3);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ CTM.restoreIndices(indices, indices.length);
+};
+
+CTM.ReaderMG2.prototype.readNormals = function(stream, body){
+ stream.readInt32(); //magic "NORM"
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(body.normals, 3);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ var smooth = CTM.calcSmoothNormals(body.indices, body.vertices);
+
+ CTM.restoreNormals(body.normals, smooth, this.MG2Header.normalPrecision);
+};
+
+CTM.ReaderMG2.prototype.readUVMaps = function(stream, uvMaps){
+ var i = 0;
+ for (; i < uvMaps.length; ++ i){
+ stream.readInt32(); //magic "TEXC"
+
+ uvMaps[i].name = stream.readString();
+ uvMaps[i].filename = stream.readString();
+
+ var precision = stream.readFloat32();
+
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ CTM.restoreMap(uvMaps[i].uv, 2, precision);
+ }
+};
+
+CTM.ReaderMG2.prototype.readAttrMaps = function(stream, attrMaps){
+ var i = 0;
+ for (; i < attrMaps.length; ++ i){
+ stream.readInt32(); //magic "ATTR"
+
+ attrMaps[i].name = stream.readString();
+
+ var precision = stream.readFloat32();
+
+ stream.readInt32(); //packed size
+
+ var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4);
+ LZMA.decompress(stream, stream, interleaved, interleaved.data.length);
+
+ CTM.restoreMap(attrMaps[i].attr, 4, precision);
+ }
+};
+
+CTM.restoreIndices = function(indices, len){
+ var i = 3;
+ if (len > 0){
+ indices[2] += indices[0];
+ }
+ for (; i < len; i += 3){
+ indices[i] += indices[i - 3];
+
+ if (indices[i] === indices[i - 3]){
+ indices[i + 1] += indices[i - 2];
+ }else{
+ indices[i + 1] += indices[i];
+ }
+
+ indices[i + 2] += indices[i];
+ }
+};
+
+CTM.restoreGridIndices = function(gridIndices, len){
+ var i = 1;
+ for (; i < len; ++ i){
+ gridIndices[i] += gridIndices[i - 1];
+ }
+};
+
+CTM.restoreVertices = function(vertices, grid, gridIndices, precision){
+ var gridIdx, delta, x, y, z,
+ intVertices = new Uint32Array(vertices.buffer, vertices.byteOffset, vertices.length),
+ ydiv = grid.divx, zdiv = ydiv * grid.divy,
+ prevGridIdx = 0x7fffffff, prevDelta = 0,
+ i = 0, j = 0, len = gridIndices.length;
+
+ for (; i < len; j += 3){
+ x = gridIdx = gridIndices[i ++];
+
+ z = ~~(x / zdiv);
+ x -= ~~(z * zdiv);
+ y = ~~(x / ydiv);
+ x -= ~~(y * ydiv);
+
+ delta = intVertices[j];
+ if (gridIdx === prevGridIdx){
+ delta += prevDelta;
+ }
+
+ vertices[j] = grid.lowerBoundx +
+ x * grid.sizex + precision * delta;
+ vertices[j + 1] = grid.lowerBoundy +
+ y * grid.sizey + precision * intVertices[j + 1];
+ vertices[j + 2] = grid.lowerBoundz +
+ z * grid.sizez + precision * intVertices[j + 2];
+
+ prevGridIdx = gridIdx;
+ prevDelta = delta;
+ }
+};
+
+CTM.restoreNormals = function(normals, smooth, precision){
+ var ro, phi, theta, sinPhi,
+ nx, ny, nz, by, bz, len,
+ intNormals = new Uint32Array(normals.buffer, normals.byteOffset, normals.length),
+ i = 0, k = normals.length,
+ PI_DIV_2 = 3.141592653589793238462643 * 0.5;
+
+ for (; i < k; i += 3){
+ ro = intNormals[i] * precision;
+ phi = intNormals[i + 1];
+
+ if (phi === 0){
+ normals[i] = smooth[i] * ro;
+ normals[i + 1] = smooth[i + 1] * ro;
+ normals[i + 2] = smooth[i + 2] * ro;
+ }else{
+
+ if (phi <= 4){
+ theta = (intNormals[i + 2] - 2) * PI_DIV_2;
+ }else{
+ theta = ( (intNormals[i + 2] * 4 / phi) - 2) * PI_DIV_2;
+ }
+
+ phi *= precision * PI_DIV_2;
+ sinPhi = ro * Math.sin(phi);
+
+ nx = sinPhi * Math.cos(theta);
+ ny = sinPhi * Math.sin(theta);
+ nz = ro * Math.cos(phi);
+
+ bz = smooth[i + 1];
+ by = smooth[i] - smooth[i + 2];
+
+ len = Math.sqrt(2 * bz * bz + by * by);
+ if (len > 1e-20){
+ by /= len;
+ bz /= len;
+ }
+
+ normals[i] = smooth[i] * nz +
+ (smooth[i + 1] * bz - smooth[i + 2] * by) * ny - bz * nx;
+ normals[i + 1] = smooth[i + 1] * nz -
+ (smooth[i + 2] + smooth[i] ) * bz * ny + by * nx;
+ normals[i + 2] = smooth[i + 2] * nz +
+ (smooth[i] * by + smooth[i + 1] * bz) * ny + bz * nx;
+ }
+ }
+};
+
+CTM.restoreMap = function(map, count, precision){
+ var delta, value,
+ intMap = new Uint32Array(map.buffer, map.byteOffset, map.length),
+ i = 0, j, len = map.length;
+
+ for (; i < count; ++ i){
+ delta = 0;
+
+ for (j = i; j < len; j += count){
+ value = intMap[j];
+
+ delta += value & 1? -( (value + 1) >> 1): value >> 1;
+
+ map[j] = delta * precision;
+ }
+ }
+};
+
+CTM.calcSmoothNormals = function(indices, vertices){
+ var smooth = new Float32Array(vertices.length),
+ indx, indy, indz, nx, ny, nz,
+ v1x, v1y, v1z, v2x, v2y, v2z, len,
+ i, k;
+
+ for (i = 0, k = indices.length; i < k;){
+ indx = indices[i ++] * 3;
+ indy = indices[i ++] * 3;
+ indz = indices[i ++] * 3;
+
+ v1x = vertices[indy] - vertices[indx];
+ v2x = vertices[indz] - vertices[indx];
+ v1y = vertices[indy + 1] - vertices[indx + 1];
+ v2y = vertices[indz + 1] - vertices[indx + 1];
+ v1z = vertices[indy + 2] - vertices[indx + 2];
+ v2z = vertices[indz + 2] - vertices[indx + 2];
+
+ nx = v1y * v2z - v1z * v2y;
+ ny = v1z * v2x - v1x * v2z;
+ nz = v1x * v2y - v1y * v2x;
+
+ len = Math.sqrt(nx * nx + ny * ny + nz * nz);
+ if (len > 1e-10){
+ nx /= len;
+ ny /= len;
+ nz /= len;
+ }
+
+ smooth[indx] += nx;
+ smooth[indx + 1] += ny;
+ smooth[indx + 2] += nz;
+ smooth[indy] += nx;
+ smooth[indy + 1] += ny;
+ smooth[indy + 2] += nz;
+ smooth[indz] += nx;
+ smooth[indz + 1] += ny;
+ smooth[indz + 2] += nz;
+ }
+
+ for (i = 0, k = smooth.length; i < k; i += 3){
+ len = Math.sqrt(smooth[i] * smooth[i] +
+ smooth[i + 1] * smooth[i + 1] +
+ smooth[i + 2] * smooth[i + 2]);
+
+ if(len > 1e-10){
+ smooth[i] /= len;
+ smooth[i + 1] /= len;
+ smooth[i + 2] /= len;
+ }
+ }
+
+ return smooth;
+};
+
+CTM.isLittleEndian = (function(){
+ var buffer = new ArrayBuffer(2),
+ bytes = new Uint8Array(buffer),
+ ints = new Uint16Array(buffer);
+
+ bytes[0] = 1;
+
+ return ints[0] === 1;
+}());
+
+CTM.InterleavedStream = function(data, count){
+ this.data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
+ this.offset = CTM.isLittleEndian? 3: 0;
+ this.count = count * 4;
+ this.len = this.data.length;
+};
+
+CTM.InterleavedStream.prototype.writeByte = function(value){
+ this.data[this.offset] = value;
+
+ this.offset += this.count;
+ if (this.offset >= this.len){
+
+ this.offset -= this.len - 4;
+ if (this.offset >= this.count){
+
+ this.offset -= this.count + (CTM.isLittleEndian? 1: -1);
+ }
+ }
+};
+
+CTM.Stream = function(data){
+ this.data = data;
+ this.offset = 0;
+};
+
+CTM.Stream.prototype.TWO_POW_MINUS23 = Math.pow(2, -23);
+
+CTM.Stream.prototype.TWO_POW_MINUS126 = Math.pow(2, -126);
+
+CTM.Stream.prototype.readByte = function(){
+ return this.data.charCodeAt(this.offset ++) & 0xff;
+};
+
+CTM.Stream.prototype.readInt32 = function(){
+ var i = this.readByte();
+ i |= this.readByte() << 8;
+ i |= this.readByte() << 16;
+ return i | (this.readByte() << 24);
+};
+
+CTM.Stream.prototype.readFloat32 = function(){
+ var m = this.readByte();
+ m += this.readByte() << 8;
+
+ var b1 = this.readByte();
+ var b2 = this.readByte();
+
+ m += (b1 & 0x7f) << 16;
+ var e = ( (b2 & 0x7f) << 1) | ( (b1 & 0x80) >>> 7);
+ var s = b2 & 0x80? -1: 1;
+
+ if (e === 255){
+ return m !== 0? NaN: s * Infinity;
+ }
+ if (e > 0){
+ return s * (1 + (m * this.TWO_POW_MINUS23) ) * Math.pow(2, e - 127);
+ }
+ if (m !== 0){
+ return s * m * this.TWO_POW_MINUS126;
+ }
+ return s * 0;
+};
+
+CTM.Stream.prototype.readString = function(){
+ var len = this.readInt32();
+
+ this.offset += len;
+
+ return this.data.substr(this.offset - len, len);
+};
+
+CTM.Stream.prototype.readArrayInt32 = function(array){
+ var i = 0, len = array.length;
+
+ while(i < len){
+ array[i ++] = this.readInt32();
+ }
+
+ return array;
+};
+
+CTM.Stream.prototype.readArrayFloat32 = function(array){
+ var i = 0, len = array.length;
+
+ while(i < len){
+ array[i ++] = this.readFloat32();
+ }
+
+ return array;
+};
diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/detail.html b/project_directory/three_d_viewer/templates/three_d_viewer/detail.html
index 12002b5..8fccf43 100644
--- a/project_directory/three_d_viewer/templates/three_d_viewer/detail.html
+++ b/project_directory/three_d_viewer/templates/three_d_viewer/detail.html
@@ -1 +1,369 @@
-
{{ sample.name }}
\ No newline at end of file
+#{{ sample.name }}
+
+
+
+
+js-openctm - Demo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
male02.ctm - 842,718 vertices - 1,685,024 triangles - 6.00 MB - No texture
+Unpacked using
js-openctm - Rendered using WebGL
+3D model courtesy of
Cyberware
+
+
+
+
\ No newline at end of file
diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/glMatrix-0.9.5.min.js b/project_directory/three_d_viewer/templates/three_d_viewer/glMatrix-0.9.5.min.js
new file mode 100755
index 0000000..e10c7bf
--- /dev/null
+++ b/project_directory/three_d_viewer/templates/three_d_viewer/glMatrix-0.9.5.min.js
@@ -0,0 +1,32 @@
+// glMatrix v0.9.5
+glMatrixArrayType=typeof Float32Array!="undefined"?Float32Array:typeof WebGLFloatArray!="undefined"?WebGLFloatArray:Array;var vec3={};vec3.create=function(a){var b=new glMatrixArrayType(3);if(a){b[0]=a[0];b[1]=a[1];b[2]=a[2]}return b};vec3.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];return b};vec3.add=function(a,b,c){if(!c||a==c){a[0]+=b[0];a[1]+=b[1];a[2]+=b[2];return a}c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];return c};
+vec3.subtract=function(a,b,c){if(!c||a==c){a[0]-=b[0];a[1]-=b[1];a[2]-=b[2];return a}c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];return c};vec3.negate=function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];return b};vec3.scale=function(a,b,c){if(!c||a==c){a[0]*=b;a[1]*=b;a[2]*=b;return a}c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;return c};
+vec3.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=Math.sqrt(c*c+d*d+e*e);if(g){if(g==1){b[0]=c;b[1]=d;b[2]=e;return b}}else{b[0]=0;b[1]=0;b[2]=0;return b}g=1/g;b[0]=c*g;b[1]=d*g;b[2]=e*g;return b};vec3.cross=function(a,b,c){c||(c=a);var d=a[0],e=a[1];a=a[2];var g=b[0],f=b[1];b=b[2];c[0]=e*b-a*f;c[1]=a*g-d*b;c[2]=d*f-e*g;return c};vec3.length=function(a){var b=a[0],c=a[1];a=a[2];return Math.sqrt(b*b+c*c+a*a)};vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]};
+vec3.direction=function(a,b,c){c||(c=a);var d=a[0]-b[0],e=a[1]-b[1];a=a[2]-b[2];b=Math.sqrt(d*d+e*e+a*a);if(!b){c[0]=0;c[1]=0;c[2]=0;return c}b=1/b;c[0]=d*b;c[1]=e*b;c[2]=a*b;return c};vec3.lerp=function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);return d};vec3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var mat3={};
+mat3.create=function(a){var b=new glMatrixArrayType(9);if(a){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9]}return b};mat3.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];return b};mat3.identity=function(a){a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a};
+mat3.transpose=function(a,b){if(!b||a==b){var c=a[1],d=a[2],e=a[5];a[1]=a[3];a[2]=a[6];a[3]=c;a[5]=a[7];a[6]=d;a[7]=e;return a}b[0]=a[0];b[1]=a[3];b[2]=a[6];b[3]=a[1];b[4]=a[4];b[5]=a[7];b[6]=a[2];b[7]=a[5];b[8]=a[8];return b};mat3.toMat4=function(a,b){b||(b=mat4.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=0;b[4]=a[3];b[5]=a[4];b[6]=a[5];b[7]=0;b[8]=a[6];b[9]=a[7];b[10]=a[8];b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};
+mat3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+"]"};var mat4={};mat4.create=function(a){var b=new glMatrixArrayType(16);if(a){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15]}return b};
+mat4.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b};mat4.identity=function(a){a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a};
+mat4.transpose=function(a,b){if(!b||a==b){var c=a[1],d=a[2],e=a[3],g=a[6],f=a[7],h=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=c;a[6]=a[9];a[7]=a[13];a[8]=d;a[9]=g;a[11]=a[14];a[12]=e;a[13]=f;a[14]=h;return a}b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b};
+mat4.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],g=a[4],f=a[5],h=a[6],i=a[7],j=a[8],k=a[9],l=a[10],o=a[11],m=a[12],n=a[13],p=a[14];a=a[15];return m*k*h*e-j*n*h*e-m*f*l*e+g*n*l*e+j*f*p*e-g*k*p*e-m*k*d*i+j*n*d*i+m*c*l*i-b*n*l*i-j*c*p*i+b*k*p*i+m*f*d*o-g*n*d*o-m*c*h*o+b*n*h*o+g*c*p*o-b*f*p*o-j*f*d*a+g*k*d*a+j*c*h*a-b*k*h*a-g*c*l*a+b*f*l*a};
+mat4.inverse=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=a[4],h=a[5],i=a[6],j=a[7],k=a[8],l=a[9],o=a[10],m=a[11],n=a[12],p=a[13],r=a[14],s=a[15],A=c*h-d*f,B=c*i-e*f,t=c*j-g*f,u=d*i-e*h,v=d*j-g*h,w=e*j-g*i,x=k*p-l*n,y=k*r-o*n,z=k*s-m*n,C=l*r-o*p,D=l*s-m*p,E=o*s-m*r,q=1/(A*E-B*D+t*C+u*z-v*y+w*x);b[0]=(h*E-i*D+j*C)*q;b[1]=(-d*E+e*D-g*C)*q;b[2]=(p*w-r*v+s*u)*q;b[3]=(-l*w+o*v-m*u)*q;b[4]=(-f*E+i*z-j*y)*q;b[5]=(c*E-e*z+g*y)*q;b[6]=(-n*w+r*t-s*B)*q;b[7]=(k*w-o*t+m*B)*q;b[8]=(f*D-h*z+j*x)*q;
+b[9]=(-c*D+d*z-g*x)*q;b[10]=(n*v-p*t+s*A)*q;b[11]=(-k*v+l*t-m*A)*q;b[12]=(-f*C+h*y-i*x)*q;b[13]=(c*C-d*y+e*x)*q;b[14]=(-n*u+p*B-r*A)*q;b[15]=(k*u-l*B+o*A)*q;return b};mat4.toRotationMat=function(a,b){b||(b=mat4.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};
+mat4.toMat3=function(a,b){b||(b=mat3.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[4];b[4]=a[5];b[5]=a[6];b[6]=a[8];b[7]=a[9];b[8]=a[10];return b};mat4.toInverseMat3=function(a,b){var c=a[0],d=a[1],e=a[2],g=a[4],f=a[5],h=a[6],i=a[8],j=a[9],k=a[10],l=k*f-h*j,o=-k*g+h*i,m=j*g-f*i,n=c*l+d*o+e*m;if(!n)return null;n=1/n;b||(b=mat3.create());b[0]=l*n;b[1]=(-k*d+e*j)*n;b[2]=(h*d-e*f)*n;b[3]=o*n;b[4]=(k*c-e*i)*n;b[5]=(-h*c+e*g)*n;b[6]=m*n;b[7]=(-j*c+d*i)*n;b[8]=(f*c-d*g)*n;return b};
+mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],f=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],o=a[9],m=a[10],n=a[11],p=a[12],r=a[13],s=a[14];a=a[15];var A=b[0],B=b[1],t=b[2],u=b[3],v=b[4],w=b[5],x=b[6],y=b[7],z=b[8],C=b[9],D=b[10],E=b[11],q=b[12],F=b[13],G=b[14];b=b[15];c[0]=A*d+B*h+t*l+u*p;c[1]=A*e+B*i+t*o+u*r;c[2]=A*g+B*j+t*m+u*s;c[3]=A*f+B*k+t*n+u*a;c[4]=v*d+w*h+x*l+y*p;c[5]=v*e+w*i+x*o+y*r;c[6]=v*g+w*j+x*m+y*s;c[7]=v*f+w*k+x*n+y*a;c[8]=z*d+C*h+D*l+E*p;c[9]=z*e+C*i+D*o+E*r;c[10]=z*
+g+C*j+D*m+E*s;c[11]=z*f+C*k+D*n+E*a;c[12]=q*d+F*h+G*l+b*p;c[13]=q*e+F*i+G*o+b*r;c[14]=q*g+F*j+G*m+b*s;c[15]=q*f+F*k+G*n+b*a;return c};mat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1];b=b[2];c[0]=a[0]*d+a[4]*e+a[8]*b+a[12];c[1]=a[1]*d+a[5]*e+a[9]*b+a[13];c[2]=a[2]*d+a[6]*e+a[10]*b+a[14];return c};
+mat4.multiplyVec4=function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2];b=b[3];c[0]=a[0]*d+a[4]*e+a[8]*g+a[12]*b;c[1]=a[1]*d+a[5]*e+a[9]*g+a[13]*b;c[2]=a[2]*d+a[6]*e+a[10]*g+a[14]*b;c[3]=a[3]*d+a[7]*e+a[11]*g+a[15]*b;return c};
+mat4.translate=function(a,b,c){var d=b[0],e=b[1];b=b[2];if(!c||a==c){a[12]=a[0]*d+a[4]*e+a[8]*b+a[12];a[13]=a[1]*d+a[5]*e+a[9]*b+a[13];a[14]=a[2]*d+a[6]*e+a[10]*b+a[14];a[15]=a[3]*d+a[7]*e+a[11]*b+a[15];return a}var g=a[0],f=a[1],h=a[2],i=a[3],j=a[4],k=a[5],l=a[6],o=a[7],m=a[8],n=a[9],p=a[10],r=a[11];c[0]=g;c[1]=f;c[2]=h;c[3]=i;c[4]=j;c[5]=k;c[6]=l;c[7]=o;c[8]=m;c[9]=n;c[10]=p;c[11]=r;c[12]=g*d+j*e+m*b+a[12];c[13]=f*d+k*e+n*b+a[13];c[14]=h*d+l*e+p*b+a[14];c[15]=i*d+o*e+r*b+a[15];return c};
+mat4.scale=function(a,b,c){var d=b[0],e=b[1];b=b[2];if(!c||a==c){a[0]*=d;a[1]*=d;a[2]*=d;a[3]*=d;a[4]*=e;a[5]*=e;a[6]*=e;a[7]*=e;a[8]*=b;a[9]*=b;a[10]*=b;a[11]*=b;return a}c[0]=a[0]*d;c[1]=a[1]*d;c[2]=a[2]*d;c[3]=a[3]*d;c[4]=a[4]*e;c[5]=a[5]*e;c[6]=a[6]*e;c[7]=a[7]*e;c[8]=a[8]*b;c[9]=a[9]*b;c[10]=a[10]*b;c[11]=a[11]*b;c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15];return c};
+mat4.rotate=function(a,b,c,d){var e=c[0],g=c[1];c=c[2];var f=Math.sqrt(e*e+g*g+c*c);if(!f)return null;if(f!=1){f=1/f;e*=f;g*=f;c*=f}var h=Math.sin(b),i=Math.cos(b),j=1-i;b=a[0];f=a[1];var k=a[2],l=a[3],o=a[4],m=a[5],n=a[6],p=a[7],r=a[8],s=a[9],A=a[10],B=a[11],t=e*e*j+i,u=g*e*j+c*h,v=c*e*j-g*h,w=e*g*j-c*h,x=g*g*j+i,y=c*g*j+e*h,z=e*c*j+g*h;e=g*c*j-e*h;g=c*c*j+i;if(d){if(a!=d){d[12]=a[12];d[13]=a[13];d[14]=a[14];d[15]=a[15]}}else d=a;d[0]=b*t+o*u+r*v;d[1]=f*t+m*u+s*v;d[2]=k*t+n*u+A*v;d[3]=l*t+p*u+B*
+v;d[4]=b*w+o*x+r*y;d[5]=f*w+m*x+s*y;d[6]=k*w+n*x+A*y;d[7]=l*w+p*x+B*y;d[8]=b*z+o*e+r*g;d[9]=f*z+m*e+s*g;d[10]=k*z+n*e+A*g;d[11]=l*z+p*e+B*g;return d};mat4.rotateX=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[4],g=a[5],f=a[6],h=a[7],i=a[8],j=a[9],k=a[10],l=a[11];if(c){if(a!=c){c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15]}}else c=a;c[4]=e*b+i*d;c[5]=g*b+j*d;c[6]=f*b+k*d;c[7]=h*b+l*d;c[8]=e*-d+i*b;c[9]=g*-d+j*b;c[10]=f*-d+k*b;c[11]=h*-d+l*b;return c};
+mat4.rotateY=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[0],g=a[1],f=a[2],h=a[3],i=a[8],j=a[9],k=a[10],l=a[11];if(c){if(a!=c){c[4]=a[4];c[5]=a[5];c[6]=a[6];c[7]=a[7];c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15]}}else c=a;c[0]=e*b+i*-d;c[1]=g*b+j*-d;c[2]=f*b+k*-d;c[3]=h*b+l*-d;c[8]=e*d+i*b;c[9]=g*d+j*b;c[10]=f*d+k*b;c[11]=h*d+l*b;return c};
+mat4.rotateZ=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[0],g=a[1],f=a[2],h=a[3],i=a[4],j=a[5],k=a[6],l=a[7];if(c){if(a!=c){c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15]}}else c=a;c[0]=e*b+i*d;c[1]=g*b+j*d;c[2]=f*b+k*d;c[3]=h*b+l*d;c[4]=e*-d+i*b;c[5]=g*-d+j*b;c[6]=f*-d+k*b;c[7]=h*-d+l*b;return c};
+mat4.frustum=function(a,b,c,d,e,g,f){f||(f=mat4.create());var h=b-a,i=d-c,j=g-e;f[0]=e*2/h;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=e*2/i;f[6]=0;f[7]=0;f[8]=(b+a)/h;f[9]=(d+c)/i;f[10]=-(g+e)/j;f[11]=-1;f[12]=0;f[13]=0;f[14]=-(g*e*2)/j;f[15]=0;return f};mat4.perspective=function(a,b,c,d,e){a=c*Math.tan(a*Math.PI/360);b=a*b;return mat4.frustum(-b,b,-a,a,c,d,e)};
+mat4.ortho=function(a,b,c,d,e,g,f){f||(f=mat4.create());var h=b-a,i=d-c,j=g-e;f[0]=2/h;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=2/i;f[6]=0;f[7]=0;f[8]=0;f[9]=0;f[10]=-2/j;f[11]=0;f[12]=-(a+b)/h;f[13]=-(d+c)/i;f[14]=-(g+e)/j;f[15]=1;return f};
+mat4.lookAt=function(a,b,c,d){d||(d=mat4.create());var e=a[0],g=a[1];a=a[2];var f=c[0],h=c[1],i=c[2];c=b[1];var j=b[2];if(e==b[0]&&g==c&&a==j)return mat4.identity(d);var k,l,o,m;c=e-b[0];j=g-b[1];b=a-b[2];m=1/Math.sqrt(c*c+j*j+b*b);c*=m;j*=m;b*=m;k=h*b-i*j;i=i*c-f*b;f=f*j-h*c;if(m=Math.sqrt(k*k+i*i+f*f)){m=1/m;k*=m;i*=m;f*=m}else f=i=k=0;h=j*f-b*i;l=b*k-c*f;o=c*i-j*k;if(m=Math.sqrt(h*h+l*l+o*o)){m=1/m;h*=m;l*=m;o*=m}else o=l=h=0;d[0]=k;d[1]=h;d[2]=c;d[3]=0;d[4]=i;d[5]=l;d[6]=j;d[7]=0;d[8]=f;d[9]=
+o;d[10]=b;d[11]=0;d[12]=-(k*e+i*g+f*a);d[13]=-(h*e+l*g+o*a);d[14]=-(c*e+j*g+b*a);d[15]=1;return d};mat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"};quat4={};quat4.create=function(a){var b=new glMatrixArrayType(4);if(a){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3]}return b};quat4.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b};
+quat4.calculateW=function(a,b){var c=a[0],d=a[1],e=a[2];if(!b||a==b){a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e));return a}b[0]=c;b[1]=d;b[2]=e;b[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e));return b};quat4.inverse=function(a,b){if(!b||a==b){a[0]*=1;a[1]*=1;a[2]*=1;return a}b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=a[3];return b};quat4.length=function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)};
+quat4.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=Math.sqrt(c*c+d*d+e*e+g*g);if(f==0){b[0]=0;b[1]=0;b[2]=0;b[3]=0;return b}f=1/f;b[0]=c*f;b[1]=d*f;b[2]=e*f;b[3]=g*f;return b};quat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2];a=a[3];var f=b[0],h=b[1],i=b[2];b=b[3];c[0]=d*b+a*f+e*i-g*h;c[1]=e*b+a*h+g*f-d*i;c[2]=g*b+a*i+d*h-e*f;c[3]=a*b-d*f-e*h-g*i;return c};
+quat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2];b=a[0];var f=a[1],h=a[2];a=a[3];var i=a*d+f*g-h*e,j=a*e+h*d-b*g,k=a*g+b*e-f*d;d=-b*d-f*e-h*g;c[0]=i*a+d*-b+j*-h-k*-f;c[1]=j*a+d*-f+k*-b-i*-h;c[2]=k*a+d*-h+i*-f-j*-b;return c};quat4.toMat3=function(a,b){b||(b=mat3.create());var c=a[0],d=a[1],e=a[2],g=a[3],f=c+c,h=d+d,i=e+e,j=c*f,k=c*h;c=c*i;var l=d*h;d=d*i;e=e*i;f=g*f;h=g*h;g=g*i;b[0]=1-(l+e);b[1]=k-g;b[2]=c+h;b[3]=k+g;b[4]=1-(j+e);b[5]=d-f;b[6]=c-h;b[7]=d+f;b[8]=1-(j+l);return b};
+quat4.toMat4=function(a,b){b||(b=mat4.create());var c=a[0],d=a[1],e=a[2],g=a[3],f=c+c,h=d+d,i=e+e,j=c*f,k=c*h;c=c*i;var l=d*h;d=d*i;e=e*i;f=g*f;h=g*h;g=g*i;b[0]=1-(l+e);b[1]=k-g;b[2]=c+h;b[3]=0;b[4]=k+g;b[5]=1-(j+e);b[6]=d-f;b[7]=0;b[8]=c-h;b[9]=d+f;b[10]=1-(j+l);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};quat4.slerp=function(a,b,c,d){d||(d=a);var e=c;if(a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]<0)e=-1*c;d[0]=1-c*a[0]+e*b[0];d[1]=1-c*a[1]+e*b[1];d[2]=1-c*a[2]+e*b[2];d[3]=1-c*a[3]+e*b[3];return d};
+quat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};
\ No newline at end of file
diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/lzma.js b/project_directory/three_d_viewer/templates/three_d_viewer/lzma.js
new file mode 100755
index 0000000..a214365
--- /dev/null
+++ b/project_directory/three_d_viewer/templates/three_d_viewer/lzma.js
@@ -0,0 +1,510 @@
+
+var LZMA = LZMA || {};
+
+LZMA.OutWindow = function(){
+ this._windowSize = 0;
+};
+
+LZMA.OutWindow.prototype.create = function(windowSize){
+ if ( (!this._buffer) || (this._windowSize !== windowSize) ){
+ this._buffer = [];
+ }
+ this._windowSize = windowSize;
+ this._pos = 0;
+ this._streamPos = 0;
+};
+
+LZMA.OutWindow.prototype.flush = function(){
+ var size = this._pos - this._streamPos;
+ if (size !== 0){
+ while(size --){
+ this._stream.writeByte(this._buffer[this._streamPos ++]);
+ }
+ if (this._pos >= this._windowSize){
+ this._pos = 0;
+ }
+ this._streamPos = this._pos;
+ }
+};
+
+LZMA.OutWindow.prototype.releaseStream = function(){
+ this.flush();
+ this._stream = null;
+};
+
+LZMA.OutWindow.prototype.setStream = function(stream){
+ this.releaseStream();
+ this._stream = stream;
+};
+
+LZMA.OutWindow.prototype.init = function(solid){
+ if (!solid){
+ this._streamPos = 0;
+ this._pos = 0;
+ }
+};
+
+LZMA.OutWindow.prototype.copyBlock = function(distance, len){
+ var pos = this._pos - distance - 1;
+ if (pos < 0){
+ pos += this._windowSize;
+ }
+ while(len --){
+ if (pos >= this._windowSize){
+ pos = 0;
+ }
+ this._buffer[this._pos ++] = this._buffer[pos ++];
+ if (this._pos >= this._windowSize){
+ this.flush();
+ }
+ }
+};
+
+LZMA.OutWindow.prototype.putByte = function(b){
+ this._buffer[this._pos ++] = b;
+ if (this._pos >= this._windowSize){
+ this.flush();
+ }
+};
+
+LZMA.OutWindow.prototype.getByte = function(distance){
+ var pos = this._pos - distance - 1;
+ if (pos < 0){
+ pos += this._windowSize;
+ }
+ return this._buffer[pos];
+};
+
+LZMA.RangeDecoder = function(){
+};
+
+LZMA.RangeDecoder.prototype.setStream = function(stream){
+ this._stream = stream;
+};
+
+LZMA.RangeDecoder.prototype.releaseStream = function(){
+ this._stream = null;
+};
+
+LZMA.RangeDecoder.prototype.init = function(){
+ var i = 5;
+
+ this._code = 0;
+ this._range = -1;
+
+ while(i --){
+ this._code = (this._code << 8) | this._stream.readByte();
+ }
+};
+
+LZMA.RangeDecoder.prototype.decodeDirectBits = function(numTotalBits){
+ var result = 0, i = numTotalBits, t;
+
+ while(i --){
+ this._range >>>= 1;
+ t = (this._code - this._range) >>> 31;
+ this._code -= this._range & (t - 1);
+ result = (result << 1) | (1 - t);
+
+ if ( (this._range & 0xff000000) === 0){
+ this._code = (this._code << 8) | this._stream.readByte();
+ this._range <<= 8;
+ }
+ }
+
+ return result;
+};
+
+LZMA.RangeDecoder.prototype.decodeBit = function(probs, index){
+ var prob = probs[index],
+ newBound = (this._range >>> 11) * prob;
+
+ if ( (this._code ^ 0x80000000) < (newBound ^ 0x80000000) ){
+ this._range = newBound;
+ probs[index] += (2048 - prob) >>> 5;
+ if ( (this._range & 0xff000000) === 0){
+ this._code = (this._code << 8) | this._stream.readByte();
+ this._range <<= 8;
+ }
+ return 0;
+ }
+
+ this._range -= newBound;
+ this._code -= newBound;
+ probs[index] -= prob >>> 5;
+ if ( (this._range & 0xff000000) === 0){
+ this._code = (this._code << 8) | this._stream.readByte();
+ this._range <<= 8;
+ }
+ return 1;
+};
+
+LZMA.initBitModels = function(probs, len){
+ while(len --){
+ probs[len] = 1024;
+ }
+};
+
+LZMA.BitTreeDecoder = function(numBitLevels){
+ this._models = [];
+ this._numBitLevels = numBitLevels;
+};
+
+LZMA.BitTreeDecoder.prototype.init = function(){
+ LZMA.initBitModels(this._models, 1 << this._numBitLevels);
+};
+
+LZMA.BitTreeDecoder.prototype.decode = function(rangeDecoder){
+ var m = 1, i = this._numBitLevels;
+
+ while(i --){
+ m = (m << 1) | rangeDecoder.decodeBit(this._models, m);
+ }
+ return m - (1 << this._numBitLevels);
+};
+
+LZMA.BitTreeDecoder.prototype.reverseDecode = function(rangeDecoder){
+ var m = 1, symbol = 0, i = 0, bit;
+
+ for (; i < this._numBitLevels; ++ i){
+ bit = rangeDecoder.decodeBit(this._models, m);
+ m = (m << 1) | bit;
+ symbol |= bit << i;
+ }
+ return symbol;
+};
+
+LZMA.reverseDecode2 = function(models, startIndex, rangeDecoder, numBitLevels){
+ var m = 1, symbol = 0, i = 0, bit;
+
+ for (; i < numBitLevels; ++ i){
+ bit = rangeDecoder.decodeBit(models, startIndex + m);
+ m = (m << 1) | bit;
+ symbol |= bit << i;
+ }
+ return symbol;
+};
+
+LZMA.LenDecoder = function(){
+ this._choice = [];
+ this._lowCoder = [];
+ this._midCoder = [];
+ this._highCoder = new LZMA.BitTreeDecoder(8);
+ this._numPosStates = 0;
+};
+
+LZMA.LenDecoder.prototype.create = function(numPosStates){
+ for (; this._numPosStates < numPosStates; ++ this._numPosStates){
+ this._lowCoder[this._numPosStates] = new LZMA.BitTreeDecoder(3);
+ this._midCoder[this._numPosStates] = new LZMA.BitTreeDecoder(3);
+ }
+};
+
+LZMA.LenDecoder.prototype.init = function(){
+ var i = this._numPosStates;
+ LZMA.initBitModels(this._choice, 2);
+ while(i --){
+ this._lowCoder[i].init();
+ this._midCoder[i].init();
+ }
+ this._highCoder.init();
+};
+
+LZMA.LenDecoder.prototype.decode = function(rangeDecoder, posState){
+ if (rangeDecoder.decodeBit(this._choice, 0) === 0){
+ return this._lowCoder[posState].decode(rangeDecoder);
+ }
+ if (rangeDecoder.decodeBit(this._choice, 1) === 0){
+ return 8 + this._midCoder[posState].decode(rangeDecoder);
+ }
+ return 16 + this._highCoder.decode(rangeDecoder);
+};
+
+LZMA.Decoder2 = function(){
+ this._decoders = [];
+};
+
+LZMA.Decoder2.prototype.init = function(){
+ LZMA.initBitModels(this._decoders, 0x300);
+};
+
+LZMA.Decoder2.prototype.decodeNormal = function(rangeDecoder){
+ var symbol = 1;
+
+ do{
+ symbol = (symbol << 1) | rangeDecoder.decodeBit(this._decoders, symbol);
+ }while(symbol < 0x100);
+
+ return symbol & 0xff;
+};
+
+LZMA.Decoder2.prototype.decodeWithMatchByte = function(rangeDecoder, matchByte){
+ var symbol = 1, matchBit, bit;
+
+ do{
+ matchBit = (matchByte >> 7) & 1;
+ matchByte <<= 1;
+ bit = rangeDecoder.decodeBit(this._decoders, ( (1 + matchBit) << 8) + symbol);
+ symbol = (symbol << 1) | bit;
+ if (matchBit !== bit){
+ while(symbol < 0x100){
+ symbol = (symbol << 1) | rangeDecoder.decodeBit(this._decoders, symbol);
+ }
+ break;
+ }
+ }while(symbol < 0x100);
+
+ return symbol & 0xff;
+};
+
+LZMA.LiteralDecoder = function(){
+};
+
+LZMA.LiteralDecoder.prototype.create = function(numPosBits, numPrevBits){
+ var i;
+
+ if (this._coders
+ && (this._numPrevBits === numPrevBits)
+ && (this._numPosBits === numPosBits) ){
+ return;
+ }
+ this._numPosBits = numPosBits;
+ this._posMask = (1 << numPosBits) - 1;
+ this._numPrevBits = numPrevBits;
+
+ this._coders = [];
+
+ i = 1 << (this._numPrevBits + this._numPosBits);
+ while(i --){
+ this._coders[i] = new LZMA.Decoder2();
+ }
+};
+
+LZMA.LiteralDecoder.prototype.init = function(){
+ var i = 1 << (this._numPrevBits + this._numPosBits);
+ while(i --){
+ this._coders[i].init();
+ }
+};
+
+LZMA.LiteralDecoder.prototype.getDecoder = function(pos, prevByte){
+ return this._coders[( (pos & this._posMask) << this._numPrevBits)
+ + ( (prevByte & 0xff) >>> (8 - this._numPrevBits) )];
+};
+
+LZMA.Decoder = function(){
+ this._outWindow = new LZMA.OutWindow();
+ this._rangeDecoder = new LZMA.RangeDecoder();
+ this._isMatchDecoders = [];
+ this._isRepDecoders = [];
+ this._isRepG0Decoders = [];
+ this._isRepG1Decoders = [];
+ this._isRepG2Decoders = [];
+ this._isRep0LongDecoders = [];
+ this._posSlotDecoder = [];
+ this._posDecoders = [];
+ this._posAlignDecoder = new LZMA.BitTreeDecoder(4);
+ this._lenDecoder = new LZMA.LenDecoder();
+ this._repLenDecoder = new LZMA.LenDecoder();
+ this._literalDecoder = new LZMA.LiteralDecoder();
+ this._dictionarySize = -1;
+ this._dictionarySizeCheck = -1;
+
+ this._posSlotDecoder[0] = new LZMA.BitTreeDecoder(6);
+ this._posSlotDecoder[1] = new LZMA.BitTreeDecoder(6);
+ this._posSlotDecoder[2] = new LZMA.BitTreeDecoder(6);
+ this._posSlotDecoder[3] = new LZMA.BitTreeDecoder(6);
+};
+
+LZMA.Decoder.prototype.setDictionarySize = function(dictionarySize){
+ if (dictionarySize < 0){
+ return false;
+ }
+ if (this._dictionarySize !== dictionarySize){
+ this._dictionarySize = dictionarySize;
+ this._dictionarySizeCheck = Math.max(this._dictionarySize, 1);
+ this._outWindow.create( Math.max(this._dictionarySizeCheck, 4096) );
+ }
+ return true;
+};
+
+LZMA.Decoder.prototype.setLcLpPb = function(lc, lp, pb){
+ var numPosStates = 1 << pb;
+
+ if (lc > 8 || lp > 4 || pb > 4){
+ return false;
+ }
+
+ this._literalDecoder.create(lp, lc);
+
+ this._lenDecoder.create(numPosStates);
+ this._repLenDecoder.create(numPosStates);
+ this._posStateMask = numPosStates - 1;
+
+ return true;
+};
+
+LZMA.Decoder.prototype.init = function(){
+ var i = 4;
+
+ this._outWindow.init(false);
+
+ LZMA.initBitModels(this._isMatchDecoders, 192);
+ LZMA.initBitModels(this._isRep0LongDecoders, 192);
+ LZMA.initBitModels(this._isRepDecoders, 12);
+ LZMA.initBitModels(this._isRepG0Decoders, 12);
+ LZMA.initBitModels(this._isRepG1Decoders, 12);
+ LZMA.initBitModels(this._isRepG2Decoders, 12);
+ LZMA.initBitModels(this._posDecoders, 114);
+
+ this._literalDecoder.init();
+
+ while(i --){
+ this._posSlotDecoder[i].init();
+ }
+
+ this._lenDecoder.init();
+ this._repLenDecoder.init();
+ this._posAlignDecoder.init();
+ this._rangeDecoder.init();
+};
+
+LZMA.Decoder.prototype.decode = function(inStream, outStream, outSize){
+ var state = 0, rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0, nowPos64 = 0, prevByte = 0,
+ posState, decoder2, len, distance, posSlot, numDirectBits;
+
+ this._rangeDecoder.setStream(inStream);
+ this._outWindow.setStream(outStream);
+
+ this.init();
+
+ while(outSize < 0 || nowPos64 < outSize){
+ posState = nowPos64 & this._posStateMask;
+
+ if (this._rangeDecoder.decodeBit(this._isMatchDecoders, (state << 4) + posState) === 0){
+ decoder2 = this._literalDecoder.getDecoder(nowPos64 ++, prevByte);
+
+ if (state >= 7){
+ prevByte = decoder2.decodeWithMatchByte(this._rangeDecoder, this._outWindow.getByte(rep0) );
+ }else{
+ prevByte = decoder2.decodeNormal(this._rangeDecoder);
+ }
+ this._outWindow.putByte(prevByte);
+
+ state = state < 4? 0: state - (state < 10? 3: 6);
+
+ }else{
+
+ if (this._rangeDecoder.decodeBit(this._isRepDecoders, state) === 1){
+ len = 0;
+ if (this._rangeDecoder.decodeBit(this._isRepG0Decoders, state) === 0){
+ if (this._rangeDecoder.decodeBit(this._isRep0LongDecoders, (state << 4) + posState) === 0){
+ state = state < 7? 9: 11;
+ len = 1;
+ }
+ }else{
+ if (this._rangeDecoder.decodeBit(this._isRepG1Decoders, state) === 0){
+ distance = rep1;
+ }else{
+ if (this._rangeDecoder.decodeBit(this._isRepG2Decoders, state) === 0){
+ distance = rep2;
+ }else{
+ distance = rep3;
+ rep3 = rep2;
+ }
+ rep2 = rep1;
+ }
+ rep1 = rep0;
+ rep0 = distance;
+ }
+ if (len === 0){
+ len = 2 + this._repLenDecoder.decode(this._rangeDecoder, posState);
+ state = state < 7? 8: 11;
+ }
+ }else{
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+
+ len = 2 + this._lenDecoder.decode(this._rangeDecoder, posState);
+ state = state < 7? 7: 10;
+
+ posSlot = this._posSlotDecoder[len <= 5? len - 2: 3].decode(this._rangeDecoder);
+ if (posSlot >= 4){
+
+ numDirectBits = (posSlot >> 1) - 1;
+ rep0 = (2 | (posSlot & 1) ) << numDirectBits;
+
+ if (posSlot < 14){
+ rep0 += LZMA.reverseDecode2(this._posDecoders,
+ rep0 - posSlot - 1, this._rangeDecoder, numDirectBits);
+ }else{
+ rep0 += this._rangeDecoder.decodeDirectBits(numDirectBits - 4) << 4;
+ rep0 += this._posAlignDecoder.reverseDecode(this._rangeDecoder);
+ if (rep0 < 0){
+ if (rep0 === -1){
+ break;
+ }
+ return false;
+ }
+ }
+ }else{
+ rep0 = posSlot;
+ }
+ }
+
+ if (rep0 >= nowPos64 || rep0 >= this._dictionarySizeCheck){
+ return false;
+ }
+
+ this._outWindow.copyBlock(rep0, len);
+ nowPos64 += len;
+ prevByte = this._outWindow.getByte(0);
+ }
+ }
+
+ this._outWindow.flush();
+ this._outWindow.releaseStream();
+ this._rangeDecoder.releaseStream();
+
+ return true;
+};
+
+LZMA.Decoder.prototype.setDecoderProperties = function(properties){
+ var value, lc, lp, pb, dictionarySize;
+
+ if (properties.size < 5){
+ return false;
+ }
+
+ value = properties.readByte();
+ lc = value % 9;
+ value = ~~(value / 9);
+ lp = value % 5;
+ pb = ~~(value / 5);
+
+ if ( !this.setLcLpPb(lc, lp, pb) ){
+ return false;
+ }
+
+ dictionarySize = properties.readByte();
+ dictionarySize |= properties.readByte() << 8;
+ dictionarySize |= properties.readByte() << 16;
+ dictionarySize += properties.readByte() * 16777216;
+
+ return this.setDictionarySize(dictionarySize);
+};
+
+LZMA.decompress = function(properties, inStream, outStream, outSize){
+ var decoder = new LZMA.Decoder();
+
+ if ( !decoder.setDecoderProperties(properties) ){
+ throw "Incorrect stream properties";
+ }
+
+ if ( !decoder.decode(inStream, outStream, outSize) ){
+ throw "Error in data stream";
+ }
+
+ return true;
+};