babylon.geometry.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var Geometry = (function () {
  9. function Geometry(id, scene, vertexData, updatable, mesh) {
  10. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  11. this._totalVertices = 0;
  12. this._isDisposed = false;
  13. this.id = id;
  14. this._engine = scene.getEngine();
  15. this._meshes = [];
  16. this._scene = scene;
  17. //Init vertex buffer cache
  18. this._vertexBuffers = {};
  19. this._indices = [];
  20. // vertexData
  21. if (vertexData) {
  22. this.setAllVerticesData(vertexData, updatable);
  23. }
  24. else {
  25. this._totalVertices = 0;
  26. this._indices = [];
  27. }
  28. // applyToMesh
  29. if (mesh) {
  30. this.applyToMesh(mesh);
  31. mesh.computeWorldMatrix(true);
  32. }
  33. }
  34. Geometry.prototype.getScene = function () {
  35. return this._scene;
  36. };
  37. Geometry.prototype.getEngine = function () {
  38. return this._engine;
  39. };
  40. Geometry.prototype.isReady = function () {
  41. return this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE;
  42. };
  43. Geometry.prototype.setAllVerticesData = function (vertexData, updatable) {
  44. vertexData.applyToGeometry(this, updatable);
  45. this.notifyUpdate();
  46. };
  47. Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
  48. if (this._vertexBuffers[kind]) {
  49. this._vertexBuffers[kind].dispose();
  50. }
  51. this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
  52. if (kind === BABYLON.VertexBuffer.PositionKind) {
  53. stride = this._vertexBuffers[kind].getStrideSize();
  54. this._totalVertices = data.length / stride;
  55. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  56. var meshes = this._meshes;
  57. var numOfMeshes = meshes.length;
  58. for (var index = 0; index < numOfMeshes; index++) {
  59. var mesh = meshes[index];
  60. mesh._resetPointsArrayCache();
  61. mesh._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  62. mesh._createGlobalSubMesh();
  63. mesh.computeWorldMatrix(true);
  64. }
  65. }
  66. this.notifyUpdate(kind);
  67. };
  68. Geometry.prototype.updateVerticesDataDirectly = function (kind, data, offset) {
  69. var vertexBuffer = this.getVertexBuffer(kind);
  70. if (!vertexBuffer) {
  71. return;
  72. }
  73. vertexBuffer.updateDirectly(data, offset);
  74. this.notifyUpdate(kind);
  75. };
  76. Geometry.prototype.updateVerticesData = function (kind, data, updateExtends) {
  77. var vertexBuffer = this.getVertexBuffer(kind);
  78. if (!vertexBuffer) {
  79. return;
  80. }
  81. vertexBuffer.update(data);
  82. if (kind === BABYLON.VertexBuffer.PositionKind) {
  83. var extend;
  84. var stride = vertexBuffer.getStrideSize();
  85. this._totalVertices = data.length / stride;
  86. if (updateExtends) {
  87. extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  88. }
  89. var meshes = this._meshes;
  90. var numOfMeshes = meshes.length;
  91. for (var index = 0; index < numOfMeshes; index++) {
  92. var mesh = meshes[index];
  93. mesh._resetPointsArrayCache();
  94. if (updateExtends) {
  95. mesh._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  96. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  97. var subMesh = mesh.subMeshes[subIndex];
  98. subMesh.refreshBoundingInfo();
  99. }
  100. }
  101. }
  102. }
  103. this.notifyUpdate(kind);
  104. };
  105. Geometry.prototype.getTotalVertices = function () {
  106. if (!this.isReady()) {
  107. return 0;
  108. }
  109. return this._totalVertices;
  110. };
  111. Geometry.prototype.getVerticesData = function (kind, copyWhenShared) {
  112. var vertexBuffer = this.getVertexBuffer(kind);
  113. if (!vertexBuffer) {
  114. return null;
  115. }
  116. var orig = vertexBuffer.getData();
  117. if (!copyWhenShared || this._meshes.length === 1) {
  118. return orig;
  119. }
  120. else {
  121. var len = orig.length;
  122. var copy = [];
  123. for (var i = 0; i < len; i++) {
  124. copy.push(orig[i]);
  125. }
  126. return copy;
  127. }
  128. };
  129. Geometry.prototype.getVertexBuffer = function (kind) {
  130. if (!this.isReady()) {
  131. return null;
  132. }
  133. return this._vertexBuffers[kind];
  134. };
  135. Geometry.prototype.getVertexBuffers = function () {
  136. if (!this.isReady()) {
  137. return null;
  138. }
  139. return this._vertexBuffers;
  140. };
  141. Geometry.prototype.isVerticesDataPresent = function (kind) {
  142. if (!this._vertexBuffers) {
  143. if (this._delayInfo) {
  144. return this._delayInfo.indexOf(kind) !== -1;
  145. }
  146. return false;
  147. }
  148. return this._vertexBuffers[kind] !== undefined;
  149. };
  150. Geometry.prototype.getVerticesDataKinds = function () {
  151. var result = [];
  152. var kind;
  153. if (!this._vertexBuffers && this._delayInfo) {
  154. for (kind in this._delayInfo) {
  155. result.push(kind);
  156. }
  157. }
  158. else {
  159. for (kind in this._vertexBuffers) {
  160. result.push(kind);
  161. }
  162. }
  163. return result;
  164. };
  165. Geometry.prototype.setIndices = function (indices, totalVertices) {
  166. if (this._indexBuffer) {
  167. this._engine._releaseBuffer(this._indexBuffer);
  168. }
  169. this._indices = indices;
  170. if (this._meshes.length !== 0 && this._indices) {
  171. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  172. }
  173. if (totalVertices !== undefined) {
  174. this._totalVertices = totalVertices;
  175. }
  176. var meshes = this._meshes;
  177. var numOfMeshes = meshes.length;
  178. for (var index = 0; index < numOfMeshes; index++) {
  179. meshes[index]._createGlobalSubMesh();
  180. }
  181. this.notifyUpdate();
  182. };
  183. Geometry.prototype.getTotalIndices = function () {
  184. if (!this.isReady()) {
  185. return 0;
  186. }
  187. return this._indices.length;
  188. };
  189. Geometry.prototype.getIndices = function (copyWhenShared) {
  190. if (!this.isReady()) {
  191. return null;
  192. }
  193. var orig = this._indices;
  194. if (!copyWhenShared || this._meshes.length === 1) {
  195. return orig;
  196. }
  197. else {
  198. var len = orig.length;
  199. var copy = [];
  200. for (var i = 0; i < len; i++) {
  201. copy.push(orig[i]);
  202. }
  203. return copy;
  204. }
  205. };
  206. Geometry.prototype.getIndexBuffer = function () {
  207. if (!this.isReady()) {
  208. return null;
  209. }
  210. return this._indexBuffer;
  211. };
  212. Geometry.prototype.releaseForMesh = function (mesh, shouldDispose) {
  213. var meshes = this._meshes;
  214. var index = meshes.indexOf(mesh);
  215. if (index === -1) {
  216. return;
  217. }
  218. for (var kind in this._vertexBuffers) {
  219. this._vertexBuffers[kind].dispose();
  220. }
  221. if (this._indexBuffer && this._engine._releaseBuffer(this._indexBuffer)) {
  222. this._indexBuffer = null;
  223. }
  224. meshes.splice(index, 1);
  225. mesh._geometry = null;
  226. if (meshes.length === 0 && shouldDispose) {
  227. this.dispose();
  228. }
  229. };
  230. Geometry.prototype.applyToMesh = function (mesh) {
  231. if (mesh._geometry === this) {
  232. return;
  233. }
  234. var previousGeometry = mesh._geometry;
  235. if (previousGeometry) {
  236. previousGeometry.releaseForMesh(mesh);
  237. }
  238. var meshes = this._meshes;
  239. // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
  240. mesh._geometry = this;
  241. this._scene.pushGeometry(this);
  242. meshes.push(mesh);
  243. if (this.isReady()) {
  244. this._applyToMesh(mesh);
  245. }
  246. else {
  247. mesh._boundingInfo = this._boundingInfo;
  248. }
  249. };
  250. Geometry.prototype._applyToMesh = function (mesh) {
  251. var numOfMeshes = this._meshes.length;
  252. // vertexBuffers
  253. for (var kind in this._vertexBuffers) {
  254. if (numOfMeshes === 1) {
  255. this._vertexBuffers[kind].create();
  256. }
  257. this._vertexBuffers[kind]._buffer.references = numOfMeshes;
  258. if (kind === BABYLON.VertexBuffer.PositionKind) {
  259. mesh._resetPointsArrayCache();
  260. var extend = BABYLON.Tools.ExtractMinAndMax(this._vertexBuffers[kind].getData(), 0, this._totalVertices);
  261. mesh._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  262. mesh._createGlobalSubMesh();
  263. //bounding info was just created again, world matrix should be applied again.
  264. mesh._updateBoundingInfo();
  265. }
  266. }
  267. // indexBuffer
  268. if (numOfMeshes === 1 && this._indices) {
  269. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  270. }
  271. if (this._indexBuffer) {
  272. this._indexBuffer.references = numOfMeshes;
  273. }
  274. };
  275. Geometry.prototype.notifyUpdate = function (kind) {
  276. if (this.onGeometryUpdated) {
  277. this.onGeometryUpdated(this, kind);
  278. }
  279. };
  280. Geometry.prototype.load = function (scene, onLoaded) {
  281. var _this = this;
  282. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  283. return;
  284. }
  285. if (this.isReady()) {
  286. if (onLoaded) {
  287. onLoaded();
  288. }
  289. return;
  290. }
  291. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
  292. scene._addPendingData(this);
  293. BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
  294. _this._delayLoadingFunction(JSON.parse(data), _this);
  295. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  296. _this._delayInfo = [];
  297. scene._removePendingData(_this);
  298. var meshes = _this._meshes;
  299. var numOfMeshes = meshes.length;
  300. for (var index = 0; index < numOfMeshes; index++) {
  301. _this._applyToMesh(meshes[index]);
  302. }
  303. if (onLoaded) {
  304. onLoaded();
  305. }
  306. }, function () { }, scene.database);
  307. };
  308. Geometry.prototype.isDisposed = function () {
  309. return this._isDisposed;
  310. };
  311. Geometry.prototype.dispose = function () {
  312. var meshes = this._meshes;
  313. var numOfMeshes = meshes.length;
  314. var index;
  315. for (index = 0; index < numOfMeshes; index++) {
  316. this.releaseForMesh(meshes[index]);
  317. }
  318. this._meshes = [];
  319. for (var kind in this._vertexBuffers) {
  320. this._vertexBuffers[kind].dispose();
  321. }
  322. this._vertexBuffers = [];
  323. this._totalVertices = 0;
  324. if (this._indexBuffer) {
  325. this._engine._releaseBuffer(this._indexBuffer);
  326. }
  327. this._indexBuffer = null;
  328. this._indices = [];
  329. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  330. this.delayLoadingFile = null;
  331. this._delayLoadingFunction = null;
  332. this._delayInfo = [];
  333. this._boundingInfo = null;
  334. this._scene.removeGeometry(this);
  335. this._isDisposed = true;
  336. };
  337. Geometry.prototype.copy = function (id) {
  338. var vertexData = new BABYLON.VertexData();
  339. vertexData.indices = [];
  340. var indices = this.getIndices();
  341. for (var index = 0; index < indices.length; index++) {
  342. vertexData.indices.push(indices[index]);
  343. }
  344. var updatable = false;
  345. var stopChecking = false;
  346. var kind;
  347. for (kind in this._vertexBuffers) {
  348. // using slice() to make a copy of the array and not just reference it
  349. var data = this.getVerticesData(kind);
  350. if (data instanceof Float32Array) {
  351. vertexData.set(new Float32Array(data), kind);
  352. }
  353. else {
  354. vertexData.set(data.slice(0), kind);
  355. }
  356. if (!stopChecking) {
  357. updatable = this.getVertexBuffer(kind).isUpdatable();
  358. stopChecking = !updatable;
  359. }
  360. }
  361. var geometry = new Geometry(id, this._scene, vertexData, updatable, null);
  362. geometry.delayLoadState = this.delayLoadState;
  363. geometry.delayLoadingFile = this.delayLoadingFile;
  364. geometry._delayLoadingFunction = this._delayLoadingFunction;
  365. for (kind in this._delayInfo) {
  366. geometry._delayInfo = geometry._delayInfo || [];
  367. geometry._delayInfo.push(kind);
  368. }
  369. // Bounding info
  370. var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this.getTotalVertices());
  371. geometry._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  372. return geometry;
  373. };
  374. // Statics
  375. Geometry.ExtractFromMesh = function (mesh, id) {
  376. var geometry = mesh._geometry;
  377. if (!geometry) {
  378. return null;
  379. }
  380. return geometry.copy(id);
  381. };
  382. // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  383. // be aware Math.random() could cause collisions
  384. Geometry.RandomId = function () {
  385. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  386. var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
  387. return v.toString(16);
  388. });
  389. };
  390. return Geometry;
  391. })();
  392. BABYLON.Geometry = Geometry;
  393. /////// Primitives //////////////////////////////////////////////
  394. var Geometry;
  395. (function (Geometry) {
  396. var Primitives;
  397. (function (Primitives) {
  398. /// Abstract class
  399. var _Primitive = (function (_super) {
  400. __extends(_Primitive, _super);
  401. function _Primitive(id, scene, vertexData, canBeRegenerated, mesh) {
  402. this._beingRegenerated = true;
  403. this._canBeRegenerated = canBeRegenerated;
  404. _super.call(this, id, scene, vertexData, false, mesh); // updatable = false to be sure not to update vertices
  405. this._beingRegenerated = false;
  406. }
  407. _Primitive.prototype.canBeRegenerated = function () {
  408. return this._canBeRegenerated;
  409. };
  410. _Primitive.prototype.regenerate = function () {
  411. if (!this._canBeRegenerated) {
  412. return;
  413. }
  414. this._beingRegenerated = true;
  415. this.setAllVerticesData(this._regenerateVertexData(), false);
  416. this._beingRegenerated = false;
  417. };
  418. _Primitive.prototype.asNewGeometry = function (id) {
  419. return _super.prototype.copy.call(this, id);
  420. };
  421. // overrides
  422. _Primitive.prototype.setAllVerticesData = function (vertexData, updatable) {
  423. if (!this._beingRegenerated) {
  424. return;
  425. }
  426. _super.prototype.setAllVerticesData.call(this, vertexData, false);
  427. };
  428. _Primitive.prototype.setVerticesData = function (kind, data, updatable) {
  429. if (!this._beingRegenerated) {
  430. return;
  431. }
  432. _super.prototype.setVerticesData.call(this, kind, data, false);
  433. };
  434. // to override
  435. // protected
  436. _Primitive.prototype._regenerateVertexData = function () {
  437. throw new Error("Abstract method");
  438. };
  439. _Primitive.prototype.copy = function (id) {
  440. throw new Error("Must be overriden in sub-classes.");
  441. };
  442. return _Primitive;
  443. })(Geometry);
  444. Primitives._Primitive = _Primitive;
  445. var Ribbon = (function (_super) {
  446. __extends(Ribbon, _super);
  447. function Ribbon(id, scene, pathArray, closeArray, closePath, offset, canBeRegenerated, mesh, side) {
  448. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  449. this.pathArray = pathArray;
  450. this.closeArray = closeArray;
  451. this.closePath = closePath;
  452. this.offset = offset;
  453. this.side = side;
  454. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  455. }
  456. Ribbon.prototype._regenerateVertexData = function () {
  457. return BABYLON.VertexData.CreateRibbon({ pathArray: this.pathArray, closeArray: this.closeArray, closePath: this.closePath, offset: this.offset, sideOrientation: this.side });
  458. };
  459. Ribbon.prototype.copy = function (id) {
  460. return new Ribbon(id, this.getScene(), this.pathArray, this.closeArray, this.closePath, this.offset, this.canBeRegenerated(), null, this.side);
  461. };
  462. return Ribbon;
  463. })(_Primitive);
  464. Primitives.Ribbon = Ribbon;
  465. var Box = (function (_super) {
  466. __extends(Box, _super);
  467. function Box(id, scene, size, canBeRegenerated, mesh, side) {
  468. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  469. this.size = size;
  470. this.side = side;
  471. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  472. }
  473. Box.prototype._regenerateVertexData = function () {
  474. return BABYLON.VertexData.CreateBox({ size: this.size, sideOrientation: this.side });
  475. };
  476. Box.prototype.copy = function (id) {
  477. return new Box(id, this.getScene(), this.size, this.canBeRegenerated(), null, this.side);
  478. };
  479. return Box;
  480. })(_Primitive);
  481. Primitives.Box = Box;
  482. var Sphere = (function (_super) {
  483. __extends(Sphere, _super);
  484. function Sphere(id, scene, segments, diameter, canBeRegenerated, mesh, side) {
  485. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  486. this.segments = segments;
  487. this.diameter = diameter;
  488. this.side = side;
  489. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  490. }
  491. Sphere.prototype._regenerateVertexData = function () {
  492. return BABYLON.VertexData.CreateSphere({ segments: this.segments, diameter: this.diameter, sideOrientation: this.side });
  493. };
  494. Sphere.prototype.copy = function (id) {
  495. return new Sphere(id, this.getScene(), this.segments, this.diameter, this.canBeRegenerated(), null, this.side);
  496. };
  497. return Sphere;
  498. })(_Primitive);
  499. Primitives.Sphere = Sphere;
  500. var Disc = (function (_super) {
  501. __extends(Disc, _super);
  502. function Disc(id, scene, radius, tessellation, canBeRegenerated, mesh, side) {
  503. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  504. this.radius = radius;
  505. this.tessellation = tessellation;
  506. this.side = side;
  507. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  508. }
  509. Disc.prototype._regenerateVertexData = function () {
  510. return BABYLON.VertexData.CreateDisc({ radius: this.radius, tessellation: this.tessellation, sideOrientation: this.side });
  511. };
  512. Disc.prototype.copy = function (id) {
  513. return new Disc(id, this.getScene(), this.radius, this.tessellation, this.canBeRegenerated(), null, this.side);
  514. };
  515. return Disc;
  516. })(_Primitive);
  517. Primitives.Disc = Disc;
  518. var Cylinder = (function (_super) {
  519. __extends(Cylinder, _super);
  520. function Cylinder(id, scene, height, diameterTop, diameterBottom, tessellation, subdivisions, canBeRegenerated, mesh, side) {
  521. if (subdivisions === void 0) { subdivisions = 1; }
  522. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  523. this.height = height;
  524. this.diameterTop = diameterTop;
  525. this.diameterBottom = diameterBottom;
  526. this.tessellation = tessellation;
  527. this.subdivisions = subdivisions;
  528. this.side = side;
  529. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  530. }
  531. Cylinder.prototype._regenerateVertexData = function () {
  532. return BABYLON.VertexData.CreateCylinder({ height: this.height, diameterTop: this.diameterTop, diameterBottom: this.diameterBottom, tessellation: this.tessellation, subdivisions: this.subdivisions, sideOrientation: this.side });
  533. };
  534. Cylinder.prototype.copy = function (id) {
  535. return new Cylinder(id, this.getScene(), this.height, this.diameterTop, this.diameterBottom, this.tessellation, this.subdivisions, this.canBeRegenerated(), null, this.side);
  536. };
  537. return Cylinder;
  538. })(_Primitive);
  539. Primitives.Cylinder = Cylinder;
  540. var Torus = (function (_super) {
  541. __extends(Torus, _super);
  542. function Torus(id, scene, diameter, thickness, tessellation, canBeRegenerated, mesh, side) {
  543. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  544. this.diameter = diameter;
  545. this.thickness = thickness;
  546. this.tessellation = tessellation;
  547. this.side = side;
  548. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  549. }
  550. Torus.prototype._regenerateVertexData = function () {
  551. return BABYLON.VertexData.CreateTorus({ diameter: this.diameter, thickness: this.thickness, tessellation: this.tessellation, sideOrientation: this.side });
  552. };
  553. Torus.prototype.copy = function (id) {
  554. return new Torus(id, this.getScene(), this.diameter, this.thickness, this.tessellation, this.canBeRegenerated(), null, this.side);
  555. };
  556. return Torus;
  557. })(_Primitive);
  558. Primitives.Torus = Torus;
  559. var Ground = (function (_super) {
  560. __extends(Ground, _super);
  561. function Ground(id, scene, width, height, subdivisions, canBeRegenerated, mesh) {
  562. this.width = width;
  563. this.height = height;
  564. this.subdivisions = subdivisions;
  565. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  566. }
  567. Ground.prototype._regenerateVertexData = function () {
  568. return BABYLON.VertexData.CreateGround({ width: this.width, height: this.height, subdivisions: this.subdivisions });
  569. };
  570. Ground.prototype.copy = function (id) {
  571. return new Ground(id, this.getScene(), this.width, this.height, this.subdivisions, this.canBeRegenerated(), null);
  572. };
  573. return Ground;
  574. })(_Primitive);
  575. Primitives.Ground = Ground;
  576. var TiledGround = (function (_super) {
  577. __extends(TiledGround, _super);
  578. function TiledGround(id, scene, xmin, zmin, xmax, zmax, subdivisions, precision, canBeRegenerated, mesh) {
  579. this.xmin = xmin;
  580. this.zmin = zmin;
  581. this.xmax = xmax;
  582. this.zmax = zmax;
  583. this.subdivisions = subdivisions;
  584. this.precision = precision;
  585. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  586. }
  587. TiledGround.prototype._regenerateVertexData = function () {
  588. return BABYLON.VertexData.CreateTiledGround({ xmin: this.xmin, zmin: this.zmin, xmax: this.xmax, zmax: this.zmax, subdivisions: this.subdivisions, precision: this.precision });
  589. };
  590. TiledGround.prototype.copy = function (id) {
  591. return new TiledGround(id, this.getScene(), this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision, this.canBeRegenerated(), null);
  592. };
  593. return TiledGround;
  594. })(_Primitive);
  595. Primitives.TiledGround = TiledGround;
  596. var Plane = (function (_super) {
  597. __extends(Plane, _super);
  598. function Plane(id, scene, size, canBeRegenerated, mesh, side) {
  599. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  600. this.size = size;
  601. this.side = side;
  602. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  603. }
  604. Plane.prototype._regenerateVertexData = function () {
  605. return BABYLON.VertexData.CreatePlane({ size: this.size, sideOrientation: this.side });
  606. };
  607. Plane.prototype.copy = function (id) {
  608. return new Plane(id, this.getScene(), this.size, this.canBeRegenerated(), null, this.side);
  609. };
  610. return Plane;
  611. })(_Primitive);
  612. Primitives.Plane = Plane;
  613. var TorusKnot = (function (_super) {
  614. __extends(TorusKnot, _super);
  615. function TorusKnot(id, scene, radius, tube, radialSegments, tubularSegments, p, q, canBeRegenerated, mesh, side) {
  616. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  617. this.radius = radius;
  618. this.tube = tube;
  619. this.radialSegments = radialSegments;
  620. this.tubularSegments = tubularSegments;
  621. this.p = p;
  622. this.q = q;
  623. this.side = side;
  624. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  625. }
  626. TorusKnot.prototype._regenerateVertexData = function () {
  627. return BABYLON.VertexData.CreateTorusKnot({ radius: this.radius, tube: this.tube, radialSegments: this.radialSegments, tubularSegments: this.tubularSegments, p: this.p, q: this.q, sideOrientation: this.side });
  628. };
  629. TorusKnot.prototype.copy = function (id) {
  630. return new TorusKnot(id, this.getScene(), this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q, this.canBeRegenerated(), null, this.side);
  631. };
  632. return TorusKnot;
  633. })(_Primitive);
  634. Primitives.TorusKnot = TorusKnot;
  635. })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
  636. })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
  637. })(BABYLON || (BABYLON = {}));