babylon.geometry.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  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. Object.defineProperty(Geometry.prototype, "extend", {
  35. get: function () {
  36. return this._extend;
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. Geometry.prototype.getScene = function () {
  42. return this._scene;
  43. };
  44. Geometry.prototype.getEngine = function () {
  45. return this._engine;
  46. };
  47. Geometry.prototype.isReady = function () {
  48. return this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE;
  49. };
  50. Geometry.prototype.setAllVerticesData = function (vertexData, updatable) {
  51. vertexData.applyToGeometry(this, updatable);
  52. this.notifyUpdate();
  53. };
  54. Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
  55. if (this._vertexBuffers[kind]) {
  56. this._vertexBuffers[kind].dispose();
  57. }
  58. this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
  59. if (kind === BABYLON.VertexBuffer.PositionKind) {
  60. stride = this._vertexBuffers[kind].getStrideSize();
  61. this._totalVertices = data.length / stride;
  62. this._extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  63. var meshes = this._meshes;
  64. var numOfMeshes = meshes.length;
  65. for (var index = 0; index < numOfMeshes; index++) {
  66. var mesh = meshes[index];
  67. mesh._resetPointsArrayCache();
  68. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  69. mesh._createGlobalSubMesh();
  70. mesh.computeWorldMatrix(true);
  71. }
  72. }
  73. this.notifyUpdate(kind);
  74. };
  75. Geometry.prototype.updateVerticesDataDirectly = function (kind, data, offset) {
  76. var vertexBuffer = this.getVertexBuffer(kind);
  77. if (!vertexBuffer) {
  78. return;
  79. }
  80. vertexBuffer.updateDirectly(data, offset);
  81. this.notifyUpdate(kind);
  82. };
  83. Geometry.prototype.updateVerticesData = function (kind, data, updateExtends) {
  84. var vertexBuffer = this.getVertexBuffer(kind);
  85. if (!vertexBuffer) {
  86. return;
  87. }
  88. vertexBuffer.update(data);
  89. if (kind === BABYLON.VertexBuffer.PositionKind) {
  90. var stride = vertexBuffer.getStrideSize();
  91. this._totalVertices = data.length / stride;
  92. if (updateExtends) {
  93. this._extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  94. }
  95. var meshes = this._meshes;
  96. var numOfMeshes = meshes.length;
  97. for (var index = 0; index < numOfMeshes; index++) {
  98. var mesh = meshes[index];
  99. mesh._resetPointsArrayCache();
  100. if (updateExtends) {
  101. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  102. for (var subIndex = 0; subIndex < mesh.subMeshes.length; subIndex++) {
  103. var subMesh = mesh.subMeshes[subIndex];
  104. subMesh.refreshBoundingInfo();
  105. }
  106. }
  107. }
  108. }
  109. this.notifyUpdate(kind);
  110. };
  111. Geometry.prototype.getTotalVertices = function () {
  112. if (!this.isReady()) {
  113. return 0;
  114. }
  115. return this._totalVertices;
  116. };
  117. Geometry.prototype.getVerticesData = function (kind, copyWhenShared) {
  118. var vertexBuffer = this.getVertexBuffer(kind);
  119. if (!vertexBuffer) {
  120. return null;
  121. }
  122. var orig = vertexBuffer.getData();
  123. if (!copyWhenShared || this._meshes.length === 1) {
  124. return orig;
  125. }
  126. else {
  127. var len = orig.length;
  128. var copy = [];
  129. for (var i = 0; i < len; i++) {
  130. copy.push(orig[i]);
  131. }
  132. return copy;
  133. }
  134. };
  135. Geometry.prototype.getVertexBuffer = function (kind) {
  136. if (!this.isReady()) {
  137. return null;
  138. }
  139. return this._vertexBuffers[kind];
  140. };
  141. Geometry.prototype.getVertexBuffers = function () {
  142. if (!this.isReady()) {
  143. return null;
  144. }
  145. return this._vertexBuffers;
  146. };
  147. Geometry.prototype.isVerticesDataPresent = function (kind) {
  148. if (!this._vertexBuffers) {
  149. if (this._delayInfo) {
  150. return this._delayInfo.indexOf(kind) !== -1;
  151. }
  152. return false;
  153. }
  154. return this._vertexBuffers[kind] !== undefined;
  155. };
  156. Geometry.prototype.getVerticesDataKinds = function () {
  157. var result = [];
  158. var kind;
  159. if (!this._vertexBuffers && this._delayInfo) {
  160. for (kind in this._delayInfo) {
  161. result.push(kind);
  162. }
  163. }
  164. else {
  165. for (kind in this._vertexBuffers) {
  166. result.push(kind);
  167. }
  168. }
  169. return result;
  170. };
  171. Geometry.prototype.setIndices = function (indices, totalVertices) {
  172. if (this._indexBuffer) {
  173. this._engine._releaseBuffer(this._indexBuffer);
  174. }
  175. this._indices = indices;
  176. if (this._meshes.length !== 0 && this._indices) {
  177. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  178. }
  179. if (totalVertices !== undefined) {
  180. this._totalVertices = totalVertices;
  181. }
  182. var meshes = this._meshes;
  183. var numOfMeshes = meshes.length;
  184. for (var index = 0; index < numOfMeshes; index++) {
  185. meshes[index]._createGlobalSubMesh();
  186. }
  187. this.notifyUpdate();
  188. };
  189. Geometry.prototype.getTotalIndices = function () {
  190. if (!this.isReady()) {
  191. return 0;
  192. }
  193. return this._indices.length;
  194. };
  195. Geometry.prototype.getIndices = function (copyWhenShared) {
  196. if (!this.isReady()) {
  197. return null;
  198. }
  199. var orig = this._indices;
  200. if (!copyWhenShared || this._meshes.length === 1) {
  201. return orig;
  202. }
  203. else {
  204. var len = orig.length;
  205. var copy = [];
  206. for (var i = 0; i < len; i++) {
  207. copy.push(orig[i]);
  208. }
  209. return copy;
  210. }
  211. };
  212. Geometry.prototype.getIndexBuffer = function () {
  213. if (!this.isReady()) {
  214. return null;
  215. }
  216. return this._indexBuffer;
  217. };
  218. Geometry.prototype.releaseForMesh = function (mesh, shouldDispose) {
  219. var meshes = this._meshes;
  220. var index = meshes.indexOf(mesh);
  221. if (index === -1) {
  222. return;
  223. }
  224. for (var kind in this._vertexBuffers) {
  225. this._vertexBuffers[kind].dispose();
  226. }
  227. if (this._indexBuffer && this._engine._releaseBuffer(this._indexBuffer)) {
  228. this._indexBuffer = null;
  229. }
  230. meshes.splice(index, 1);
  231. mesh._geometry = null;
  232. if (meshes.length === 0 && shouldDispose) {
  233. this.dispose();
  234. }
  235. };
  236. Geometry.prototype.applyToMesh = function (mesh) {
  237. if (mesh._geometry === this) {
  238. return;
  239. }
  240. var previousGeometry = mesh._geometry;
  241. if (previousGeometry) {
  242. previousGeometry.releaseForMesh(mesh);
  243. }
  244. var meshes = this._meshes;
  245. // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
  246. mesh._geometry = this;
  247. this._scene.pushGeometry(this);
  248. meshes.push(mesh);
  249. if (this.isReady()) {
  250. this._applyToMesh(mesh);
  251. }
  252. else {
  253. mesh._boundingInfo = this._boundingInfo;
  254. }
  255. };
  256. Geometry.prototype._applyToMesh = function (mesh) {
  257. var numOfMeshes = this._meshes.length;
  258. // vertexBuffers
  259. for (var kind in this._vertexBuffers) {
  260. if (numOfMeshes === 1) {
  261. this._vertexBuffers[kind].create();
  262. }
  263. this._vertexBuffers[kind]._buffer.references = numOfMeshes;
  264. if (kind === BABYLON.VertexBuffer.PositionKind) {
  265. mesh._resetPointsArrayCache();
  266. if (!this._extend) {
  267. this._extend = BABYLON.Tools.ExtractMinAndMax(this._vertexBuffers[kind].getData(), 0, this._totalVertices);
  268. }
  269. mesh._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  270. mesh._createGlobalSubMesh();
  271. //bounding info was just created again, world matrix should be applied again.
  272. mesh._updateBoundingInfo();
  273. }
  274. }
  275. // indexBuffer
  276. if (numOfMeshes === 1 && this._indices) {
  277. this._indexBuffer = this._engine.createIndexBuffer(this._indices);
  278. }
  279. if (this._indexBuffer) {
  280. this._indexBuffer.references = numOfMeshes;
  281. }
  282. };
  283. Geometry.prototype.notifyUpdate = function (kind) {
  284. if (this.onGeometryUpdated) {
  285. this.onGeometryUpdated(this, kind);
  286. }
  287. };
  288. Geometry.prototype.load = function (scene, onLoaded) {
  289. var _this = this;
  290. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
  291. return;
  292. }
  293. if (this.isReady()) {
  294. if (onLoaded) {
  295. onLoaded();
  296. }
  297. return;
  298. }
  299. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
  300. scene._addPendingData(this);
  301. BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
  302. _this._delayLoadingFunction(JSON.parse(data), _this);
  303. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  304. _this._delayInfo = [];
  305. scene._removePendingData(_this);
  306. var meshes = _this._meshes;
  307. var numOfMeshes = meshes.length;
  308. for (var index = 0; index < numOfMeshes; index++) {
  309. _this._applyToMesh(meshes[index]);
  310. }
  311. if (onLoaded) {
  312. onLoaded();
  313. }
  314. }, function () { }, scene.database);
  315. };
  316. Geometry.prototype.isDisposed = function () {
  317. return this._isDisposed;
  318. };
  319. Geometry.prototype.dispose = function () {
  320. var meshes = this._meshes;
  321. var numOfMeshes = meshes.length;
  322. var index;
  323. for (index = 0; index < numOfMeshes; index++) {
  324. this.releaseForMesh(meshes[index]);
  325. }
  326. this._meshes = [];
  327. for (var kind in this._vertexBuffers) {
  328. this._vertexBuffers[kind].dispose();
  329. }
  330. this._vertexBuffers = [];
  331. this._totalVertices = 0;
  332. if (this._indexBuffer) {
  333. this._engine._releaseBuffer(this._indexBuffer);
  334. }
  335. this._indexBuffer = null;
  336. this._indices = [];
  337. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  338. this.delayLoadingFile = null;
  339. this._delayLoadingFunction = null;
  340. this._delayInfo = [];
  341. this._boundingInfo = null;
  342. this._scene.removeGeometry(this);
  343. this._isDisposed = true;
  344. };
  345. Geometry.prototype.copy = function (id) {
  346. var vertexData = new BABYLON.VertexData();
  347. vertexData.indices = [];
  348. var indices = this.getIndices();
  349. for (var index = 0; index < indices.length; index++) {
  350. vertexData.indices.push(indices[index]);
  351. }
  352. var updatable = false;
  353. var stopChecking = false;
  354. var kind;
  355. for (kind in this._vertexBuffers) {
  356. // using slice() to make a copy of the array and not just reference it
  357. var data = this.getVerticesData(kind);
  358. if (data instanceof Float32Array) {
  359. vertexData.set(new Float32Array(data), kind);
  360. }
  361. else {
  362. vertexData.set(data.slice(0), kind);
  363. }
  364. if (!stopChecking) {
  365. updatable = this.getVertexBuffer(kind).isUpdatable();
  366. stopChecking = !updatable;
  367. }
  368. }
  369. var geometry = new Geometry(id, this._scene, vertexData, updatable, null);
  370. geometry.delayLoadState = this.delayLoadState;
  371. geometry.delayLoadingFile = this.delayLoadingFile;
  372. geometry._delayLoadingFunction = this._delayLoadingFunction;
  373. for (kind in this._delayInfo) {
  374. geometry._delayInfo = geometry._delayInfo || [];
  375. geometry._delayInfo.push(kind);
  376. }
  377. // Bounding info
  378. geometry._boundingInfo = new BABYLON.BoundingInfo(this._extend.minimum, this._extend.maximum);
  379. return geometry;
  380. };
  381. Geometry.prototype.serialize = function () {
  382. var serializationObject = {};
  383. serializationObject.id = this.id;
  384. if (BABYLON.Tags.HasTags(this)) {
  385. serializationObject.tags = BABYLON.Tags.GetTags(this);
  386. }
  387. return serializationObject;
  388. };
  389. Geometry.prototype.serializeVerticeData = function () {
  390. var serializationObject = this.serialize();
  391. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  392. serializationObject.positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  393. }
  394. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  395. serializationObject.normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  396. }
  397. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  398. serializationObject.uvs = this.getVerticesData(BABYLON.VertexBuffer.UVKind);
  399. }
  400. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  401. serializationObject.uvs2 = this.getVerticesData(BABYLON.VertexBuffer.UV2Kind);
  402. }
  403. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV3Kind)) {
  404. serializationObject.uvs3 = this.getVerticesData(BABYLON.VertexBuffer.UV3Kind);
  405. }
  406. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV4Kind)) {
  407. serializationObject.uvs4 = this.getVerticesData(BABYLON.VertexBuffer.UV4Kind);
  408. }
  409. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV5Kind)) {
  410. serializationObject.uvs5 = this.getVerticesData(BABYLON.VertexBuffer.UV5Kind);
  411. }
  412. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.UV6Kind)) {
  413. serializationObject.uvs6 = this.getVerticesData(BABYLON.VertexBuffer.UV6Kind);
  414. }
  415. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  416. serializationObject.colors = this.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  417. }
  418. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
  419. serializationObject.matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
  420. serializationObject.matricesIndices._isExpanded = true;
  421. }
  422. if (this.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
  423. serializationObject.matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
  424. }
  425. serializationObject.indices = this.getIndices();
  426. return serializationObject;
  427. };
  428. // Statics
  429. Geometry.ExtractFromMesh = function (mesh, id) {
  430. var geometry = mesh._geometry;
  431. if (!geometry) {
  432. return null;
  433. }
  434. return geometry.copy(id);
  435. };
  436. // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  437. // be aware Math.random() could cause collisions
  438. Geometry.RandomId = function () {
  439. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  440. var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
  441. return v.toString(16);
  442. });
  443. };
  444. Geometry.ImportGeometry = function (parsedGeometry, mesh) {
  445. var scene = mesh.getScene();
  446. // Geometry
  447. var geometryId = parsedGeometry.geometryId;
  448. if (geometryId) {
  449. var geometry = scene.getGeometryByID(geometryId);
  450. if (geometry) {
  451. geometry.applyToMesh(mesh);
  452. }
  453. }
  454. else if (parsedGeometry instanceof ArrayBuffer) {
  455. var binaryInfo = mesh._binaryInfo;
  456. if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {
  457. var positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);
  458. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData, false);
  459. }
  460. if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {
  461. var normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);
  462. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData, false);
  463. }
  464. if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {
  465. var uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);
  466. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvsData, false);
  467. }
  468. if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {
  469. var uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);
  470. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, uvs2Data, false);
  471. }
  472. if (binaryInfo.uvs3AttrDesc && binaryInfo.uvs3AttrDesc.count > 0) {
  473. var uvs3Data = new Float32Array(parsedGeometry, binaryInfo.uvs3AttrDesc.offset, binaryInfo.uvs3AttrDesc.count);
  474. mesh.setVerticesData(BABYLON.VertexBuffer.UV3Kind, uvs3Data, false);
  475. }
  476. if (binaryInfo.uvs4AttrDesc && binaryInfo.uvs4AttrDesc.count > 0) {
  477. var uvs4Data = new Float32Array(parsedGeometry, binaryInfo.uvs4AttrDesc.offset, binaryInfo.uvs4AttrDesc.count);
  478. mesh.setVerticesData(BABYLON.VertexBuffer.UV4Kind, uvs4Data, false);
  479. }
  480. if (binaryInfo.uvs5AttrDesc && binaryInfo.uvs5AttrDesc.count > 0) {
  481. var uvs5Data = new Float32Array(parsedGeometry, binaryInfo.uvs5AttrDesc.offset, binaryInfo.uvs5AttrDesc.count);
  482. mesh.setVerticesData(BABYLON.VertexBuffer.UV5Kind, uvs5Data, false);
  483. }
  484. if (binaryInfo.uvs6AttrDesc && binaryInfo.uvs6AttrDesc.count > 0) {
  485. var uvs6Data = new Float32Array(parsedGeometry, binaryInfo.uvs6AttrDesc.offset, binaryInfo.uvs6AttrDesc.count);
  486. mesh.setVerticesData(BABYLON.VertexBuffer.UV6Kind, uvs6Data, false);
  487. }
  488. if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
  489. var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
  490. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false, binaryInfo.colorsAttrDesc.stride);
  491. }
  492. if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
  493. var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);
  494. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndicesData, false);
  495. }
  496. if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
  497. var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
  498. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
  499. }
  500. if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {
  501. var indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);
  502. mesh.setIndices(indicesData);
  503. }
  504. if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {
  505. var subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);
  506. mesh.subMeshes = [];
  507. for (var i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {
  508. var materialIndex = subMeshesData[(i * 5) + 0];
  509. var verticesStart = subMeshesData[(i * 5) + 1];
  510. var verticesCount = subMeshesData[(i * 5) + 2];
  511. var indexStart = subMeshesData[(i * 5) + 3];
  512. var indexCount = subMeshesData[(i * 5) + 4];
  513. var subMesh = new BABYLON.SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);
  514. }
  515. }
  516. }
  517. else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
  518. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, parsedGeometry.positions, false);
  519. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, parsedGeometry.normals, false);
  520. if (parsedGeometry.uvs) {
  521. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, parsedGeometry.uvs, false);
  522. }
  523. if (parsedGeometry.uvs2) {
  524. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, parsedGeometry.uvs2, false);
  525. }
  526. if (parsedGeometry.uvs3) {
  527. mesh.setVerticesData(BABYLON.VertexBuffer.UV3Kind, parsedGeometry.uvs3, false);
  528. }
  529. if (parsedGeometry.uvs4) {
  530. mesh.setVerticesData(BABYLON.VertexBuffer.UV4Kind, parsedGeometry.uvs4, false);
  531. }
  532. if (parsedGeometry.uvs5) {
  533. mesh.setVerticesData(BABYLON.VertexBuffer.UV5Kind, parsedGeometry.uvs5, false);
  534. }
  535. if (parsedGeometry.uvs6) {
  536. mesh.setVerticesData(BABYLON.VertexBuffer.UV6Kind, parsedGeometry.uvs6, false);
  537. }
  538. if (parsedGeometry.colors) {
  539. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, BABYLON.Color4.CheckColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), false);
  540. }
  541. if (parsedGeometry.matricesIndices) {
  542. if (!parsedGeometry.matricesIndices._isExpanded) {
  543. var floatIndices = [];
  544. for (var i = 0; i < parsedGeometry.matricesIndices.length; i++) {
  545. var matricesIndex = parsedGeometry.matricesIndices[i];
  546. floatIndices.push(matricesIndex & 0x000000FF);
  547. floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
  548. floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
  549. floatIndices.push(matricesIndex >> 24);
  550. }
  551. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, floatIndices, false);
  552. }
  553. else {
  554. delete parsedGeometry.matricesIndices._isExpanded;
  555. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, false);
  556. }
  557. }
  558. if (parsedGeometry.matricesIndicesExtra) {
  559. if (!parsedGeometry.matricesIndicesExtra._isExpanded) {
  560. var floatIndices = [];
  561. for (var i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {
  562. var matricesIndex = parsedGeometry.matricesIndicesExtra[i];
  563. floatIndices.push(matricesIndex & 0x000000FF);
  564. floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
  565. floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
  566. floatIndices.push(matricesIndex >> 24);
  567. }
  568. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, floatIndices, false);
  569. }
  570. else {
  571. delete parsedGeometry.matricesIndices._isExpanded;
  572. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, false);
  573. }
  574. }
  575. if (parsedGeometry.matricesWeights) {
  576. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, false);
  577. }
  578. if (parsedGeometry.matricesWeightsExtra) {
  579. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, false);
  580. }
  581. mesh.setIndices(parsedGeometry.indices);
  582. }
  583. // SubMeshes
  584. if (parsedGeometry.subMeshes) {
  585. mesh.subMeshes = [];
  586. for (var subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {
  587. var parsedSubMesh = parsedGeometry.subMeshes[subIndex];
  588. var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);
  589. }
  590. }
  591. // Flat shading
  592. if (mesh._shouldGenerateFlatShading) {
  593. mesh.convertToFlatShadedMesh();
  594. delete mesh._shouldGenerateFlatShading;
  595. }
  596. // Update
  597. mesh.computeWorldMatrix(true);
  598. // Octree
  599. if (scene['_selectionOctree']) {
  600. scene['_selectionOctree'].addMesh(mesh);
  601. }
  602. };
  603. Geometry.Parse = function (parsedVertexData, scene, rootUrl) {
  604. if (scene.getGeometryByID(parsedVertexData.id)) {
  605. return null; // null since geometry could be something else than a box...
  606. }
  607. var geometry = new Geometry(parsedVertexData.id, scene);
  608. BABYLON.Tags.AddTagsTo(geometry, parsedVertexData.tags);
  609. if (parsedVertexData.delayLoadingFile) {
  610. geometry.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  611. geometry.delayLoadingFile = rootUrl + parsedVertexData.delayLoadingFile;
  612. geometry._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMaximum));
  613. geometry._delayInfo = [];
  614. if (parsedVertexData.hasUVs) {
  615. geometry._delayInfo.push(BABYLON.VertexBuffer.UVKind);
  616. }
  617. if (parsedVertexData.hasUVs2) {
  618. geometry._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
  619. }
  620. if (parsedVertexData.hasUVs3) {
  621. geometry._delayInfo.push(BABYLON.VertexBuffer.UV3Kind);
  622. }
  623. if (parsedVertexData.hasUVs4) {
  624. geometry._delayInfo.push(BABYLON.VertexBuffer.UV4Kind);
  625. }
  626. if (parsedVertexData.hasUVs5) {
  627. geometry._delayInfo.push(BABYLON.VertexBuffer.UV5Kind);
  628. }
  629. if (parsedVertexData.hasUVs6) {
  630. geometry._delayInfo.push(BABYLON.VertexBuffer.UV6Kind);
  631. }
  632. if (parsedVertexData.hasColors) {
  633. geometry._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
  634. }
  635. if (parsedVertexData.hasMatricesIndices) {
  636. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  637. }
  638. if (parsedVertexData.hasMatricesWeights) {
  639. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  640. }
  641. geometry._delayLoadingFunction = BABYLON.VertexData.ImportVertexData;
  642. }
  643. else {
  644. BABYLON.VertexData.ImportVertexData(parsedVertexData, geometry);
  645. }
  646. scene.pushGeometry(geometry, true);
  647. return geometry;
  648. };
  649. return Geometry;
  650. })();
  651. BABYLON.Geometry = Geometry;
  652. /////// Primitives //////////////////////////////////////////////
  653. var Geometry;
  654. (function (Geometry) {
  655. var Primitives;
  656. (function (Primitives) {
  657. /// Abstract class
  658. var _Primitive = (function (_super) {
  659. __extends(_Primitive, _super);
  660. function _Primitive(id, scene, vertexData, canBeRegenerated, mesh) {
  661. this._beingRegenerated = true;
  662. this._canBeRegenerated = canBeRegenerated;
  663. _super.call(this, id, scene, vertexData, false, mesh); // updatable = false to be sure not to update vertices
  664. this._beingRegenerated = false;
  665. }
  666. _Primitive.prototype.canBeRegenerated = function () {
  667. return this._canBeRegenerated;
  668. };
  669. _Primitive.prototype.regenerate = function () {
  670. if (!this._canBeRegenerated) {
  671. return;
  672. }
  673. this._beingRegenerated = true;
  674. this.setAllVerticesData(this._regenerateVertexData(), false);
  675. this._beingRegenerated = false;
  676. };
  677. _Primitive.prototype.asNewGeometry = function (id) {
  678. return _super.prototype.copy.call(this, id);
  679. };
  680. // overrides
  681. _Primitive.prototype.setAllVerticesData = function (vertexData, updatable) {
  682. if (!this._beingRegenerated) {
  683. return;
  684. }
  685. _super.prototype.setAllVerticesData.call(this, vertexData, false);
  686. };
  687. _Primitive.prototype.setVerticesData = function (kind, data, updatable) {
  688. if (!this._beingRegenerated) {
  689. return;
  690. }
  691. _super.prototype.setVerticesData.call(this, kind, data, false);
  692. };
  693. // to override
  694. // protected
  695. _Primitive.prototype._regenerateVertexData = function () {
  696. throw new Error("Abstract method");
  697. };
  698. _Primitive.prototype.copy = function (id) {
  699. throw new Error("Must be overriden in sub-classes.");
  700. };
  701. _Primitive.prototype.serialize = function () {
  702. var serializationObject = _super.prototype.serialize.call(this);
  703. serializationObject.canBeRegenerated = this.canBeRegenerated();
  704. return serializationObject;
  705. };
  706. return _Primitive;
  707. })(Geometry);
  708. Primitives._Primitive = _Primitive;
  709. var Ribbon = (function (_super) {
  710. __extends(Ribbon, _super);
  711. function Ribbon(id, scene, pathArray, closeArray, closePath, offset, canBeRegenerated, mesh, side) {
  712. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  713. this.pathArray = pathArray;
  714. this.closeArray = closeArray;
  715. this.closePath = closePath;
  716. this.offset = offset;
  717. this.side = side;
  718. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  719. }
  720. Ribbon.prototype._regenerateVertexData = function () {
  721. return BABYLON.VertexData.CreateRibbon({ pathArray: this.pathArray, closeArray: this.closeArray, closePath: this.closePath, offset: this.offset, sideOrientation: this.side });
  722. };
  723. Ribbon.prototype.copy = function (id) {
  724. return new Ribbon(id, this.getScene(), this.pathArray, this.closeArray, this.closePath, this.offset, this.canBeRegenerated(), null, this.side);
  725. };
  726. return Ribbon;
  727. })(_Primitive);
  728. Primitives.Ribbon = Ribbon;
  729. var Box = (function (_super) {
  730. __extends(Box, _super);
  731. function Box(id, scene, size, canBeRegenerated, mesh, side) {
  732. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  733. this.size = size;
  734. this.side = side;
  735. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  736. }
  737. Box.prototype._regenerateVertexData = function () {
  738. return BABYLON.VertexData.CreateBox({ size: this.size, sideOrientation: this.side });
  739. };
  740. Box.prototype.copy = function (id) {
  741. return new Box(id, this.getScene(), this.size, this.canBeRegenerated(), null, this.side);
  742. };
  743. Box.prototype.serialize = function () {
  744. var serializationObject = _super.prototype.serialize.call(this);
  745. serializationObject.size = this.size;
  746. return serializationObject;
  747. };
  748. Box.Parse = function (parsedBox, scene) {
  749. if (scene.getGeometryByID(parsedBox.id)) {
  750. return null; // null since geometry could be something else than a box...
  751. }
  752. var box = new Geometry.Primitives.Box(parsedBox.id, scene, parsedBox.size, parsedBox.canBeRegenerated, null);
  753. BABYLON.Tags.AddTagsTo(box, parsedBox.tags);
  754. scene.pushGeometry(box, true);
  755. return box;
  756. };
  757. return Box;
  758. })(_Primitive);
  759. Primitives.Box = Box;
  760. var Sphere = (function (_super) {
  761. __extends(Sphere, _super);
  762. function Sphere(id, scene, segments, diameter, canBeRegenerated, mesh, side) {
  763. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  764. this.segments = segments;
  765. this.diameter = diameter;
  766. this.side = side;
  767. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  768. }
  769. Sphere.prototype._regenerateVertexData = function () {
  770. return BABYLON.VertexData.CreateSphere({ segments: this.segments, diameter: this.diameter, sideOrientation: this.side });
  771. };
  772. Sphere.prototype.copy = function (id) {
  773. return new Sphere(id, this.getScene(), this.segments, this.diameter, this.canBeRegenerated(), null, this.side);
  774. };
  775. Sphere.prototype.serialize = function () {
  776. var serializationObject = _super.prototype.serialize.call(this);
  777. serializationObject.segments = this.segments;
  778. serializationObject.diameter = this.diameter;
  779. return serializationObject;
  780. };
  781. Sphere.Parse = function (parsedSphere, scene) {
  782. if (scene.getGeometryByID(parsedSphere.id)) {
  783. return null; // null since geometry could be something else than a sphere...
  784. }
  785. var sphere = new Geometry.Primitives.Sphere(parsedSphere.id, scene, parsedSphere.segments, parsedSphere.diameter, parsedSphere.canBeRegenerated, null);
  786. BABYLON.Tags.AddTagsTo(sphere, parsedSphere.tags);
  787. scene.pushGeometry(sphere, true);
  788. return sphere;
  789. };
  790. return Sphere;
  791. })(_Primitive);
  792. Primitives.Sphere = Sphere;
  793. var Disc = (function (_super) {
  794. __extends(Disc, _super);
  795. function Disc(id, scene, radius, tessellation, canBeRegenerated, mesh, side) {
  796. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  797. this.radius = radius;
  798. this.tessellation = tessellation;
  799. this.side = side;
  800. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  801. }
  802. Disc.prototype._regenerateVertexData = function () {
  803. return BABYLON.VertexData.CreateDisc({ radius: this.radius, tessellation: this.tessellation, sideOrientation: this.side });
  804. };
  805. Disc.prototype.copy = function (id) {
  806. return new Disc(id, this.getScene(), this.radius, this.tessellation, this.canBeRegenerated(), null, this.side);
  807. };
  808. return Disc;
  809. })(_Primitive);
  810. Primitives.Disc = Disc;
  811. var Cylinder = (function (_super) {
  812. __extends(Cylinder, _super);
  813. function Cylinder(id, scene, height, diameterTop, diameterBottom, tessellation, subdivisions, canBeRegenerated, mesh, side) {
  814. if (subdivisions === void 0) { subdivisions = 1; }
  815. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  816. this.height = height;
  817. this.diameterTop = diameterTop;
  818. this.diameterBottom = diameterBottom;
  819. this.tessellation = tessellation;
  820. this.subdivisions = subdivisions;
  821. this.side = side;
  822. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  823. }
  824. Cylinder.prototype._regenerateVertexData = function () {
  825. return BABYLON.VertexData.CreateCylinder({ height: this.height, diameterTop: this.diameterTop, diameterBottom: this.diameterBottom, tessellation: this.tessellation, subdivisions: this.subdivisions, sideOrientation: this.side });
  826. };
  827. Cylinder.prototype.copy = function (id) {
  828. return new Cylinder(id, this.getScene(), this.height, this.diameterTop, this.diameterBottom, this.tessellation, this.subdivisions, this.canBeRegenerated(), null, this.side);
  829. };
  830. Cylinder.prototype.serialize = function () {
  831. var serializationObject = _super.prototype.serialize.call(this);
  832. serializationObject.height = this.height;
  833. serializationObject.diameterTop = this.diameterTop;
  834. serializationObject.diameterBottom = this.diameterBottom;
  835. serializationObject.tessellation = this.tessellation;
  836. return serializationObject;
  837. };
  838. Cylinder.Parse = function (parsedCylinder, scene) {
  839. if (scene.getGeometryByID(parsedCylinder.id)) {
  840. return null; // null since geometry could be something else than a cylinder...
  841. }
  842. var cylinder = new Geometry.Primitives.Cylinder(parsedCylinder.id, scene, parsedCylinder.height, parsedCylinder.diameterTop, parsedCylinder.diameterBottom, parsedCylinder.tessellation, parsedCylinder.subdivisions, parsedCylinder.canBeRegenerated, null);
  843. BABYLON.Tags.AddTagsTo(cylinder, parsedCylinder.tags);
  844. scene.pushGeometry(cylinder, true);
  845. return cylinder;
  846. };
  847. return Cylinder;
  848. })(_Primitive);
  849. Primitives.Cylinder = Cylinder;
  850. var Torus = (function (_super) {
  851. __extends(Torus, _super);
  852. function Torus(id, scene, diameter, thickness, tessellation, canBeRegenerated, mesh, side) {
  853. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  854. this.diameter = diameter;
  855. this.thickness = thickness;
  856. this.tessellation = tessellation;
  857. this.side = side;
  858. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  859. }
  860. Torus.prototype._regenerateVertexData = function () {
  861. return BABYLON.VertexData.CreateTorus({ diameter: this.diameter, thickness: this.thickness, tessellation: this.tessellation, sideOrientation: this.side });
  862. };
  863. Torus.prototype.copy = function (id) {
  864. return new Torus(id, this.getScene(), this.diameter, this.thickness, this.tessellation, this.canBeRegenerated(), null, this.side);
  865. };
  866. Torus.prototype.serialize = function () {
  867. var serializationObject = _super.prototype.serialize.call(this);
  868. serializationObject.diameter = this.diameter;
  869. serializationObject.thickness = this.thickness;
  870. serializationObject.tessellation = this.tessellation;
  871. return serializationObject;
  872. };
  873. Torus.Parse = function (parsedTorus, scene) {
  874. if (scene.getGeometryByID(parsedTorus.id)) {
  875. return null; // null since geometry could be something else than a torus...
  876. }
  877. var torus = new Geometry.Primitives.Torus(parsedTorus.id, scene, parsedTorus.diameter, parsedTorus.thickness, parsedTorus.tessellation, parsedTorus.canBeRegenerated, null);
  878. BABYLON.Tags.AddTagsTo(torus, parsedTorus.tags);
  879. scene.pushGeometry(torus, true);
  880. return torus;
  881. };
  882. return Torus;
  883. })(_Primitive);
  884. Primitives.Torus = Torus;
  885. var Ground = (function (_super) {
  886. __extends(Ground, _super);
  887. function Ground(id, scene, width, height, subdivisions, canBeRegenerated, mesh) {
  888. this.width = width;
  889. this.height = height;
  890. this.subdivisions = subdivisions;
  891. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  892. }
  893. Ground.prototype._regenerateVertexData = function () {
  894. return BABYLON.VertexData.CreateGround({ width: this.width, height: this.height, subdivisions: this.subdivisions });
  895. };
  896. Ground.prototype.copy = function (id) {
  897. return new Ground(id, this.getScene(), this.width, this.height, this.subdivisions, this.canBeRegenerated(), null);
  898. };
  899. Ground.prototype.serialize = function () {
  900. var serializationObject = _super.prototype.serialize.call(this);
  901. serializationObject.width = this.width;
  902. serializationObject.height = this.height;
  903. serializationObject.subdivisions = this.subdivisions;
  904. return serializationObject;
  905. };
  906. Ground.Parse = function (parsedGround, scene) {
  907. if (scene.getGeometryByID(parsedGround.id)) {
  908. return null; // null since geometry could be something else than a ground...
  909. }
  910. var ground = new Geometry.Primitives.Ground(parsedGround.id, scene, parsedGround.width, parsedGround.height, parsedGround.subdivisions, parsedGround.canBeRegenerated, null);
  911. BABYLON.Tags.AddTagsTo(ground, parsedGround.tags);
  912. scene.pushGeometry(ground, true);
  913. return ground;
  914. };
  915. return Ground;
  916. })(_Primitive);
  917. Primitives.Ground = Ground;
  918. var TiledGround = (function (_super) {
  919. __extends(TiledGround, _super);
  920. function TiledGround(id, scene, xmin, zmin, xmax, zmax, subdivisions, precision, canBeRegenerated, mesh) {
  921. this.xmin = xmin;
  922. this.zmin = zmin;
  923. this.xmax = xmax;
  924. this.zmax = zmax;
  925. this.subdivisions = subdivisions;
  926. this.precision = precision;
  927. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  928. }
  929. TiledGround.prototype._regenerateVertexData = function () {
  930. return BABYLON.VertexData.CreateTiledGround({ xmin: this.xmin, zmin: this.zmin, xmax: this.xmax, zmax: this.zmax, subdivisions: this.subdivisions, precision: this.precision });
  931. };
  932. TiledGround.prototype.copy = function (id) {
  933. return new TiledGround(id, this.getScene(), this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision, this.canBeRegenerated(), null);
  934. };
  935. return TiledGround;
  936. })(_Primitive);
  937. Primitives.TiledGround = TiledGround;
  938. var Plane = (function (_super) {
  939. __extends(Plane, _super);
  940. function Plane(id, scene, size, canBeRegenerated, mesh, side) {
  941. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  942. this.size = size;
  943. this.side = side;
  944. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  945. }
  946. Plane.prototype._regenerateVertexData = function () {
  947. return BABYLON.VertexData.CreatePlane({ size: this.size, sideOrientation: this.side });
  948. };
  949. Plane.prototype.copy = function (id) {
  950. return new Plane(id, this.getScene(), this.size, this.canBeRegenerated(), null, this.side);
  951. };
  952. Plane.prototype.serialize = function () {
  953. var serializationObject = _super.prototype.serialize.call(this);
  954. serializationObject.size = this.size;
  955. return serializationObject;
  956. };
  957. Plane.Parse = function (parsedPlane, scene) {
  958. if (scene.getGeometryByID(parsedPlane.id)) {
  959. return null; // null since geometry could be something else than a ground...
  960. }
  961. var plane = new Geometry.Primitives.Plane(parsedPlane.id, scene, parsedPlane.size, parsedPlane.canBeRegenerated, null);
  962. BABYLON.Tags.AddTagsTo(plane, parsedPlane.tags);
  963. scene.pushGeometry(plane, true);
  964. return plane;
  965. };
  966. return Plane;
  967. })(_Primitive);
  968. Primitives.Plane = Plane;
  969. var TorusKnot = (function (_super) {
  970. __extends(TorusKnot, _super);
  971. function TorusKnot(id, scene, radius, tube, radialSegments, tubularSegments, p, q, canBeRegenerated, mesh, side) {
  972. if (side === void 0) { side = BABYLON.Mesh.DEFAULTSIDE; }
  973. this.radius = radius;
  974. this.tube = tube;
  975. this.radialSegments = radialSegments;
  976. this.tubularSegments = tubularSegments;
  977. this.p = p;
  978. this.q = q;
  979. this.side = side;
  980. _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);
  981. }
  982. TorusKnot.prototype._regenerateVertexData = function () {
  983. 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 });
  984. };
  985. TorusKnot.prototype.copy = function (id) {
  986. return new TorusKnot(id, this.getScene(), this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q, this.canBeRegenerated(), null, this.side);
  987. };
  988. TorusKnot.prototype.serialize = function () {
  989. var serializationObject = _super.prototype.serialize.call(this);
  990. serializationObject.radius = this.radius;
  991. serializationObject.tube = this.tube;
  992. serializationObject.radialSegments = this.radialSegments;
  993. serializationObject.tubularSegments = this.tubularSegments;
  994. serializationObject.p = this.p;
  995. serializationObject.q = this.q;
  996. return serializationObject;
  997. };
  998. ;
  999. TorusKnot.Parse = function (parsedTorusKnot, scene) {
  1000. if (scene.getGeometryByID(parsedTorusKnot.id)) {
  1001. return null; // null since geometry could be something else than a ground...
  1002. }
  1003. var torusKnot = new Geometry.Primitives.TorusKnot(parsedTorusKnot.id, scene, parsedTorusKnot.radius, parsedTorusKnot.tube, parsedTorusKnot.radialSegments, parsedTorusKnot.tubularSegments, parsedTorusKnot.p, parsedTorusKnot.q, parsedTorusKnot.canBeRegenerated, null);
  1004. BABYLON.Tags.AddTagsTo(torusKnot, parsedTorusKnot.tags);
  1005. scene.pushGeometry(torusKnot, true);
  1006. return torusKnot;
  1007. };
  1008. return TorusKnot;
  1009. })(_Primitive);
  1010. Primitives.TorusKnot = TorusKnot;
  1011. })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
  1012. })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
  1013. })(BABYLON || (BABYLON = {}));