소스 검색

Merge pull request #4950 from jahting/pnltrixmpl

New example WebGl-Geometry-Text-2 uses new triangulation PnlTri.js V1.0
Mr.doob 11 년 전
부모
커밋
f60cc4e317
2개의 변경된 파일699개의 추가작업 그리고 0개의 파일을 삭제
  1. 32 0
      examples/js/libs/pnltri.min.js
  2. 667 0
      examples/webgl_geometry_text2.html

+ 32 - 0
examples/js/libs/pnltri.min.js

@@ -0,0 +1,32 @@
+// pnltri.js / raw.github.com/jahting/pnltri.js/master/LICENSE
+'use strict';var PNLTRI={REVISION:"1.0"};PNLTRI.Math={log2:function(a){return Math.log(a)/Math.LN2},random:Math.random,array_shuffle:function(a){for(var c=a.length-1;0<c;c--){var b=Math.floor(PNLTRI.Math.random()*(c+1)),d=a[c];a[c]=a[b];a[b]=d}return a},ptsCrossProd:function(a,c,b){return(c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x)}};PNLTRI.Math.EPSILON_P=Math.pow(2,-43);PNLTRI.Math.EPSILON_N=-PNLTRI.Math.EPSILON_P;PNLTRI.PolygonData=function(a){this.vertices=[];this.segments=[];this.idNextPolyChain=0;this.monoSubPolyChains=[];this.triangles=[];if(a)for(var c=0,b=a.length;c<b;c++)this.addPolygonChain(a[c])};
+PNLTRI.PolygonData.prototype={constructor:PNLTRI.PolygonData,getSegments:function(){return this.segments},getFirstSegment:function(){return this.segments[0]},getMonoSubPolys:function(){return this.monoSubPolyChains},getTriangles:function(){return this.triangles.concat()},nbPolyChains:function(){return this.idNextPolyChain},compare_pts_yx:function(a,c){var b=a.y-c.y;if(b>PNLTRI.Math.EPSILON_P)return 1;if(b<PNLTRI.Math.EPSILON_N)return-1;b=a.x-c.x;return b>PNLTRI.Math.EPSILON_P?1:b<PNLTRI.Math.EPSILON_N?
+-1:0},isClockWise:function(a){var c=a,b=0;do b+=(c.vFrom.x-c.vTo.x)*(c.vFrom.y+c.vTo.y),c=c.snext;while(c!=a);return 0>b},appendVertexEntry:function(a){a=a?a:{x:null,y:null,outSegs:[]};a.id=this.vertices.length;this.vertices.push(a);return a},createSegmentEntry:function(a,c){return{chainId:this.idNextPolyChain,vFrom:a,vTo:c,upward:1==this.compare_pts_yx(c,a),sprev:null,snext:null}},appendSegmentEntry:function(a){this.segments.push(a);0==this.monoSubPolyChains.length&&(this.monoSubPolyChains=[this.segments[0]]);
+return a},addVertexChain:function(a){function c(a,b){return Math.abs(a.x-b.x)<PNLTRI.Math.EPSILON_P&&Math.abs(a.y-b.y)<PNLTRI.Math.EPSILON_P}for(var b=[],d,e,g,h=0;h<a.length;h++)d=this.appendVertexEntry({x:a[h].x,y:a[h].y}),e=!0,g=b.length-1,0<=g&&c(d,b[g])&&(e=!1),e&&b.push(d);1<b.length&&c(b[b.length-1],b[0])&&b.pop();return b},addPolygonChain:function(a){a=this.addVertexChain(a);if(3>a.length)return console.log("Polygon has < 3 vertices!",a),0;for(var c=this.segments.length,b,d,e,g=0;g<a.length-
+1;g++)b=this.createSegmentEntry(a[g],a[g+1]),e?(b.sprev=e,e.snext=b):d=b,e=b,this.appendSegmentEntry(b);b=this.createSegmentEntry(a[a.length-1],a[0]);b.sprev=e;e.snext=b;this.appendSegmentEntry(b);d.sprev=b;b.snext=d;this.idNextPolyChain++;return this.segments.length-c},initMonoChains:function(){for(var a=0;a<this.segments.length;a++)this.segments[a].marked=!1,this.segments[a].mprev=this.segments[a].sprev,this.segments[a].mnext=this.segments[a].snext,this.segments[a].vFrom.outSegs=[{segOut:this.segments[a],
+vertTo:this.segments[a].vTo}]},appendVertexOutsegEntry:function(a,c){var b=c?c:{segOut:null,vertTo:null};a.outSegs.push(b);return b},splitPolygonChain:function(a,c,b){function d(a,b){for(var c,d,f=null,e=4,h=0;h<a.outSegs.length;h++){c=a.outSegs[h];var g=c.vertTo;d=g.x-a.x;var g=g.y-a.y,k=b.x-a.x,t=b.y-a.y,v=(d*k+g*t)/Math.sqrt(d*d+g*g)/Math.sqrt(k*k+t*t);(d=0<=d*t-k*g?1-v:3+v)<e&&(e=d,f=c)}return f}var e=d(c,b),g=d(b,c),e=e.segOut,g=g.segOut,h=1==this.compare_pts_yx(c,b),k=this.appendSegmentEntry({vFrom:c,
+vTo:b,upward:!h,mprev:e.mprev,mnext:g}),h=this.appendSegmentEntry({vFrom:b,vTo:c,upward:h,mprev:g.mprev,mnext:e});e.mprev.mnext=k;g.mprev.mnext=h;e.mprev=h;g.mprev=k;this.appendVertexOutsegEntry(c,{segOut:k,vertTo:b});this.appendVertexOutsegEntry(b,{segOut:h,vertTo:c});this.monoSubPolyChains[a]=g;this.monoSubPolyChains.push(e);return this.monoSubPolyChains.length-1},unique_monotone_chains_max:function(){var a,c,b,d,e,g;for(g=0;g<this.segments.length;g++)this.segments[g].marked=!1;var h=[];for(g=0;g<
+this.monoSubPolyChains.length;g++){a=c=this.monoSubPolyChains[g];d=e=a.vFrom;a.marked=!0;a=a.mnext;for(var k=!1;(b=a.vFrom)!=d;){if(a.marked){k=!0;break}else a.marked=!0;1==this.compare_pts_yx(b,e)&&(e=b,c=a);a=a.mnext}k||h.push(c)}return h},normalize_monotone_chains:function(){this.monoSubPolyChains=this.unique_monotone_chains_max();return this.monoSubPolyChains.length},clearTriangles:function(){this.triangles=[]},addTriangle:function(a,c,b){this.triangles.push([a.id,c.id,b.id])}};PNLTRI.EarClipTriangulator=function(a){this.polyData=a};
+PNLTRI.EarClipTriangulator.prototype={constructor:PNLTRI.EarClipTriangulator,triangulate_polygon_no_holes:function(){var a=this.polyData,c=a.getFirstSegment(),b=c;if(a.isClockWise(c)){do b.mprev=b.snext,b=b.mnext=b.sprev;while(b!=c)}else{do b.mprev=b.sprev,b=b.mnext=b.snext;while(b!=c)}for(c=a=c;a.mnext!=a.mprev;){a:{var b=a.mprev.vFrom.x,d=a.mprev.vFrom.y,e=a.vFrom.x,g=a.vFrom.y,h=a.mnext.vFrom.x,k=a.mnext.vFrom.y,n=h-e,p=k-g,q=b-h,u=d-k,f=e-b,m=g-d;if(PNLTRI.Math.EPSILON_P>f*p-n*m)b=!1;else{for(var l=
+a.mprev.mprev,s=a.mnext;s!=l;){var s=s.mnext,r=s.vFrom.x,t=s.vFrom.y,v=r-b,w=t-d;if(0!=v||0!=w){var x=r-e,y=t-g;if(0!=x||0!=y)if(r-=h,t-=k,(0!=r||0!=t)&&n*y-p*x>=PNLTRI.Math.EPSILON_N&&f*w-m*v>=PNLTRI.Math.EPSILON_N&&q*t-u*r>=PNLTRI.Math.EPSILON_N){b=!1;break a}}}b=!0}}if(b)this.polyData.addTriangle(a.mprev.vFrom,a.vFrom,a.mnext.vFrom),a.mprev.mnext=a.mnext,a.mnext.mprev=a.mprev,c=a=a.mnext;else if(a=a.mnext,a==c)return!1}return!0}};PNLTRI.trapCnt=0;PNLTRI.Trapezoid=function(a,c,b,d){this.trapID=PNLTRI.trapCnt++;this.vHigh=a?a:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY};this.vLow=c?c:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY};this.lseg=b;this.rseg=d;this.depth=-1;this.monoDiag=null};
+PNLTRI.Trapezoid.prototype={constructor:PNLTRI.Trapezoid,clone:function(){var a=new PNLTRI.Trapezoid(this.vHigh,this.vLow,this.lseg,this.rseg);a.uL=this.uL;a.uR=this.uR;a.dL=this.dL;a.dR=this.dR;a.sink=this.sink;return a},setAbove:function(a,c){this.uL=a;this.uR=c},setBelow:function(a,c){this.dL=a;this.dR=c},splitOffLower:function(a){var c=this.clone();this.vLow=c.vHigh=a;this.setBelow(c,null);c.setAbove(this,null);c.dL&&(c.dL.uL=c);c.dR&&(c.dR.uR=c);return c}};PNLTRI.T_Y=1;PNLTRI.T_X=2;
+PNLTRI.T_SINK=3;PNLTRI.S_LEFT=1;PNLTRI.S_RIGHT=2;PNLTRI.QsNode=function(a){this.nodetype=PNLTRI.T_SINK;this.trap=a;a.sink=this};PNLTRI.QsNode.prototype={constructor:PNLTRI.QsNode};
+PNLTRI.QueryStructure=function(a){PNLTRI.trapCnt=0;var c=new PNLTRI.Trapezoid(null,null,null,null);this.root=new PNLTRI.QsNode(c);this.trapArray=[c];this.segListArray=null;if(a){this.segListArray=a.getSegments();for(c=0;c<this.segListArray.length;c++)this.segListArray[c].rootFrom=this.segListArray[c].rootTo=this.root,this.segListArray[c].is_inserted=!1;this.compare_pts_yx=a.compare_pts_yx}else this.compare_pts_yx=PNLTRI.PolygonData.prototype.compare_pts_yx};
+PNLTRI.QueryStructure.prototype={constructor:PNLTRI.QueryStructure,getRoot:function(){return this.root},getSegListArray:function(){return this.segListArray},cloneTrap:function(a){a=a.clone();this.trapArray.push(a);return a},splitNodeAtPoint:function(a,c,b){var d=a.trap;if(d.vHigh==c||d.vLow==c)return a;var e=d.splitOffLower(c);this.trapArray.push(e);a.nodetype=PNLTRI.T_Y;a.yval=c;a.trap=null;a.right=new PNLTRI.QsNode(d);a.left=new PNLTRI.QsNode(e);return b?d.sink:e.sink},fpEqual:function(a,c){return Math.abs(a-
+c)<PNLTRI.Math.EPSILON_P},is_left_of:function(a,c,b){b=a.vFrom.x-c.x;var d=a.vTo.x-c.x;if(Math.abs(a.vTo.y-c.y)<PNLTRI.Math.EPSILON_P)a=d,c=b;else if(Math.abs(a.vFrom.y-c.y)<PNLTRI.Math.EPSILON_P)a=b,c=d;else return a.upward?PNLTRI.Math.ptsCrossProd(a.vFrom,a.vTo,c):PNLTRI.Math.ptsCrossProd(a.vTo,a.vFrom,c);return Math.abs(a)<PNLTRI.Math.EPSILON_P?Math.abs(c)<PNLTRI.Math.EPSILON_P?0:c:a},ptNode:function(a,c,b){var d,e=!0;switch(b.nodetype){case PNLTRI.T_SINK:return b;case PNLTRI.T_Y:d=a;d==b.yval&&
+(d=c);d=this.compare_pts_yx(d,b.yval);-1==d&&(e=!1);break;case PNLTRI.T_X:if(a==b.seg.vFrom||a==b.seg.vTo){if(this.fpEqual(a.y,c.y)){c.x<a.x&&(e=!1);break}else d=this.is_left_of(b.seg,c,!1),0<d?e=!1:0==d&&(e=a==b.seg.vFrom?!0:!1);break}else d=this.is_left_of(b.seg,a,!0),0<d?e=!1:0==d&&(e=!0);break;default:console.log("ptNode: undef. NodeType: ",b.nodetype)}return e?this.ptNode(a,c,b.right):this.ptNode(a,c,b.left)},add_segment:function(a){function c(){var a=f.uL||f.uR;a.dL&&a.dR?f==a.dR?(m.setAbove(null,
+null),l.setAbove(null,a),a.setBelow(a.dL,l)):(l.setAbove(null,null),m.setAbove(a,null),a.setBelow(m,a.dR)):(m.setAbove(a,null),l.setAbove(null,a),a.setBelow(m,l))}function b(a){f.vLow==u.vLow&&q?f.dL?(m.setBelow(a,null),l.setBelow(null,null),a.setAbove(m,a.uR)):(l.setBelow(null,a),m.setBelow(null,null),a.setAbove(a.uL,l)):(a.uL&&a.uR?a.uL==f?(a.usave=a.uR,a.uside=PNLTRI.S_LEFT,m.setBelow(a,null),l.setBelow(a,null)):(a.usave=a.uL,a.uside=PNLTRI.S_RIGHT,m.setBelow(null,a),l.setBelow(null,a)):f.vLow==
+u.vLow?(m.setBelow(a,null),l.setBelow(null,a)):(m.setBelow(null,a),l.setBelow(a,null)),a.setAbove(m,l))}function d(){var b;f.vLow==u.vLow&&q?(f.dL.setAbove(m,null),f.dR.setAbove(null,l),b=f.dR,m.setBelow(f.dL,null),l.setBelow(null,b),b=null):0<e.is_left_of(a,f.vLow,!0)?(b=f.dR,f.dL.setAbove(m,null),f.dR.setAbove(m,l),m.setBelow(f.dL,f.dR),l.setBelow(null,f.dR)):(b=f.dL,f.dL.setAbove(m,l),f.dR.setAbove(null,l),l.setBelow(f.dL,f.dR),m.setBelow(f.dL,null));return b}var e=this,g,h,k,n,p,q;a.upward?(n=
+a.vFrom,g=a.vTo,p=a.rootFrom,h=a.rootTo,q=a.sprev.is_inserted,k=a.snext.is_inserted):(n=a.vTo,g=a.vFrom,p=a.rootTo,h=a.rootFrom,q=a.snext.is_inserted,k=a.sprev.is_inserted);h=this.ptNode(g,n,h);k||(h=this.splitNodeAtPoint(h,g,!1));k=h.trap;if(k.uL||k.uR){h=this.ptNode(n,g,p);q||(h=this.splitNodeAtPoint(h,n,!0));var u=h.trap,f=k,m,l,s,r;for(g=this.trapArray.length+2;f;){if(0>--g){console.log("ERR add_segment: infinite loop",f,a,this);return}if(!f.dL&&!f.dR){console.log("ERR add_segment: missing successors",
+f,a,this);return}h=f.sink;h.nodetype=PNLTRI.T_X;h.seg=a;h.trap=null;n=p=!0;r&&r.rseg==f.rseg?(p=!1,m=f,l=r,l.vLow=f.vLow,h.right=r.sink,h.left=new PNLTRI.QsNode(m)):s&&s.lseg==f.lseg?(n=!1,l=f,m=s,m.vLow=f.vLow,h.left=s.sink,h.right=new PNLTRI.QsNode(l)):(m=f,l=this.cloneTrap(f),h.right=new PNLTRI.QsNode(l),h.left=new PNLTRI.QsNode(m));f.uL&&f.uR?f.usave?(f.uside==PNLTRI.S_LEFT?(l.setAbove(f.uR,f.usave),l.uL.setBelow(l,null),l.uR.setBelow(null,l)):(m.setAbove(f.usave,f.uL),m.uL.setBelow(m,null),m.uR.setBelow(null,
+m)),m.usave=l.usave=null):f.vHigh==k.vHigh?(l.setAbove(null,f.uR),l.uR.setBelow(null,l),m.setAbove(f.uL,null)):(p&&(l.setAbove(f.uR,null),l.uL.setBelow(l,l.uL.dR)),n&&m.setAbove(null,f.uL)):c();f.dL&&f.dR?n=d():(n=f.dL?f.dL:f.dR,b(n));m.rseg&&(m.rseg.trLeft=l);l.lseg&&(l.lseg.trRight=m);m.rseg=l.lseg=a;a.trLeft=m;a.trRight=l;f.vLow!=u.vLow?(s=m,r=l,f=n):f=null}a.is_inserted=!0}else console.log("ERR add_segment: missing trFirst.uX: ",k)},assignDepths:function(){var a=[this.trapArray[0]],c=[],b,d,e=
+0;do{for(;b=a.pop();)-1==b.depth&&(b.depth=e,b.uL&&a.push(b.uL),b.uR&&a.push(b.uR),b.dL&&a.push(b.dL),b.dR&&a.push(b.dR),(d=b.lseg)&&-1==d.trLeft.depth&&c.push(d.trLeft),(d=b.rseg)&&-1==d.trRight.depth&&c.push(d.trRight));a=c;c=[];e++}while(0<a.length)},reverse_polygon_chain:function(a){var c,b=a;do c=b.snext,b.snext=b.sprev,b.sprev=c,c=b.vTo,b.vTo=b.vFrom,b.vFrom=c,b.upward=!b.upward,b=b.sprev;while(b!=a)},normalize_segment_orientation:function(){for(var a,c=0;c<this.segListArray.length;c++)a=this.segListArray[c],
+a.upward==(0==a.trLeft.depth%2)&&this.reverse_polygon_chain(a)},find_first_inside:function(){for(var a,c=0,b=this.trapArray.length;c<b;c++)if(a=this.trapArray[c],1==a.depth%2&&!a.monoDiag&&(!a.uL&&!a.uR||!a.dL&&!a.dR))return a;return null}};PNLTRI.Trapezoider=function(a){this.polyData=a;this.queryStructure=new PNLTRI.QueryStructure(this.polyData)};
+PNLTRI.Trapezoider.prototype={constructor:PNLTRI.Trapezoider,find_first_inside:function(){return this.queryStructure.find_first_inside()},math_logstar_n:function(a){var c;for(c=0;1<=a;c++)a=PNLTRI.Math.log2(a);return c-1},math_NH:function(a,c){var b,d;b=0;for(d=a;b<c;b++)d=PNLTRI.Math.log2(d);return Math.ceil(1*a/d)},optimise_randomlist:function(a){var c=0,b=this.polyData.nbPolyChains();if(1!=b)for(var d=Array(b),e=a.concat(),g=0;g<e.length;g++){var h=e[g].chainId;d[h]?a[b++]=e[g]:(a[c++]=e[g],d[h]=
+!0)}},find_new_roots:function(a){a.is_inserted||(a.rootFrom=this.queryStructure.ptNode(a.vFrom,a.vTo,a.rootFrom),a.rootTo=this.queryStructure.ptNode(a.vTo,a.vFrom,a.rootTo))},trapezoide_polygon:function(){var a=this.queryStructure,c=a.segListArray.concat();PNLTRI.Math.array_shuffle(c);this.optimise_randomlist(c);var b,d,e=c.length,g=this.math_logstar_n(e);for(d=1;d<=g;d++){for(b=this.math_NH(e,d-1);b<this.math_NH(e,d);b++)a.add_segment(c[b-1]);for(b=0;b<e;b++)this.find_new_roots(c[b])}for(b=this.math_NH(e,
+g);b<=e;b++)a.add_segment(c[b-1]);a.assignDepths();a.normalize_segment_orientation()}};PNLTRI.MonoSplitter=function(a){this.polyData=a;this.startTrap=this.trapezoider=null};
+PNLTRI.MonoSplitter.prototype={constructor:PNLTRI.MonoSplitter,monotonate_trapezoids:function(){this.trapezoider=new PNLTRI.Trapezoider(this.polyData);this.trapezoider.trapezoide_polygon();this.startTrap=this.trapezoider.find_first_inside();this.polyData.initMonoChains();for(var a=0,c=this.startTrap;c;)if(this.polyData.monoSubPolyChains[a]=c.lseg,this.alyTrap(a,c,null,null,null),c=this.trapezoider.find_first_inside())a=this.polyData.monoSubPolyChains.length;return this.polyData.normalize_monotone_chains()},
+doSplit:function(a,c,b,d){return d?this.polyData.splitPolygonChain(a,c,b):this.polyData.splitPolygonChain(a,b,c)},alyTrap:function(a,c,b,d,e){function g(){var a;return(a=h.pop())?(k=a[0],n=a[1],p=a[2],q=a[3],!0):!1}var h=[],k,n,p,q,u;null==b&&(d=!0,c.uL?b=!0:c.dL?b=!1:(d=!1,b=c.uR?!0:!1));for(c&&h.push([c,b,d,a]);g();)if(!k.monoDiag){if(!k.lseg||!k.rseg)return console.log("ERR alyTrap: lseg/rseg missing",k),h;n?p?(a=k.uL,c=k.uR,b=k.dL,d=k.dR):(a=k.uR,c=k.uL,b=k.dR,d=k.dL):p?(a=k.dL,c=k.dR,b=k.uL,
+d=k.uR):(a=k.dR,c=k.dL,b=k.uR,d=k.uL);if(c||d)u=this.doSplit(q,k.vLow,k.vHigh,p);d&&h.push([d,n,!p,u]);c&&h.push([c,!n,!p,u]);b&&h.push([b,n,p,q]);b||d||a&&h.push([a,!n,p,q]);k.monoDiag=!0;if(e)return h}return[]}};PNLTRI.MonoTriangulator=function(a){this.polyData=a};
+PNLTRI.MonoTriangulator.prototype={constructor:PNLTRI.MonoTriangulator,triangulate_all_polygons:function(){var a=this.polyData.getMonoSubPolys();this.polyData.clearTriangles();for(var c=0;c<a.length;c++){var b=a[c],d=b.mprev,e=b.mnext;e.mnext==d?this.polyData.addTriangle(b.vFrom,e.vFrom,d.vFrom):this.triangulate_monotone_polygon(b)}},triangulate_monotone_polygon:function(a){var c=a.mnext;a=a.vFrom;var b=[c.vFrom],d=0,c=c.mnext,e=c.vFrom;if(e!=a){for(;e!=a||1<d;)if(0<d)if(0<PNLTRI.Math.ptsCrossProd(e,
+b[d-1],b[d]))this.polyData.addTriangle(b[d-1],b[d],e),d--;else if(b[++d]=e,e==a)for(console.log("ERR uni-y-monotone: only concave angles left",b);1<d;)d--,this.polyData.addTriangle(b[d-1],b[d],b[d+1]);else c=c.mnext,e=c.vFrom;else b[++d]=e,c=c.mnext,e=c.vFrom;this.polyData.addTriangle(b[d-1],b[d],e)}}};PNLTRI.Triangulator=function(){this.lastPolyData=null};PNLTRI.Triangulator.prototype={constructor:PNLTRI.Triangulator,triangulate_polygon:function(a,c){if(!a||0==a.length)return[];var b=new PNLTRI.PolygonData(a),d;d=c?!1:1==b.nbPolyChains();d&&(d=new PNLTRI.EarClipTriangulator(b),d=d.triangulate_polygon_no_holes());d||((new PNLTRI.MonoSplitter(b)).monotonate_trapezoids(),d=new PNLTRI.MonoTriangulator(b),d.triangulate_all_polygons());this.lastPolyData=b;return b.getTriangles()}};

+ 667 - 0
examples/webgl_geometry_text2.html

@@ -0,0 +1,667 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - geometry - text</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<style>
+			body {
+				font-family: Monospace;
+				background-color: #000;
+				color: #fff;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				position: absolute;
+				top: 10px;
+				width: 100%;
+				text-align: center;
+				z-index: 100;
+				display:block;
+			}
+			#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
+		</style>
+	</head>
+	<body>
+
+		<div id="info">
+		<a href="http://threejs.org" target="_blank">three.js</a> - procedural 3D text by <a href="http://www.lab4games.net/zz85/blog" target="_blank">zz85</a> &amp; alteredq
+		(fonts from <a href="http://typeface.neocracy.org/">typeface.js</a> and <a href="http://en.wikipedia.org/wiki/Droid_%28font%29">Droid</a>)
+		<br/>built-in shape triangulation has been replaced with <a href="https://github.com/jahting/pnltri.js">PnlTri.js</a> by <a href="https://github.com/jahting" target="_blank">j ahting</a>
+		<br/>type to enter new text, drag to spin the text
+		<br/><span class="button" id="color">change color</span>,
+			<span class="button" id="font">change font</span>,
+			<span class="button" id="weight">change weight</span>,
+			<span class="button" id="bevel">change bevel</span>,
+			<span class="button" id="postprocessing">change postprocessing</span>,
+			<a id="permalink" href="#">permalink</a>
+		</div>
+
+
+		<script src="../build/three.min.js"></script>
+		<script src="js/utils/GeometryUtils.js"></script>
+
+		<script src="js/shaders/ConvolutionShader.js"></script>
+		<script src="js/shaders/CopyShader.js"></script>
+		<script src="js/shaders/FilmShader.js"></script>
+		<script src="js/shaders/FXAAShader.js"></script>
+
+		<script src="js/postprocessing/EffectComposer.js"></script>
+		<script src="js/postprocessing/RenderPass.js"></script>
+		<script src="js/postprocessing/ShaderPass.js"></script>
+		<script src="js/postprocessing/MaskPass.js"></script>
+		<script src="js/postprocessing/BloomPass.js"></script>
+		<script src="js/postprocessing/FilmPass.js"></script>
+
+		<script src="js/Detector.js"></script>
+		<script src="js/libs/stats.min.js"></script>
+
+		<!-- load the font files -->
+
+		<script src="fonts/gentilis_bold.typeface.js"></script>
+		<script src="fonts/gentilis_regular.typeface.js"></script>
+		<script src="fonts/optimer_bold.typeface.js"></script>
+		<script src="fonts/optimer_regular.typeface.js"></script>
+		<script src="fonts/helvetiker_bold.typeface.js"></script>
+		<script src="fonts/helvetiker_regular.typeface.js"></script>
+		<script src="fonts/droid/droid_sans_regular.typeface.js"></script>
+		<script src="fonts/droid/droid_sans_bold.typeface.js"></script>
+		<script src="fonts/droid/droid_serif_regular.typeface.js"></script>
+		<script src="fonts/droid/droid_serif_bold.typeface.js"></script>
+
+		<!-- todo async loader for fonts -->
+
+
+		<!-- replace built-in triangulation with PnlTri.js -->
+		<script src="js/libs/pnltri.min.js"></script>
+		<script>
+			THREE.Shape.Utils.triangulateShape = ( function () {
+				var pnlTriangulator = new PNLTRI.Triangulator();
+				return function ( contour, holes ) {
+					// console.log("new Triangulation: PnlTri.js " + PNLTRI.REVISION );
+					return pnlTriangulator.triangulate_polygon( [ contour ].concat(holes) );
+				};
+			} )();
+		</script>
+		
+
+		<script>
+
+			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+			var container, stats, permalink, hex, color;
+
+			var camera, cameraTarget, scene, renderer;
+
+			var composer;
+			var effectFXAA;
+
+			var group, textMesh1, textMesh2, textGeo, material;
+
+			var firstLetter = true;
+
+			var text = "three.js",
+
+				height = 20,
+				size = 70,
+				hover = 30,
+
+				curveSegments = 4,
+
+				bevelThickness = 2,
+				bevelSize = 1.5,
+				bevelSegments = 3,
+				bevelEnabled = true,
+
+				font = "optimer", // helvetiker, optimer, gentilis, droid sans, droid serif
+				weight = "bold", // normal bold
+				style = "normal"; // normal italic
+
+			var mirror = true;
+
+			var fontMap = {
+
+				"helvetiker": 0,
+				"optimer": 1,
+				"gentilis": 2,
+				"droid sans": 3,
+				"droid serif": 4
+
+			};
+
+			var weightMap = {
+
+				"normal": 0,
+				"bold": 1
+
+			};
+
+			var reverseFontMap = {};
+			var reverseWeightMap = {};
+
+			for ( var i in fontMap ) reverseFontMap[ fontMap[i] ] = i;
+			for ( var i in weightMap ) reverseWeightMap[ weightMap[i] ] = i;
+
+			var targetRotation = 0;
+			var targetRotationOnMouseDown = 0;
+
+			var mouseX = 0;
+			var mouseXOnMouseDown = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			var postprocessing = { enabled : false };
+			var glow = 0.9;
+
+			init();
+			animate();
+
+			function capitalize( txt ) {
+
+				return txt.substring( 0, 1 ).toUpperCase() + txt.substring( 1 );
+
+			}
+
+			function decimalToHex( d ) {
+
+				var hex = Number( d ).toString( 16 );
+				hex = "000000".substr( 0, 6 - hex.length ) + hex;
+				return hex.toUpperCase();
+
+			}
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				permalink = document.getElementById( "permalink" );
+
+				// CAMERA
+
+				camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 1500 );
+				camera.position.set( 0, 400, 700 );
+
+				cameraTarget = new THREE.Vector3( 0, 150, 0 );
+
+				// SCENE
+
+				scene = new THREE.Scene();
+				scene.fog = new THREE.Fog( 0x000000, 250, 1400 );
+
+				// LIGHTS
+
+				var dirLight = new THREE.DirectionalLight( 0xffffff, 0.125 );
+				dirLight.position.set( 0, 0, 1 ).normalize();
+				scene.add( dirLight );
+
+				var pointLight = new THREE.PointLight( 0xffffff, 1.5 );
+				pointLight.position.set( 0, 100, 90 );
+				scene.add( pointLight );
+
+				//text = capitalize( font ) + " " + capitalize( weight );
+				//text = "abcdefghijklmnopqrstuvwxyz0123456789";
+				//text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+				// Get text from hash
+
+				var hash = document.location.hash.substr( 1 );
+
+				if ( hash.length !== 0 ) {
+
+					var colorhash  = hash.substring( 0, 6 );
+					var fonthash   = hash.substring( 6, 7 );
+					var weighthash = hash.substring( 7, 8 );
+					var pphash 	   = hash.substring( 8, 9 );
+					var bevelhash  = hash.substring( 9, 10 );
+					var texthash   = hash.substring( 10 );
+
+					hex = colorhash;
+					pointLight.color.setHex( parseInt( colorhash, 16 ) );
+
+					font = reverseFontMap[ parseInt( fonthash ) ];
+					weight = reverseWeightMap[ parseInt( weighthash ) ];
+
+					postprocessing.enabled = parseInt( pphash );
+					bevelEnabled = parseInt( bevelhash );
+
+					text = decodeURI( texthash );
+
+					updatePermalink();
+
+				} else {
+
+					pointLight.color.setHSL( Math.random(), 1, 0.5 );
+					hex = decimalToHex( pointLight.color.getHex() );
+
+				}
+
+				material = new THREE.MeshFaceMaterial( [ 
+					new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front
+					new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side
+				] );
+
+				group = new THREE.Object3D();
+				group.position.y = 100;
+
+				scene.add( group );
+
+				createText();
+
+				var plane = new THREE.Mesh( new THREE.PlaneGeometry( 10000, 10000 ), new THREE.MeshBasicMaterial( { color: 0xffffff, opacity: 0.5, transparent: true } ) );
+				plane.position.y = 100;
+				plane.rotation.x = - Math.PI / 2;
+				scene.add( plane );
+
+				// RENDERER
+
+				renderer = new THREE.WebGLRenderer( { antialias: true } );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				renderer.setClearColor( scene.fog.color, 1 );
+
+				container.appendChild( renderer.domElement );
+
+				// STATS
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				//container.appendChild( stats.domElement );
+
+				// EVENTS
+
+				document.addEventListener( 'mousedown', onDocumentMouseDown, false );
+				document.addEventListener( 'touchstart', onDocumentTouchStart, false );
+				document.addEventListener( 'touchmove', onDocumentTouchMove, false );
+				document.addEventListener( 'keypress', onDocumentKeyPress, false );
+				document.addEventListener( 'keydown', onDocumentKeyDown, false );
+
+				document.getElementById( "color" ).addEventListener( 'click', function() {
+
+					pointLight.color.setHSL( Math.random(), 1, 0.5 );
+					hex = decimalToHex( pointLight.color.getHex() );
+
+					updatePermalink();
+
+				}, false );
+
+				document.getElementById( "font" ).addEventListener( 'click', function() {
+
+					if ( font == "helvetiker" ) {
+
+						font = "optimer";
+
+					} else if ( font == "optimer" ) {
+
+						font = "gentilis";
+
+					} else if ( font == "gentilis" ) {
+
+						font = "droid sans";
+
+					} else if ( font == "droid sans" ) {
+
+						font = "droid serif";
+
+					} else {
+
+						font = "helvetiker";
+
+					}
+
+					refreshText();
+
+				}, false );
+
+				document.getElementById( "weight" ).addEventListener( 'click', function() {
+
+					if ( weight == "bold" ) {
+
+						weight = "normal";
+
+					} else {
+
+						weight = "bold";
+
+					}
+
+					refreshText();
+
+				}, false );
+
+				document.getElementById( "bevel" ).addEventListener( 'click', function() {
+
+					bevelEnabled = !bevelEnabled;
+
+					refreshText();
+
+				}, false );
+
+				document.getElementById( "postprocessing" ).addEventListener( 'click', function() {
+
+					postprocessing.enabled = !postprocessing.enabled;
+					updatePermalink();
+
+				}, false );
+
+
+				// POSTPROCESSING
+
+				renderer.autoClear = false;
+
+				var renderModel = new THREE.RenderPass( scene, camera );
+				var effectBloom = new THREE.BloomPass( 0.25 );
+				var effectFilm = new THREE.FilmPass( 0.5, 0.125, 2048, false );
+
+				effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
+
+				var width = window.innerWidth || 2;
+				var height = window.innerHeight || 2;
+
+				effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
+
+				effectFilm.renderToScreen = true;
+
+				composer = new THREE.EffectComposer( renderer );
+
+				composer.addPass( renderModel );
+				composer.addPass( effectFXAA );
+				composer.addPass( effectBloom );
+				composer.addPass( effectFilm );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				composer.reset();
+
+				effectFXAA.uniforms[ 'resolution' ].value.set( 1 / window.innerWidth, 1 / window.innerHeight );
+
+			}
+
+			//
+
+			function boolToNum( b ) {
+
+				return b ? 1 : 0;
+
+			}
+
+			function updatePermalink() {
+
+				var link = hex + fontMap[ font ] + weightMap[ weight ] + boolToNum( postprocessing.enabled ) + boolToNum( bevelEnabled ) + "#" + encodeURI( text );
+
+				permalink.href = "#" + link;
+				window.location.hash = link;
+
+			}
+
+			function onDocumentKeyDown( event ) {
+
+				if ( firstLetter ) {
+
+					firstLetter = false;
+					text = "";
+
+				}
+
+				var keyCode = event.keyCode;
+
+				// backspace
+
+				if ( keyCode == 8 ) {
+
+					event.preventDefault();
+
+					text = text.substring( 0, text.length - 1 );
+					refreshText();
+
+					return false;
+
+				}
+
+			}
+
+			function onDocumentKeyPress( event ) {
+
+				var keyCode = event.which;
+
+				// backspace
+
+				if ( keyCode == 8 ) {
+
+					event.preventDefault();
+
+				} else {
+
+					var ch = String.fromCharCode( keyCode );
+					text += ch;
+
+					refreshText();
+
+				}
+
+			}
+
+			function createText() {
+
+				textGeo = new THREE.TextGeometry( text, {
+
+					size: size,
+					height: height,
+					curveSegments: curveSegments,
+
+					font: font,
+					weight: weight,
+					style: style,
+
+					bevelThickness: bevelThickness,
+					bevelSize: bevelSize,
+					bevelEnabled: bevelEnabled,
+
+					material: 0,
+					extrudeMaterial: 1
+
+				});
+
+				textGeo.computeBoundingBox();
+				textGeo.computeVertexNormals();
+
+				// "fix" side normals by removing z-component of normals for side faces
+				// (this doesn't work well for beveled geometry as then we lose nice curvature around z-axis)
+
+				if ( ! bevelEnabled ) {
+
+					var triangleAreaHeuristics = 0.1 * ( height * size );
+
+					for ( var i = 0; i < textGeo.faces.length; i ++ ) {
+
+						var face = textGeo.faces[ i ];
+
+						if ( face.materialIndex == 1 ) {
+
+							for ( var j = 0; j < face.vertexNormals.length; j ++ ) {
+
+								face.vertexNormals[ j ].z = 0;
+								face.vertexNormals[ j ].normalize();
+
+							}
+
+							var va = textGeo.vertices[ face.a ];
+							var vb = textGeo.vertices[ face.b ];
+							var vc = textGeo.vertices[ face.c ];
+
+							var s = THREE.GeometryUtils.triangleArea( va, vb, vc );
+
+							if ( s > triangleAreaHeuristics ) {
+
+								for ( var j = 0; j < face.vertexNormals.length; j ++ ) {
+
+									face.vertexNormals[ j ].copy( face.normal );
+
+								}
+
+							}
+
+						}
+
+					}
+
+				}
+
+				var centerOffset = -0.5 * ( textGeo.boundingBox.max.x - textGeo.boundingBox.min.x );
+
+				textMesh1 = new THREE.Mesh( textGeo, material );
+
+				textMesh1.position.x = centerOffset;
+				textMesh1.position.y = hover;
+				textMesh1.position.z = 0;
+
+				textMesh1.rotation.x = 0;
+				textMesh1.rotation.y = Math.PI * 2;
+
+				group.add( textMesh1 );
+
+				if ( mirror ) {
+
+					textMesh2 = new THREE.Mesh( textGeo, material );
+
+					textMesh2.position.x = centerOffset;
+					textMesh2.position.y = -hover;
+					textMesh2.position.z = height;
+
+					textMesh2.rotation.x = Math.PI;
+					textMesh2.rotation.y = Math.PI * 2;
+
+					group.add( textMesh2 );
+
+				}
+
+			}
+
+			function refreshText() {
+
+				updatePermalink();
+
+				group.remove( textMesh1 );
+				if ( mirror ) group.remove( textMesh2 );
+
+				if ( !text ) return;
+
+				createText();
+
+			}
+
+			function onDocumentMouseDown( event ) {
+
+				event.preventDefault();
+
+				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.addEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.addEventListener( 'mouseout', onDocumentMouseOut, false );
+
+				mouseXOnMouseDown = event.clientX - windowHalfX;
+				targetRotationOnMouseDown = targetRotation;
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				mouseX = event.clientX - windowHalfX;
+
+				targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
+
+			}
+
+			function onDocumentMouseUp( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentMouseOut( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentTouchStart( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotationOnMouseDown = targetRotation;
+
+				}
+
+			}
+
+			function onDocumentTouchMove( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseX = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
+
+				}
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				group.rotation.y += ( targetRotation - group.rotation.y ) * 0.05;
+
+				camera.lookAt( cameraTarget );
+
+				renderer.clear();
+
+				if ( postprocessing.enabled ) {
+
+					composer.render( 0.05 );
+
+				} else {
+
+					renderer.render( scene, camera );
+
+				}
+
+			}
+
+		</script>
+
+	</body>
+</html>