Three.js 5.1 KB

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