index.js 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. if(typeof require !== 'undefined'){
  12. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  13. var BABYLON = globalObject["BABYLON"] || {};
  14. var BABYLON0 = require('babylonjs/core');
  15. if(BABYLON !== BABYLON0) __extends(BABYLON, BABYLON0);
  16. var BABYLON1 = require('babylonjs/additionalMeshes');
  17. if(BABYLON !== BABYLON1) __extends(BABYLON, BABYLON1);
  18. var BABYLON;
  19. (function (BABYLON) {
  20. var MeshBuilder = /** @class */ (function () {
  21. function MeshBuilder() {
  22. }
  23. MeshBuilder.updateSideOrientation = function (orientation) {
  24. if (orientation == BABYLON.Mesh.DOUBLESIDE) {
  25. return BABYLON.Mesh.DOUBLESIDE;
  26. }
  27. if (orientation === undefined || orientation === null) {
  28. return BABYLON.Mesh.FRONTSIDE;
  29. }
  30. return orientation;
  31. };
  32. /**
  33. * Creates a box mesh.
  34. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box
  35. * The parameter `size` sets the size (float) of each box side (default 1).
  36. * You can set some different box dimensions by using the parameters `width`, `height` and `depth` (all by default have the same value than `size`).
  37. * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of 6 Color3 elements) and `faceUV` (an array of 6 Vector4 elements).
  38. * Please read this tutorial : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  39. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  40. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  41. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  42. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  43. */
  44. MeshBuilder.CreateBox = function (name, options, scene) {
  45. if (scene === void 0) { scene = null; }
  46. var box = new BABYLON.Mesh(name, scene);
  47. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  48. box._originalBuilderSideOrientation = options.sideOrientation;
  49. var vertexData = BABYLON.VertexData.CreateBox(options);
  50. vertexData.applyToMesh(box, options.updatable);
  51. return box;
  52. };
  53. /**
  54. * Creates a sphere mesh.
  55. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#sphere
  56. * The parameter `diameter` sets the diameter size (float) of the sphere (default 1).
  57. * You can set some different sphere dimensions, for instance to build an ellipsoid, by using the parameters `diameterX`, `diameterY` and `diameterZ` (all by default have the same value than `diameter`).
  58. * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32).
  59. * You can create an unclosed sphere with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference (latitude) : 2 x PI x ratio
  60. * You can create an unclosed sphere on its height with the parameter `slice` (positive float, default1), valued between 0 and 1, what is the height ratio (longitude).
  61. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  62. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  63. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  64. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  65. */
  66. MeshBuilder.CreateSphere = function (name, options, scene) {
  67. var sphere = new BABYLON.Mesh(name, scene);
  68. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  69. sphere._originalBuilderSideOrientation = options.sideOrientation;
  70. var vertexData = BABYLON.VertexData.CreateSphere(options);
  71. vertexData.applyToMesh(sphere, options.updatable);
  72. return sphere;
  73. };
  74. /**
  75. * Creates a plane polygonal mesh. By default, this is a disc.
  76. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#disc
  77. * The parameter `radius` sets the radius size (float) of the polygon (default 0.5).
  78. * The parameter `tessellation` sets the number of polygon sides (positive integer, default 64). So a tessellation valued to 3 will build a triangle, to 4 a square, etc.
  79. * You can create an unclosed polygon with the parameter `arc` (positive float, default 1), valued between 0 and 1, what is the ratio of the circumference : 2 x PI x ratio
  80. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  81. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  82. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  83. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  84. */
  85. MeshBuilder.CreateDisc = function (name, options, scene) {
  86. if (scene === void 0) { scene = null; }
  87. var disc = new BABYLON.Mesh(name, scene);
  88. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  89. disc._originalBuilderSideOrientation = options.sideOrientation;
  90. var vertexData = BABYLON.VertexData.CreateDisc(options);
  91. vertexData.applyToMesh(disc, options.updatable);
  92. return disc;
  93. };
  94. /**
  95. * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided.
  96. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#icosphere
  97. * The parameter `radius` sets the radius size (float) of the icosphere (default 1).
  98. * You can set some different icosphere dimensions, for instance to build an ellipsoid, by using the parameters `radiusX`, `radiusY` and `radiusZ` (all by default have the same value than `radius`).
  99. * The parameter `subdivisions` sets the number of subdivisions (postive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size.
  100. * The parameter `flat` (boolean, default true) gives each side its own normals. Set it to false to get a smooth continuous light reflection on the surface.
  101. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  102. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  103. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  104. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  105. */
  106. MeshBuilder.CreateIcoSphere = function (name, options, scene) {
  107. var sphere = new BABYLON.Mesh(name, scene);
  108. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  109. sphere._originalBuilderSideOrientation = options.sideOrientation;
  110. var vertexData = BABYLON.VertexData.CreateIcoSphere(options);
  111. vertexData.applyToMesh(sphere, options.updatable);
  112. return sphere;
  113. };
  114. ;
  115. /**
  116. * Creates a ribbon mesh.
  117. * The ribbon is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  118. *
  119. * Please read this full tutorial to understand how to design a ribbon : http://doc.babylonjs.com/tutorials/Ribbon_Tutorial
  120. * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry.
  121. * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array.
  122. * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array.
  123. * The parameter `offset` (positive integer, default : rounded half size of the pathArray length), is taken in account only if the `pathArray` is containing a single path.
  124. * It's the offset to join the points from the same path. Ex : offset = 10 means the point 1 is joined to the point 11.
  125. * The optional parameter `instance` is an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#ribbon
  126. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  127. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  128. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  129. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  130. * The parameter `uvs` is an optional flat array of `Vector2` to update/set each ribbon vertex with its own custom UV values instead of the computed ones.
  131. * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values.
  132. * Note that if you use the parameters `uvs` or `colors`, the passed arrays must be populated with the right number of elements, it is to say the number of ribbon vertices. Remember that
  133. * if you set `closePath` to `true`, there's one extra vertex per path in the geometry.
  134. * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time.
  135. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  136. */
  137. MeshBuilder.CreateRibbon = function (name, options, scene) {
  138. if (scene === void 0) { scene = null; }
  139. var pathArray = options.pathArray;
  140. var closeArray = options.closeArray;
  141. var closePath = options.closePath;
  142. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  143. var instance = options.instance;
  144. var updatable = options.updatable;
  145. if (instance) {
  146. // positionFunction : ribbon case
  147. // only pathArray and sideOrientation parameters are taken into account for positions update
  148. BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, BABYLON.Tmp.Vector3[0]); // minimum
  149. BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, BABYLON.Tmp.Vector3[1]);
  150. var positionFunction = function (positions) {
  151. var minlg = pathArray[0].length;
  152. var i = 0;
  153. var ns = (instance._originalBuilderSideOrientation === BABYLON.Mesh.DOUBLESIDE) ? 2 : 1;
  154. for (var si = 1; si <= ns; si++) {
  155. for (var p = 0; p < pathArray.length; p++) {
  156. var path = pathArray[p];
  157. var l = path.length;
  158. minlg = (minlg < l) ? minlg : l;
  159. var j = 0;
  160. while (j < minlg) {
  161. positions[i] = path[j].x;
  162. positions[i + 1] = path[j].y;
  163. positions[i + 2] = path[j].z;
  164. if (path[j].x < BABYLON.Tmp.Vector3[0].x) {
  165. BABYLON.Tmp.Vector3[0].x = path[j].x;
  166. }
  167. if (path[j].x > BABYLON.Tmp.Vector3[1].x) {
  168. BABYLON.Tmp.Vector3[1].x = path[j].x;
  169. }
  170. if (path[j].y < BABYLON.Tmp.Vector3[0].y) {
  171. BABYLON.Tmp.Vector3[0].y = path[j].y;
  172. }
  173. if (path[j].y > BABYLON.Tmp.Vector3[1].y) {
  174. BABYLON.Tmp.Vector3[1].y = path[j].y;
  175. }
  176. if (path[j].z < BABYLON.Tmp.Vector3[0].z) {
  177. BABYLON.Tmp.Vector3[0].z = path[j].z;
  178. }
  179. if (path[j].z > BABYLON.Tmp.Vector3[1].z) {
  180. BABYLON.Tmp.Vector3[1].z = path[j].z;
  181. }
  182. j++;
  183. i += 3;
  184. }
  185. if (instance._closePath) {
  186. positions[i] = path[0].x;
  187. positions[i + 1] = path[0].y;
  188. positions[i + 2] = path[0].z;
  189. i += 3;
  190. }
  191. }
  192. }
  193. };
  194. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  195. positionFunction(positions);
  196. instance._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Tmp.Vector3[0], BABYLON.Tmp.Vector3[1]);
  197. instance._boundingInfo.update(instance._worldMatrix);
  198. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  199. if (options.colors) {
  200. var colors = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  201. for (var c = 0; c < options.colors.length; c++) {
  202. colors[c * 4] = options.colors[c].r;
  203. colors[c * 4 + 1] = options.colors[c].g;
  204. colors[c * 4 + 2] = options.colors[c].b;
  205. colors[c * 4 + 3] = options.colors[c].a;
  206. }
  207. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, colors, false, false);
  208. }
  209. if (options.uvs) {
  210. var uvs = instance.getVerticesData(BABYLON.VertexBuffer.UVKind);
  211. for (var i = 0; i < options.uvs.length; i++) {
  212. uvs[i * 2] = options.uvs[i].x;
  213. uvs[i * 2 + 1] = options.uvs[i].y;
  214. }
  215. instance.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs, false, false);
  216. }
  217. if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {
  218. var indices = instance.getIndices();
  219. var normals = instance.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  220. var params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;
  221. BABYLON.VertexData.ComputeNormals(positions, indices, normals, params);
  222. if (instance._closePath) {
  223. var indexFirst = 0;
  224. var indexLast = 0;
  225. for (var p = 0; p < pathArray.length; p++) {
  226. indexFirst = instance._idx[p] * 3;
  227. if (p + 1 < pathArray.length) {
  228. indexLast = (instance._idx[p + 1] - 1) * 3;
  229. }
  230. else {
  231. indexLast = normals.length - 3;
  232. }
  233. normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;
  234. normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;
  235. normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;
  236. normals[indexLast] = normals[indexFirst];
  237. normals[indexLast + 1] = normals[indexFirst + 1];
  238. normals[indexLast + 2] = normals[indexFirst + 2];
  239. }
  240. }
  241. if (!(instance.areNormalsFrozen)) {
  242. instance.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
  243. }
  244. }
  245. return instance;
  246. }
  247. else {
  248. var ribbon = new BABYLON.Mesh(name, scene);
  249. ribbon._originalBuilderSideOrientation = sideOrientation;
  250. var vertexData = BABYLON.VertexData.CreateRibbon(options);
  251. if (closePath) {
  252. ribbon._idx = vertexData._idx;
  253. }
  254. ribbon._closePath = closePath;
  255. ribbon._closeArray = closeArray;
  256. vertexData.applyToMesh(ribbon, updatable);
  257. return ribbon;
  258. }
  259. };
  260. /**
  261. * Creates a cylinder or a cone mesh.
  262. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#cylinder-or-cone
  263. * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).
  264. * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).
  265. * The parameters `diameterTop` and `diameterBottom` overwrite the parameter `diameter` and set respectively the top cap and bottom cap diameter (floats, default 1). The parameter "diameterBottom" can't be zero.
  266. * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.
  267. * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).
  268. * The parameter `hasRings` (boolean, default false) makes the subdivisions independent from each other, so they become different faces.
  269. * The parameter `enclose` (boolean, default false) adds two extra faces per subdivision to a sliced cylinder to close it around its height axis.
  270. * The parameter `arc` (float, default 1) is the ratio (max 1) to apply to the circumference to slice the cylinder.
  271. * You can set different colors and different images to each box side by using the parameters `faceColors` (an array of n Color3 elements) and `faceUV` (an array of n Vector4 elements).
  272. * The value of n is the number of cylinder faces. If the cylinder has only 1 subdivisions, n equals : top face + cylinder surface + bottom face = 3
  273. * Now, if the cylinder has 5 independent subdivisions (hasRings = true), n equals : top face + 5 stripe surfaces + bottom face = 2 + 5 = 7
  274. * Finally, if the cylinder has 5 independent subdivisions and is enclose, n equals : top face + 5 x (stripe surface + 2 closing faces) + bottom face = 2 + 5 * 3 = 17
  275. * Each array (color or UVs) is always ordered the same way : the first element is the bottom cap, the last element is the top cap. The other elements are each a ring surface.
  276. * If `enclose` is false, a ring surface is one element.
  277. * If `enclose` is true, a ring surface is 3 successive elements in the array : the tubular surface, then the two closing faces.
  278. * Example how to set colors and textures on a sliced cylinder : http://www.html5gamedevs.com/topic/17945-creating-a-closed-slice-of-a-cylinder/#comment-106379
  279. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  280. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  281. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  282. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  283. */
  284. MeshBuilder.CreateCylinder = function (name, options, scene) {
  285. var cylinder = new BABYLON.Mesh(name, scene);
  286. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  287. cylinder._originalBuilderSideOrientation = options.sideOrientation;
  288. var vertexData = BABYLON.VertexData.CreateCylinder(options);
  289. vertexData.applyToMesh(cylinder, options.updatable);
  290. return cylinder;
  291. };
  292. /**
  293. * Creates a torus mesh.
  294. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus
  295. * The parameter `diameter` sets the diameter size (float) of the torus (default 1).
  296. * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5).
  297. * The parameter `tessellation` sets the number of torus sides (postive integer, default 16).
  298. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  299. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  300. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  301. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  302. */
  303. MeshBuilder.CreateTorus = function (name, options, scene) {
  304. var torus = new BABYLON.Mesh(name, scene);
  305. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  306. torus._originalBuilderSideOrientation = options.sideOrientation;
  307. var vertexData = BABYLON.VertexData.CreateTorus(options);
  308. vertexData.applyToMesh(torus, options.updatable);
  309. return torus;
  310. };
  311. /**
  312. * Creates a torus knot mesh.
  313. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus-knot
  314. * The parameter `radius` sets the global radius size (float) of the torus knot (default 2).
  315. * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32).
  316. * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32).
  317. * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3).
  318. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  319. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  320. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  321. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  322. */
  323. MeshBuilder.CreateTorusKnot = function (name, options, scene) {
  324. var torusKnot = new BABYLON.Mesh(name, scene);
  325. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  326. torusKnot._originalBuilderSideOrientation = options.sideOrientation;
  327. var vertexData = BABYLON.VertexData.CreateTorusKnot(options);
  328. vertexData.applyToMesh(torusKnot, options.updatable);
  329. return torusKnot;
  330. };
  331. /**
  332. * Creates a line system mesh.
  333. * A line system is a pool of many lines gathered in a single mesh.
  334. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem
  335. * A line system mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of lines as an input parameter.
  336. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineSystem to this static function.
  337. * The parameter `lines` is an array of lines, each line being an array of successive Vector3.
  338. * The optional parameter `instance` is an instance of an existing LineSystem object to be updated with the passed `lines` parameter. The way to update it is the same than for
  339. * The optional parameter `colors` is an array of line colors, each line colors being an array of successive Color4, one per line point.
  340. * The optional parameter `useVertexAlpha' is to be set to `false` (default `true`) when you don't need the alpha blending (faster).
  341. * updating a simple Line mesh, you just need to update every line in the `lines` array : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  342. * When updating an instance, remember that only line point positions can change, not the number of points, neither the number of lines.
  343. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  344. */
  345. MeshBuilder.CreateLineSystem = function (name, options, scene) {
  346. var instance = options.instance;
  347. var lines = options.lines;
  348. var colors = options.colors;
  349. if (instance) {
  350. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  351. var vertexColor;
  352. var lineColors;
  353. if (colors) {
  354. vertexColor = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  355. }
  356. var i = 0;
  357. var c = 0;
  358. for (var l = 0; l < lines.length; l++) {
  359. var points = lines[l];
  360. for (var p = 0; p < points.length; p++) {
  361. positions[i] = points[p].x;
  362. positions[i + 1] = points[p].y;
  363. positions[i + 2] = points[p].z;
  364. if (colors && vertexColor) {
  365. lineColors = colors[l];
  366. vertexColor[c] = lineColors[p].r;
  367. vertexColor[c + 1] = lineColors[p].g;
  368. vertexColor[c + 2] = lineColors[p].b;
  369. vertexColor[c + 3] = lineColors[p].a;
  370. c += 4;
  371. }
  372. i += 3;
  373. }
  374. }
  375. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  376. if (colors && vertexColor) {
  377. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, vertexColor, false, false);
  378. }
  379. return instance;
  380. }
  381. // line system creation
  382. var useVertexColor = (colors) ? true : false;
  383. var lineSystem = new BABYLON.LinesMesh(name, scene, null, undefined, undefined, useVertexColor, options.useVertexAlpha);
  384. var vertexData = BABYLON.VertexData.CreateLineSystem(options);
  385. vertexData.applyToMesh(lineSystem, options.updatable);
  386. return lineSystem;
  387. };
  388. /**
  389. * Creates a line mesh.
  390. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#lines
  391. * A line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter.
  392. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  393. * The parameter `points` is an array successive Vector3.
  394. * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  395. * The optional parameter `colors` is an array of successive Color4, one per line point.
  396. * The optional parameter `useVertexAlpha' is to be set to `false` (default `true`) when you don't need alpha blending (faster).
  397. * When updating an instance, remember that only point positions can change, not the number of points.
  398. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  399. */
  400. MeshBuilder.CreateLines = function (name, options, scene) {
  401. if (scene === void 0) { scene = null; }
  402. var colors = (options.colors) ? [options.colors] : null;
  403. var lines = MeshBuilder.CreateLineSystem(name, { lines: [options.points], updatable: options.updatable, instance: options.instance, colors: colors, useVertexAlpha: options.useVertexAlpha }, scene);
  404. return lines;
  405. };
  406. /**
  407. * Creates a dashed line mesh.
  408. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#dashed-lines
  409. * A dashed line mesh is considered as a parametric shape since it has no predefined original shape. Its shape is determined by the passed array of points as an input parameter.
  410. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  411. * The parameter `points` is an array successive Vector3.
  412. * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200).
  413. * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3).
  414. * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1).
  415. * The optional parameter `instance` is an instance of an existing LineMesh object to be updated with the passed `points` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#lines-and-dashedlines
  416. * When updating an instance, remember that only point positions can change, not the number of points.
  417. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  418. */
  419. MeshBuilder.CreateDashedLines = function (name, options, scene) {
  420. if (scene === void 0) { scene = null; }
  421. var points = options.points;
  422. var instance = options.instance;
  423. var gapSize = options.gapSize || 1;
  424. var dashSize = options.dashSize || 3;
  425. if (instance) {
  426. var positionFunction = function (positions) {
  427. var curvect = BABYLON.Vector3.Zero();
  428. var nbSeg = positions.length / 6;
  429. var lg = 0;
  430. var nb = 0;
  431. var shft = 0;
  432. var dashshft = 0;
  433. var curshft = 0;
  434. var p = 0;
  435. var i = 0;
  436. var j = 0;
  437. for (i = 0; i < points.length - 1; i++) {
  438. points[i + 1].subtractToRef(points[i], curvect);
  439. lg += curvect.length();
  440. }
  441. shft = lg / nbSeg;
  442. dashshft = instance.dashSize * shft / (instance.dashSize + instance.gapSize);
  443. for (i = 0; i < points.length - 1; i++) {
  444. points[i + 1].subtractToRef(points[i], curvect);
  445. nb = Math.floor(curvect.length() / shft);
  446. curvect.normalize();
  447. j = 0;
  448. while (j < nb && p < positions.length) {
  449. curshft = shft * j;
  450. positions[p] = points[i].x + curshft * curvect.x;
  451. positions[p + 1] = points[i].y + curshft * curvect.y;
  452. positions[p + 2] = points[i].z + curshft * curvect.z;
  453. positions[p + 3] = points[i].x + (curshft + dashshft) * curvect.x;
  454. positions[p + 4] = points[i].y + (curshft + dashshft) * curvect.y;
  455. positions[p + 5] = points[i].z + (curshft + dashshft) * curvect.z;
  456. p += 6;
  457. j++;
  458. }
  459. }
  460. while (p < positions.length) {
  461. positions[p] = points[i].x;
  462. positions[p + 1] = points[i].y;
  463. positions[p + 2] = points[i].z;
  464. p += 3;
  465. }
  466. };
  467. instance.updateMeshPositions(positionFunction, false);
  468. return instance;
  469. }
  470. // dashed lines creation
  471. var dashedLines = new BABYLON.LinesMesh(name, scene);
  472. var vertexData = BABYLON.VertexData.CreateDashedLines(options);
  473. vertexData.applyToMesh(dashedLines, options.updatable);
  474. dashedLines.dashSize = dashSize;
  475. dashedLines.gapSize = gapSize;
  476. return dashedLines;
  477. };
  478. /**
  479. * Creates an extruded shape mesh.
  480. * The extrusion is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  481. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#extruded-shapes
  482. *
  483. * Please read this full tutorial to understand how to design an extruded shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes#extrusion
  484. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be
  485. * extruded along the Z axis.
  486. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  487. * The parameter `rotation` (float, default 0 radians) is the angle value to rotate the shape each step (each path point), from the former step (so rotation added each step) along the curve.
  488. * The parameter `scale` (float, default 1) is the value to scale the shape.
  489. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  490. * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  491. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  492. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  493. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  494. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  495. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  496. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  497. */
  498. MeshBuilder.ExtrudeShape = function (name, options, scene) {
  499. if (scene === void 0) { scene = null; }
  500. var path = options.path;
  501. var shape = options.shape;
  502. var scale = options.scale || 1;
  503. var rotation = options.rotation || 0;
  504. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  505. var updatable = options.updatable;
  506. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  507. var instance = options.instance || null;
  508. var invertUV = options.invertUV || false;
  509. return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, cap, false, scene, updatable ? true : false, sideOrientation, instance, invertUV, options.frontUVs || null, options.backUVs || null);
  510. };
  511. /**
  512. * Creates an custom extruded shape mesh.
  513. * The custom extrusion is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  514. * tuto :http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#custom-extruded-shapes
  515. *
  516. * Please read this full tutorial to understand how to design a custom extruded shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes#extrusion
  517. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be extruded in its local space : the shape must be designed in the xOy plane and will be
  518. * extruded along the Z axis.
  519. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  520. * The parameter `rotationFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path
  521. * and the distance of this point from the begining of the path :
  522. * ```javascript
  523. * var rotationFunction = function(i, distance) {
  524. * // do things
  525. * return rotationValue; }
  526. * ```
  527. * It must returns a float value that will be the rotation in radians applied to the shape on each path point.
  528. * The parameter `scaleFunction` (JS function) is a custom Javascript function called on each path point. This function is passed the position i of the point in the path
  529. * and the distance of this point from the begining of the path :
  530. * ```javascript
  531. * var scaleFunction = function(i, distance) {
  532. * // do things
  533. * return scaleValue;}
  534. * ```
  535. * It must returns a float value that will be the scale value applied to the shape on each path point.
  536. * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray`.
  537. * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray`.
  538. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  539. * The optional parameter `instance` is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#extruded-shape
  540. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  541. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  542. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  543. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  544. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  545. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  546. */
  547. MeshBuilder.ExtrudeShapeCustom = function (name, options, scene) {
  548. var path = options.path;
  549. var shape = options.shape;
  550. var scaleFunction = options.scaleFunction || (function () { return 1; });
  551. var rotationFunction = options.rotationFunction || (function () { return 0; });
  552. var ribbonCloseArray = options.ribbonCloseArray || false;
  553. var ribbonClosePath = options.ribbonClosePath || false;
  554. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  555. var updatable = options.updatable;
  556. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  557. var instance = options.instance;
  558. var invertUV = options.invertUV || false;
  559. return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable ? true : false, sideOrientation, instance || null, invertUV, options.frontUVs || null, options.backUVs || null);
  560. };
  561. /**
  562. * Creates lathe mesh.
  563. * The lathe is a shape with a symetry axis : a 2D model shape is rotated around this axis to design the lathe.
  564. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#lathe
  565. *
  566. * The parameter `shape` is a required array of successive Vector3. This array depicts the shape to be rotated in its local space : the shape must be designed in the xOy plane and will be
  567. * rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero.
  568. * The parameter `radius` (positive float, default 1) is the radius value of the lathe.
  569. * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe.
  570. * The parameter `arc` (positive float, default 1) is the ratio of the lathe. 0.5 builds for instance half a lathe, so an opened shape.
  571. * The parameter `closed` (boolean, default true) opens/closes the lathe circumference. This should be set to false when used with the parameter "arc".
  572. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  573. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  574. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  575. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  576. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  577. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  578. */
  579. MeshBuilder.CreateLathe = function (name, options, scene) {
  580. var arc = options.arc ? ((options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc) : 1.0;
  581. var closed = (options.closed === undefined) ? true : options.closed;
  582. var shape = options.shape;
  583. var radius = options.radius || 1;
  584. var tessellation = options.tessellation || 64;
  585. var updatable = options.updatable;
  586. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  587. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  588. var pi2 = Math.PI * 2;
  589. var paths = new Array();
  590. var invertUV = options.invertUV || false;
  591. var i = 0;
  592. var p = 0;
  593. var step = pi2 / tessellation * arc;
  594. var rotated;
  595. var path = new Array();
  596. ;
  597. for (i = 0; i <= tessellation; i++) {
  598. var path = [];
  599. if (cap == BABYLON.Mesh.CAP_START || cap == BABYLON.Mesh.CAP_ALL) {
  600. path.push(new BABYLON.Vector3(0, shape[0].y, 0));
  601. path.push(new BABYLON.Vector3(Math.cos(i * step) * shape[0].x * radius, shape[0].y, Math.sin(i * step) * shape[0].x * radius));
  602. }
  603. for (p = 0; p < shape.length; p++) {
  604. rotated = new BABYLON.Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y, Math.sin(i * step) * shape[p].x * radius);
  605. path.push(rotated);
  606. }
  607. if (cap == BABYLON.Mesh.CAP_END || cap == BABYLON.Mesh.CAP_ALL) {
  608. path.push(new BABYLON.Vector3(Math.cos(i * step) * shape[shape.length - 1].x * radius, shape[shape.length - 1].y, Math.sin(i * step) * shape[shape.length - 1].x * radius));
  609. path.push(new BABYLON.Vector3(0, shape[shape.length - 1].y, 0));
  610. }
  611. paths.push(path);
  612. }
  613. // lathe ribbon
  614. var lathe = MeshBuilder.CreateRibbon(name, { pathArray: paths, closeArray: closed, sideOrientation: sideOrientation, updatable: updatable, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  615. return lathe;
  616. };
  617. /**
  618. * Creates a plane mesh.
  619. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  620. * The parameter `size` sets the size (float) of both sides of the plane at once (default 1).
  621. * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value than `size`).
  622. * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane.
  623. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  624. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  625. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  626. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  627. */
  628. MeshBuilder.CreatePlane = function (name, options, scene) {
  629. var plane = new BABYLON.Mesh(name, scene);
  630. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  631. plane._originalBuilderSideOrientation = options.sideOrientation;
  632. var vertexData = BABYLON.VertexData.CreatePlane(options);
  633. vertexData.applyToMesh(plane, options.updatable);
  634. if (options.sourcePlane) {
  635. plane.translate(options.sourcePlane.normal, options.sourcePlane.d);
  636. var product = Math.acos(BABYLON.Vector3.Dot(options.sourcePlane.normal, BABYLON.Axis.Z));
  637. var vectorProduct = BABYLON.Vector3.Cross(BABYLON.Axis.Z, options.sourcePlane.normal);
  638. plane.rotate(vectorProduct, product);
  639. }
  640. return plane;
  641. };
  642. /**
  643. * Creates a ground mesh.
  644. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  645. * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground.
  646. * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side.
  647. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  648. */
  649. MeshBuilder.CreateGround = function (name, options, scene) {
  650. var ground = new BABYLON.GroundMesh(name, scene);
  651. ground._setReady(false);
  652. ground._subdivisionsX = options.subdivisionsX || options.subdivisions || 1;
  653. ground._subdivisionsY = options.subdivisionsY || options.subdivisions || 1;
  654. ground._width = options.width || 1;
  655. ground._height = options.height || 1;
  656. ground._maxX = ground._width / 2;
  657. ground._maxZ = ground._height / 2;
  658. ground._minX = -ground._maxX;
  659. ground._minZ = -ground._maxZ;
  660. var vertexData = BABYLON.VertexData.CreateGround(options);
  661. vertexData.applyToMesh(ground, options.updatable);
  662. ground._setReady(true);
  663. return ground;
  664. };
  665. /**
  666. * Creates a tiled ground mesh.
  667. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tiled-ground
  668. * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates.
  669. * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates.
  670. * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the
  671. * numbers of subdivisions on the ground width and height. Each subdivision is called a tile.
  672. * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the
  673. * numbers of subdivisions on the ground width and height of each tile.
  674. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  675. */
  676. MeshBuilder.CreateTiledGround = function (name, options, scene) {
  677. var tiledGround = new BABYLON.Mesh(name, scene);
  678. var vertexData = BABYLON.VertexData.CreateTiledGround(options);
  679. vertexData.applyToMesh(tiledGround, options.updatable);
  680. return tiledGround;
  681. };
  682. /**
  683. * Creates a ground mesh from a height map.
  684. * tuto : http://doc.babylonjs.com/tutorials/14._Height_Map
  685. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#ground-from-a-height-map
  686. * The parameter `url` sets the URL of the height map image resource.
  687. * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.
  688. * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.
  689. * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.
  690. * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.
  691. * The parameter `colorFilter` (optional Color3, default (0.3, 0.59, 0.11) ) is the filter to apply to the image pixel colors to compute the height.
  692. * The parameter `onReady` is a javascript callback function that will be called once the mesh is just built (the height map download can last some time).
  693. * This function is passed the newly built mesh :
  694. * ```javascript
  695. * function(mesh) { // do things
  696. * return; }
  697. * ```
  698. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  699. */
  700. MeshBuilder.CreateGroundFromHeightMap = function (name, url, options, scene) {
  701. var width = options.width || 10.0;
  702. var height = options.height || 10.0;
  703. var subdivisions = options.subdivisions || 1 | 0;
  704. var minHeight = options.minHeight || 0.0;
  705. var maxHeight = options.maxHeight || 1.0;
  706. var filter = options.colorFilter || new BABYLON.Color3(0.3, 0.59, 0.11);
  707. var updatable = options.updatable;
  708. var onReady = options.onReady;
  709. var ground = new BABYLON.GroundMesh(name, scene);
  710. ground._subdivisionsX = subdivisions;
  711. ground._subdivisionsY = subdivisions;
  712. ground._width = width;
  713. ground._height = height;
  714. ground._maxX = ground._width / 2.0;
  715. ground._maxZ = ground._height / 2.0;
  716. ground._minX = -ground._maxX;
  717. ground._minZ = -ground._maxZ;
  718. ground._setReady(false);
  719. var onload = function (img) {
  720. // Getting height map data
  721. var canvas = document.createElement("canvas");
  722. var context = canvas.getContext("2d");
  723. if (!context) {
  724. throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");
  725. }
  726. if (scene.isDisposed) {
  727. return;
  728. }
  729. var bufferWidth = img.width;
  730. var bufferHeight = img.height;
  731. canvas.width = bufferWidth;
  732. canvas.height = bufferHeight;
  733. context.drawImage(img, 0, 0);
  734. // Create VertexData from map data
  735. // Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949
  736. var buffer = context.getImageData(0, 0, bufferWidth, bufferHeight).data;
  737. var vertexData = BABYLON.VertexData.CreateGroundFromHeightMap({
  738. width: width, height: height,
  739. subdivisions: subdivisions,
  740. minHeight: minHeight, maxHeight: maxHeight, colorFilter: filter,
  741. buffer: buffer, bufferWidth: bufferWidth, bufferHeight: bufferHeight
  742. });
  743. vertexData.applyToMesh(ground, updatable);
  744. ground._setReady(true);
  745. //execute ready callback, if set
  746. if (onReady) {
  747. onReady(ground);
  748. }
  749. };
  750. BABYLON.Tools.LoadImage(url, onload, function () { }, scene.database);
  751. return ground;
  752. };
  753. /**
  754. * Creates a polygon mesh.
  755. * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.
  756. * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
  757. * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  758. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  759. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  760. * Remember you can only change the shape positions, not their number when updating a polygon.
  761. */
  762. MeshBuilder.CreatePolygon = function (name, options, scene) {
  763. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  764. var shape = options.shape;
  765. var holes = options.holes || [];
  766. var depth = options.depth || 0;
  767. var contours = [];
  768. var hole = [];
  769. for (var i = 0; i < shape.length; i++) {
  770. contours[i] = new BABYLON.Vector2(shape[i].x, shape[i].z);
  771. }
  772. var epsilon = 0.00000001;
  773. if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
  774. contours.pop();
  775. }
  776. var polygonTriangulation = new BABYLON.PolygonMeshBuilder(name, contours, scene);
  777. for (var hNb = 0; hNb < holes.length; hNb++) {
  778. hole = [];
  779. for (var hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
  780. hole.push(new BABYLON.Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
  781. }
  782. polygonTriangulation.addHole(hole);
  783. }
  784. var polygon = polygonTriangulation.build(options.updatable, depth);
  785. polygon._originalBuilderSideOrientation = options.sideOrientation;
  786. var vertexData = BABYLON.VertexData.CreatePolygon(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs);
  787. vertexData.applyToMesh(polygon, options.updatable);
  788. return polygon;
  789. };
  790. ;
  791. /**
  792. * Creates an extruded polygon mesh, with depth in the Y direction.
  793. * You can set different colors and different images to the top, bottom and extruded side by using the parameters `faceColors` (an array of 3 Color3 elements) and `faceUV` (an array of 3 Vector4 elements).
  794. * Please read this tutorial : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  795. */
  796. MeshBuilder.ExtrudePolygon = function (name, options, scene) {
  797. return MeshBuilder.CreatePolygon(name, options, scene);
  798. };
  799. ;
  800. /**
  801. * Creates a tube mesh.
  802. * The tube is a parametric shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes. It has no predefined shape. Its final shape will depend on the input parameters.
  803. *
  804. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tube
  805. * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube.
  806. * The parameter `radius` (positive float, default 1) sets the tube radius size.
  807. * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface.
  808. * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overwrittes the parameter `radius`.
  809. * This function is called on each point of the tube path and is passed the index `i` of the i-th point and the distance of this point from the first point of the path.
  810. * It must return a radius value (positive float) :
  811. * ```javascript
  812. * var radiusFunction = function(i, distance) {
  813. * // do things
  814. * return radius; }
  815. * ```
  816. * The parameter `arc` (positive float, maximum 1, default 1) is the ratio to apply to the tube circumference : 2 x PI x arc.
  817. * The parameter `cap` sets the way the extruded shape is capped. Possible values : BABYLON.Mesh.NO_CAP (default), BABYLON.Mesh.CAP_START, BABYLON.Mesh.CAP_END, BABYLON.Mesh.CAP_ALL
  818. * The optional parameter `instance` is an instance of an existing Tube object to be updated with the passed `pathArray` parameter : http://doc.babylonjs.com/tutorials/How_to_dynamically_morph_a_mesh#tube
  819. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  820. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  821. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  822. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  823. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  824. */
  825. MeshBuilder.CreateTube = function (name, options, scene) {
  826. var path = options.path;
  827. var instance = options.instance;
  828. var radius = 1.0;
  829. if (instance) {
  830. radius = instance.radius;
  831. }
  832. if (options.radius !== undefined) {
  833. radius = options.radius;
  834. }
  835. ;
  836. var tessellation = options.tessellation || 64 | 0;
  837. var radiusFunction = options.radiusFunction || null;
  838. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  839. var invertUV = options.invertUV || false;
  840. var updatable = options.updatable;
  841. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  842. options.arc = options.arc && (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
  843. // tube geometry
  844. var tubePathArray = function (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) {
  845. var tangents = path3D.getTangents();
  846. var normals = path3D.getNormals();
  847. var distances = path3D.getDistances();
  848. var pi2 = Math.PI * 2;
  849. var step = pi2 / tessellation * arc;
  850. var returnRadius = function () { return radius; };
  851. var radiusFunctionFinal = radiusFunction || returnRadius;
  852. var circlePath;
  853. var rad;
  854. var normal;
  855. var rotated;
  856. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  857. var index = (cap === BABYLON.Mesh._NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  858. for (var i = 0; i < path.length; i++) {
  859. rad = radiusFunctionFinal(i, distances[i]); // current radius
  860. circlePath = Array(); // current circle array
  861. normal = normals[i]; // current normal
  862. for (var t = 0; t < tessellation; t++) {
  863. BABYLON.Matrix.RotationAxisToRef(tangents[i], step * t, rotationMatrix);
  864. rotated = circlePath[t] ? circlePath[t] : BABYLON.Vector3.Zero();
  865. BABYLON.Vector3.TransformCoordinatesToRef(normal, rotationMatrix, rotated);
  866. rotated.scaleInPlace(rad).addInPlace(path[i]);
  867. circlePath[t] = rotated;
  868. }
  869. circlePaths[index] = circlePath;
  870. index++;
  871. }
  872. // cap
  873. var capPath = function (nbPoints, pathIndex) {
  874. var pointCap = Array();
  875. for (var i = 0; i < nbPoints; i++) {
  876. pointCap.push(path[pathIndex]);
  877. }
  878. return pointCap;
  879. };
  880. switch (cap) {
  881. case BABYLON.Mesh.NO_CAP:
  882. break;
  883. case BABYLON.Mesh.CAP_START:
  884. circlePaths[0] = capPath(tessellation, 0);
  885. circlePaths[1] = circlePaths[2].slice(0);
  886. break;
  887. case BABYLON.Mesh.CAP_END:
  888. circlePaths[index] = circlePaths[index - 1].slice(0);
  889. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  890. break;
  891. case BABYLON.Mesh.CAP_ALL:
  892. circlePaths[0] = capPath(tessellation, 0);
  893. circlePaths[1] = circlePaths[2].slice(0);
  894. circlePaths[index] = circlePaths[index - 1].slice(0);
  895. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  896. break;
  897. default:
  898. break;
  899. }
  900. return circlePaths;
  901. };
  902. var path3D;
  903. var pathArray;
  904. if (instance) {
  905. var arc = options.arc || instance.arc;
  906. path3D = (instance.path3D).update(path);
  907. pathArray = tubePathArray(path, path3D, instance.pathArray, radius, instance.tessellation, radiusFunction, instance.cap, arc);
  908. instance = MeshBuilder.CreateRibbon("", { pathArray: pathArray, instance: instance });
  909. instance.path3D = path3D;
  910. instance.pathArray = pathArray;
  911. instance.arc = arc;
  912. instance.radius = radius;
  913. return instance;
  914. }
  915. // tube creation
  916. path3D = new BABYLON.Path3D(path);
  917. var newPathArray = new Array();
  918. cap = (cap < 0 || cap > 3) ? 0 : cap;
  919. pathArray = tubePathArray(path, path3D, newPathArray, radius, tessellation, radiusFunction, cap, options.arc);
  920. var tube = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closePath: true, closeArray: false, updatable: updatable, sideOrientation: sideOrientation, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  921. tube.pathArray = pathArray;
  922. tube.path3D = path3D;
  923. tube.tessellation = tessellation;
  924. tube.cap = cap;
  925. tube.arc = options.arc;
  926. tube.radius = radius;
  927. return tube;
  928. };
  929. /**
  930. * Creates a polyhedron mesh.
  931. *
  932. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#polyhedron
  933. * The parameter `type` (positive integer, max 14, default 0) sets the polyhedron type to build among the 15 embbeded types. Please refer to the type sheet in the tutorial
  934. * to choose the wanted type.
  935. * The parameter `size` (positive float, default 1) sets the polygon size.
  936. * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value).
  937. * You can build other polyhedron types than the 15 embbeded ones by setting the parameter `custom` (`polyhedronObject`, default null). If you set the parameter `custom`, this overwrittes the parameter `type`.
  938. * A `polyhedronObject` is a formatted javascript object. You'll find a full file with pre-set polyhedra here : https://github.com/BabylonJS/Extensions/tree/master/Polyhedron
  939. * You can set the color and the UV of each side of the polyhedron with the parameters `faceColors` (Color4, default `(1, 1, 1, 1)`) and faceUV (Vector4, default `(0, 0, 1, 1)`).
  940. * To understand how to set `faceUV` or `faceColors`, please read this by considering the right number of faces of your polyhedron, instead of only 6 for the box : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  941. * The parameter `flat` (boolean, default true). If set to false, it gives the polyhedron a single global face, so less vertices and shared normals. In this case, `faceColors` and `faceUV` are ignored.
  942. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  943. * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4).
  944. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  945. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  946. */
  947. MeshBuilder.CreatePolyhedron = function (name, options, scene) {
  948. var polyhedron = new BABYLON.Mesh(name, scene);
  949. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  950. polyhedron._originalBuilderSideOrientation = options.sideOrientation;
  951. var vertexData = BABYLON.VertexData.CreatePolyhedron(options);
  952. vertexData.applyToMesh(polyhedron, options.updatable);
  953. return polyhedron;
  954. };
  955. /**
  956. * Creates a decal mesh.
  957. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#decals
  958. * A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal.
  959. * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates.
  960. * The parameter `normal` (Vector3, default `Vector3.Up`) sets the normal of the mesh where the decal is applied onto in World coordinates.
  961. * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling.
  962. * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal.
  963. */
  964. MeshBuilder.CreateDecal = function (name, sourceMesh, options) {
  965. var indices = sourceMesh.getIndices();
  966. var positions = sourceMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  967. var normals = sourceMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  968. var position = options.position || BABYLON.Vector3.Zero();
  969. var normal = options.normal || BABYLON.Vector3.Up();
  970. var size = options.size || BABYLON.Vector3.One();
  971. var angle = options.angle || 0;
  972. // Getting correct rotation
  973. if (!normal) {
  974. var target = new BABYLON.Vector3(0, 0, 1);
  975. var camera = sourceMesh.getScene().activeCamera;
  976. var cameraWorldTarget = BABYLON.Vector3.TransformCoordinates(target, camera.getWorldMatrix());
  977. normal = camera.globalPosition.subtract(cameraWorldTarget);
  978. }
  979. var yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;
  980. var len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);
  981. var pitch = Math.atan2(normal.y, len);
  982. // Matrix
  983. var decalWorldMatrix = BABYLON.Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(BABYLON.Matrix.Translation(position.x, position.y, position.z));
  984. var inverseDecalWorldMatrix = BABYLON.Matrix.Invert(decalWorldMatrix);
  985. var meshWorldMatrix = sourceMesh.getWorldMatrix();
  986. var transformMatrix = meshWorldMatrix.multiply(inverseDecalWorldMatrix);
  987. var vertexData = new BABYLON.VertexData();
  988. vertexData.indices = [];
  989. vertexData.positions = [];
  990. vertexData.normals = [];
  991. vertexData.uvs = [];
  992. var currentVertexDataIndex = 0;
  993. var extractDecalVector3 = function (indexId) {
  994. var result = new BABYLON.PositionNormalVertex();
  995. if (!indices || !positions || !normals) {
  996. return result;
  997. }
  998. var vertexId = indices[indexId];
  999. result.position = new BABYLON.Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);
  1000. // Send vector to decal local world
  1001. result.position = BABYLON.Vector3.TransformCoordinates(result.position, transformMatrix);
  1002. // Get normal
  1003. result.normal = new BABYLON.Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
  1004. result.normal = BABYLON.Vector3.TransformNormal(result.normal, transformMatrix);
  1005. return result;
  1006. }; // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
  1007. var clip = function (vertices, axis) {
  1008. if (vertices.length === 0) {
  1009. return vertices;
  1010. }
  1011. var clipSize = 0.5 * Math.abs(BABYLON.Vector3.Dot(size, axis));
  1012. var clipVertices = function (v0, v1) {
  1013. var clipFactor = BABYLON.Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);
  1014. return new BABYLON.PositionNormalVertex(BABYLON.Vector3.Lerp(v0.position, v1.position, clipFactor), BABYLON.Vector3.Lerp(v0.normal, v1.normal, clipFactor));
  1015. };
  1016. var result = new Array();
  1017. for (var index = 0; index < vertices.length; index += 3) {
  1018. var v1Out;
  1019. var v2Out;
  1020. var v3Out;
  1021. var total = 0;
  1022. var nV1 = null;
  1023. var nV2 = null;
  1024. var nV3 = null;
  1025. var nV4 = null;
  1026. var d1 = BABYLON.Vector3.Dot(vertices[index].position, axis) - clipSize;
  1027. var d2 = BABYLON.Vector3.Dot(vertices[index + 1].position, axis) - clipSize;
  1028. var d3 = BABYLON.Vector3.Dot(vertices[index + 2].position, axis) - clipSize;
  1029. v1Out = d1 > 0;
  1030. v2Out = d2 > 0;
  1031. v3Out = d3 > 0;
  1032. total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);
  1033. switch (total) {
  1034. case 0:
  1035. result.push(vertices[index]);
  1036. result.push(vertices[index + 1]);
  1037. result.push(vertices[index + 2]);
  1038. break;
  1039. case 1:
  1040. if (v1Out) {
  1041. nV1 = vertices[index + 1];
  1042. nV2 = vertices[index + 2];
  1043. nV3 = clipVertices(vertices[index], nV1);
  1044. nV4 = clipVertices(vertices[index], nV2);
  1045. }
  1046. if (v2Out) {
  1047. nV1 = vertices[index];
  1048. nV2 = vertices[index + 2];
  1049. nV3 = clipVertices(vertices[index + 1], nV1);
  1050. nV4 = clipVertices(vertices[index + 1], nV2);
  1051. result.push(nV3);
  1052. result.push(nV2.clone());
  1053. result.push(nV1.clone());
  1054. result.push(nV2.clone());
  1055. result.push(nV3.clone());
  1056. result.push(nV4);
  1057. break;
  1058. }
  1059. if (v3Out) {
  1060. nV1 = vertices[index];
  1061. nV2 = vertices[index + 1];
  1062. nV3 = clipVertices(vertices[index + 2], nV1);
  1063. nV4 = clipVertices(vertices[index + 2], nV2);
  1064. }
  1065. if (nV1 && nV2 && nV3 && nV4) {
  1066. result.push(nV1.clone());
  1067. result.push(nV2.clone());
  1068. result.push(nV3);
  1069. result.push(nV4);
  1070. result.push(nV3.clone());
  1071. result.push(nV2.clone());
  1072. }
  1073. break;
  1074. case 2:
  1075. if (!v1Out) {
  1076. nV1 = vertices[index].clone();
  1077. nV2 = clipVertices(nV1, vertices[index + 1]);
  1078. nV3 = clipVertices(nV1, vertices[index + 2]);
  1079. result.push(nV1);
  1080. result.push(nV2);
  1081. result.push(nV3);
  1082. }
  1083. if (!v2Out) {
  1084. nV1 = vertices[index + 1].clone();
  1085. nV2 = clipVertices(nV1, vertices[index + 2]);
  1086. nV3 = clipVertices(nV1, vertices[index]);
  1087. result.push(nV1);
  1088. result.push(nV2);
  1089. result.push(nV3);
  1090. }
  1091. if (!v3Out) {
  1092. nV1 = vertices[index + 2].clone();
  1093. nV2 = clipVertices(nV1, vertices[index]);
  1094. nV3 = clipVertices(nV1, vertices[index + 1]);
  1095. result.push(nV1);
  1096. result.push(nV2);
  1097. result.push(nV3);
  1098. }
  1099. break;
  1100. case 3:
  1101. break;
  1102. }
  1103. }
  1104. return result;
  1105. };
  1106. for (var index = 0; index < indices.length; index += 3) {
  1107. var faceVertices = new Array();
  1108. faceVertices.push(extractDecalVector3(index));
  1109. faceVertices.push(extractDecalVector3(index + 1));
  1110. faceVertices.push(extractDecalVector3(index + 2));
  1111. // Clip
  1112. faceVertices = clip(faceVertices, new BABYLON.Vector3(1, 0, 0));
  1113. faceVertices = clip(faceVertices, new BABYLON.Vector3(-1, 0, 0));
  1114. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 1, 0));
  1115. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, -1, 0));
  1116. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, 1));
  1117. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, -1));
  1118. if (faceVertices.length === 0) {
  1119. continue;
  1120. }
  1121. // Add UVs and get back to world
  1122. for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
  1123. var vertex = faceVertices[vIndex];
  1124. //TODO check for Int32Array | Uint32Array | Uint16Array
  1125. vertexData.indices.push(currentVertexDataIndex);
  1126. vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
  1127. vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
  1128. vertexData.uvs.push(0.5 + vertex.position.x / size.x);
  1129. vertexData.uvs.push(0.5 + vertex.position.y / size.y);
  1130. currentVertexDataIndex++;
  1131. }
  1132. }
  1133. // Return mesh
  1134. var decal = new BABYLON.Mesh(name, sourceMesh.getScene());
  1135. vertexData.applyToMesh(decal);
  1136. decal.position = position.clone();
  1137. decal.rotation = new BABYLON.Vector3(pitch, yaw, angle);
  1138. return decal;
  1139. };
  1140. // Privates
  1141. MeshBuilder._ExtrudeShapeGeneric = function (name, shape, curve, scale, rotation, scaleFunction, rotateFunction, rbCA, rbCP, cap, custom, scene, updtbl, side, instance, invertUV, frontUVs, backUVs) {
  1142. // extrusion geometry
  1143. var extrusionPathArray = function (shape, curve, path3D, shapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom) {
  1144. var tangents = path3D.getTangents();
  1145. var normals = path3D.getNormals();
  1146. var binormals = path3D.getBinormals();
  1147. var distances = path3D.getDistances();
  1148. var angle = 0;
  1149. var returnScale = function () { return scale !== null ? scale : 1; };
  1150. var returnRotation = function () { return rotation !== null ? rotation : 0; };
  1151. var rotate = custom && rotateFunction ? rotateFunction : returnRotation;
  1152. var scl = custom && scaleFunction ? scaleFunction : returnScale;
  1153. var index = (cap === BABYLON.Mesh.NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  1154. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  1155. for (var i = 0; i < curve.length; i++) {
  1156. var shapePath = new Array();
  1157. var angleStep = rotate(i, distances[i]);
  1158. var scaleRatio = scl(i, distances[i]);
  1159. for (var p = 0; p < shape.length; p++) {
  1160. BABYLON.Matrix.RotationAxisToRef(tangents[i], angle, rotationMatrix);
  1161. var planed = ((tangents[i].scale(shape[p].z)).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y)));
  1162. var rotated = shapePath[p] ? shapePath[p] : BABYLON.Vector3.Zero();
  1163. BABYLON.Vector3.TransformCoordinatesToRef(planed, rotationMatrix, rotated);
  1164. rotated.scaleInPlace(scaleRatio).addInPlace(curve[i]);
  1165. shapePath[p] = rotated;
  1166. }
  1167. shapePaths[index] = shapePath;
  1168. angle += angleStep;
  1169. index++;
  1170. }
  1171. // cap
  1172. var capPath = function (shapePath) {
  1173. var pointCap = Array();
  1174. var barycenter = BABYLON.Vector3.Zero();
  1175. var i;
  1176. for (i = 0; i < shapePath.length; i++) {
  1177. barycenter.addInPlace(shapePath[i]);
  1178. }
  1179. barycenter.scaleInPlace(1.0 / shapePath.length);
  1180. for (i = 0; i < shapePath.length; i++) {
  1181. pointCap.push(barycenter);
  1182. }
  1183. return pointCap;
  1184. };
  1185. switch (cap) {
  1186. case BABYLON.Mesh.NO_CAP:
  1187. break;
  1188. case BABYLON.Mesh.CAP_START:
  1189. shapePaths[0] = capPath(shapePaths[2]);
  1190. shapePaths[1] = shapePaths[2];
  1191. break;
  1192. case BABYLON.Mesh.CAP_END:
  1193. shapePaths[index] = shapePaths[index - 1];
  1194. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  1195. break;
  1196. case BABYLON.Mesh.CAP_ALL:
  1197. shapePaths[0] = capPath(shapePaths[2]);
  1198. shapePaths[1] = shapePaths[2];
  1199. shapePaths[index] = shapePaths[index - 1];
  1200. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  1201. break;
  1202. default:
  1203. break;
  1204. }
  1205. return shapePaths;
  1206. };
  1207. var path3D;
  1208. var pathArray;
  1209. if (instance) {
  1210. path3D = (instance.path3D).update(curve);
  1211. pathArray = extrusionPathArray(shape, curve, instance.path3D, instance.pathArray, scale, rotation, scaleFunction, rotateFunction, instance.cap, custom);
  1212. instance = BABYLON.Mesh.CreateRibbon("", pathArray, false, false, 0, scene || undefined, false, 0, instance);
  1213. return instance;
  1214. }
  1215. // extruded shape creation
  1216. path3D = new BABYLON.Path3D(curve);
  1217. var newShapePaths = new Array();
  1218. cap = (cap < 0 || cap > 3) ? 0 : cap;
  1219. pathArray = extrusionPathArray(shape, curve, path3D, newShapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom);
  1220. var extrudedGeneric = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closeArray: rbCA, closePath: rbCP, updatable: updtbl, sideOrientation: side, invertUV: invertUV, frontUVs: frontUVs || undefined, backUVs: backUVs || undefined }, scene);
  1221. extrudedGeneric.pathArray = pathArray;
  1222. extrudedGeneric.path3D = path3D;
  1223. extrudedGeneric.cap = cap;
  1224. return extrudedGeneric;
  1225. };
  1226. return MeshBuilder;
  1227. }());
  1228. BABYLON.MeshBuilder = MeshBuilder;
  1229. })(BABYLON || (BABYLON = {}));
  1230. //# sourceMappingURL=babylon.meshBuilder.js.map
  1231. BABYLON.Effect.ShadersStore['defaultVertexShader'] = "#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}";
  1232. BABYLON.Effect.ShadersStore['defaultPixelShader'] = "#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}";
  1233. BABYLON.Effect.ShadersStore['colorVertexShader'] = "\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 viewProjection;\nuniform mat4 world;\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n}";
  1234. BABYLON.Effect.ShadersStore['colorPixelShader'] = "#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#else\nuniform vec4 color;\n#endif\nvoid main(void) {\n#ifdef VERTEXCOLOR\ngl_FragColor=vColor;\n#else\ngl_FragColor=color;\n#endif\n}";
  1235. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1236. BABYLON.Effect.IncludesShadersStore['bonesDeclaration'] = "#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif";
  1237. BABYLON.Effect.IncludesShadersStore['instancesDeclaration'] = "#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif";
  1238. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1239. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1240. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1241. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1242. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1243. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexDeclaration'] = "#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif";
  1244. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1245. BABYLON.Effect.IncludesShadersStore['morphTargetsVertex'] = "#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif";
  1246. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1247. BABYLON.Effect.IncludesShadersStore['bonesVertex'] = "#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif";
  1248. BABYLON.Effect.IncludesShadersStore['bumpVertex'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif";
  1249. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1250. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1251. BABYLON.Effect.IncludesShadersStore['shadowsVertex'] = "#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif";
  1252. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1253. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1254. BABYLON.Effect.IncludesShadersStore['helperFunctions'] = "const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nvec3 dither(vec2 seed,vec3 color) {\nfloat rand=getRand(seed);\ncolor+=mix(-0.5/255.0,0.5/255.0,rand);\ncolor=max(color,0.0);\nreturn color;\n}";
  1255. BABYLON.Effect.IncludesShadersStore['lightFragmentDeclaration'] = "#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif";
  1256. BABYLON.Effect.IncludesShadersStore['lightsFragmentFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n";
  1257. BABYLON.Effect.IncludesShadersStore['lightUboDeclaration'] = "#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif";
  1258. BABYLON.Effect.IncludesShadersStore['defaultVertexDeclaration'] = "\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  1259. BABYLON.Effect.IncludesShadersStore['defaultFragmentDeclaration'] = "uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif";
  1260. BABYLON.Effect.IncludesShadersStore['defaultUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  1261. BABYLON.Effect.IncludesShadersStore['shadowsFragmentFunctions'] = "#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n";
  1262. BABYLON.Effect.IncludesShadersStore['fresnelFunction'] = "#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif";
  1263. BABYLON.Effect.IncludesShadersStore['reflectionFunction'] = "vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}";
  1264. BABYLON.Effect.IncludesShadersStore['imageProcessingDeclaration'] = "#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif";
  1265. BABYLON.Effect.IncludesShadersStore['imageProcessingFunctions'] = "#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}";
  1266. BABYLON.Effect.IncludesShadersStore['bumpFragmentFunctions'] = "#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif";
  1267. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1268. BABYLON.Effect.IncludesShadersStore['fogFragmentDeclaration'] = "#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif";
  1269. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1270. BABYLON.Effect.IncludesShadersStore['bumpFragment'] = "vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif";
  1271. BABYLON.Effect.IncludesShadersStore['lightFragment'] = "#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif";
  1272. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1273. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1274. (function() {
  1275. var EXPORTS = {};EXPORTS['MeshBuilder'] = BABYLON['MeshBuilder'];
  1276. globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
  1277. module.exports = EXPORTS;
  1278. })();
  1279. }