es6.js 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. import * as BABYLON from 'babylonjs/core/es6';
  12. import * as additionalMeshes from 'babylonjs/additionalMeshes/es6';
  13. __extends(BABYLON, additionalMeshes);
  14. var BABYLON;
  15. (function (BABYLON) {
  16. var MeshBuilder = /** @class */ (function () {
  17. function MeshBuilder() {
  18. }
  19. MeshBuilder.updateSideOrientation = function (orientation) {
  20. if (orientation == BABYLON.Mesh.DOUBLESIDE) {
  21. return BABYLON.Mesh.DOUBLESIDE;
  22. }
  23. if (orientation === undefined || orientation === null) {
  24. return BABYLON.Mesh.FRONTSIDE;
  25. }
  26. return orientation;
  27. };
  28. /**
  29. * Creates a box mesh.
  30. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box
  31. * The parameter `size` sets the size (float) of each box side (default 1).
  32. * You can set some different box dimensions by using the parameters `width`, `height` and `depth` (all by default have the same value than `size`).
  33. * 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).
  34. * Please read this tutorial : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  35. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  36. * 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).
  37. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  38. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  39. */
  40. MeshBuilder.CreateBox = function (name, options, scene) {
  41. if (scene === void 0) { scene = null; }
  42. var box = new BABYLON.Mesh(name, scene);
  43. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  44. box._originalBuilderSideOrientation = options.sideOrientation;
  45. var vertexData = BABYLON.VertexData.CreateBox(options);
  46. vertexData.applyToMesh(box, options.updatable);
  47. return box;
  48. };
  49. /**
  50. * Creates a sphere mesh.
  51. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#sphere
  52. * The parameter `diameter` sets the diameter size (float) of the sphere (default 1).
  53. * 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`).
  54. * The parameter `segments` sets the sphere number of horizontal stripes (positive integer, default 32).
  55. * 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
  56. * 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).
  57. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  58. * 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).
  59. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  60. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  61. */
  62. MeshBuilder.CreateSphere = function (name, options, scene) {
  63. var sphere = new BABYLON.Mesh(name, scene);
  64. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  65. sphere._originalBuilderSideOrientation = options.sideOrientation;
  66. var vertexData = BABYLON.VertexData.CreateSphere(options);
  67. vertexData.applyToMesh(sphere, options.updatable);
  68. return sphere;
  69. };
  70. /**
  71. * Creates a plane polygonal mesh. By default, this is a disc.
  72. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#disc
  73. * The parameter `radius` sets the radius size (float) of the polygon (default 0.5).
  74. * 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.
  75. * 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
  76. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  77. * 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).
  78. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  79. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  80. */
  81. MeshBuilder.CreateDisc = function (name, options, scene) {
  82. if (scene === void 0) { scene = null; }
  83. var disc = new BABYLON.Mesh(name, scene);
  84. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  85. disc._originalBuilderSideOrientation = options.sideOrientation;
  86. var vertexData = BABYLON.VertexData.CreateDisc(options);
  87. vertexData.applyToMesh(disc, options.updatable);
  88. return disc;
  89. };
  90. /**
  91. * Creates a sphere based upon an icosahedron with 20 triangular faces which can be subdivided.
  92. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#icosphere
  93. * The parameter `radius` sets the radius size (float) of the icosphere (default 1).
  94. * 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`).
  95. * The parameter `subdivisions` sets the number of subdivisions (postive integer, default 4). The more subdivisions, the more faces on the icosphere whatever its size.
  96. * 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.
  97. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  98. * 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).
  99. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  100. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  101. */
  102. MeshBuilder.CreateIcoSphere = function (name, options, scene) {
  103. var sphere = new BABYLON.Mesh(name, scene);
  104. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  105. sphere._originalBuilderSideOrientation = options.sideOrientation;
  106. var vertexData = BABYLON.VertexData.CreateIcoSphere(options);
  107. vertexData.applyToMesh(sphere, options.updatable);
  108. return sphere;
  109. };
  110. ;
  111. /**
  112. * Creates a ribbon mesh.
  113. * 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.
  114. *
  115. * Please read this full tutorial to understand how to design a ribbon : http://doc.babylonjs.com/tutorials/Ribbon_Tutorial
  116. * The parameter `pathArray` is a required array of paths, what are each an array of successive Vector3. The pathArray parameter depicts the ribbon geometry.
  117. * The parameter `closeArray` (boolean, default false) creates a seam between the first and the last paths of the path array.
  118. * The parameter `closePath` (boolean, default false) creates a seam between the first and the last points of each path of the path array.
  119. * 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.
  120. * 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.
  121. * 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
  122. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  123. * 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).
  124. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  125. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  126. * 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.
  127. * The parameters `colors` is an optional flat array of `Color4` to set/update each ribbon vertex with its own custom color values.
  128. * 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
  129. * if you set `closePath` to `true`, there's one extra vertex per path in the geometry.
  130. * Moreover, you can use the parameter `color` with `instance` (to update the ribbon), only if you previously used it at creation time.
  131. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  132. */
  133. MeshBuilder.CreateRibbon = function (name, options, scene) {
  134. if (scene === void 0) { scene = null; }
  135. var pathArray = options.pathArray;
  136. var closeArray = options.closeArray;
  137. var closePath = options.closePath;
  138. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  139. var instance = options.instance;
  140. var updatable = options.updatable;
  141. if (instance) {
  142. // positionFunction : ribbon case
  143. // only pathArray and sideOrientation parameters are taken into account for positions update
  144. BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, BABYLON.Tmp.Vector3[0]); // minimum
  145. BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, BABYLON.Tmp.Vector3[1]);
  146. var positionFunction = function (positions) {
  147. var minlg = pathArray[0].length;
  148. var i = 0;
  149. var ns = (instance._originalBuilderSideOrientation === BABYLON.Mesh.DOUBLESIDE) ? 2 : 1;
  150. for (var si = 1; si <= ns; si++) {
  151. for (var p = 0; p < pathArray.length; p++) {
  152. var path = pathArray[p];
  153. var l = path.length;
  154. minlg = (minlg < l) ? minlg : l;
  155. var j = 0;
  156. while (j < minlg) {
  157. positions[i] = path[j].x;
  158. positions[i + 1] = path[j].y;
  159. positions[i + 2] = path[j].z;
  160. if (path[j].x < BABYLON.Tmp.Vector3[0].x) {
  161. BABYLON.Tmp.Vector3[0].x = path[j].x;
  162. }
  163. if (path[j].x > BABYLON.Tmp.Vector3[1].x) {
  164. BABYLON.Tmp.Vector3[1].x = path[j].x;
  165. }
  166. if (path[j].y < BABYLON.Tmp.Vector3[0].y) {
  167. BABYLON.Tmp.Vector3[0].y = path[j].y;
  168. }
  169. if (path[j].y > BABYLON.Tmp.Vector3[1].y) {
  170. BABYLON.Tmp.Vector3[1].y = path[j].y;
  171. }
  172. if (path[j].z < BABYLON.Tmp.Vector3[0].z) {
  173. BABYLON.Tmp.Vector3[0].z = path[j].z;
  174. }
  175. if (path[j].z > BABYLON.Tmp.Vector3[1].z) {
  176. BABYLON.Tmp.Vector3[1].z = path[j].z;
  177. }
  178. j++;
  179. i += 3;
  180. }
  181. if (instance._closePath) {
  182. positions[i] = path[0].x;
  183. positions[i + 1] = path[0].y;
  184. positions[i + 2] = path[0].z;
  185. i += 3;
  186. }
  187. }
  188. }
  189. };
  190. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  191. positionFunction(positions);
  192. instance._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Tmp.Vector3[0], BABYLON.Tmp.Vector3[1]);
  193. instance._boundingInfo.update(instance._worldMatrix);
  194. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  195. if (options.colors) {
  196. var colors = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  197. for (var c = 0; c < options.colors.length; c++) {
  198. colors[c * 4] = options.colors[c].r;
  199. colors[c * 4 + 1] = options.colors[c].g;
  200. colors[c * 4 + 2] = options.colors[c].b;
  201. colors[c * 4 + 3] = options.colors[c].a;
  202. }
  203. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, colors, false, false);
  204. }
  205. if (options.uvs) {
  206. var uvs = instance.getVerticesData(BABYLON.VertexBuffer.UVKind);
  207. for (var i = 0; i < options.uvs.length; i++) {
  208. uvs[i * 2] = options.uvs[i].x;
  209. uvs[i * 2 + 1] = options.uvs[i].y;
  210. }
  211. instance.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs, false, false);
  212. }
  213. if (!instance.areNormalsFrozen || instance.isFacetDataEnabled) {
  214. var indices = instance.getIndices();
  215. var normals = instance.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  216. var params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;
  217. BABYLON.VertexData.ComputeNormals(positions, indices, normals, params);
  218. if (instance._closePath) {
  219. var indexFirst = 0;
  220. var indexLast = 0;
  221. for (var p = 0; p < pathArray.length; p++) {
  222. indexFirst = instance._idx[p] * 3;
  223. if (p + 1 < pathArray.length) {
  224. indexLast = (instance._idx[p + 1] - 1) * 3;
  225. }
  226. else {
  227. indexLast = normals.length - 3;
  228. }
  229. normals[indexFirst] = (normals[indexFirst] + normals[indexLast]) * 0.5;
  230. normals[indexFirst + 1] = (normals[indexFirst + 1] + normals[indexLast + 1]) * 0.5;
  231. normals[indexFirst + 2] = (normals[indexFirst + 2] + normals[indexLast + 2]) * 0.5;
  232. normals[indexLast] = normals[indexFirst];
  233. normals[indexLast + 1] = normals[indexFirst + 1];
  234. normals[indexLast + 2] = normals[indexFirst + 2];
  235. }
  236. }
  237. if (!(instance.areNormalsFrozen)) {
  238. instance.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
  239. }
  240. }
  241. return instance;
  242. }
  243. else {
  244. var ribbon = new BABYLON.Mesh(name, scene);
  245. ribbon._originalBuilderSideOrientation = sideOrientation;
  246. var vertexData = BABYLON.VertexData.CreateRibbon(options);
  247. if (closePath) {
  248. ribbon._idx = vertexData._idx;
  249. }
  250. ribbon._closePath = closePath;
  251. ribbon._closeArray = closeArray;
  252. vertexData.applyToMesh(ribbon, updatable);
  253. return ribbon;
  254. }
  255. };
  256. /**
  257. * Creates a cylinder or a cone mesh.
  258. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#cylinder-or-cone
  259. * The parameter `height` sets the height size (float) of the cylinder/cone (float, default 2).
  260. * The parameter `diameter` sets the diameter of the top and bottom cap at once (float, default 1).
  261. * 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.
  262. * The parameter `tessellation` sets the number of cylinder sides (positive integer, default 24). Set it to 3 to get a prism for instance.
  263. * The parameter `subdivisions` sets the number of rings along the cylinder height (positive integer, default 1).
  264. * The parameter `hasRings` (boolean, default false) makes the subdivisions independent from each other, so they become different faces.
  265. * The parameter `enclose` (boolean, default false) adds two extra faces per subdivision to a sliced cylinder to close it around its height axis.
  266. * The parameter `arc` (float, default 1) is the ratio (max 1) to apply to the circumference to slice the cylinder.
  267. * 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).
  268. * 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
  269. * Now, if the cylinder has 5 independent subdivisions (hasRings = true), n equals : top face + 5 stripe surfaces + bottom face = 2 + 5 = 7
  270. * 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
  271. * 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.
  272. * If `enclose` is false, a ring surface is one element.
  273. * If `enclose` is true, a ring surface is 3 successive elements in the array : the tubular surface, then the two closing faces.
  274. * 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
  275. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  276. * 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).
  277. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  278. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  279. */
  280. MeshBuilder.CreateCylinder = function (name, options, scene) {
  281. var cylinder = new BABYLON.Mesh(name, scene);
  282. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  283. cylinder._originalBuilderSideOrientation = options.sideOrientation;
  284. var vertexData = BABYLON.VertexData.CreateCylinder(options);
  285. vertexData.applyToMesh(cylinder, options.updatable);
  286. return cylinder;
  287. };
  288. /**
  289. * Creates a torus mesh.
  290. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus
  291. * The parameter `diameter` sets the diameter size (float) of the torus (default 1).
  292. * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5).
  293. * The parameter `tessellation` sets the number of torus sides (postive integer, default 16).
  294. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  295. * 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).
  296. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  297. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  298. */
  299. MeshBuilder.CreateTorus = function (name, options, scene) {
  300. var torus = new BABYLON.Mesh(name, scene);
  301. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  302. torus._originalBuilderSideOrientation = options.sideOrientation;
  303. var vertexData = BABYLON.VertexData.CreateTorus(options);
  304. vertexData.applyToMesh(torus, options.updatable);
  305. return torus;
  306. };
  307. /**
  308. * Creates a torus knot mesh.
  309. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#torus-knot
  310. * The parameter `radius` sets the global radius size (float) of the torus knot (default 2).
  311. * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32).
  312. * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32).
  313. * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3).
  314. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  315. * 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).
  316. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  317. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  318. */
  319. MeshBuilder.CreateTorusKnot = function (name, options, scene) {
  320. var torusKnot = new BABYLON.Mesh(name, scene);
  321. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  322. torusKnot._originalBuilderSideOrientation = options.sideOrientation;
  323. var vertexData = BABYLON.VertexData.CreateTorusKnot(options);
  324. vertexData.applyToMesh(torusKnot, options.updatable);
  325. return torusKnot;
  326. };
  327. /**
  328. * Creates a line system mesh.
  329. * A line system is a pool of many lines gathered in a single mesh.
  330. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem
  331. * 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.
  332. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineSystem to this static function.
  333. * The parameter `lines` is an array of lines, each line being an array of successive Vector3.
  334. * 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
  335. * The optional parameter `colors` is an array of line colors, each line colors being an array of successive Color4, one per line point.
  336. * The optional parameter `useVertexAlpha' is to be set to `false` (default `true`) when you don't need the alpha blending (faster).
  337. * 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
  338. * When updating an instance, remember that only line point positions can change, not the number of points, neither the number of lines.
  339. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  340. */
  341. MeshBuilder.CreateLineSystem = function (name, options, scene) {
  342. var instance = options.instance;
  343. var lines = options.lines;
  344. var colors = options.colors;
  345. if (instance) {
  346. var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  347. var vertexColor;
  348. var lineColors;
  349. if (colors) {
  350. vertexColor = instance.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  351. }
  352. var i = 0;
  353. var c = 0;
  354. for (var l = 0; l < lines.length; l++) {
  355. var points = lines[l];
  356. for (var p = 0; p < points.length; p++) {
  357. positions[i] = points[p].x;
  358. positions[i + 1] = points[p].y;
  359. positions[i + 2] = points[p].z;
  360. if (colors && vertexColor) {
  361. lineColors = colors[l];
  362. vertexColor[c] = lineColors[p].r;
  363. vertexColor[c + 1] = lineColors[p].g;
  364. vertexColor[c + 2] = lineColors[p].b;
  365. vertexColor[c + 3] = lineColors[p].a;
  366. c += 4;
  367. }
  368. i += 3;
  369. }
  370. }
  371. instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
  372. if (colors && vertexColor) {
  373. instance.updateVerticesData(BABYLON.VertexBuffer.ColorKind, vertexColor, false, false);
  374. }
  375. return instance;
  376. }
  377. // line system creation
  378. var useVertexColor = (colors) ? true : false;
  379. var lineSystem = new BABYLON.LinesMesh(name, scene, null, undefined, undefined, useVertexColor, options.useVertexAlpha);
  380. var vertexData = BABYLON.VertexData.CreateLineSystem(options);
  381. vertexData.applyToMesh(lineSystem, options.updatable);
  382. return lineSystem;
  383. };
  384. /**
  385. * Creates a line mesh.
  386. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#lines
  387. * 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.
  388. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  389. * The parameter `points` is an array successive Vector3.
  390. * 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
  391. * The optional parameter `colors` is an array of successive Color4, one per line point.
  392. * The optional parameter `useVertexAlpha' is to be set to `false` (default `true`) when you don't need alpha blending (faster).
  393. * When updating an instance, remember that only point positions can change, not the number of points.
  394. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  395. */
  396. MeshBuilder.CreateLines = function (name, options, scene) {
  397. if (scene === void 0) { scene = null; }
  398. var colors = (options.colors) ? [options.colors] : null;
  399. var lines = MeshBuilder.CreateLineSystem(name, { lines: [options.points], updatable: options.updatable, instance: options.instance, colors: colors, useVertexAlpha: options.useVertexAlpha }, scene);
  400. return lines;
  401. };
  402. /**
  403. * Creates a dashed line mesh.
  404. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#dashed-lines
  405. * 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.
  406. * Like every other parametric shape, it is dynamically updatable by passing an existing instance of LineMesh to this static function.
  407. * The parameter `points` is an array successive Vector3.
  408. * The parameter `dashNb` is the intended total number of dashes (positive integer, default 200).
  409. * The parameter `dashSize` is the size of the dashes relatively the dash number (positive float, default 3).
  410. * The parameter `gapSize` is the size of the gap between two successive dashes relatively the dash number (positive float, default 1).
  411. * 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
  412. * When updating an instance, remember that only point positions can change, not the number of points.
  413. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  414. */
  415. MeshBuilder.CreateDashedLines = function (name, options, scene) {
  416. if (scene === void 0) { scene = null; }
  417. var points = options.points;
  418. var instance = options.instance;
  419. var gapSize = options.gapSize || 1;
  420. var dashSize = options.dashSize || 3;
  421. if (instance) {
  422. var positionFunction = function (positions) {
  423. var curvect = BABYLON.Vector3.Zero();
  424. var nbSeg = positions.length / 6;
  425. var lg = 0;
  426. var nb = 0;
  427. var shft = 0;
  428. var dashshft = 0;
  429. var curshft = 0;
  430. var p = 0;
  431. var i = 0;
  432. var j = 0;
  433. for (i = 0; i < points.length - 1; i++) {
  434. points[i + 1].subtractToRef(points[i], curvect);
  435. lg += curvect.length();
  436. }
  437. shft = lg / nbSeg;
  438. dashshft = instance.dashSize * shft / (instance.dashSize + instance.gapSize);
  439. for (i = 0; i < points.length - 1; i++) {
  440. points[i + 1].subtractToRef(points[i], curvect);
  441. nb = Math.floor(curvect.length() / shft);
  442. curvect.normalize();
  443. j = 0;
  444. while (j < nb && p < positions.length) {
  445. curshft = shft * j;
  446. positions[p] = points[i].x + curshft * curvect.x;
  447. positions[p + 1] = points[i].y + curshft * curvect.y;
  448. positions[p + 2] = points[i].z + curshft * curvect.z;
  449. positions[p + 3] = points[i].x + (curshft + dashshft) * curvect.x;
  450. positions[p + 4] = points[i].y + (curshft + dashshft) * curvect.y;
  451. positions[p + 5] = points[i].z + (curshft + dashshft) * curvect.z;
  452. p += 6;
  453. j++;
  454. }
  455. }
  456. while (p < positions.length) {
  457. positions[p] = points[i].x;
  458. positions[p + 1] = points[i].y;
  459. positions[p + 2] = points[i].z;
  460. p += 3;
  461. }
  462. };
  463. instance.updateMeshPositions(positionFunction, false);
  464. return instance;
  465. }
  466. // dashed lines creation
  467. var dashedLines = new BABYLON.LinesMesh(name, scene);
  468. var vertexData = BABYLON.VertexData.CreateDashedLines(options);
  469. vertexData.applyToMesh(dashedLines, options.updatable);
  470. dashedLines.dashSize = dashSize;
  471. dashedLines.gapSize = gapSize;
  472. return dashedLines;
  473. };
  474. /**
  475. * Creates an extruded shape mesh.
  476. * 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.
  477. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#extruded-shapes
  478. *
  479. * Please read this full tutorial to understand how to design an extruded shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes#extrusion
  480. * 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
  481. * extruded along the Z axis.
  482. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  483. * 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.
  484. * The parameter `scale` (float, default 1) is the value to scale the shape.
  485. * 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
  486. * 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
  487. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  488. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  489. * 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).
  490. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  491. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  492. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  493. */
  494. MeshBuilder.ExtrudeShape = function (name, options, scene) {
  495. if (scene === void 0) { scene = null; }
  496. var path = options.path;
  497. var shape = options.shape;
  498. var scale = options.scale || 1;
  499. var rotation = options.rotation || 0;
  500. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  501. var updatable = options.updatable;
  502. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  503. var instance = options.instance || null;
  504. var invertUV = options.invertUV || false;
  505. 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);
  506. };
  507. /**
  508. * Creates an custom extruded shape mesh.
  509. * 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.
  510. * tuto :http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#custom-extruded-shapes
  511. *
  512. * Please read this full tutorial to understand how to design a custom extruded shape : http://doc.babylonjs.com/tutorials/Parametric_Shapes#extrusion
  513. * 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
  514. * extruded along the Z axis.
  515. * The parameter `path` is a required array of successive Vector3. This is the axis curve the shape is extruded along.
  516. * 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
  517. * and the distance of this point from the begining of the path :
  518. * ```javascript
  519. * var rotationFunction = function(i, distance) {
  520. * // do things
  521. * return rotationValue; }
  522. * ```
  523. * It must returns a float value that will be the rotation in radians applied to the shape on each path point.
  524. * 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
  525. * and the distance of this point from the begining of the path :
  526. * ```javascript
  527. * var scaleFunction = function(i, distance) {
  528. * // do things
  529. * return scaleValue;}
  530. * ```
  531. * It must returns a float value that will be the scale value applied to the shape on each path point.
  532. * The parameter `ribbonClosePath` (boolean, default false) forces the extrusion underlying ribbon to close all the paths in its `pathArray`.
  533. * The parameter `ribbonCloseArray` (boolean, default false) forces the extrusion underlying ribbon to close its `pathArray`.
  534. * 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
  535. * 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
  536. * Remember you can only change the shape or path point positions, not their number when updating an extruded shape.
  537. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  538. * 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).
  539. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  540. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  541. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  542. */
  543. MeshBuilder.ExtrudeShapeCustom = function (name, options, scene) {
  544. var path = options.path;
  545. var shape = options.shape;
  546. var scaleFunction = options.scaleFunction || (function () { return 1; });
  547. var rotationFunction = options.rotationFunction || (function () { return 0; });
  548. var ribbonCloseArray = options.ribbonCloseArray || false;
  549. var ribbonClosePath = options.ribbonClosePath || false;
  550. var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
  551. var updatable = options.updatable;
  552. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  553. var instance = options.instance;
  554. var invertUV = options.invertUV || false;
  555. 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);
  556. };
  557. /**
  558. * Creates lathe mesh.
  559. * The lathe is a shape with a symetry axis : a 2D model shape is rotated around this axis to design the lathe.
  560. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#lathe
  561. *
  562. * 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
  563. * rotated around the Y axis. It's usually a 2D shape, so the Vector3 z coordinates are often set to zero.
  564. * The parameter `radius` (positive float, default 1) is the radius value of the lathe.
  565. * The parameter `tessellation` (positive integer, default 64) is the side number of the lathe.
  566. * 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.
  567. * The parameter `closed` (boolean, default true) opens/closes the lathe circumference. This should be set to false when used with the parameter "arc".
  568. * 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
  569. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  570. * 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).
  571. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  572. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  573. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  574. */
  575. MeshBuilder.CreateLathe = function (name, options, scene) {
  576. var arc = options.arc ? ((options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc) : 1.0;
  577. var closed = (options.closed === undefined) ? true : options.closed;
  578. var shape = options.shape;
  579. var radius = options.radius || 1;
  580. var tessellation = options.tessellation || 64;
  581. var updatable = options.updatable;
  582. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  583. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  584. var pi2 = Math.PI * 2;
  585. var paths = new Array();
  586. var invertUV = options.invertUV || false;
  587. var i = 0;
  588. var p = 0;
  589. var step = pi2 / tessellation * arc;
  590. var rotated;
  591. var path = new Array();
  592. ;
  593. for (i = 0; i <= tessellation; i++) {
  594. var path = [];
  595. if (cap == BABYLON.Mesh.CAP_START || cap == BABYLON.Mesh.CAP_ALL) {
  596. path.push(new BABYLON.Vector3(0, shape[0].y, 0));
  597. path.push(new BABYLON.Vector3(Math.cos(i * step) * shape[0].x * radius, shape[0].y, Math.sin(i * step) * shape[0].x * radius));
  598. }
  599. for (p = 0; p < shape.length; p++) {
  600. rotated = new BABYLON.Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y, Math.sin(i * step) * shape[p].x * radius);
  601. path.push(rotated);
  602. }
  603. if (cap == BABYLON.Mesh.CAP_END || cap == BABYLON.Mesh.CAP_ALL) {
  604. 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));
  605. path.push(new BABYLON.Vector3(0, shape[shape.length - 1].y, 0));
  606. }
  607. paths.push(path);
  608. }
  609. // lathe ribbon
  610. var lathe = MeshBuilder.CreateRibbon(name, { pathArray: paths, closeArray: closed, sideOrientation: sideOrientation, updatable: updatable, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  611. return lathe;
  612. };
  613. /**
  614. * Creates a plane mesh.
  615. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  616. * The parameter `size` sets the size (float) of both sides of the plane at once (default 1).
  617. * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value than `size`).
  618. * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane.
  619. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  620. * 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).
  621. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  622. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  623. */
  624. MeshBuilder.CreatePlane = function (name, options, scene) {
  625. var plane = new BABYLON.Mesh(name, scene);
  626. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  627. plane._originalBuilderSideOrientation = options.sideOrientation;
  628. var vertexData = BABYLON.VertexData.CreatePlane(options);
  629. vertexData.applyToMesh(plane, options.updatable);
  630. if (options.sourcePlane) {
  631. plane.translate(options.sourcePlane.normal, options.sourcePlane.d);
  632. var product = Math.acos(BABYLON.Vector3.Dot(options.sourcePlane.normal, BABYLON.Axis.Z));
  633. var vectorProduct = BABYLON.Vector3.Cross(BABYLON.Axis.Z, options.sourcePlane.normal);
  634. plane.rotate(vectorProduct, product);
  635. }
  636. return plane;
  637. };
  638. /**
  639. * Creates a ground mesh.
  640. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#plane
  641. * The parameters `width` and `height` (floats, default 1) set the width and height sizes of the ground.
  642. * The parameter `subdivisions` (positive integer) sets the number of subdivisions per side.
  643. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  644. */
  645. MeshBuilder.CreateGround = function (name, options, scene) {
  646. var ground = new BABYLON.GroundMesh(name, scene);
  647. ground._setReady(false);
  648. ground._subdivisionsX = options.subdivisionsX || options.subdivisions || 1;
  649. ground._subdivisionsY = options.subdivisionsY || options.subdivisions || 1;
  650. ground._width = options.width || 1;
  651. ground._height = options.height || 1;
  652. ground._maxX = ground._width / 2;
  653. ground._maxZ = ground._height / 2;
  654. ground._minX = -ground._maxX;
  655. ground._minZ = -ground._maxZ;
  656. var vertexData = BABYLON.VertexData.CreateGround(options);
  657. vertexData.applyToMesh(ground, options.updatable);
  658. ground._setReady(true);
  659. return ground;
  660. };
  661. /**
  662. * Creates a tiled ground mesh.
  663. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tiled-ground
  664. * The parameters `xmin` and `xmax` (floats, default -1 and 1) set the ground minimum and maximum X coordinates.
  665. * The parameters `zmin` and `zmax` (floats, default -1 and 1) set the ground minimum and maximum Z coordinates.
  666. * The parameter `subdivisions` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the
  667. * numbers of subdivisions on the ground width and height. Each subdivision is called a tile.
  668. * The parameter `precision` is a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the
  669. * numbers of subdivisions on the ground width and height of each tile.
  670. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  671. */
  672. MeshBuilder.CreateTiledGround = function (name, options, scene) {
  673. var tiledGround = new BABYLON.Mesh(name, scene);
  674. var vertexData = BABYLON.VertexData.CreateTiledGround(options);
  675. vertexData.applyToMesh(tiledGround, options.updatable);
  676. return tiledGround;
  677. };
  678. /**
  679. * Creates a ground mesh from a height map.
  680. * tuto : http://doc.babylonjs.com/tutorials/14._Height_Map
  681. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#ground-from-a-height-map
  682. * The parameter `url` sets the URL of the height map image resource.
  683. * The parameters `width` and `height` (positive floats, default 10) set the ground width and height sizes.
  684. * The parameter `subdivisions` (positive integer, default 1) sets the number of subdivision per side.
  685. * The parameter `minHeight` (float, default 0) is the minimum altitude on the ground.
  686. * The parameter `maxHeight` (float, default 1) is the maximum altitude on the ground.
  687. * 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.
  688. * 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).
  689. * This function is passed the newly built mesh :
  690. * ```javascript
  691. * function(mesh) { // do things
  692. * return; }
  693. * ```
  694. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  695. */
  696. MeshBuilder.CreateGroundFromHeightMap = function (name, url, options, scene) {
  697. var width = options.width || 10.0;
  698. var height = options.height || 10.0;
  699. var subdivisions = options.subdivisions || 1 | 0;
  700. var minHeight = options.minHeight || 0.0;
  701. var maxHeight = options.maxHeight || 1.0;
  702. var filter = options.colorFilter || new BABYLON.Color3(0.3, 0.59, 0.11);
  703. var updatable = options.updatable;
  704. var onReady = options.onReady;
  705. var ground = new BABYLON.GroundMesh(name, scene);
  706. ground._subdivisionsX = subdivisions;
  707. ground._subdivisionsY = subdivisions;
  708. ground._width = width;
  709. ground._height = height;
  710. ground._maxX = ground._width / 2.0;
  711. ground._maxZ = ground._height / 2.0;
  712. ground._minX = -ground._maxX;
  713. ground._minZ = -ground._maxZ;
  714. ground._setReady(false);
  715. var onload = function (img) {
  716. // Getting height map data
  717. var canvas = document.createElement("canvas");
  718. var context = canvas.getContext("2d");
  719. if (!context) {
  720. throw new Error("Unable to get 2d context for CreateGroundFromHeightMap");
  721. }
  722. if (scene.isDisposed) {
  723. return;
  724. }
  725. var bufferWidth = img.width;
  726. var bufferHeight = img.height;
  727. canvas.width = bufferWidth;
  728. canvas.height = bufferHeight;
  729. context.drawImage(img, 0, 0);
  730. // Create VertexData from map data
  731. // Cast is due to wrong definition in lib.d.ts from ts 1.3 - https://github.com/Microsoft/TypeScript/issues/949
  732. var buffer = context.getImageData(0, 0, bufferWidth, bufferHeight).data;
  733. var vertexData = BABYLON.VertexData.CreateGroundFromHeightMap({
  734. width: width, height: height,
  735. subdivisions: subdivisions,
  736. minHeight: minHeight, maxHeight: maxHeight, colorFilter: filter,
  737. buffer: buffer, bufferWidth: bufferWidth, bufferHeight: bufferHeight
  738. });
  739. vertexData.applyToMesh(ground, updatable);
  740. ground._setReady(true);
  741. //execute ready callback, if set
  742. if (onReady) {
  743. onReady(ground);
  744. }
  745. };
  746. BABYLON.Tools.LoadImage(url, onload, function () { }, scene.database);
  747. return ground;
  748. };
  749. /**
  750. * Creates a polygon mesh.
  751. * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.
  752. * 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.
  753. * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  754. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  755. * 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).
  756. * Remember you can only change the shape positions, not their number when updating a polygon.
  757. */
  758. MeshBuilder.CreatePolygon = function (name, options, scene) {
  759. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  760. var shape = options.shape;
  761. var holes = options.holes || [];
  762. var depth = options.depth || 0;
  763. var contours = [];
  764. var hole = [];
  765. for (var i = 0; i < shape.length; i++) {
  766. contours[i] = new BABYLON.Vector2(shape[i].x, shape[i].z);
  767. }
  768. var epsilon = 0.00000001;
  769. if (contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
  770. contours.pop();
  771. }
  772. var polygonTriangulation = new BABYLON.PolygonMeshBuilder(name, contours, scene);
  773. for (var hNb = 0; hNb < holes.length; hNb++) {
  774. hole = [];
  775. for (var hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
  776. hole.push(new BABYLON.Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
  777. }
  778. polygonTriangulation.addHole(hole);
  779. }
  780. var polygon = polygonTriangulation.build(options.updatable, depth);
  781. polygon._originalBuilderSideOrientation = options.sideOrientation;
  782. var vertexData = BABYLON.VertexData.CreatePolygon(polygon, options.sideOrientation, options.faceUV, options.faceColors, options.frontUVs, options.backUVs);
  783. vertexData.applyToMesh(polygon, options.updatable);
  784. return polygon;
  785. };
  786. ;
  787. /**
  788. * Creates an extruded polygon mesh, with depth in the Y direction.
  789. * 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).
  790. * Please read this tutorial : http://doc.babylonjs.com/tutorials/CreateBox_Per_Face_Textures_And_Colors
  791. */
  792. MeshBuilder.ExtrudePolygon = function (name, options, scene) {
  793. return MeshBuilder.CreatePolygon(name, options, scene);
  794. };
  795. ;
  796. /**
  797. * Creates a tube mesh.
  798. * 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.
  799. *
  800. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#tube
  801. * The parameter `path` is a required array of successive Vector3. It is the curve used as the axis of the tube.
  802. * The parameter `radius` (positive float, default 1) sets the tube radius size.
  803. * The parameter `tessellation` (positive float, default 64) is the number of sides on the tubular surface.
  804. * The parameter `radiusFunction` (javascript function, default null) is a vanilla javascript function. If it is not null, it overwrittes the parameter `radius`.
  805. * 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.
  806. * It must return a radius value (positive float) :
  807. * ```javascript
  808. * var radiusFunction = function(i, distance) {
  809. * // do things
  810. * return radius; }
  811. * ```
  812. * The parameter `arc` (positive float, maximum 1, default 1) is the ratio to apply to the tube circumference : 2 x PI x arc.
  813. * 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
  814. * 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
  815. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  816. * 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).
  817. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  818. * The optional parameter `invertUV` (boolean, default false) swaps in the geometry the U and V coordinates to apply a texture.
  819. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  820. */
  821. MeshBuilder.CreateTube = function (name, options, scene) {
  822. var path = options.path;
  823. var instance = options.instance;
  824. var radius = 1.0;
  825. if (instance) {
  826. radius = instance.radius;
  827. }
  828. if (options.radius !== undefined) {
  829. radius = options.radius;
  830. }
  831. ;
  832. var tessellation = options.tessellation || 64 | 0;
  833. var radiusFunction = options.radiusFunction || null;
  834. var cap = options.cap || BABYLON.Mesh.NO_CAP;
  835. var invertUV = options.invertUV || false;
  836. var updatable = options.updatable;
  837. var sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  838. options.arc = options.arc && (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
  839. // tube geometry
  840. var tubePathArray = function (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) {
  841. var tangents = path3D.getTangents();
  842. var normals = path3D.getNormals();
  843. var distances = path3D.getDistances();
  844. var pi2 = Math.PI * 2;
  845. var step = pi2 / tessellation * arc;
  846. var returnRadius = function () { return radius; };
  847. var radiusFunctionFinal = radiusFunction || returnRadius;
  848. var circlePath;
  849. var rad;
  850. var normal;
  851. var rotated;
  852. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  853. var index = (cap === BABYLON.Mesh._NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  854. for (var i = 0; i < path.length; i++) {
  855. rad = radiusFunctionFinal(i, distances[i]); // current radius
  856. circlePath = Array(); // current circle array
  857. normal = normals[i]; // current normal
  858. for (var t = 0; t < tessellation; t++) {
  859. BABYLON.Matrix.RotationAxisToRef(tangents[i], step * t, rotationMatrix);
  860. rotated = circlePath[t] ? circlePath[t] : BABYLON.Vector3.Zero();
  861. BABYLON.Vector3.TransformCoordinatesToRef(normal, rotationMatrix, rotated);
  862. rotated.scaleInPlace(rad).addInPlace(path[i]);
  863. circlePath[t] = rotated;
  864. }
  865. circlePaths[index] = circlePath;
  866. index++;
  867. }
  868. // cap
  869. var capPath = function (nbPoints, pathIndex) {
  870. var pointCap = Array();
  871. for (var i = 0; i < nbPoints; i++) {
  872. pointCap.push(path[pathIndex]);
  873. }
  874. return pointCap;
  875. };
  876. switch (cap) {
  877. case BABYLON.Mesh.NO_CAP:
  878. break;
  879. case BABYLON.Mesh.CAP_START:
  880. circlePaths[0] = capPath(tessellation, 0);
  881. circlePaths[1] = circlePaths[2].slice(0);
  882. break;
  883. case BABYLON.Mesh.CAP_END:
  884. circlePaths[index] = circlePaths[index - 1].slice(0);
  885. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  886. break;
  887. case BABYLON.Mesh.CAP_ALL:
  888. circlePaths[0] = capPath(tessellation, 0);
  889. circlePaths[1] = circlePaths[2].slice(0);
  890. circlePaths[index] = circlePaths[index - 1].slice(0);
  891. circlePaths[index + 1] = capPath(tessellation, path.length - 1);
  892. break;
  893. default:
  894. break;
  895. }
  896. return circlePaths;
  897. };
  898. var path3D;
  899. var pathArray;
  900. if (instance) {
  901. var arc = options.arc || instance.arc;
  902. path3D = (instance.path3D).update(path);
  903. pathArray = tubePathArray(path, path3D, instance.pathArray, radius, instance.tessellation, radiusFunction, instance.cap, arc);
  904. instance = MeshBuilder.CreateRibbon("", { pathArray: pathArray, instance: instance });
  905. instance.path3D = path3D;
  906. instance.pathArray = pathArray;
  907. instance.arc = arc;
  908. instance.radius = radius;
  909. return instance;
  910. }
  911. // tube creation
  912. path3D = new BABYLON.Path3D(path);
  913. var newPathArray = new Array();
  914. cap = (cap < 0 || cap > 3) ? 0 : cap;
  915. pathArray = tubePathArray(path, path3D, newPathArray, radius, tessellation, radiusFunction, cap, options.arc);
  916. var tube = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closePath: true, closeArray: false, updatable: updatable, sideOrientation: sideOrientation, invertUV: invertUV, frontUVs: options.frontUVs, backUVs: options.backUVs }, scene);
  917. tube.pathArray = pathArray;
  918. tube.path3D = path3D;
  919. tube.tessellation = tessellation;
  920. tube.cap = cap;
  921. tube.arc = options.arc;
  922. tube.radius = radius;
  923. return tube;
  924. };
  925. /**
  926. * Creates a polyhedron mesh.
  927. *
  928. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#polyhedron
  929. * 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
  930. * to choose the wanted type.
  931. * The parameter `size` (positive float, default 1) sets the polygon size.
  932. * You can overwrite the `size` on each dimension bu using the parameters `sizeX`, `sizeY` or `sizeZ` (positive floats, default to `size` value).
  933. * 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`.
  934. * 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
  935. * 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)`).
  936. * 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
  937. * 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.
  938. * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
  939. * 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).
  940. * Detail here : http://doc.babylonjs.com/tutorials/02._Discover_Basic_Elements#side-orientation
  941. * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
  942. */
  943. MeshBuilder.CreatePolyhedron = function (name, options, scene) {
  944. var polyhedron = new BABYLON.Mesh(name, scene);
  945. options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation);
  946. polyhedron._originalBuilderSideOrientation = options.sideOrientation;
  947. var vertexData = BABYLON.VertexData.CreatePolyhedron(options);
  948. vertexData.applyToMesh(polyhedron, options.updatable);
  949. return polyhedron;
  950. };
  951. /**
  952. * Creates a decal mesh.
  953. * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#decals
  954. * 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.
  955. * The parameter `position` (Vector3, default `(0, 0, 0)`) sets the position of the decal in World coordinates.
  956. * The parameter `normal` (Vector3, default `Vector3.Up`) sets the normal of the mesh where the decal is applied onto in World coordinates.
  957. * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling.
  958. * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal.
  959. */
  960. MeshBuilder.CreateDecal = function (name, sourceMesh, options) {
  961. var indices = sourceMesh.getIndices();
  962. var positions = sourceMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  963. var normals = sourceMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  964. var position = options.position || BABYLON.Vector3.Zero();
  965. var normal = options.normal || BABYLON.Vector3.Up();
  966. var size = options.size || BABYLON.Vector3.One();
  967. var angle = options.angle || 0;
  968. // Getting correct rotation
  969. if (!normal) {
  970. var target = new BABYLON.Vector3(0, 0, 1);
  971. var camera = sourceMesh.getScene().activeCamera;
  972. var cameraWorldTarget = BABYLON.Vector3.TransformCoordinates(target, camera.getWorldMatrix());
  973. normal = camera.globalPosition.subtract(cameraWorldTarget);
  974. }
  975. var yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;
  976. var len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);
  977. var pitch = Math.atan2(normal.y, len);
  978. // Matrix
  979. var decalWorldMatrix = BABYLON.Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(BABYLON.Matrix.Translation(position.x, position.y, position.z));
  980. var inverseDecalWorldMatrix = BABYLON.Matrix.Invert(decalWorldMatrix);
  981. var meshWorldMatrix = sourceMesh.getWorldMatrix();
  982. var transformMatrix = meshWorldMatrix.multiply(inverseDecalWorldMatrix);
  983. var vertexData = new BABYLON.VertexData();
  984. vertexData.indices = [];
  985. vertexData.positions = [];
  986. vertexData.normals = [];
  987. vertexData.uvs = [];
  988. var currentVertexDataIndex = 0;
  989. var extractDecalVector3 = function (indexId) {
  990. var result = new BABYLON.PositionNormalVertex();
  991. if (!indices || !positions || !normals) {
  992. return result;
  993. }
  994. var vertexId = indices[indexId];
  995. result.position = new BABYLON.Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);
  996. // Send vector to decal local world
  997. result.position = BABYLON.Vector3.TransformCoordinates(result.position, transformMatrix);
  998. // Get normal
  999. result.normal = new BABYLON.Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
  1000. result.normal = BABYLON.Vector3.TransformNormal(result.normal, transformMatrix);
  1001. return result;
  1002. }; // Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
  1003. var clip = function (vertices, axis) {
  1004. if (vertices.length === 0) {
  1005. return vertices;
  1006. }
  1007. var clipSize = 0.5 * Math.abs(BABYLON.Vector3.Dot(size, axis));
  1008. var clipVertices = function (v0, v1) {
  1009. var clipFactor = BABYLON.Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);
  1010. return new BABYLON.PositionNormalVertex(BABYLON.Vector3.Lerp(v0.position, v1.position, clipFactor), BABYLON.Vector3.Lerp(v0.normal, v1.normal, clipFactor));
  1011. };
  1012. var result = new Array();
  1013. for (var index = 0; index < vertices.length; index += 3) {
  1014. var v1Out;
  1015. var v2Out;
  1016. var v3Out;
  1017. var total = 0;
  1018. var nV1 = null;
  1019. var nV2 = null;
  1020. var nV3 = null;
  1021. var nV4 = null;
  1022. var d1 = BABYLON.Vector3.Dot(vertices[index].position, axis) - clipSize;
  1023. var d2 = BABYLON.Vector3.Dot(vertices[index + 1].position, axis) - clipSize;
  1024. var d3 = BABYLON.Vector3.Dot(vertices[index + 2].position, axis) - clipSize;
  1025. v1Out = d1 > 0;
  1026. v2Out = d2 > 0;
  1027. v3Out = d3 > 0;
  1028. total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);
  1029. switch (total) {
  1030. case 0:
  1031. result.push(vertices[index]);
  1032. result.push(vertices[index + 1]);
  1033. result.push(vertices[index + 2]);
  1034. break;
  1035. case 1:
  1036. if (v1Out) {
  1037. nV1 = vertices[index + 1];
  1038. nV2 = vertices[index + 2];
  1039. nV3 = clipVertices(vertices[index], nV1);
  1040. nV4 = clipVertices(vertices[index], nV2);
  1041. }
  1042. if (v2Out) {
  1043. nV1 = vertices[index];
  1044. nV2 = vertices[index + 2];
  1045. nV3 = clipVertices(vertices[index + 1], nV1);
  1046. nV4 = clipVertices(vertices[index + 1], nV2);
  1047. result.push(nV3);
  1048. result.push(nV2.clone());
  1049. result.push(nV1.clone());
  1050. result.push(nV2.clone());
  1051. result.push(nV3.clone());
  1052. result.push(nV4);
  1053. break;
  1054. }
  1055. if (v3Out) {
  1056. nV1 = vertices[index];
  1057. nV2 = vertices[index + 1];
  1058. nV3 = clipVertices(vertices[index + 2], nV1);
  1059. nV4 = clipVertices(vertices[index + 2], nV2);
  1060. }
  1061. if (nV1 && nV2 && nV3 && nV4) {
  1062. result.push(nV1.clone());
  1063. result.push(nV2.clone());
  1064. result.push(nV3);
  1065. result.push(nV4);
  1066. result.push(nV3.clone());
  1067. result.push(nV2.clone());
  1068. }
  1069. break;
  1070. case 2:
  1071. if (!v1Out) {
  1072. nV1 = vertices[index].clone();
  1073. nV2 = clipVertices(nV1, vertices[index + 1]);
  1074. nV3 = clipVertices(nV1, vertices[index + 2]);
  1075. result.push(nV1);
  1076. result.push(nV2);
  1077. result.push(nV3);
  1078. }
  1079. if (!v2Out) {
  1080. nV1 = vertices[index + 1].clone();
  1081. nV2 = clipVertices(nV1, vertices[index + 2]);
  1082. nV3 = clipVertices(nV1, vertices[index]);
  1083. result.push(nV1);
  1084. result.push(nV2);
  1085. result.push(nV3);
  1086. }
  1087. if (!v3Out) {
  1088. nV1 = vertices[index + 2].clone();
  1089. nV2 = clipVertices(nV1, vertices[index]);
  1090. nV3 = clipVertices(nV1, vertices[index + 1]);
  1091. result.push(nV1);
  1092. result.push(nV2);
  1093. result.push(nV3);
  1094. }
  1095. break;
  1096. case 3:
  1097. break;
  1098. }
  1099. }
  1100. return result;
  1101. };
  1102. for (var index = 0; index < indices.length; index += 3) {
  1103. var faceVertices = new Array();
  1104. faceVertices.push(extractDecalVector3(index));
  1105. faceVertices.push(extractDecalVector3(index + 1));
  1106. faceVertices.push(extractDecalVector3(index + 2));
  1107. // Clip
  1108. faceVertices = clip(faceVertices, new BABYLON.Vector3(1, 0, 0));
  1109. faceVertices = clip(faceVertices, new BABYLON.Vector3(-1, 0, 0));
  1110. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 1, 0));
  1111. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, -1, 0));
  1112. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, 1));
  1113. faceVertices = clip(faceVertices, new BABYLON.Vector3(0, 0, -1));
  1114. if (faceVertices.length === 0) {
  1115. continue;
  1116. }
  1117. // Add UVs and get back to world
  1118. for (var vIndex = 0; vIndex < faceVertices.length; vIndex++) {
  1119. var vertex = faceVertices[vIndex];
  1120. //TODO check for Int32Array | Uint32Array | Uint16Array
  1121. vertexData.indices.push(currentVertexDataIndex);
  1122. vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
  1123. vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
  1124. vertexData.uvs.push(0.5 + vertex.position.x / size.x);
  1125. vertexData.uvs.push(0.5 + vertex.position.y / size.y);
  1126. currentVertexDataIndex++;
  1127. }
  1128. }
  1129. // Return mesh
  1130. var decal = new BABYLON.Mesh(name, sourceMesh.getScene());
  1131. vertexData.applyToMesh(decal);
  1132. decal.position = position.clone();
  1133. decal.rotation = new BABYLON.Vector3(pitch, yaw, angle);
  1134. return decal;
  1135. };
  1136. // Privates
  1137. MeshBuilder._ExtrudeShapeGeneric = function (name, shape, curve, scale, rotation, scaleFunction, rotateFunction, rbCA, rbCP, cap, custom, scene, updtbl, side, instance, invertUV, frontUVs, backUVs) {
  1138. // extrusion geometry
  1139. var extrusionPathArray = function (shape, curve, path3D, shapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom) {
  1140. var tangents = path3D.getTangents();
  1141. var normals = path3D.getNormals();
  1142. var binormals = path3D.getBinormals();
  1143. var distances = path3D.getDistances();
  1144. var angle = 0;
  1145. var returnScale = function () { return scale !== null ? scale : 1; };
  1146. var returnRotation = function () { return rotation !== null ? rotation : 0; };
  1147. var rotate = custom && rotateFunction ? rotateFunction : returnRotation;
  1148. var scl = custom && scaleFunction ? scaleFunction : returnScale;
  1149. var index = (cap === BABYLON.Mesh.NO_CAP || cap === BABYLON.Mesh.CAP_END) ? 0 : 2;
  1150. var rotationMatrix = BABYLON.Tmp.Matrix[0];
  1151. for (var i = 0; i < curve.length; i++) {
  1152. var shapePath = new Array();
  1153. var angleStep = rotate(i, distances[i]);
  1154. var scaleRatio = scl(i, distances[i]);
  1155. for (var p = 0; p < shape.length; p++) {
  1156. BABYLON.Matrix.RotationAxisToRef(tangents[i], angle, rotationMatrix);
  1157. var planed = ((tangents[i].scale(shape[p].z)).add(normals[i].scale(shape[p].x)).add(binormals[i].scale(shape[p].y)));
  1158. var rotated = shapePath[p] ? shapePath[p] : BABYLON.Vector3.Zero();
  1159. BABYLON.Vector3.TransformCoordinatesToRef(planed, rotationMatrix, rotated);
  1160. rotated.scaleInPlace(scaleRatio).addInPlace(curve[i]);
  1161. shapePath[p] = rotated;
  1162. }
  1163. shapePaths[index] = shapePath;
  1164. angle += angleStep;
  1165. index++;
  1166. }
  1167. // cap
  1168. var capPath = function (shapePath) {
  1169. var pointCap = Array();
  1170. var barycenter = BABYLON.Vector3.Zero();
  1171. var i;
  1172. for (i = 0; i < shapePath.length; i++) {
  1173. barycenter.addInPlace(shapePath[i]);
  1174. }
  1175. barycenter.scaleInPlace(1.0 / shapePath.length);
  1176. for (i = 0; i < shapePath.length; i++) {
  1177. pointCap.push(barycenter);
  1178. }
  1179. return pointCap;
  1180. };
  1181. switch (cap) {
  1182. case BABYLON.Mesh.NO_CAP:
  1183. break;
  1184. case BABYLON.Mesh.CAP_START:
  1185. shapePaths[0] = capPath(shapePaths[2]);
  1186. shapePaths[1] = shapePaths[2];
  1187. break;
  1188. case BABYLON.Mesh.CAP_END:
  1189. shapePaths[index] = shapePaths[index - 1];
  1190. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  1191. break;
  1192. case BABYLON.Mesh.CAP_ALL:
  1193. shapePaths[0] = capPath(shapePaths[2]);
  1194. shapePaths[1] = shapePaths[2];
  1195. shapePaths[index] = shapePaths[index - 1];
  1196. shapePaths[index + 1] = capPath(shapePaths[index - 1]);
  1197. break;
  1198. default:
  1199. break;
  1200. }
  1201. return shapePaths;
  1202. };
  1203. var path3D;
  1204. var pathArray;
  1205. if (instance) {
  1206. path3D = (instance.path3D).update(curve);
  1207. pathArray = extrusionPathArray(shape, curve, instance.path3D, instance.pathArray, scale, rotation, scaleFunction, rotateFunction, instance.cap, custom);
  1208. instance = BABYLON.Mesh.CreateRibbon("", pathArray, false, false, 0, scene || undefined, false, 0, instance);
  1209. return instance;
  1210. }
  1211. // extruded shape creation
  1212. path3D = new BABYLON.Path3D(curve);
  1213. var newShapePaths = new Array();
  1214. cap = (cap < 0 || cap > 3) ? 0 : cap;
  1215. pathArray = extrusionPathArray(shape, curve, path3D, newShapePaths, scale, rotation, scaleFunction, rotateFunction, cap, custom);
  1216. var extrudedGeneric = MeshBuilder.CreateRibbon(name, { pathArray: pathArray, closeArray: rbCA, closePath: rbCP, updatable: updtbl, sideOrientation: side, invertUV: invertUV, frontUVs: frontUVs || undefined, backUVs: backUVs || undefined }, scene);
  1217. extrudedGeneric.pathArray = pathArray;
  1218. extrudedGeneric.path3D = path3D;
  1219. extrudedGeneric.cap = cap;
  1220. return extrudedGeneric;
  1221. };
  1222. return MeshBuilder;
  1223. }());
  1224. BABYLON.MeshBuilder = MeshBuilder;
  1225. })(BABYLON || (BABYLON = {}));
  1226. //# sourceMappingURL=babylon.meshBuilder.js.map
  1227. 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}";
  1228. 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}";
  1229. 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}";
  1230. 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}";
  1231. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1232. 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";
  1233. 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";
  1234. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1235. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1236. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1237. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1238. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1239. 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";
  1240. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1241. 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";
  1242. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1243. 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";
  1244. 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";
  1245. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1246. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1247. 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";
  1248. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1249. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1250. 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}";
  1251. 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";
  1252. 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";
  1253. 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";
  1254. 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";
  1255. 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";
  1256. 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};";
  1257. 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";
  1258. 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";
  1259. 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}";
  1260. 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";
  1261. 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}";
  1262. 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";
  1263. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1264. 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";
  1265. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1266. 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";
  1267. 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";
  1268. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1269. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1270. var MeshBuilder = BABYLON.MeshBuilder;
  1271. export { MeshBuilder };