Three.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author Larry Battle / http://bateru.com/news
  4. */
  5. var THREE = THREE || { REVISION: '54dev' };
  6. self.console = self.console || {
  7. info: function () {},
  8. log: function () {},
  9. debug: function () {},
  10. warn: function () {},
  11. error: function () {}
  12. };
  13. self.Int32Array = self.Int32Array || Array;
  14. self.Float32Array = self.Float32Array || Array;
  15. // Shims for "startsWith", "endsWith", and "trim" for browsers where this is not yet implemented
  16. // not sure we should have this, or at least not have it here
  17. // http://stackoverflow.com/questions/646628/javascript-startswith
  18. // http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript
  19. // http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras
  20. String.prototype.startsWith = String.prototype.startsWith || function ( str ) {
  21. return this.slice( 0, str.length ) === str;
  22. };
  23. String.prototype.endsWith = String.prototype.endsWith || function ( str ) {
  24. var t = String( str );
  25. var index = this.lastIndexOf( t );
  26. return ( -1 < index && index ) === (this.length - t.length);
  27. };
  28. String.prototype.trim = String.prototype.trim || function () {
  29. return this.replace( /^\s+|\s+$/g, '' );
  30. };
  31. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  32. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  33. // requestAnimationFrame polyfill by Erik Möller
  34. // fixes from Paul Irish and Tino Zijdel
  35. ( function () {
  36. var lastTime = 0;
  37. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  38. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  39. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  40. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  41. }
  42. if ( window.requestAnimationFrame === undefined ) {
  43. window.requestAnimationFrame = function ( callback, element ) {
  44. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  45. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  46. lastTime = currTime + timeToCall;
  47. return id;
  48. };
  49. }
  50. window.cancelAnimationFrame = window.cancelAnimationFrame || function ( id ) { window.clearTimeout( id ) };
  51. }() );
  52. // GL STATE CONSTANTS
  53. THREE.CullFaceNone = 0;
  54. THREE.CullFaceBack = 1;
  55. THREE.CullFaceFront = 2;
  56. THREE.CullFaceFrontBack = 3;
  57. THREE.FrontFaceDirectionCW = 0;
  58. THREE.FrontFaceDirectionCCW = 1;
  59. // MATERIAL CONSTANTS
  60. // side
  61. THREE.FrontSide = 0;
  62. THREE.BackSide = 1;
  63. THREE.DoubleSide = 2;
  64. // shading
  65. THREE.NoShading = 0;
  66. THREE.FlatShading = 1;
  67. THREE.SmoothShading = 2;
  68. // colors
  69. THREE.NoColors = 0;
  70. THREE.FaceColors = 1;
  71. THREE.VertexColors = 2;
  72. // blending modes
  73. THREE.NoBlending = 0;
  74. THREE.NormalBlending = 1;
  75. THREE.AdditiveBlending = 2;
  76. THREE.SubtractiveBlending = 3;
  77. THREE.MultiplyBlending = 4;
  78. THREE.CustomBlending = 5;
  79. // custom blending equations
  80. // (numbers start from 100 not to clash with other
  81. // mappings to OpenGL constants defined in Texture.js)
  82. THREE.AddEquation = 100;
  83. THREE.SubtractEquation = 101;
  84. THREE.ReverseSubtractEquation = 102;
  85. // custom blending destination factors
  86. THREE.ZeroFactor = 200;
  87. THREE.OneFactor = 201;
  88. THREE.SrcColorFactor = 202;
  89. THREE.OneMinusSrcColorFactor = 203;
  90. THREE.SrcAlphaFactor = 204;
  91. THREE.OneMinusSrcAlphaFactor = 205;
  92. THREE.DstAlphaFactor = 206;
  93. THREE.OneMinusDstAlphaFactor = 207;
  94. // custom blending source factors
  95. //THREE.ZeroFactor = 200;
  96. //THREE.OneFactor = 201;
  97. //THREE.SrcAlphaFactor = 204;
  98. //THREE.OneMinusSrcAlphaFactor = 205;
  99. //THREE.DstAlphaFactor = 206;
  100. //THREE.OneMinusDstAlphaFactor = 207;
  101. THREE.DstColorFactor = 208;
  102. THREE.OneMinusDstColorFactor = 209;
  103. THREE.SrcAlphaSaturateFactor = 210;
  104. // TEXTURE CONSTANTS
  105. THREE.MultiplyOperation = 0;
  106. THREE.MixOperation = 1;
  107. THREE.AddOperation = 2;
  108. // Mapping modes
  109. THREE.UVMapping = function () {};
  110. THREE.CubeReflectionMapping = function () {};
  111. THREE.CubeRefractionMapping = function () {};
  112. THREE.SphericalReflectionMapping = function () {};
  113. THREE.SphericalRefractionMapping = function () {};
  114. // Wrapping modes
  115. THREE.RepeatWrapping = 1000;
  116. THREE.ClampToEdgeWrapping = 1001;
  117. THREE.MirroredRepeatWrapping = 1002;
  118. // Filters
  119. THREE.NearestFilter = 1003;
  120. THREE.NearestMipMapNearestFilter = 1004;
  121. THREE.NearestMipMapLinearFilter = 1005;
  122. THREE.LinearFilter = 1006;
  123. THREE.LinearMipMapNearestFilter = 1007;
  124. THREE.LinearMipMapLinearFilter = 1008;
  125. // Data types
  126. THREE.UnsignedByteType = 1009;
  127. THREE.ByteType = 1010;
  128. THREE.ShortType = 1011;
  129. THREE.UnsignedShortType = 1012;
  130. THREE.IntType = 1013;
  131. THREE.UnsignedIntType = 1014;
  132. THREE.FloatType = 1015;
  133. // Pixel types
  134. //THREE.UnsignedByteType = 1009;
  135. THREE.UnsignedShort4444Type = 1016;
  136. THREE.UnsignedShort5551Type = 1017;
  137. THREE.UnsignedShort565Type = 1018;
  138. // Pixel formats
  139. THREE.AlphaFormat = 1019;
  140. THREE.RGBFormat = 1020;
  141. THREE.RGBAFormat = 1021;
  142. THREE.LuminanceFormat = 1022;
  143. THREE.LuminanceAlphaFormat = 1023;
  144. // Compressed texture formats
  145. THREE.RGB_S3TC_DXT1_Format = 2001;
  146. THREE.RGBA_S3TC_DXT1_Format = 2002;
  147. THREE.RGBA_S3TC_DXT3_Format = 2003;
  148. THREE.RGBA_S3TC_DXT5_Format = 2004;
  149. /*
  150. // Potential future PVRTC compressed texture formats
  151. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  152. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  153. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  154. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  155. */