three.shim.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. import * as THREE from "../../libs/three.js/build/three.module.js";
  2. !function() {
  3. if ("performance"in window == 0 && (window.performance = {}),
  4. "now"in window.performance == 0) {
  5. var e = Date.now();
  6. performance.timing && performance.timing.navigationStart && (e = performance.timing.navigationStart),
  7. window.performance.now = function() {
  8. return Date.now() - e
  9. }
  10. }
  11. }(),
  12. THREE.WebGLRenderer.prototype.paramThreeToGL = function(e) {
  13. var t, i = this.extensions, r = this.getContext();//context;
  14. if (e === THREE.RepeatWrapping)
  15. return r.REPEAT;
  16. if (e === THREE.ClampToEdgeWrapping)
  17. return r.CLAMP_TO_EDGE;
  18. if (e === THREE.MirroredRepeatWrapping)
  19. return r.MIRRORED_REPEAT;
  20. if (e === THREE.NearestFilter)
  21. return r.NEAREST;
  22. if (e === THREE.NearestMipMapNearestFilter)
  23. return r.NEAREST_MIPMAP_NEAREST;
  24. if (e === THREE.NearestMipMapLinearFilter)
  25. return r.NEAREST_MIPMAP_LINEAR;
  26. if (e === THREE.LinearFilter)
  27. return r.LINEAR;
  28. if (e === THREE.LinearMipMapNearestFilter)
  29. return r.LINEAR_MIPMAP_NEAREST;
  30. if (e === THREE.LinearMipMapLinearFilter)
  31. return r.LINEAR_MIPMAP_LINEAR;
  32. if (e === THREE.UnsignedByteType)
  33. return r.UNSIGNED_BYTE;
  34. if (e === THREE.UnsignedShort4444Type)
  35. return r.UNSIGNED_SHORT_4_4_4_4;
  36. if (e === THREE.UnsignedShort5551Type)
  37. return r.UNSIGNED_SHORT_5_5_5_1;
  38. if (e === THREE.UnsignedShort565Type)
  39. return r.UNSIGNED_SHORT_5_6_5;
  40. if (e === THREE.ByteType)
  41. return r.BYTE;
  42. if (e === THREE.ShortType)
  43. return r.SHORT;
  44. if (e === THREE.UnsignedShortType)
  45. return r.UNSIGNED_SHORT;
  46. if (e === THREE.IntType)
  47. return r.INT;
  48. if (e === THREE.UnsignedIntType)
  49. return r.UNSIGNED_INT;
  50. if (e === THREE.FloatType)
  51. return r.FLOAT;
  52. if (t = i.get("OES_texture_half_float"),
  53. null !== t && e === THREE.HalfFloatType)
  54. return t.HALF_FLOAT_OES;
  55. if (e === THREE.AlphaFormat)
  56. return r.ALPHA;
  57. if (e === THREE.RGBFormat)
  58. return r.RGB;
  59. if (e === THREE.RGBAFormat)
  60. return r.RGBA;
  61. if (e === THREE.LuminanceFormat)
  62. return r.LUMINANCE;
  63. if (e === THREE.LuminanceAlphaFormat)
  64. return r.LUMINANCE_ALPHA;
  65. if (e === THREE.AddEquation)
  66. return r.FUNC_ADD;
  67. if (e === THREE.SubtractEquation)
  68. return r.FUNC_SUBTRACT;
  69. if (e === THREE.ReverseSubtractEquation)
  70. return r.FUNC_REVERSE_SUBTRACT;
  71. if (e === THREE.ZeroFactor)
  72. return r.ZERO;
  73. if (e === THREE.OneFactor)
  74. return r.ONE;
  75. if (e === THREE.SrcColorFactor)
  76. return r.SRC_COLOR;
  77. if (e === THREE.OneMinusSrcColorFactor)
  78. return r.ONE_MINUS_SRC_COLOR;
  79. if (e === THREE.SrcAlphaFactor)
  80. return r.SRC_ALPHA;
  81. if (e === THREE.OneMinusSrcAlphaFactor)
  82. return r.ONE_MINUS_SRC_ALPHA;
  83. if (e === THREE.DstAlphaFactor)
  84. return r.DST_ALPHA;
  85. if (e === THREE.OneMinusDstAlphaFactor)
  86. return r.ONE_MINUS_DST_ALPHA;
  87. if (e === THREE.DstColorFactor)
  88. return r.DST_COLOR;
  89. if (e === THREE.OneMinusDstColorFactor)
  90. return r.ONE_MINUS_DST_COLOR;
  91. if (e === THREE.SrcAlphaSaturateFactor)
  92. return r.SRC_ALPHA_SATURATE;
  93. if (t = i.get("WEBGL_compressed_texture_s3tc"),
  94. null !== t) {
  95. if (e === THREE.RGB_S3TC_DXT1_Format)
  96. return t.COMPRESSED_RGB_S3TC_DXT1_EXT;
  97. if (e === THREE.RGBA_S3TC_DXT1_Format)
  98. return t.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  99. if (e === THREE.RGBA_S3TC_DXT3_Format)
  100. return t.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  101. if (e === THREE.RGBA_S3TC_DXT5_Format)
  102. return t.COMPRESSED_RGBA_S3TC_DXT5_EXT
  103. }
  104. if (t = i.get("WEBGL_compressed_texture_pvrtc"),
  105. null !== t) {
  106. if (e === THREE.RGB_PVRTC_4BPPV1_Format)
  107. return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  108. if (e === THREE.RGB_PVRTC_2BPPV1_Format)
  109. return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  110. if (e === THREE.RGBA_PVRTC_4BPPV1_Format)
  111. return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  112. if (e === THREE.RGBA_PVRTC_2BPPV1_Format)
  113. return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  114. }
  115. if (t = i.get("WEBGL_compressed_texture_etc1"),
  116. null !== t && e === THREE.RGB_ETC1_Format)
  117. return t.COMPRESSED_RGB_ETC1_WEBGL;
  118. if (t = i.get("EXT_blend_minmax"),
  119. null !== t) {
  120. if (e === THREE.MinEquation)
  121. return t.MIN_EXT;
  122. if (e === THREE.MaxEquation)
  123. return t.MAX_EXT
  124. }
  125. return 0
  126. }
  127. /* ,
  128. THREE.WebGLState = function(e, t, i) {
  129. var r = this
  130. , o = new THREE.Vector4
  131. , a = e.getParameter(e.MAX_VERTEX_ATTRIBS)
  132. , s = new Uint8Array(a)
  133. , l = new Uint8Array(a)
  134. , c = new Uint8Array(a)
  135. , h = {}
  136. , u = null
  137. , d = null
  138. , p = null
  139. , f = null
  140. , g = null
  141. , m = null
  142. , v = null
  143. , A = null
  144. , y = !1
  145. , C = null
  146. , I = null
  147. , E = null
  148. , b = null
  149. , w = null
  150. , _ = null
  151. , T = null
  152. , x = null
  153. , S = null
  154. , M = null
  155. , R = null
  156. , P = null
  157. , O = null
  158. , L = null
  159. , D = null
  160. , N = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)
  161. , B = void 0
  162. , F = {}
  163. , V = new THREE.Vector4
  164. , U = null
  165. , k = null
  166. , H = new THREE.Vector4
  167. , G = new THREE.Vector4;
  168. this.init = function() {
  169. this.clearColor(0, 0, 0, 1),
  170. this.clearDepth(1),
  171. this.clearStencil(0),
  172. this.enable(e.DEPTH_TEST),
  173. e.depthFunc(e.LEQUAL),
  174. e.frontFace(e.CCW),
  175. e.cullFace(e.BACK),
  176. this.enable(e.CULL_FACE),
  177. this.enable(e.BLEND),
  178. e.blendEquation(e.FUNC_ADD),
  179. e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA)
  180. }
  181. ,
  182. this.initAttributes = function() {
  183. for (var e = 0, t = s.length; e < t; e++)
  184. s[e] = 0
  185. }
  186. ,
  187. this.enableAttribute = function(i) {
  188. if (s[i] = 1,
  189. 0 === l[i] && (e.enableVertexAttribArray(i),
  190. l[i] = 1),
  191. 0 !== c[i]) {
  192. var n = t.get("ANGLE_instanced_arrays");
  193. n.vertexAttribDivisorANGLE(i, 0),
  194. c[i] = 0
  195. }
  196. }
  197. ,
  198. this.enableAttributeAndDivisor = function(t, i, n) {
  199. s[t] = 1,
  200. 0 === l[t] && (e.enableVertexAttribArray(t),
  201. l[t] = 1),
  202. c[t] !== i && (n.vertexAttribDivisorANGLE(t, i),
  203. c[t] = i)
  204. }
  205. ,
  206. this.disableUnusedAttributes = function() {
  207. for (var t = 0, i = l.length; t < i; t++)
  208. l[t] !== s[t] && (e.disableVertexAttribArray(t),
  209. l[t] = 0)
  210. }
  211. ,
  212. this.enable = function(t) {
  213. h[t] !== !0 && (e.enable(t),
  214. h[t] = !0)
  215. }
  216. ,
  217. this.disable = function(t) {
  218. h[t] !== !1 && (e.disable(t),
  219. h[t] = !1)
  220. }
  221. ,
  222. this.getCompressedTextureFormats = function() {
  223. if (null === u && (u = [],
  224. t.get("WEBGL_compressed_texture_pvrtc") || t.get("WEBGL_compressed_texture_s3tc") || t.get("WEBGL_compressed_texture_etc1")))
  225. for (var i = e.getParameter(e.COMPRESSED_TEXTURE_FORMATS), n = 0; n < i.length; n++)
  226. u.push(i[n]);
  227. return u
  228. }
  229. ,
  230. this.setBlending = function(t, r, o, a, s, l, c, h) {
  231. t === THREE.NoBlending ? this.disable(e.BLEND) : this.enable(e.BLEND),
  232. t === d && h === y || (t === THREE.AdditiveBlending ? h ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD),
  233. e.blendFuncSeparate(e.ONE, e.ONE, e.ONE, e.ONE)) : (e.blendEquation(e.FUNC_ADD),
  234. e.blendFunc(e.SRC_ALPHA, e.ONE)) : t === THREE.SubtractiveBlending ? h ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD),
  235. e.blendFuncSeparate(e.ZERO, e.ZERO, e.ONE_MINUS_SRC_COLOR, e.ONE_MINUS_SRC_ALPHA)) : (e.blendEquation(e.FUNC_ADD),
  236. e.blendFunc(e.ZERO, e.ONE_MINUS_SRC_COLOR)) : t === THREE.MultiplyBlending ? h ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD),
  237. e.blendFuncSeparate(e.ZERO, e.ZERO, e.SRC_COLOR, e.SRC_ALPHA)) : (e.blendEquation(e.FUNC_ADD),
  238. e.blendFunc(e.ZERO, e.SRC_COLOR)) : h ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD),
  239. e.blendFuncSeparate(e.ONE, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA)) : (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD),
  240. e.blendFuncSeparate(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA)),
  241. d = t,
  242. y = h),
  243. t === THREE.CustomBlending ? (s = s || r,
  244. l = l || o,
  245. c = c || a,
  246. r === p && s === m || (e.blendEquationSeparate(i(r), i(s)),
  247. p = r,
  248. m = s),
  249. o === f && a === g && l === v && c === A || (e.blendFuncSeparate(i(o), i(a), i(l), i(c)),
  250. f = o,
  251. g = a,
  252. v = l,
  253. A = c)) : (p = null,
  254. f = null,
  255. g = null,
  256. m = null,
  257. v = null,
  258. A = null)
  259. }
  260. ,
  261. this.setDepthFunc = function(t) {
  262. if (C !== t) {
  263. if (t)
  264. switch (t) {
  265. case THREE.NeverDepth:
  266. e.depthFunc(e.NEVER);
  267. break;
  268. case THREE.AlwaysDepth:
  269. e.depthFunc(e.ALWAYS);
  270. break;
  271. case THREE.LessDepth:
  272. e.depthFunc(e.LESS);
  273. break;
  274. case THREE.LessEqualDepth:
  275. e.depthFunc(e.LEQUAL);
  276. break;
  277. case THREE.EqualDepth:
  278. e.depthFunc(e.EQUAL);
  279. break;
  280. case THREE.GreaterEqualDepth:
  281. e.depthFunc(e.GEQUAL);
  282. break;
  283. case THREE.GreaterDepth:
  284. e.depthFunc(e.GREATER);
  285. break;
  286. case THREE.NotEqualDepth:
  287. e.depthFunc(e.NOTEQUAL);
  288. break;
  289. default:
  290. e.depthFunc(e.LEQUAL)
  291. }
  292. else
  293. e.depthFunc(e.LEQUAL);
  294. C = t
  295. }
  296. }
  297. ,
  298. this.setDepthTest = function(t) {
  299. t ? this.enable(e.DEPTH_TEST) : this.disable(e.DEPTH_TEST)
  300. }
  301. ,
  302. this.setDepthWrite = function(t) {
  303. I !== t && (e.depthMask(t),
  304. I = t)
  305. }
  306. ,
  307. this.setColorWrite = function(t) {
  308. E !== t && (e.colorMask(t, t, t, t),
  309. E = t)
  310. }
  311. ,
  312. this.setStencilFunc = function(t, i, n) {
  313. w === t && _ === i && T === n || (e.stencilFunc(t, i, n),
  314. w = t,
  315. _ = i,
  316. T = n)
  317. }
  318. ,
  319. this.setStencilOp = function(t, i, n) {
  320. x === t && S === i && M === n || (e.stencilOp(t, i, n),
  321. x = t,
  322. S = i,
  323. M = n)
  324. }
  325. ,
  326. this.setStencilTest = function(t) {
  327. t ? this.enable(e.STENCIL_TEST) : this.disable(e.STENCIL_TEST)
  328. }
  329. ,
  330. this.setStencilWrite = function(t) {
  331. b !== t && (e.stencilMask(t),
  332. b = t)
  333. }
  334. ,
  335. this.setFlipSided = function(t) {
  336. R !== t && (t ? e.frontFace(e.CW) : e.frontFace(e.CCW),
  337. R = t)
  338. }
  339. ,
  340. this.setLineWidth = function(t) {
  341. t !== P && (e.lineWidth(t),
  342. P = t)
  343. }
  344. ,
  345. this.setPolygonOffset = function(t, i, n) {
  346. t ? this.enable(e.POLYGON_OFFSET_FILL) : this.disable(e.POLYGON_OFFSET_FILL),
  347. !t || O === i && L === n || (e.polygonOffset(i, n),
  348. O = i,
  349. L = n)
  350. }
  351. ,
  352. this.getScissorTest = function() {
  353. return D
  354. }
  355. ,
  356. this.setScissorTest = function(t) {
  357. D = t,
  358. t ? this.enable(e.SCISSOR_TEST) : this.disable(e.SCISSOR_TEST)
  359. }
  360. ,
  361. this.activeTexture = function(t) {
  362. void 0 === t && (t = e.TEXTURE0 + N - 1),
  363. B !== t && (e.activeTexture(t),
  364. B = t)
  365. }
  366. ,
  367. this.bindTexture = function(t, i) {
  368. void 0 === B && r.activeTexture();
  369. var n = F[B];
  370. void 0 === n && (n = {
  371. type: void 0,
  372. texture: void 0
  373. },
  374. F[B] = n),
  375. n.type === t && n.texture === i || (e.bindTexture(t, i),
  376. n.type = t,
  377. n.texture = i)
  378. }
  379. ,
  380. this.compressedTexImage2D = function() {
  381. try {
  382. e.compressedTexImage2D.apply(e, arguments)
  383. } catch (e) {
  384. console.error(e)
  385. }
  386. }
  387. ,
  388. this.texImage2D = function() {
  389. try {
  390. e.texImage2D.apply(e, arguments)
  391. } catch (e) {
  392. console.error(e)
  393. }
  394. }
  395. ,
  396. this.clearColor = function(t, i, n, r) {
  397. o.set(t, i, n, r),
  398. V.equals(o) === !1 && (e.clearColor(t, i, n, r),
  399. V.copy(o))
  400. }
  401. ,
  402. this.clearDepth = function(t) {
  403. U !== t && (e.clearDepth(t),
  404. U = t)
  405. }
  406. ,
  407. this.clearStencil = function(t) {
  408. k !== t && (e.clearStencil(t),
  409. k = t)
  410. }
  411. ,
  412. this.scissor = function(t) {
  413. H.equals(t) === !1 && (e.scissor(t.x, t.y, t.z, t.w),
  414. H.copy(t))
  415. }
  416. ,
  417. this.viewport = function(t) {
  418. G.equals(t) === !1 && (e.viewport(t.x, t.y, t.z, t.w),
  419. G.copy(t))
  420. }
  421. ,
  422. this.reset = function() {
  423. for (var t = 0; t < l.length; t++)
  424. 1 === l[t] && (e.disableVertexAttribArray(t),
  425. l[t] = 0);
  426. h = {},
  427. u = null,
  428. B = void 0,
  429. F = {},
  430. d = null,
  431. E = null,
  432. I = null,
  433. b = null,
  434. R = null
  435. }
  436. } */