babylon.geometry.js 29 KB

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