-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tautology.min.js
2 lines (2 loc) · 8.53 KB
/
Tautology.min.js
1
2
Tautology={},Array["const"]=function(t,e){return Array.apply(null,new Array(t)).map(function(){return e})},Array.constDeep=function(t,e){return Array.apply(null,new Array(t)).map(function(){return new e})},Array.range=function(t){return Object.keys(Array["const"](t)).map(function(t){return parseInt(t)})},Array.prototype.outer=function(t,e){return this.map(function(i){return t.map(function(t){return e(i,t)})})},Array.mesh=function(t){var e=Array.range(t.reduce(function(t,e){return t*e}));return t.reduce(function(t,e){return t.partition(e)},e)[0]},Array.grid=function(t){return Array.mesh(t).slide(2).map(function(t){return t.transpose().slide(2)}).flatten().map(function(t){return t.flatten()}).map(function(t){return t.slide(3).tail()}).flatten().map(function(t){return t.toFace3()})},Array.prototype.partition=function(t){return Array.range(~~this.length/t).map(function(e){return e*t}).map(function(e){return this.slice(e,e+t)},this)},Array.prototype.flatten=function(){return this.reduce(function(t,e){return t.concat(e)})},Array.prototype.slide=function(t){for(var e=[],i=this.length-t;i>=0;i--)e.push(this.slice(i,i+t));return e.reverse()},Array.prototype.transpose=function(){return Object.keys(this[0]).map(function(t){return this.map(function(e){return e[t]})}.bind(this))},Array.prototype.toFace3=function(){if(3!=this.length)throw new Error("have to be length of 3");return new THREE.Face3(this[0],this[1],this[2])},Array.prototype.tail=function(){var t=this[1];return t.push(t.shift()),[this[0],t.reverse()]},Array.prototype.last=function(){return this[this.length-1]},Array.prototype.accum=function(){return this.reduce(function(t,e){return t.concat(t.last()+e)},[0]).slice(1)},Array.prototype.accumUpdate=function(){for(var t=1;t<this.length;t++)this[t]+=this[t-1]},Array.prototype.constUpdate=function(t){for(var e=0;e<this.length;e++)this[e]=t},Array.prototype.normalize=function(){for(var t=(this[0],this[this.length-1]-this[0]),e=this.length-1;e>=0;e--)this[e]=(this[e]-this[0])/t},THREE.Vector3.prototype.roll=function(t,e){for(var i=0;t>i;i++)this.applyMatrix4(e)},Object.values=function(t){return Object.keys(t).map(function(e){return t[e]})},Tautology.Range=function(t,e){this.range=t,this.set(this.range,e)},Tautology.Range.prototype.constructor=Tautology.Range,Tautology.Range.prototype.set=function(t,e){this.range=t,isNaN(this.range)?Array.isArray(t)?this.range=this.interval(e):"all"==this.range&&(this.range=this.all(e)):this.range=this.single(e)},Tautology.Range.prototype.neg=function(t,e){return t>=0?t:e+t},Tautology.Range.prototype.all=function(t){return Array.range(t)},Tautology.Range.prototype.single=function(t){return[this.neg(this.range,t)]},Tautology.Range.prototype.interval=function(t){var e=this.neg(this.range[0],t),i=this.neg(this.range[1],t),r=this.range[2]?this.range[2]:1;return Array.range(~~(i-e+1)/r).map(function(t){return t*r+e})},Tautology.Region=function(t,e){this.ranges=t.map(function(t,i){return new Tautology.Range(t,e[i])}),this.getTable(e)},Tautology.Region.prototype.constructor=Tautology.Region,Tautology.Region.prototype.getTable=function(t){var e=t.slice().reverse();this.table=this.ranges.reduce(function(t,e){return e.range.outer(t,function(t,e){return e.concat(t)}).flatten()},[[]]).map(function(t){return t.reverse().reduce(function(t,i,r){return t*e[r]+i})})},Tautology.Transform=function(t,e,i){this.labels=t.labels,this.vertices=t.vertices,this.texels=t.texels,this.indices=t.regions[i.region].table,this.param=e.param,this.shape=e.shape,this[i.command](i.callback,i.dimension)},Tautology.Transform.prototype.constructor=Tautology.Transform,Tautology.Transform.prototype.tran=function(t){this.v=new THREE.Vector3,this.settingCallback=t,this.update=function(){this.indices.forEach(function(t){this.settingCallback.call(this),this.vertices[t].add(this.v)}.bind(this))}},Tautology.Transform.prototype.rot=function(t){this.r=new THREE.Quaternion,this.settingCallback=t,this.update=function(){this.indices.forEach(function(t){this.settingCallback.call(this),this.vertices[t].applyQuaternion(this.r)}.bind(this))}},Tautology.Transform.prototype.radiate=function(t,e){this.v=new THREE.Vector3,this.axis=new THREE.Vector3,this.dim=e,this.settingCallback=t,this.update=function(){this.settingCallback.call(this);var t=this.labels,e=this.shape,i=this.dim;this.indices.forEach(function(r){this.vertices[r].add(this.v),this.vertices[r].applyAxisAngle(this.axis,2*Math.PI*t[r][i]/(e[i]-1))}.bind(this))}},Tautology.Transform.prototype.bend=function(t,e){this.bendAxis=new THREE.Vector3,this.feed=new THREE.Vector3,this.matrices=Array.constDeep(this.shape[e],THREE.Matrix4),this.settingCallback=t,this.dim=e,this.update=function(){this.settingCallback.call(this);for(var t=this.labels,e=this.dim,i=1;i<this.matrices.length;i++)this.matrices[i].multiplyMatrices(this.matrices[i-1],this.matrices[0]);this.indices.forEach(function(i){this.vertices[i].applyMatrix4(this.matrices[t[i][e]])}.bind(this))}},Tautology.Transform.prototype.uniformRemap=function(t,e){this.dim=e,this.settingCallback=t,this.update=function(){this.settingCallback.call(this);var t=this.labels,i=e,r={0:"x",1:"y"}[i];this.indices.forEach(function(e){this.texels[e][r]=t[e][i]/(this.shape[i]-1)}.bind(this))}},Tautology.Transform.prototype.remap=function(t,e){this.stepArray=Array["const"](this.shape[e],0),this.dim=e,this.settingCallback=t,this.update=function(){this.settingCallback.call(this);var t=this.labels,i=e,r={0:"x",1:"y"}[i];this.indices.forEach(function(e){this.texels[e][r]=this.stepArray[t[e][i]]}.bind(this))}},Tautology.Geometry=function(t){this.labels=t.shape.reduce(function(t,e){return Array.range(e).outer(t,function(t,e){return e.concat(t)}).flatten()},[[]]),this.vertices=this.labels.map(function(){return new THREE.Vector3}),this.texels=this.labels.map(function(){return new THREE.Vector2}),this.faces=Array.grid(t.shape),this.regions={};for(key in t.regions)this.regions[key]=new Tautology.Region(t.regions[key],t.shape);this.instructions=[],t.manuever.forEach(function(e){this.instructions.push(new Tautology.Transform(this,t,e))}.bind(this)),this.init(),this.update()},Tautology.Geometry.prototype.constructor=Tautology.Geometry,Tautology.Geometry.prototype.init=function(){this.geom&&this.geom.dispose(),this.geom=new THREE.Geometry,this.geom.vertices=this.vertices,this.geom.faces=this.faces,this.geom.faceVertexUvs=[],this.geom.faceVertexUvs.push(this.faces.map(function(t){return[this.texels[t.a],this.texels[t.b],this.texels[t.c]]}.bind(this)))},Tautology.Geometry.prototype.update=function(){this.vertices.forEach(function(t){t.set(0,0,0)}),this.instructions.forEach(function(t){t.update()}.bind(this)),this.geom.verticesNeedUpdate=!0,this.geom.uvsNeedUpdate=!0,this.geom.computeFaceNormals(),this.geom.normalsNeedUpdate=!0},Tautology.Material=function(t,e){this.param=t,this.texture=e,this.materials={},this.init(),this.update()},Tautology.Material.prototype.constructor=Tautology.Material,Tautology.Material.prototype.init=function(){var t=function(t){return{basic:"MeshBasicMaterial",lambert:"MeshLambertMaterial",phong:"MeshPhongMaterial",point:"PointCloudMaterial"}[t]};this.materials.outside&&this.materials.outside.dispose(),this.materials.outside=new(THREE[t(this.param.mainType)])({map:this.texture?this.texture:null,opacity:this.param.opacity.val,transparent:!0,side:THREE.FrontSide,_needsUpdate:!0}),this.materials.inside&&this.materials.inside.dispose(),this.materials.inside=new(THREE[t(this.param.mainType)])({map:this.texture?this.texture:null,opacity:this.param.opacity.val,transparent:!0,side:THREE.BackSide,_needsUpdate:!0})},Tautology.Material.prototype.update=function(){this.materials.outside.opacity=this.param.opacity.val,this.materials.inside.opacity=this.param.opacity.val},Tautology.ModelManager=function(t,e,i){this.models={},this.texture=new THREE.Texture(i.getElement()),this.texture.needsUpdate=!0,this.material=new Tautology.Material(e,this.texture),i.on("after:render",function(){this.texture.needsUpdate=!0}.bind(this)),this.init()},Tautology.ModelManager.prototype.constructor=Tautology.ModelManager,Tautology.ModelManager.prototype.init=function(){Object.keys(models).forEach(function(t){this.models[t]={},this.models[t].geom=new Tautology.Geometry(models[t].model),this.models[t].meshes=new THREE.Object3D,this.models[t].meshes.add(new THREE.Mesh(this.models[t].geom.geom,this.material.materials.outside)),this.models[t].meshes.add(new THREE.Mesh(this.models[t].geom.geom,this.material.materials.inside))}.bind(this))},Tautology.ModelManager.prototype.select=function(t,e){for(var i=0;i<e.children.length;i++)"Object3D"==e.children[i].type&&e.remove(e.children[i]);e.add(this.models[t].meshes)};
//# sourceMappingURL=Tautology.min.js.map