babylonjs.expand.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. BABYLON.AssetContainer.prototype.clone = function(d, o=!0, s, c=!0) {
  2. const _ = new BABYLON.AssetContainer(this.scene);
  3. d || (d = "");
  4. const b = tt=>d + "_CloneOf_" + tt
  5. , k = {}
  6. , j = {}
  7. , $ = []
  8. , _e = [];
  9. s || (s = {
  10. doNotInstantiate: !0
  11. });
  12. const et = (tt,rt)=>{
  13. if (k[tt.uniqueId] = rt.uniqueId,
  14. j[rt.uniqueId] = rt,
  15. b && (rt.name = b(tt.name)),
  16. rt instanceof Mesh) {
  17. const it = rt;
  18. if (_.meshes.push(rt),
  19. rt.geometry && _.geometries.push(rt.geometry),
  20. it.morphTargetManager) {
  21. const nt = tt.morphTargetManager;
  22. it.morphTargetManager = nt.clone(),
  23. _.morphTargetManagers.push(it.morphTargetManager);
  24. for (let at = 0; at < nt.numTargets; at++) {
  25. const ot = nt.getTarget(at)
  26. , st = it.morphTargetManager.getTarget(at);
  27. k[ot.uniqueId] = st.uniqueId,
  28. j[st.uniqueId] = st
  29. }
  30. }
  31. } else
  32. rt instanceof TransformNode && _.transformNodes.push(rt)
  33. }
  34. ;
  35. return this.transformNodes.forEach(tt=>{
  36. if (!tt.parent) {
  37. const rt = tt.instantiateHierarchy(null, s, (it,nt)=>{
  38. et(it, nt)
  39. }
  40. );
  41. rt && _.rootNodes.push(rt)
  42. }
  43. }
  44. ),
  45. this.meshes.forEach(tt=>{
  46. if (!tt.parent) {
  47. const rt = tt.instantiateHierarchy(null, s, (it,nt)=>{
  48. if (et(it, nt),
  49. nt.material) {
  50. const at = nt;
  51. if (at.material)
  52. if (o) {
  53. const ot = it.material;
  54. if (_e.indexOf(ot) === -1) {
  55. let st = ot.clone(b ? b(ot.name) : "Clone of " + ot.name);
  56. if (_.materials.push(st),
  57. _e.push(ot),
  58. k[ot.uniqueId] = st.uniqueId,
  59. j[st.uniqueId] = st,
  60. ot.getClassName() === "MultiMaterial") {
  61. const lt = ot;
  62. for (const ut of lt.subMaterials)
  63. !ut || (st = ut.clone(b ? b(ut.name) : "Clone of " + ut.name),
  64. _e.push(ut),
  65. k[ut.uniqueId] = st.uniqueId,
  66. j[st.uniqueId] = st);
  67. lt.subMaterials = lt.subMaterials.map(ut=>ut && j[k[ut.uniqueId]]),
  68. _.multiMaterials.push(lt)
  69. }
  70. }
  71. at.getClassName() !== "InstancedMesh" && (at.material = j[k[ot.uniqueId]])
  72. } else
  73. at.material.getClassName() === "MultiMaterial" ? (this.scene.multiMaterials.indexOf(at.material) === -1 && this.scene.addMultiMaterial(at.material),
  74. _.multiMaterials.indexOf(at.material) === -1 && _.multiMaterials.push(at.material)) : (this.scene.materials.indexOf(at.material) === -1 && this.scene.addMaterial(at.material),
  75. _.materials.indexOf(at.material) === -1 && _.materials.push(at.material))
  76. }
  77. }
  78. );
  79. rt && _.rootNodes.push(rt)
  80. }
  81. }
  82. ),
  83. this.skeletons.forEach(tt=>{
  84. const rt = tt.clone(b ? b(tt.name) : "Clone of " + tt.name);
  85. tt.overrideMesh && (rt.overrideMesh = j[k[tt.overrideMesh.uniqueId]]);
  86. for (const it of this.meshes)
  87. if (it.skeleton === tt && !it.isAnInstance) {
  88. const nt = j[k[it.uniqueId]];
  89. if (nt.isAnInstance || (nt.skeleton = rt,
  90. $.indexOf(rt) !== -1))
  91. continue;
  92. $.push(rt);
  93. for (const at of rt.bones)
  94. at._linkedTransformNode && (at._linkedTransformNode = j[k[at._linkedTransformNode.uniqueId]])
  95. }
  96. _.skeletons.push(rt)
  97. }
  98. ),
  99. this.animationGroups.forEach(tt=>{
  100. const rt = tt.clone(tt.name, it=>j[k[it.uniqueId]] || it, c);
  101. _.animationGroups.push(rt)
  102. }
  103. ),
  104. this.textures.forEach(tt=>{
  105. const rt = tt.clone();
  106. rt && _.textures.push(rt)
  107. }
  108. ),
  109. this.cameras.forEach(tt=>{
  110. _.cameras.push(tt.clone(b(tt.name)))
  111. }
  112. ),
  113. this.lights.forEach(tt=>{
  114. const rt = tt.clone(b(tt.name));
  115. rt && _.lights.push(rt)
  116. }
  117. ),
  118. _
  119. }
  120. ;
  121. BABYLON.AssetContainer.prototype.GetName = function() {
  122. return this._name || (this._name = ""),
  123. this._name
  124. }
  125. ;
  126. BABYLON.AssetContainer.prototype.SetName = function(d) {
  127. this._name = d
  128. }
  129. ;
  130. BABYLON.AssetContainer.prototype.GetRootNode = function() {
  131. return this._rootNode || (this._rootNode = this.meshes[0]),
  132. this._rootNode
  133. }
  134. ;
  135. BABYLON.AssetContainer.prototype.CreateRootNodeByName = function(d) {
  136. const o = new Mesh("BABYLON.AssetContainerRootMesh_" + d,this.scene);
  137. return this.meshes.forEach(s=>{
  138. s.parent || o.addChild(s)
  139. }
  140. ),
  141. this.meshes.unshift(o),
  142. o
  143. }
  144. ;
  145. BABYLON.AssetContainer.prototype.GetMeshesWithoutParent = function() {
  146. const d = new Array;
  147. return this.meshes.forEach(o=>{
  148. o.parent || d.push(o)
  149. }
  150. ),
  151. d
  152. }
  153. ;
  154. BABYLON.AssetContainer.prototype.GetOwner = function() {
  155. return this._owner
  156. }
  157. ;
  158. BABYLON.AssetContainer.prototype.SetOwner = function(d) {
  159. this._owner || (this._owner = new XObject),
  160. this._owner = d
  161. }
  162. ;
  163. BABYLON.AssetContainer.prototype.toJSON = function() {
  164. const d = this.GetOwner()
  165. , o = d == null ? void 0 : d.outer;
  166. return o ? o.SaveAsset(this) : ""
  167. }
  168. ;
  169. BABYLON.AssetContainer.prototype.getClassName = function() {
  170. return "BABYLON.AssetContainer"
  171. }
  172. ;
  173. function CreateScreenshot(d, o, s, c, _="image/png", b=!1) {
  174. const {height: k, width: j} = _getScreenshotSize(d, o, s);
  175. if (console.info("[Engine]CreateScreenshot!"),
  176. !(k && j)) {
  177. console.error("[Engine]CreateScreenshot Invalid 'size' parameter !");
  178. return
  179. }
  180. BABYLON.Tools._ScreenshotCanvas || (BABYLON.Tools._ScreenshotCanvas = document.createElement("canvas")),
  181. BABYLON.Tools._ScreenshotCanvas.width = j,
  182. BABYLON.Tools._ScreenshotCanvas.height = k;
  183. const $ = BABYLON.Tools._ScreenshotCanvas.getContext("2d")
  184. , _e = d.getRenderWidth() / d.getRenderHeight();
  185. let et = j
  186. , tt = et / _e;
  187. tt > k && (tt = k,
  188. et = tt * _e);
  189. const rt = Math.max(0, j - et) / 2
  190. , it = Math.max(0, k - tt) / 2;
  191. o.getScene().onAfterRenderObservable.addOnce(function() {
  192. const at = d.getRenderingCanvas();
  193. $ && at ? $.drawImage(at, rt, it, et, tt) : console.error("[Engine]CreateScreenshot Invalid renderContext and renderingCanvas!"),
  194. b ? (BABYLON.Tools.EncodeScreenshotCanvasData(void 0, _),
  195. c && c("")) : BABYLON.Tools.EncodeScreenshotCanvasData(c, _)
  196. })
  197. }
  198. function CreateScreenshotAsync(d, o, s, c="image/png") {
  199. return new Promise((_,b)=>{
  200. CreateScreenshot(d, o, s, k=>{
  201. typeof k != "undefined" ? _(k) : b(new Error("Data is undefined"))
  202. }
  203. , c)
  204. }
  205. )
  206. }
  207. function CreateScreenshotUsingRenderTarget(d, o, s, c, _="image/png", b=1, k=!1, j, $=!1, _e=!1) {
  208. const {height: et, width: tt} = _getScreenshotSize(d, o, s)
  209. , rt = {
  210. width: tt,
  211. height: et
  212. };
  213. if (!(et && tt)) {
  214. console.error("Invalid 'size' parameter !");
  215. return
  216. }
  217. const it = o.getScene();
  218. let nt = null;
  219. const at = it.activeCameras;
  220. it.activeCameras = null,
  221. it.activeCamera !== o && (nt = it.activeCamera,
  222. it.activeCamera = o),
  223. it.render();
  224. const ot = new RenderTargetTexture("screenShot",rt,it,!1,!1,Constants.TEXTURETYPE_UNSIGNED_INT,!1,Texture.NEAREST_SAMPLINGMODE,void 0,_e,void 0,void 0,void 0,b);
  225. ot.renderList = null,
  226. ot.samples = b,
  227. ot.renderSprites = $,
  228. it.onAfterRenderTargetsRenderObservable.addOnce(function() {
  229. ot.readPixels(void 0, void 0, void 0, !1).then(lt=>{
  230. BABYLON.Tools.DumpData(tt, et, lt, c, _, j, !0),
  231. ot.dispose()
  232. }
  233. )
  234. });
  235. const st = ()=>{
  236. it.incrementRenderId(),
  237. it.resetCachedMaterial(),
  238. ot.render(!0),
  239. it.incrementRenderId(),
  240. it.resetCachedMaterial(),
  241. nt && (it.activeCamera = nt),
  242. it.activeCameras = at,
  243. o.getProjectionMatrix(!0),
  244. it.render()
  245. }
  246. ;
  247. if (k) {
  248. const lt = new FxaaPostProcess("antialiasing",1,it.activeCamera);
  249. ot.addPostProcess(lt),
  250. lt.getEffect().isReady() ? st() : lt.getEffect().onCompiled = ()=>{
  251. st()
  252. }
  253. } else
  254. st()
  255. }
  256. function CreateScreenshotUsingRenderTargetAsync(d, o, s, c="image/png", _=1, b=!1, k, j=!1) {
  257. return new Promise(($,_e)=>{
  258. CreateScreenshotUsingRenderTarget(d, o, s, et=>{
  259. typeof et != "undefined" ? $(et) : _e(new Error("Data is undefined"))
  260. }
  261. , c, _, b, k, j)
  262. }
  263. )
  264. }
  265. function _getScreenshotSize(d, o, s) {
  266. let c = 0
  267. , _ = 0;
  268. if (typeof s == "object") {
  269. const b = s.precision ? Math.abs(s.precision) : 1;
  270. s.width && s.height ? (c = s.height * b,
  271. _ = s.width * b) : s.width && !s.height ? (_ = s.width * b,
  272. c = Math.round(_ / d.getAspectRatio(o))) : s.height && !s.width ? (c = s.height * b,
  273. _ = Math.round(c * d.getAspectRatio(o))) : (_ = Math.round(d.getRenderWidth() * b),
  274. c = Math.round(_ / d.getAspectRatio(o)))
  275. } else
  276. isNaN(s) || (c = s,
  277. _ = s);
  278. return _ && (_ = Math.floor(_)),
  279. c && (c = Math.floor(c)),
  280. {
  281. height: c | 0,
  282. width: _ | 0
  283. }
  284. }
  285. const initSideEffects = ()=>{
  286. BABYLON.Tools.CreateScreenshot = CreateScreenshot,
  287. BABYLON.Tools.CreateScreenshotAsync = CreateScreenshotAsync,
  288. BABYLON.Tools.CreateScreenshotUsingRenderTarget = CreateScreenshotUsingRenderTarget,
  289. BABYLON.Tools.CreateScreenshotUsingRenderTargetAsync = CreateScreenshotUsingRenderTargetAsync
  290. }
  291. ;
  292. BABYLON.ParticleSystem.prototype.isReady = function() {
  293. if (!this.emitter || this._imageProcessingConfiguration && !this._imageProcessingConfiguration.isReady())
  294. return !1;
  295. if (this.blendMode !== BABYLON.ParticleSystem.BLENDMODE_MULTIPLYADD) {
  296. if (!this._getWrapper(this.blendMode).effect.isReady())
  297. return !1
  298. } else if (!this._getWrapper(BABYLON.ParticleSystem.BLENDMODE_MULTIPLY).effect.isReady() || !this._getWrapper(BABYLON.ParticleSystem.BLENDMODE_ADD).effect.isReady())
  299. return !1;
  300. return !0
  301. }
  302. ;
  303. function LinearBezierCurves(d, o, s) {
  304. return BABYLON.Vector3.Lerp(o, s, 1 - d)
  305. }
  306. function QuadraticBezierCurves(d, o, s, c) {
  307. const _ = LinearBezierCurves(d, o, s)
  308. , b = LinearBezierCurves(d, s, c);
  309. return LinearBezierCurves(d, _, b)
  310. }
  311. function CubicBezierCurves(d, o, s, c, _) {
  312. const b = QuadraticBezierCurves(d, o, s, c)
  313. , k = QuadraticBezierCurves(d, s, c, _);
  314. return LinearBezierCurves(d, b, k)
  315. }
  316. function CardinalMultiply(d, o, s, c, _, b) {
  317. const k = d[0] * o + d[1] * s + d[2] * c + d[3] * _
  318. , j = d[4] * o + d[5] * s + d[6] * c + d[7] * _
  319. , $ = d[8] * o + d[9] * s + d[10] * c + d[11] * _;
  320. return d[12] * o + d[13] * s + d[14] * c + d[15] * _ + b * ($ + b * (j + b * k))
  321. }
  322. function CardinalCurves(d, o, s, c, _, b) {
  323. const k = new Array(16)
  324. , j = b;
  325. return k[0] = -j,
  326. k[1] = 2 - j,
  327. k[2] = j - 2,
  328. k[3] = j,
  329. k[4] = 2 * j,
  330. k[5] = j - 3,
  331. k[8] = -j,
  332. k[9] = 0,
  333. k[12] = 0,
  334. k[13] = 1,
  335. k[6] = 3 - 2 * j,
  336. k[7] = -j,
  337. k[10] = j,
  338. k[11] = 0,
  339. k[14] = 0,
  340. k[15] = 0,
  341. new BABYLON.Vector3(CardinalMultiply(k, o.x, s.x, c.x, _.x, d),CardinalMultiply(k, o.y, s.y, c.y, _.x, d),CardinalMultiply(k, o.z, s.z, c.z, _.x, d))
  342. }
  343. function HermiteCurves(d, o, s, c, _) {
  344. const b = Math.pow(d, 3)
  345. , k = Math.pow(d, 2)
  346. , j = 2 * b - 3 * k + 1
  347. , $ = -2 * b + 3 * k
  348. , _e = b - 2 * k + d
  349. , et = b - k
  350. , tt = o.multiplyByFloats(j, j, j)
  351. , rt = s.multiplyByFloats($, $, $)
  352. , it = c.multiplyByFloats(_e, _e, _e)
  353. , nt = _.multiplyByFloats(et, et, et);
  354. return tt.add(rt.add(it).add(nt))
  355. }