Three.js 5.1 KB

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