babylon.csg.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. // Constructive Solid Geometry for BABYLON
  4. // Based on https://github.com/evanw/csg.js/
  5. (function () {
  6. // Unique ID when we import meshes from Babylon to CSG
  7. var _currentCSGMeshId = 0;
  8. BABYLON.CSG = function () {
  9. this.polygons = [];
  10. };
  11. // Convert BABYLON.Mesh to BABYLON.CSG
  12. BABYLON.CSG.FromMesh = function (mesh) {
  13. var vertex, normal, uv, position,
  14. polygon,
  15. polygons = [],
  16. vertices;
  17. if (mesh instanceof BABYLON.Mesh) {
  18. mesh.computeWorldMatrix(true);
  19. this.matrix = mesh.getWorldMatrix();
  20. this.position = mesh.position.clone();
  21. this.rotation = mesh.rotation.clone();
  22. this.scaling = mesh.scaling.clone();
  23. } else {
  24. throw 'BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh';
  25. }
  26. var indices = mesh.getIndices(),
  27. positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind),
  28. normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind),
  29. uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  30. var subMeshes = mesh.subMeshes;
  31. for (var sm = 0, sml = subMeshes.length; sm < sml; sm++) {
  32. for (var i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {
  33. vertices = [];
  34. for (var j = 0; j < 3; j++) {
  35. normal = new BABYLON.Vector3(normals[indices[i + j] * 3], normals[indices[i + j] * 3 + 1], normals[indices[i + j] * 3 + 2]);
  36. uv = new BABYLON.Vector2(uvs[indices[i + j] * 2], uvs[indices[i + j] * 2 + 1]);
  37. position = new BABYLON.Vector3(positions[indices[i + j] * 3], positions[indices[i + j] * 3 + 1], positions[indices[i + j] * 3 + 2]);
  38. position = BABYLON.Vector3.TransformCoordinates(position, this.matrix);
  39. normal = BABYLON.Vector3.TransformNormal(normal, this.matrix);
  40. vertex = new BABYLON.CSG.Vertex(position, normal, uv);
  41. vertices.push(vertex);
  42. }
  43. polygon = new BABYLON.CSG.Polygon(vertices, { subMeshId: sm, meshId: _currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });
  44. // To handle the case of degenerated triangle
  45. // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated
  46. if (polygon.plane)
  47. polygons.push(polygon);
  48. }
  49. }
  50. var csg = BABYLON.CSG.fromPolygons(polygons);
  51. csg.copyTransformAttributes(this);
  52. _currentCSGMeshId++;
  53. return csg;
  54. };
  55. // Construct a BABYLON.CSG solid from a list of `BABYLON.CSG.Polygon` instances.
  56. BABYLON.CSG.fromPolygons = function (polygons) {
  57. var csg = new BABYLON.CSG();
  58. csg.polygons = polygons;
  59. return csg;
  60. };
  61. BABYLON.CSG.prototype = {
  62. clone: function () {
  63. var csg = new BABYLON.CSG();
  64. csg.polygons = this.polygons.map(function (p) { return p.clone(); });
  65. csg.copyTransformAttributes(this);
  66. return csg;
  67. },
  68. toPolygons: function () {
  69. return this.polygons;
  70. },
  71. union: function (csg) {
  72. var a = new BABYLON.CSG.Node(this.clone().polygons);
  73. var b = new BABYLON.CSG.Node(csg.clone().polygons);
  74. a.clipTo(b);
  75. b.clipTo(a);
  76. b.invert();
  77. b.clipTo(a);
  78. b.invert();
  79. a.build(b.allPolygons());
  80. return BABYLON.CSG.fromPolygons(a.allPolygons()).copyTransformAttributes(this);
  81. },
  82. subtract: function (csg) {
  83. var a = new BABYLON.CSG.Node(this.clone().polygons);
  84. var b = new BABYLON.CSG.Node(csg.clone().polygons);
  85. a.invert();
  86. a.clipTo(b);
  87. b.clipTo(a);
  88. b.invert();
  89. b.clipTo(a);
  90. b.invert();
  91. a.build(b.allPolygons());
  92. a.invert();
  93. return BABYLON.CSG.fromPolygons(a.allPolygons()).copyTransformAttributes(this);
  94. },
  95. intersect: function (csg) {
  96. var a = new BABYLON.CSG.Node(this.clone().polygons);
  97. var b = new BABYLON.CSG.Node(csg.clone().polygons);
  98. a.invert();
  99. b.clipTo(a);
  100. b.invert();
  101. a.clipTo(b);
  102. b.clipTo(a);
  103. a.build(b.allPolygons());
  104. a.invert();
  105. return BABYLON.CSG.fromPolygons(a.allPolygons()).copyTransformAttributes(this);
  106. },
  107. // Return a new BABYLON.CSG solid with solid and empty space switched. This solid is
  108. // not modified.
  109. inverse: function () {
  110. var csg = this.clone();
  111. csg.polygons.map(function (p) { p.flip(); });
  112. return csg;
  113. }
  114. };
  115. // This is used to keep meshes transformations so they can be restored
  116. // when we build back a Babylon Mesh
  117. // NB : All CSG operations are performed in world coordinates
  118. BABYLON.CSG.prototype.copyTransformAttributes = function(object) {
  119. this.matrix = object.matrix;
  120. this.position = object.position;
  121. this.rotation = object.rotation;
  122. this.scaling = object.scaling;
  123. return this;
  124. };
  125. // Build Raw mesh from CSG
  126. // Coordinates here are in world space
  127. BABYLON.CSG.prototype.buildMeshGeometry = function (name, scene, keepSubMeshes) {
  128. var matrix = this.matrix.clone();
  129. matrix.invert();
  130. var mesh = new BABYLON.Mesh(name, scene),
  131. vertices = [],
  132. indices = [],
  133. normals = [],
  134. uvs = [],
  135. vertex, normal, uv,
  136. polygons = this.polygons,
  137. polygonIndices = [0, 0, 0],
  138. polygon,
  139. vertice_dict = {},
  140. vertex_idx,
  141. currentIndex = 0,
  142. subMesh_dict = {},
  143. subMesh_obj;
  144. if (keepSubMeshes) {
  145. // Sort Polygons, since subMeshes are indices range
  146. polygons.sort(function (a, b) {
  147. if (a.shared.meshId === b.shared.meshId) {
  148. return a.shared.subMeshId - b.shared.subMeshId;
  149. } else {
  150. return a.shared.meshId - b.shared.meshId;
  151. }
  152. });
  153. }
  154. for (var i = 0, il = polygons.length; i < il; i++) {
  155. polygon = polygons[i];
  156. // Building SubMeshes
  157. if (!subMesh_dict[polygon.shared.meshId]) {
  158. subMesh_dict[polygon.shared.meshId] = {};
  159. }
  160. if (!subMesh_dict[polygon.shared.meshId][polygon.shared.subMeshId]) {
  161. subMesh_dict[polygon.shared.meshId][polygon.shared.subMeshId] = {
  162. indexStart: +Infinity,
  163. indexEnd: -Infinity,
  164. materialIndex: polygon.shared.materialIndex
  165. };
  166. }
  167. subMesh_obj = subMesh_dict[polygon.shared.meshId][polygon.shared.subMeshId];
  168. for (var j = 2, jl = polygon.vertices.length; j < jl; j++) {
  169. polygonIndices[0] = 0;
  170. polygonIndices[1] = j - 1;
  171. polygonIndices[2] = j;
  172. for (var k = 0; k < 3; k++) {
  173. vertex = polygon.vertices[polygonIndices[k]].pos;
  174. normal = polygon.vertices[polygonIndices[k]].normal;
  175. uv = polygon.vertices[polygonIndices[k]].uv;
  176. vertex = new BABYLON.Vector3(vertex.x, vertex.y, vertex.z);
  177. normal = new BABYLON.Vector3(normal.x, normal.y, normal.z);
  178. vertex = BABYLON.Vector3.TransformCoordinates(vertex, matrix);
  179. normal = BABYLON.Vector3.TransformNormal(normal, matrix);
  180. vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z];
  181. // Check if 2 points can be merged
  182. if (!(typeof vertex_idx !== 'undefined' &&
  183. normals[vertex_idx * 3] === normal.x &&
  184. normals[vertex_idx * 3 + 1] === normal.y &&
  185. normals[vertex_idx * 3 + 2] === normal.z &&
  186. uvs[vertex_idx * 2] === uv.x &&
  187. uvs[vertex_idx * 2 + 1] === uv.y)) {
  188. vertices.push(vertex.x, vertex.y, vertex.z);
  189. uvs.push(uv.x, uv.y);
  190. normals.push(normal.x, normal.y, normal.z);
  191. vertex_idx = vertice_dict[vertex.x + ',' + vertex.y + ',' + vertex.z] = (vertices.length / 3) - 1;
  192. }
  193. indices.push(vertex_idx);
  194. subMesh_obj.indexStart = Math.min(currentIndex, subMesh_obj.indexStart);
  195. subMesh_obj.indexEnd = Math.max(currentIndex, subMesh_obj.indexEnd);
  196. currentIndex++;
  197. }
  198. }
  199. }
  200. mesh.setVerticesData(vertices, BABYLON.VertexBuffer.PositionKind);
  201. mesh.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind);
  202. mesh.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind);
  203. mesh.setIndices(indices);
  204. if (keepSubMeshes) {
  205. // We offset the materialIndex by the previous number of materials in the CSG mixed meshes
  206. var materialIndexOffset = 0,
  207. materialMaxIndex;
  208. mesh.subMeshes.length = 0;
  209. for (var m in subMesh_dict) {
  210. materialMaxIndex = -1;
  211. for (var sm in subMesh_dict[m]) {
  212. subMesh_obj = subMesh_dict[m][sm];
  213. BABYLON.SubMesh.CreateFromIndices(subMesh_obj.materialIndex + materialIndexOffset, subMesh_obj.indexStart, subMesh_obj.indexEnd - subMesh_obj.indexStart + 1, mesh);
  214. materialMaxIndex = Math.max(subMesh_obj.materialIndex, materialMaxIndex);
  215. }
  216. materialIndexOffset += ++materialMaxIndex;
  217. }
  218. }
  219. return mesh;
  220. };
  221. // Build Mesh from CSG taking material and transforms into account
  222. BABYLON.CSG.prototype.toMesh = function (name, material, scene, keepSubMeshes) {
  223. var mesh = this.buildMeshGeometry(name, scene, keepSubMeshes);
  224. mesh.material = material;
  225. mesh.position.copyFrom(this.position);
  226. mesh.rotation.copyFrom(this.rotation);
  227. mesh.scaling.copyFrom(this.scaling);
  228. mesh.computeWorldMatrix(true);
  229. return mesh;
  230. };
  231. // # class Vector
  232. // Represents a 3D vector.
  233. //
  234. // Example usage:
  235. //
  236. // new BABYLON.CSG.Vector(1, 2, 3);
  237. // new BABYLON.CSG.Vector([1, 2, 3]);
  238. // new BABYLON.CSG.Vector({ x: 1, y: 2, z: 3 });
  239. BABYLON.CSG.Vector = function (x, y, z) {
  240. if (arguments.length == 3) {
  241. this.x = x;
  242. this.y = y;
  243. this.z = z;
  244. } else if ('x' in x) {
  245. this.x = x.x;
  246. this.y = x.y;
  247. this.z = x.z;
  248. } else {
  249. this.x = x[0];
  250. this.y = x[1];
  251. this.z = x[2];
  252. }
  253. };
  254. BABYLON.CSG.Vector.prototype = {
  255. clone: function () {
  256. return new BABYLON.CSG.Vector(this.x, this.y, this.z);
  257. },
  258. negated: function () {
  259. return new BABYLON.CSG.Vector(-this.x, -this.y, -this.z);
  260. },
  261. plus: function (a) {
  262. return new BABYLON.CSG.Vector(this.x + a.x, this.y + a.y, this.z + a.z);
  263. },
  264. minus: function (a) {
  265. return new BABYLON.CSG.Vector(this.x - a.x, this.y - a.y, this.z - a.z);
  266. },
  267. times: function (a) {
  268. return new BABYLON.CSG.Vector(this.x * a, this.y * a, this.z * a);
  269. },
  270. dividedBy: function (a) {
  271. return new BABYLON.CSG.Vector(this.x / a, this.y / a, this.z / a);
  272. },
  273. dot: function (a) {
  274. return this.x * a.x + this.y * a.y + this.z * a.z;
  275. },
  276. lerp: function (a, t) {
  277. return this.plus(a.minus(this).times(t));
  278. },
  279. length: function () {
  280. return Math.sqrt(this.dot(this));
  281. },
  282. lengthSq: function () {
  283. return this.dot(this);
  284. },
  285. unit: function () {
  286. return this.dividedBy(this.length());
  287. },
  288. cross: function (a) {
  289. return new BABYLON.CSG.Vector(
  290. this.y * a.z - this.z * a.y,
  291. this.z * a.x - this.x * a.z,
  292. this.x * a.y - this.y * a.x
  293. );
  294. }
  295. };
  296. // # class Vertex
  297. // Represents a vertex of a polygon. Use your own vertex class instead of this
  298. // one to provide additional features like texture coordinates and vertex
  299. // colors. Custom vertex classes need to provide a `pos` property and `clone()`,
  300. // `flip()`, and `interpolate()` methods that behave analogous to the ones
  301. // defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience
  302. // functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`
  303. // is not used anywhere else.
  304. // Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes
  305. BABYLON.CSG.Vertex = function (pos, normal, uv) {
  306. this.pos = new BABYLON.CSG.Vector(pos);
  307. this.normal = new BABYLON.CSG.Vector(normal);
  308. this.uv = new BABYLON.CSG.Vector(uv.x, uv.y, 0);
  309. };
  310. BABYLON.CSG.Vertex.prototype = {
  311. clone: function () {
  312. return new BABYLON.CSG.Vertex(this.pos.clone(), this.normal.clone(), this.uv.clone());
  313. },
  314. // Invert all orientation-specific data (e.g. vertex normal). Called when the
  315. // orientation of a polygon is flipped.
  316. flip: function () {
  317. this.normal = this.normal.negated();
  318. },
  319. // Create a new vertex between this vertex and `other` by linearly
  320. // interpolating all properties using a parameter of `t`. Subclasses should
  321. // override this to interpolate additional properties.
  322. interpolate: function (other, t) {
  323. return new BABYLON.CSG.Vertex(
  324. this.pos.lerp(other.pos, t),
  325. this.normal.lerp(other.normal, t),
  326. this.uv.lerp(other.uv, t)
  327. );
  328. }
  329. };
  330. // # class Plane
  331. // Represents a plane in 3D space.
  332. BABYLON.CSG.Plane = function (normal, w) {
  333. this.normal = normal;
  334. this.w = w;
  335. };
  336. // `BABYLON.CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a
  337. // point is on the plane.
  338. BABYLON.CSG.Plane.EPSILON = 1e-5;
  339. BABYLON.CSG.Plane.fromPoints = function (a, b, c) {
  340. var v0 = c.minus(a);
  341. var v1 = b.minus(a);
  342. if (v0.lengthSq() === 0 || v1.lengthSq() === 0) {
  343. return null;
  344. }
  345. var n = c.minus(a).cross(b.minus(a)).unit();
  346. return new BABYLON.CSG.Plane(n, n.dot(a));
  347. };
  348. BABYLON.CSG.Plane.prototype = {
  349. clone: function () {
  350. return new BABYLON.CSG.Plane(this.normal.clone(), this.w);
  351. },
  352. flip: function () {
  353. this.normal = this.normal.negated();
  354. this.w = -this.w;
  355. },
  356. // Split `polygon` by this plane if needed, then put the polygon or polygon
  357. // fragments in the appropriate lists. Coplanar polygons go into either
  358. // `coplanarFront` or `coplanarBack` depending on their orientation with
  359. // respect to this plane. Polygons in front or in back of this plane go into
  360. // either `front` or `back`.
  361. splitPolygon: function (polygon, coplanarFront, coplanarBack, front, back) {
  362. var COPLANAR = 0;
  363. var FRONT = 1;
  364. var BACK = 2;
  365. var SPANNING = 3;
  366. // Classify each point as well as the entire polygon into one of the above
  367. // four classes.
  368. var polygonType = 0;
  369. var types = [];
  370. for (var i = 0; i < polygon.vertices.length; i++) {
  371. var t = this.normal.dot(polygon.vertices[i].pos) - this.w;
  372. var type = (t < -BABYLON.CSG.Plane.EPSILON) ? BACK : (t > BABYLON.CSG.Plane.EPSILON) ? FRONT : COPLANAR;
  373. polygonType |= type;
  374. types.push(type);
  375. }
  376. // Put the polygon in the correct list, splitting it when necessary.
  377. switch (polygonType) {
  378. case COPLANAR:
  379. (this.normal.dot(polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);
  380. break;
  381. case FRONT:
  382. front.push(polygon);
  383. break;
  384. case BACK:
  385. back.push(polygon);
  386. break;
  387. case SPANNING:
  388. var f = [], b = [];
  389. for (var i = 0; i < polygon.vertices.length; i++) {
  390. var j = (i + 1) % polygon.vertices.length;
  391. var ti = types[i], tj = types[j];
  392. var vi = polygon.vertices[i], vj = polygon.vertices[j];
  393. if (ti != BACK) f.push(vi);
  394. if (ti != FRONT) b.push(ti != BACK ? vi.clone() : vi);
  395. if ((ti | tj) == SPANNING) {
  396. var t = (this.w - this.normal.dot(vi.pos)) / this.normal.dot(vj.pos.minus(vi.pos));
  397. var v = vi.interpolate(vj, t);
  398. f.push(v);
  399. b.push(v.clone());
  400. }
  401. }
  402. if (f.length >= 3) front.push(new BABYLON.CSG.Polygon(f, polygon.shared));
  403. if (b.length >= 3) back.push(new BABYLON.CSG.Polygon(b, polygon.shared));
  404. break;
  405. }
  406. }
  407. };
  408. // # class Polygon
  409. // Represents a convex polygon. The vertices used to initialize a polygon must
  410. // be coplanar and form a convex loop. They do not have to be `BABYLON.CSG.Vertex`
  411. // instances but they must behave similarly (duck typing can be used for
  412. // customization).
  413. //
  414. // Each convex polygon has a `shared` property, which is shared between all
  415. // polygons that are clones of each other or were split from the same polygon.
  416. // This can be used to define per-polygon properties (such as surface color).
  417. BABYLON.CSG.Polygon = function (vertices, shared) {
  418. this.vertices = vertices;
  419. this.shared = shared;
  420. this.plane = BABYLON.CSG.Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
  421. };
  422. BABYLON.CSG.Polygon.prototype = {
  423. clone: function () {
  424. var vertices = this.vertices.map(function (v) { return v.clone(); });
  425. return new BABYLON.CSG.Polygon(vertices, this.shared);
  426. },
  427. flip: function () {
  428. this.vertices.reverse().map(function (v) { v.flip(); });
  429. this.plane.flip();
  430. }
  431. };
  432. // # class Node
  433. // Holds a node in a BSP tree. A BSP tree is built from a collection of polygons
  434. // by picking a polygon to split along. That polygon (and all other coplanar
  435. // polygons) are added directly to that node and the other polygons are added to
  436. // the front and/or back subtrees. This is not a leafy BSP tree since there is
  437. // no distinction between internal and leaf nodes.
  438. BABYLON.CSG.Node = function (polygons) {
  439. this.plane = null;
  440. this.front = null;
  441. this.back = null;
  442. this.polygons = [];
  443. if (polygons) this.build(polygons);
  444. };
  445. BABYLON.CSG.Node.prototype = {
  446. clone: function () {
  447. var node = new BABYLON.CSG.Node();
  448. node.plane = this.plane && this.plane.clone();
  449. node.front = this.front && this.front.clone();
  450. node.back = this.back && this.back.clone();
  451. node.polygons = this.polygons.map(function (p) { return p.clone(); });
  452. return node;
  453. },
  454. // Convert solid space to empty space and empty space to solid space.
  455. invert: function () {
  456. for (var i = 0; i < this.polygons.length; i++) {
  457. this.polygons[i].flip();
  458. }
  459. this.plane.flip();
  460. if (this.front) {
  461. this.front.invert();
  462. }
  463. if (this.back) {
  464. this.back.invert();
  465. }
  466. var temp = this.front;
  467. this.front = this.back;
  468. this.back = temp;
  469. },
  470. // Recursively remove all polygons in `polygons` that are inside this BSP
  471. // tree.
  472. clipPolygons: function (polygons) {
  473. if (!this.plane) return polygons.slice();
  474. var front = [], back = [];
  475. for (var i = 0; i < polygons.length; i++) {
  476. this.plane.splitPolygon(polygons[i], front, back, front, back);
  477. }
  478. if (this.front) {
  479. front = this.front.clipPolygons(front);
  480. }
  481. if (this.back) {
  482. back = this.back.clipPolygons(back);
  483. } else {
  484. back = [];
  485. }
  486. return front.concat(back);
  487. },
  488. // Remove all polygons in this BSP tree that are inside the other BSP tree
  489. // `bsp`.
  490. clipTo: function (bsp) {
  491. this.polygons = bsp.clipPolygons(this.polygons);
  492. if (this.front) this.front.clipTo(bsp);
  493. if (this.back) this.back.clipTo(bsp);
  494. },
  495. // Return a list of all polygons in this BSP tree.
  496. allPolygons: function () {
  497. var polygons = this.polygons.slice();
  498. if (this.front) polygons = polygons.concat(this.front.allPolygons());
  499. if (this.back) polygons = polygons.concat(this.back.allPolygons());
  500. return polygons;
  501. },
  502. // Build a BSP tree out of `polygons`. When called on an existing tree, the
  503. // new polygons are filtered down to the bottom of the tree and become new
  504. // nodes there. Each set of polygons is partitioned using the first polygon
  505. // (no heuristic is used to pick a good split).
  506. build: function (polygons) {
  507. if (!polygons.length) return;
  508. if (!this.plane) this.plane = polygons[0].plane.clone();
  509. var front = [], back = [];
  510. for (var i = 0; i < polygons.length; i++) {
  511. this.plane.splitPolygon(polygons[i], this.polygons, this.polygons, front, back);
  512. }
  513. if (front.length) {
  514. if (!this.front) this.front = new BABYLON.CSG.Node();
  515. this.front.build(front);
  516. }
  517. if (back.length) {
  518. if (!this.back) this.back = new BABYLON.CSG.Node();
  519. this.back.build(back);
  520. }
  521. }
  522. };
  523. })();