three_shim.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. !(function () {
  2. if (('performance' in window == 0 && (window.performance = {}), 'now' in window.performance == 0)) {
  3. var e = Date.now()
  4. performance.timing && performance.timing.navigationStart && (e = performance.timing.navigationStart),
  5. (window.performance.now = function () {
  6. return Date.now() - e
  7. })
  8. }
  9. })(),
  10. (THREE.WebGLRenderer.prototype.paramThreeToGL = function (e) {
  11. var t,
  12. i = this.extensions,
  13. r = this.getContext() // this.context
  14. if (e === THREE.RepeatWrapping) return r.REPEAT
  15. if (e === THREE.ClampToEdgeWrapping) return r.CLAMP_TO_EDGE
  16. if (e === THREE.MirroredRepeatWrapping) return r.MIRRORED_REPEAT
  17. if (e === THREE.NearestFilter) return r.NEAREST
  18. if (e === THREE.NearestMipMapNearestFilter) return r.NEAREST_MIPMAP_NEAREST
  19. if (e === THREE.NearestMipMapLinearFilter) return r.NEAREST_MIPMAP_LINEAR
  20. if (e === THREE.LinearFilter) return r.LINEAR
  21. if (e === THREE.LinearMipMapNearestFilter) return r.LINEAR_MIPMAP_NEAREST
  22. if (e === THREE.LinearMipMapLinearFilter) return r.LINEAR_MIPMAP_LINEAR
  23. if (e === THREE.UnsignedByteType) return r.UNSIGNED_BYTE
  24. if (e === THREE.UnsignedShort4444Type) return r.UNSIGNED_SHORT_4_4_4_4
  25. if (e === THREE.UnsignedShort5551Type) return r.UNSIGNED_SHORT_5_5_5_1
  26. if (e === THREE.UnsignedShort565Type) return r.UNSIGNED_SHORT_5_6_5
  27. if (e === THREE.ByteType) return r.BYTE
  28. if (e === THREE.ShortType) return r.SHORT
  29. if (e === THREE.UnsignedShortType) return r.UNSIGNED_SHORT
  30. if (e === THREE.IntType) return r.INT
  31. if (e === THREE.UnsignedIntType) return r.UNSIGNED_INT
  32. if (e === THREE.FloatType) return r.FLOAT
  33. if (e === THREE.HalfFloatType && i.get('OES_texture_half_float') !== null) return t.HALF_FLOAT_OES
  34. if (e === THREE.AlphaFormat) return r.ALPHA
  35. if (e === THREE.RGBFormat) return r.RGB
  36. if (e === THREE.RGBAFormat) return r.RGBA
  37. if (e === THREE.LuminanceFormat) return r.LUMINANCE
  38. if (e === THREE.LuminanceAlphaFormat) return r.LUMINANCE_ALPHA
  39. if (e === THREE.AddEquation) return r.FUNC_ADD
  40. if (e === THREE.SubtractEquation) return r.FUNC_SUBTRACT
  41. if (e === THREE.ReverseSubtractEquation) return r.FUNC_REVERSE_SUBTRACT
  42. if (e === THREE.ZeroFactor) return r.ZERO
  43. if (e === THREE.OneFactor) return r.ONE
  44. if (e === THREE.SrcColorFactor) return r.SRC_COLOR
  45. if (e === THREE.OneMinusSrcColorFactor) return r.ONE_MINUS_SRC_COLOR
  46. if (e === THREE.SrcAlphaFactor) return r.SRC_ALPHA
  47. if (e === THREE.OneMinusSrcAlphaFactor) return r.ONE_MINUS_SRC_ALPHA
  48. if (e === THREE.DstAlphaFactor) return r.DST_ALPHA
  49. if (e === THREE.OneMinusDstAlphaFactor) return r.ONE_MINUS_DST_ALPHA
  50. if (e === THREE.DstColorFactor) return r.DST_COLOR
  51. if (e === THREE.OneMinusDstColorFactor) return r.ONE_MINUS_DST_COLOR
  52. if (e === THREE.SrcAlphaSaturateFactor) return r.SRC_ALPHA_SATURATE
  53. if (((t = i.get('WEBGL_compressed_texture_s3tc')), null !== t)) {
  54. if (e === THREE.RGB_S3TC_DXT1_Format) return t.COMPRESSED_RGB_S3TC_DXT1_EXT
  55. if (e === THREE.RGBA_S3TC_DXT1_Format) return t.COMPRESSED_RGBA_S3TC_DXT1_EXT
  56. if (e === THREE.RGBA_S3TC_DXT3_Format) return t.COMPRESSED_RGBA_S3TC_DXT3_EXT
  57. if (e === THREE.RGBA_S3TC_DXT5_Format) return t.COMPRESSED_RGBA_S3TC_DXT5_EXT
  58. }
  59. if (((t = i.get('WEBGL_compressed_texture_pvrtc')), null !== t)) {
  60. if (e === THREE.RGB_PVRTC_4BPPV1_Format) return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  61. if (e === THREE.RGB_PVRTC_2BPPV1_Format) return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG
  62. if (e === THREE.RGBA_PVRTC_4BPPV1_Format) return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  63. if (e === THREE.RGBA_PVRTC_2BPPV1_Format) return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  64. }
  65. if (((t = i.get('WEBGL_compressed_texture_etc1')), null !== t && e === THREE.RGB_ETC1_Format)) return t.COMPRESSED_RGB_ETC1_WEBGL
  66. if (((t = i.get('EXT_blend_minmax')), null !== t)) {
  67. if (e === THREE.MinEquation) return t.MIN_EXT
  68. if (e === THREE.MaxEquation) return t.MAX_EXT
  69. }
  70. return 0
  71. }),
  72. (THREE.WebGLState = function (e, t, i) {
  73. var r = this,
  74. o = new THREE.Vector4(),
  75. a = e.getParameter(e.MAX_VERTEX_ATTRIBS),
  76. s = new Uint8Array(a),
  77. l = new Uint8Array(a),
  78. c = new Uint8Array(a),
  79. h = {},
  80. u = null,
  81. d = null,
  82. p = null,
  83. f = null,
  84. g = null,
  85. m = null,
  86. v = null,
  87. A = null,
  88. y = !1,
  89. C = null,
  90. I = null,
  91. E = null,
  92. b = null,
  93. w = null,
  94. _ = null,
  95. T = null,
  96. x = null,
  97. S = null,
  98. M = null,
  99. R = null,
  100. P = null,
  101. O = null,
  102. L = null,
  103. D = null,
  104. N = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),
  105. B = void 0,
  106. F = {},
  107. V = new THREE.Vector4(),
  108. U = null,
  109. k = null,
  110. H = new THREE.Vector4(),
  111. G = new THREE.Vector4()
  112. ;(this.init = function () {
  113. this.clearColor(0, 0, 0, 1),
  114. this.clearDepth(1),
  115. this.clearStencil(0),
  116. this.enable(e.DEPTH_TEST),
  117. e.depthFunc(e.LEQUAL),
  118. e.frontFace(e.CCW),
  119. e.cullFace(e.BACK),
  120. this.enable(e.CULL_FACE),
  121. this.enable(e.BLEND),
  122. e.blendEquation(e.FUNC_ADD),
  123. e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA)
  124. }),
  125. (this.initAttributes = function () {
  126. for (var e = 0, t = s.length; e < t; e++) s[e] = 0
  127. }),
  128. (this.enableAttribute = function (i) {
  129. if (((s[i] = 1), 0 === l[i] && (e.enableVertexAttribArray(i), (l[i] = 1)), 0 !== c[i])) {
  130. var n = t.get('ANGLE_instanced_arrays')
  131. n.vertexAttribDivisorANGLE(i, 0), (c[i] = 0)
  132. }
  133. }),
  134. (this.enableAttributeAndDivisor = function (t, i, n) {
  135. ;(s[t] = 1), 0 === l[t] && (e.enableVertexAttribArray(t), (l[t] = 1)), c[t] !== i && (n.vertexAttribDivisorANGLE(t, i), (c[t] = i))
  136. }),
  137. (this.disableUnusedAttributes = function () {
  138. for (var t = 0, i = l.length; t < i; t++) l[t] !== s[t] && (e.disableVertexAttribArray(t), (l[t] = 0))
  139. }),
  140. (this.enable = function (t) {
  141. h[t] !== !0 && (e.enable(t), (h[t] = !0))
  142. }),
  143. (this.disable = function (t) {
  144. h[t] !== !1 && (e.disable(t), (h[t] = !1))
  145. }),
  146. (this.getCompressedTextureFormats = function () {
  147. if (null === u && ((u = []), t.get('WEBGL_compressed_texture_pvrtc') || t.get('WEBGL_compressed_texture_s3tc') || t.get('WEBGL_compressed_texture_etc1')))
  148. for (var i = e.getParameter(e.COMPRESSED_TEXTURE_FORMATS), n = 0; n < i.length; n++) u.push(i[n])
  149. return u
  150. }),
  151. (this.setBlending = function (t, r, o, a, s, l, c, h) {
  152. t === THREE.NoBlending ? this.disable(e.BLEND) : this.enable(e.BLEND),
  153. (t === d && h === y) ||
  154. (t === THREE.AdditiveBlending
  155. ? h
  156. ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD), e.blendFuncSeparate(e.ONE, e.ONE, e.ONE, e.ONE))
  157. : (e.blendEquation(e.FUNC_ADD), e.blendFunc(e.SRC_ALPHA, e.ONE))
  158. : t === THREE.SubtractiveBlending
  159. ? h
  160. ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD), e.blendFuncSeparate(e.ZERO, e.ZERO, e.ONE_MINUS_SRC_COLOR, e.ONE_MINUS_SRC_ALPHA))
  161. : (e.blendEquation(e.FUNC_ADD), e.blendFunc(e.ZERO, e.ONE_MINUS_SRC_COLOR))
  162. : t === THREE.MultiplyBlending
  163. ? h
  164. ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD), e.blendFuncSeparate(e.ZERO, e.ZERO, e.SRC_COLOR, e.SRC_ALPHA))
  165. : (e.blendEquation(e.FUNC_ADD), e.blendFunc(e.ZERO, e.SRC_COLOR))
  166. : h
  167. ? (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD), e.blendFuncSeparate(e.ONE, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA))
  168. : (e.blendEquationSeparate(e.FUNC_ADD, e.FUNC_ADD), e.blendFuncSeparate(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA)),
  169. (d = t),
  170. (y = h)),
  171. t === THREE.CustomBlending
  172. ? ((s = s || r),
  173. (l = l || o),
  174. (c = c || a),
  175. (r === p && s === m) || (e.blendEquationSeparate(i(r), i(s)), (p = r), (m = s)),
  176. (o === f && a === g && l === v && c === A) || (e.blendFuncSeparate(i(o), i(a), i(l), i(c)), (f = o), (g = a), (v = l), (A = c)))
  177. : ((p = null), (f = null), (g = null), (m = null), (v = null), (A = null))
  178. }),
  179. (this.setDepthFunc = function (t) {
  180. if (C !== t) {
  181. if (t)
  182. switch (t) {
  183. case THREE.NeverDepth:
  184. e.depthFunc(e.NEVER)
  185. break
  186. case THREE.AlwaysDepth:
  187. e.depthFunc(e.ALWAYS)
  188. break
  189. case THREE.LessDepth:
  190. e.depthFunc(e.LESS)
  191. break
  192. case THREE.LessEqualDepth:
  193. e.depthFunc(e.LEQUAL)
  194. break
  195. case THREE.EqualDepth:
  196. e.depthFunc(e.EQUAL)
  197. break
  198. case THREE.GreaterEqualDepth:
  199. e.depthFunc(e.GEQUAL)
  200. break
  201. case THREE.GreaterDepth:
  202. e.depthFunc(e.GREATER)
  203. break
  204. case THREE.NotEqualDepth:
  205. e.depthFunc(e.NOTEQUAL)
  206. break
  207. default:
  208. e.depthFunc(e.LEQUAL)
  209. }
  210. else e.depthFunc(e.LEQUAL)
  211. C = t
  212. }
  213. }),
  214. (this.setDepthTest = function (t) {
  215. t ? this.enable(e.DEPTH_TEST) : this.disable(e.DEPTH_TEST)
  216. }),
  217. (this.setDepthWrite = function (t) {
  218. I !== t && (e.depthMask(t), (I = t))
  219. }),
  220. (this.setColorWrite = function (t) {
  221. E !== t && (e.colorMask(t, t, t, t), (E = t))
  222. }),
  223. (this.setStencilFunc = function (t, i, n) {
  224. ;(w === t && _ === i && T === n) || (e.stencilFunc(t, i, n), (w = t), (_ = i), (T = n))
  225. }),
  226. (this.setStencilOp = function (t, i, n) {
  227. ;(x === t && S === i && M === n) || (e.stencilOp(t, i, n), (x = t), (S = i), (M = n))
  228. }),
  229. (this.setStencilTest = function (t) {
  230. t ? this.enable(e.STENCIL_TEST) : this.disable(e.STENCIL_TEST)
  231. }),
  232. (this.setStencilWrite = function (t) {
  233. b !== t && (e.stencilMask(t), (b = t))
  234. }),
  235. (this.setFlipSided = function (t) {
  236. R !== t && (t ? e.frontFace(e.CW) : e.frontFace(e.CCW), (R = t))
  237. }),
  238. (this.setLineWidth = function (t) {
  239. t !== P && (e.lineWidth(t), (P = t))
  240. }),
  241. (this.setPolygonOffset = function (t, i, n) {
  242. t ? this.enable(e.POLYGON_OFFSET_FILL) : this.disable(e.POLYGON_OFFSET_FILL), !t || (O === i && L === n) || (e.polygonOffset(i, n), (O = i), (L = n))
  243. }),
  244. (this.getScissorTest = function () {
  245. return D
  246. }),
  247. (this.setScissorTest = function (t) {
  248. ;(D = t), t ? this.enable(e.SCISSOR_TEST) : this.disable(e.SCISSOR_TEST)
  249. }),
  250. (this.activeTexture = function (t) {
  251. void 0 === t && (t = e.TEXTURE0 + N - 1), B !== t && (e.activeTexture(t), (B = t))
  252. }),
  253. (this.bindTexture = function (t, i) {
  254. void 0 === B && r.activeTexture()
  255. var n = F[B]
  256. void 0 === n &&
  257. ((n = {
  258. type: void 0,
  259. texture: void 0,
  260. }),
  261. (F[B] = n)),
  262. (n.type === t && n.texture === i) || (e.bindTexture(t, i), (n.type = t), (n.texture = i))
  263. }),
  264. (this.compressedTexImage2D = function () {
  265. try {
  266. e.compressedTexImage2D.apply(e, arguments)
  267. } catch (e) {
  268. console.error(e)
  269. }
  270. }),
  271. (this.texImage2D = function () {
  272. try {
  273. e.texImage2D.apply(e, arguments)
  274. } catch (e) {
  275. console.error(e)
  276. }
  277. }),
  278. (this.clearColor = function (t, i, n, r) {
  279. o.set(t, i, n, r), V.equals(o) === !1 && (e.clearColor(t, i, n, r), V.copy(o))
  280. }),
  281. (this.clearDepth = function (t) {
  282. U !== t && (e.clearDepth(t), (U = t))
  283. }),
  284. (this.clearStencil = function (t) {
  285. k !== t && (e.clearStencil(t), (k = t))
  286. }),
  287. (this.scissor = function (t) {
  288. H.equals(t) === !1 && (e.scissor(t.x, t.y, t.z, t.w), H.copy(t))
  289. }),
  290. (this.viewport = function (t) {
  291. G.equals(t) === !1 && (e.viewport(t.x, t.y, t.z, t.w), G.copy(t))
  292. }),
  293. (this.reset = function () {
  294. for (var t = 0; t < l.length; t++) 1 === l[t] && (e.disableVertexAttribArray(t), (l[t] = 0))
  295. ;(h = {}), (u = null), (B = void 0), (F = {}), (d = null), (E = null), (I = null), (b = null), (R = null)
  296. })
  297. })