Three.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author Larry Battle / http://bateru.com/news
  4. */
  5. var THREE = THREE || { REVISION: '55' };
  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. THREE.extend = function ( target, other ) {
  32. target = target || {};
  33. for (var prop in other) {
  34. if ( typeof other[prop] === 'object' ) {
  35. target[prop] = THREE.extend( target[prop], other[prop] );
  36. } else {
  37. target[prop] = other[prop];
  38. }
  39. }
  40. return target;
  41. };
  42. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  43. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  44. // requestAnimationFrame polyfill by Erik Möller
  45. // fixes from Paul Irish and Tino Zijdel
  46. ( function () {
  47. var lastTime = 0;
  48. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  49. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  50. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  51. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  52. }
  53. if ( window.requestAnimationFrame === undefined ) {
  54. window.requestAnimationFrame = function ( callback, element ) {
  55. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  56. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  57. lastTime = currTime + timeToCall;
  58. return id;
  59. };
  60. }
  61. window.cancelAnimationFrame = window.cancelAnimationFrame || function ( id ) { window.clearTimeout( id ) };
  62. }() );
  63. // GL STATE CONSTANTS
  64. THREE.CullFaceNone = 0;
  65. THREE.CullFaceBack = 1;
  66. THREE.CullFaceFront = 2;
  67. THREE.CullFaceFrontBack = 3;
  68. THREE.FrontFaceDirectionCW = 0;
  69. THREE.FrontFaceDirectionCCW = 1;
  70. // SHADOWING TYPES
  71. THREE.BasicShadowMap = 0;
  72. THREE.PCFShadowMap = 1;
  73. THREE.PCFSoftShadowMap = 2;
  74. // MATERIAL CONSTANTS
  75. // side
  76. THREE.FrontSide = 0;
  77. THREE.BackSide = 1;
  78. THREE.DoubleSide = 2;
  79. // shading
  80. THREE.NoShading = 0;
  81. THREE.FlatShading = 1;
  82. THREE.SmoothShading = 2;
  83. // colors
  84. THREE.NoColors = 0;
  85. THREE.FaceColors = 1;
  86. THREE.VertexColors = 2;
  87. // blending modes
  88. THREE.NoBlending = 0;
  89. THREE.NormalBlending = 1;
  90. THREE.AdditiveBlending = 2;
  91. THREE.SubtractiveBlending = 3;
  92. THREE.MultiplyBlending = 4;
  93. THREE.CustomBlending = 5;
  94. // custom blending equations
  95. // (numbers start from 100 not to clash with other
  96. // mappings to OpenGL constants defined in Texture.js)
  97. THREE.AddEquation = 100;
  98. THREE.SubtractEquation = 101;
  99. THREE.ReverseSubtractEquation = 102;
  100. // custom blending destination factors
  101. THREE.ZeroFactor = 200;
  102. THREE.OneFactor = 201;
  103. THREE.SrcColorFactor = 202;
  104. THREE.OneMinusSrcColorFactor = 203;
  105. THREE.SrcAlphaFactor = 204;
  106. THREE.OneMinusSrcAlphaFactor = 205;
  107. THREE.DstAlphaFactor = 206;
  108. THREE.OneMinusDstAlphaFactor = 207;
  109. // custom blending source factors
  110. //THREE.ZeroFactor = 200;
  111. //THREE.OneFactor = 201;
  112. //THREE.SrcAlphaFactor = 204;
  113. //THREE.OneMinusSrcAlphaFactor = 205;
  114. //THREE.DstAlphaFactor = 206;
  115. //THREE.OneMinusDstAlphaFactor = 207;
  116. THREE.DstColorFactor = 208;
  117. THREE.OneMinusDstColorFactor = 209;
  118. THREE.SrcAlphaSaturateFactor = 210;
  119. // TEXTURE CONSTANTS
  120. THREE.MultiplyOperation = 0;
  121. THREE.MixOperation = 1;
  122. THREE.AddOperation = 2;
  123. // Mapping modes
  124. THREE.UVMapping = function () {};
  125. THREE.CubeReflectionMapping = function () {};
  126. THREE.CubeRefractionMapping = function () {};
  127. THREE.SphericalReflectionMapping = function () {};
  128. THREE.SphericalRefractionMapping = function () {};
  129. // Wrapping modes
  130. THREE.RepeatWrapping = 1000;
  131. THREE.ClampToEdgeWrapping = 1001;
  132. THREE.MirroredRepeatWrapping = 1002;
  133. // Filters
  134. THREE.NearestFilter = 1003;
  135. THREE.NearestMipMapNearestFilter = 1004;
  136. THREE.NearestMipMapLinearFilter = 1005;
  137. THREE.LinearFilter = 1006;
  138. THREE.LinearMipMapNearestFilter = 1007;
  139. THREE.LinearMipMapLinearFilter = 1008;
  140. // Data types
  141. THREE.UnsignedByteType = 1009;
  142. THREE.ByteType = 1010;
  143. THREE.ShortType = 1011;
  144. THREE.UnsignedShortType = 1012;
  145. THREE.IntType = 1013;
  146. THREE.UnsignedIntType = 1014;
  147. THREE.FloatType = 1015;
  148. // Pixel types
  149. //THREE.UnsignedByteType = 1009;
  150. THREE.UnsignedShort4444Type = 1016;
  151. THREE.UnsignedShort5551Type = 1017;
  152. THREE.UnsignedShort565Type = 1018;
  153. // Pixel formats
  154. THREE.AlphaFormat = 1019;
  155. THREE.RGBFormat = 1020;
  156. THREE.RGBAFormat = 1021;
  157. THREE.LuminanceFormat = 1022;
  158. THREE.LuminanceAlphaFormat = 1023;
  159. // Compressed texture formats
  160. THREE.RGB_S3TC_DXT1_Format = 2001;
  161. THREE.RGBA_S3TC_DXT1_Format = 2002;
  162. THREE.RGBA_S3TC_DXT3_Format = 2003;
  163. THREE.RGBA_S3TC_DXT5_Format = 2004;
  164. /*
  165. // Potential future PVRTC compressed texture formats
  166. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  167. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  168. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  169. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  170. */