babylon.mesh.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. var __extends = 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. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var Mesh = (function (_super) {
  10. __extends(Mesh, _super);
  11. //ANY
  12. function Mesh(name, scene) {
  13. _super.call(this, name, scene);
  14. // Members
  15. this.position = new BABYLON.Vector3(0, 0, 0);
  16. this.rotation = new BABYLON.Vector3(0, 0, 0);
  17. this.rotationQuaternion = null;
  18. this.scaling = new BABYLON.Vector3(1, 1, 1);
  19. this.delayLoadState = 0;
  20. this.material = null;
  21. this.isVisible = true;
  22. this.isPickable = true;
  23. this.visibility = 1.0;
  24. this.billboardMode = BABYLON.Mesh.BILLBOARDMODE_NONE;
  25. this.checkCollisions = false;
  26. this.receiveShadows = false;
  27. this._isDisposed = false;
  28. this.onDispose = null;
  29. this.skeleton = null;
  30. this.renderingGroupId = 0;
  31. this.infiniteDistance = false;
  32. this.showBoundingBox = false;
  33. // Cache
  34. this._positions = null;
  35. this._localScaling = BABYLON.Matrix.Zero();
  36. this._localRotation = BABYLON.Matrix.Zero();
  37. this._localTranslation = BABYLON.Matrix.Zero();
  38. this._localBillboard = BABYLON.Matrix.Zero();
  39. this._localPivotScaling = BABYLON.Matrix.Zero();
  40. this._localPivotScalingRotation = BABYLON.Matrix.Zero();
  41. this._localWorld = BABYLON.Matrix.Zero();
  42. this._worldMatrix = BABYLON.Matrix.Zero();
  43. this._rotateYByPI = BABYLON.Matrix.RotationY(Math.PI);
  44. this._collisionsTransformMatrix = BABYLON.Matrix.Zero();
  45. this._collisionsScalingMatrix = BABYLON.Matrix.Zero();
  46. this._absolutePosition = BABYLON.Vector3.Zero();
  47. // Physics
  48. this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
  49. this._totalVertices = 0;
  50. this._pivotMatrix = BABYLON.Matrix.Identity();
  51. this._indices = [];
  52. this._renderId = 0;
  53. this._onBeforeRenderCallbacks = [];
  54. this._vertexStrideSize = 0;
  55. this._animationStarted = false;
  56. scene.meshes.push(this);
  57. }
  58. Mesh.prototype.getBoundingInfo = function () {
  59. return this._boundingInfo;
  60. };
  61. Mesh.prototype.getWorldMatrix = function () {
  62. if (this._currentRenderId !== this.getScene().getRenderId()) {
  63. this.computeWorldMatrix();
  64. }
  65. return this._worldMatrix;
  66. };
  67. Mesh.prototype.rotate = function (axis, amount, space) {
  68. if (!this.rotationQuaternion) {
  69. this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
  70. this.rotation = BABYLON.Vector3.Zero();
  71. }
  72. if (!space || space == 0 /* LOCAL */) {
  73. var rotationQuaternion = BABYLON.Quaternion.RotationAxis(axis, amount);
  74. this.rotationQuaternion = this.rotationQuaternion.multiply(rotationQuaternion);
  75. } else {
  76. if (this.parent) {
  77. var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
  78. invertParentWorldMatrix.invert();
  79. axis = BABYLON.Vector3.TransformNormal(axis, invertParentWorldMatrix);
  80. }
  81. rotationQuaternion = BABYLON.Quaternion.RotationAxis(axis, amount);
  82. this.rotationQuaternion = rotationQuaternion.multiply(this.rotationQuaternion);
  83. }
  84. };
  85. Mesh.prototype.translate = function (axis, distance, space) {
  86. var displacementVector = axis.scale(distance);
  87. if (!space || space == 0 /* LOCAL */) {
  88. var tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);
  89. this.setPositionWithLocalVector(tempV3);
  90. } else {
  91. this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));
  92. }
  93. };
  94. Mesh.prototype.getAbsolutePosition = function () {
  95. this.computeWorldMatrix();
  96. return this._absolutePosition;
  97. };
  98. Mesh.prototype.setAbsolutePosition = function (absolutePosition) {
  99. if (!absolutePosition) {
  100. return;
  101. }
  102. var absolutePositionX;
  103. var absolutePositionY;
  104. var absolutePositionZ;
  105. if (absolutePosition.x === undefined) {
  106. if (arguments.length < 3) {
  107. return;
  108. }
  109. absolutePositionX = arguments[0];
  110. absolutePositionY = arguments[1];
  111. absolutePositionZ = arguments[2];
  112. } else {
  113. absolutePositionX = absolutePosition.x;
  114. absolutePositionY = absolutePosition.y;
  115. absolutePositionZ = absolutePosition.z;
  116. }
  117. if (this.parent) {
  118. var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
  119. invertParentWorldMatrix.invert();
  120. var worldPosition = new BABYLON.Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
  121. this.position = BABYLON.Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
  122. } else {
  123. this.position.x = absolutePositionX;
  124. this.position.y = absolutePositionY;
  125. this.position.z = absolutePositionZ;
  126. }
  127. };
  128. Mesh.prototype.getTotalVertices = function () {
  129. return this._totalVertices;
  130. };
  131. Mesh.prototype.getVerticesData = function (kind) {
  132. return this._vertexBuffers[kind].getData();
  133. };
  134. Mesh.prototype.getVertexBuffer = function (kind) {
  135. return this._vertexBuffers[kind];
  136. };
  137. Mesh.prototype.isVerticesDataPresent = function (kind) {
  138. if (!this._vertexBuffers) {
  139. if (this._delayInfo) {
  140. return this._delayInfo.indexOf(kind) !== -1;
  141. }
  142. return false;
  143. }
  144. return this._vertexBuffers[kind] !== undefined;
  145. };
  146. Mesh.prototype.getVerticesDataKinds = function () {
  147. var result = [];
  148. if (!this._vertexBuffers && this._delayInfo) {
  149. for (var kind in this._delayInfo) {
  150. result.push(kind);
  151. }
  152. } else {
  153. for (kind in this._vertexBuffers) {
  154. result.push(kind);
  155. }
  156. }
  157. return result;
  158. };
  159. Mesh.prototype.getTotalIndices = function () {
  160. return this._indices.length;
  161. };
  162. Mesh.prototype.getIndices = function () {
  163. return this._indices;
  164. };
  165. Mesh.prototype.getVertexStrideSize = function () {
  166. return this._vertexStrideSize;
  167. };
  168. Mesh.prototype.setPivotMatrix = function (matrix) {
  169. this._pivotMatrix = matrix;
  170. this._cache.pivotMatrixUpdated = true;
  171. };
  172. Mesh.prototype.getPivotMatrix = function () {
  173. return this._pivotMatrix;
  174. };
  175. Mesh.prototype._isSynchronized = function () {
  176. if (this.billboardMode !== Mesh.BILLBOARDMODE_NONE)
  177. return false;
  178. if (this._cache.pivotMatrixUpdated) {
  179. return false;
  180. }
  181. if (this.infiniteDistance) {
  182. return false;
  183. }
  184. if (!this._cache.position.equals(this.position))
  185. return false;
  186. if (this.rotationQuaternion) {
  187. if (!this._cache.rotationQuaternion.equals(this.rotationQuaternion))
  188. return false;
  189. } else {
  190. if (!this._cache.rotation.equals(this.rotation))
  191. return false;
  192. }
  193. if (!this._cache.scaling.equals(this.scaling))
  194. return false;
  195. return true;
  196. };
  197. Mesh.prototype.isReady = function () {
  198. return this._isReady;
  199. };
  200. Mesh.prototype.isAnimated = function () {
  201. return this._animationStarted;
  202. };
  203. Mesh.prototype.isDisposed = function () {
  204. return this._isDisposed;
  205. };
  206. // Methods
  207. Mesh.prototype._initCache = function () {
  208. _super.prototype._initCache.call(this);
  209. this._cache.localMatrixUpdated = false;
  210. this._cache.position = BABYLON.Vector3.Zero();
  211. this._cache.scaling = BABYLON.Vector3.Zero();
  212. this._cache.rotation = BABYLON.Vector3.Zero();
  213. this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
  214. };
  215. Mesh.prototype.markAsDirty = function (property) {
  216. if (property === "rotation") {
  217. this.rotationQuaternion = null;
  218. }
  219. this._currentRenderId = -1;
  220. };
  221. Mesh.prototype.refreshBoundingInfo = function () {
  222. var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  223. if (!data) {
  224. return;
  225. }
  226. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  227. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  228. for (var index = 0; index < this.subMeshes.length; index++) {
  229. this.subMeshes[index].refreshBoundingInfo();
  230. }
  231. this._updateBoundingInfo();
  232. };
  233. Mesh.prototype._updateBoundingInfo = function () {
  234. this._boundingInfo = this._boundingInfo || new BABYLON.BoundingInfo(this._absolutePosition, this._absolutePosition);
  235. this._boundingInfo._update(this._worldMatrix);
  236. if (!this.subMeshes) {
  237. return;
  238. }
  239. for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
  240. var subMesh = this.subMeshes[subIndex];
  241. subMesh.updateBoundingInfo(this._worldMatrix);
  242. }
  243. };
  244. Mesh.prototype.computeWorldMatrix = function (force) {
  245. if (!force && (this._currentRenderId == this.getScene().getRenderId() || this.isSynchronized(true))) {
  246. return this._worldMatrix;
  247. }
  248. this._cache.position.copyFrom(this.position);
  249. this._cache.scaling.copyFrom(this.scaling);
  250. this._cache.pivotMatrixUpdated = false;
  251. this._currentRenderId = this.getScene().getRenderId();
  252. // Scaling
  253. BABYLON.Matrix.ScalingToRef(this.scaling.x, this.scaling.y, this.scaling.z, this._localScaling);
  254. // Rotation
  255. if (this.rotationQuaternion) {
  256. this.rotationQuaternion.toRotationMatrix(this._localRotation);
  257. this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
  258. } else {
  259. BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._localRotation);
  260. this._cache.rotation.copyFrom(this.rotation);
  261. }
  262. // Translation
  263. if (this.infiniteDistance && !this.parent) {
  264. var camera = this.getScene().activeCamera;
  265. var cameraWorldMatrix = camera.getWorldMatrix();
  266. var cameraGlobalPosition = new BABYLON.Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);
  267. BABYLON.Matrix.TranslationToRef(this.position.x + cameraGlobalPosition.x, this.position.y + cameraGlobalPosition.y, this.position.z + cameraGlobalPosition.z, this._localTranslation);
  268. } else {
  269. BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._localTranslation);
  270. }
  271. // Composing transformations
  272. this._pivotMatrix.multiplyToRef(this._localScaling, this._localPivotScaling);
  273. this._localPivotScaling.multiplyToRef(this._localRotation, this._localPivotScalingRotation);
  274. // Billboarding
  275. if (this.billboardMode !== Mesh.BILLBOARDMODE_NONE) {
  276. var localPosition = this.position.clone();
  277. var zero = this.getScene().activeCamera.position.clone();
  278. if (this.parent && this.parent.position) {
  279. localPosition.addInPlace(this.parent.position);
  280. BABYLON.Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, this._localTranslation);
  281. }
  282. if ((this.billboardMode & Mesh.BILLBOARDMODE_ALL) === Mesh.BILLBOARDMODE_ALL) {
  283. zero = this.getScene().activeCamera.position;
  284. } else {
  285. if (this.billboardMode & BABYLON.Mesh.BILLBOARDMODE_X)
  286. zero.x = localPosition.x + 0.001; //ANY:BABYLON.Engine.epsilon
  287. if (this.billboardMode & BABYLON.Mesh.BILLBOARDMODE_Y)
  288. zero.y = localPosition.y + 0.001;
  289. if (this.billboardMode & BABYLON.Mesh.BILLBOARDMODE_Z)
  290. zero.z = localPosition.z + 0.001;
  291. }
  292. BABYLON.Matrix.LookAtLHToRef(localPosition, zero, BABYLON.Vector3.Up(), this._localBillboard);
  293. this._localBillboard.m[12] = this._localBillboard.m[13] = this._localBillboard.m[14] = 0;
  294. this._localBillboard.invert();
  295. this._localPivotScalingRotation.multiplyToRef(this._localBillboard, this._localWorld);
  296. this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotation);
  297. }
  298. // Local world
  299. this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
  300. // Parent
  301. if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.Mesh.BILLBOARDMODE_NONE) {
  302. this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
  303. } else {
  304. this._worldMatrix.copyFrom(this._localWorld);
  305. }
  306. // Bounding info
  307. this._updateBoundingInfo();
  308. // Absolute position
  309. this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
  310. return this._worldMatrix;
  311. };
  312. Mesh.prototype._createGlobalSubMesh = function () {
  313. if (!this._totalVertices || !this._indices) {
  314. return null;
  315. }
  316. this.subMeshes = [];
  317. return new BABYLON.SubMesh(0, 0, this._totalVertices, 0, this._indices.length, this);
  318. };
  319. Mesh.prototype.subdivide = function (count) {
  320. if (count < 1) {
  321. return;
  322. }
  323. var subdivisionSize = this._indices.length / count;
  324. var offset = 0;
  325. this.subMeshes = [];
  326. for (var index = 0; index < count; index++) {
  327. BABYLON.SubMesh.CreateFromIndices(0, offset, Math.min(subdivisionSize, this._indices.length - offset), this);
  328. offset += subdivisionSize;
  329. }
  330. };
  331. Mesh.prototype.setVerticesData = function (data, kind, updatable) {
  332. if (!this._vertexBuffers) {
  333. this._vertexBuffers = {};
  334. }
  335. if (this._vertexBuffers[kind]) {
  336. this._vertexBuffers[kind].dispose();
  337. }
  338. this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this, data, kind, updatable);
  339. if (kind === BABYLON.VertexBuffer.PositionKind) {
  340. this._resetPointsArrayCache();
  341. var stride = this._vertexBuffers[kind].getStrideSize();
  342. this._totalVertices = data.length / stride;
  343. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  344. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  345. this._createGlobalSubMesh();
  346. }
  347. };
  348. Mesh.prototype.updateVerticesData = function (kind, data, updateExtends) {
  349. if (this._vertexBuffers[kind]) {
  350. this._vertexBuffers[kind].update(data);
  351. if (kind === BABYLON.VertexBuffer.PositionKind) {
  352. this._resetPointsArrayCache();
  353. if (updateExtends) {
  354. var stride = this._vertexBuffers[kind].getStrideSize();
  355. this._totalVertices = data.length / stride;
  356. var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
  357. this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  358. }
  359. }
  360. }
  361. };
  362. Mesh.prototype.setIndices = function (indices) {
  363. if (this._indexBuffer) {
  364. this.getScene().getEngine()._releaseBuffer(this._indexBuffer);
  365. }
  366. this._indexBuffer = this.getScene().getEngine().createIndexBuffer(indices);
  367. this._indices = indices;
  368. this._createGlobalSubMesh();
  369. };
  370. // ANY
  371. Mesh.prototype.bindAndDraw = function (subMesh, effect, wireframe) {
  372. var engine = this.getScene().getEngine();
  373. // Wireframe
  374. var indexToBind = this._indexBuffer;
  375. var useTriangles = true;
  376. if (wireframe) {
  377. indexToBind = subMesh.getLinesIndexBuffer(this._indices, engine);
  378. useTriangles = false;
  379. }
  380. // VBOs
  381. engine.bindMultiBuffers(this._vertexBuffers, indexToBind, effect);
  382. // Draw order
  383. engine.draw(useTriangles, useTriangles ? subMesh.indexStart : 0, useTriangles ? subMesh.indexCount : subMesh.linesIndexCount);
  384. };
  385. Mesh.prototype.registerBeforeRender = function (func) {
  386. this._onBeforeRenderCallbacks.push(func);
  387. };
  388. Mesh.prototype.unregisterBeforeRender = function (func) {
  389. var index = this._onBeforeRenderCallbacks.indexOf(func);
  390. if (index > -1) {
  391. this._onBeforeRenderCallbacks.splice(index, 1);
  392. }
  393. };
  394. Mesh.prototype.render = function (subMesh) {
  395. if (!this._vertexBuffers || !this._indexBuffer) {
  396. return;
  397. }
  398. for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
  399. this._onBeforeRenderCallbacks[callbackIndex]();
  400. }
  401. // World
  402. var world = this.getWorldMatrix();
  403. // Material
  404. var effectiveMaterial = subMesh.getMaterial();
  405. if (!effectiveMaterial || !effectiveMaterial.isReady(this)) {
  406. return;
  407. }
  408. effectiveMaterial._preBind();
  409. effectiveMaterial.bind(world, this);
  410. // Bind and draw
  411. var engine = this.getScene().getEngine();
  412. this.bindAndDraw(subMesh, effectiveMaterial.getEffect(), engine.forceWireframe || effectiveMaterial.wireframe);
  413. // Unbind
  414. effectiveMaterial.unbind();
  415. };
  416. //ANY
  417. Mesh.prototype.getEmittedParticleSystems = function () {
  418. var results = [];
  419. for (var index = 0; index < this.getScene().particleSystems.length; index++) {
  420. var particleSystem = this.getScene().particleSystems[index];
  421. if (particleSystem.emitter === this) {
  422. results.push(particleSystem);
  423. }
  424. }
  425. return results;
  426. };
  427. //ANY
  428. Mesh.prototype.getHierarchyEmittedParticleSystems = function () {
  429. var results = [];
  430. var descendants = this.getDescendants();
  431. descendants.push(this);
  432. for (var index = 0; index < this.getScene().particleSystems.length; index++) {
  433. var particleSystem = this.getScene().particleSystems[index];
  434. if (descendants.indexOf(particleSystem.emitter) !== -1) {
  435. results.push(particleSystem);
  436. }
  437. }
  438. return results;
  439. };
  440. Mesh.prototype.getChildren = function () {
  441. var results = [];
  442. for (var index = 0; index < this.getScene().meshes.length; index++) {
  443. var mesh = this.getScene().meshes[index];
  444. if (mesh.parent == this) {
  445. results.push(mesh);
  446. }
  447. }
  448. return results;
  449. };
  450. Mesh.prototype.isInFrustum = function (frustumPlanes) {
  451. var _this = this;
  452. if (this.delayLoadState === 2) {
  453. return false;
  454. }
  455. var result = this._boundingInfo.isInFrustum(frustumPlanes);
  456. if (result && this.delayLoadState === 4) {
  457. this.delayLoadState = 2; //ANY BABYLON.Engine.DELAYLOADSTATE_LOADING
  458. this.getScene()._addPendingData(this);
  459. BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
  460. _this._delayLoadingFunction(JSON.parse(data), _this);
  461. _this.delayLoadState = 1; //ANY BABYLON.Engine.DELAYLOADSTATE_LOADED;
  462. _this.getScene()._removePendingData(_this);
  463. }, function () {
  464. }, this.getScene().database);
  465. }
  466. return result;
  467. };
  468. Mesh.prototype.setMaterialByID = function (id) {
  469. var materials = this.getScene().materials;
  470. for (var index = 0; index < materials.length; index++) {
  471. if (materials[index].id == id) {
  472. this.material = materials[index];
  473. return;
  474. }
  475. }
  476. // Multi
  477. var multiMaterials = this.getScene().multiMaterials;
  478. for (index = 0; index < multiMaterials.length; index++) {
  479. if (multiMaterials[index].id == id) {
  480. this.material = multiMaterials[index];
  481. return;
  482. }
  483. }
  484. };
  485. Mesh.prototype.getAnimatables = function () {
  486. var results = [];
  487. if (this.material) {
  488. results.push(this.material);
  489. }
  490. return results;
  491. };
  492. // Geometry
  493. Mesh.prototype.setPositionWithLocalVector = function (vector3) {
  494. this.computeWorldMatrix();
  495. this.position = BABYLON.Vector3.TransformNormal(vector3, this._localWorld);
  496. };
  497. Mesh.prototype.getPositionExpressedInLocalSpace = function () {
  498. this.computeWorldMatrix();
  499. var invLocalWorldMatrix = this._localWorld.clone();
  500. invLocalWorldMatrix.invert();
  501. return BABYLON.Vector3.TransformNormal(this.position, invLocalWorldMatrix);
  502. };
  503. Mesh.prototype.locallyTranslate = function (vector3) {
  504. this.computeWorldMatrix();
  505. this.position = BABYLON.Vector3.TransformCoordinates(vector3, this._localWorld);
  506. };
  507. Mesh.prototype.bakeTransformIntoVertices = function (transform) {
  508. // Position
  509. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
  510. return;
  511. }
  512. this._resetPointsArrayCache();
  513. var data = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].getData();
  514. var temp = [];
  515. for (var index = 0; index < data.length; index += 3) {
  516. BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
  517. }
  518. this.setVerticesData(temp, BABYLON.VertexBuffer.PositionKind, this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].isUpdatable());
  519. // Normals
  520. if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  521. return;
  522. }
  523. data = this._vertexBuffers[BABYLON.VertexBuffer.NormalKind].getData();
  524. for (index = 0; index < data.length; index += 3) {
  525. BABYLON.Vector3.TransformNormal(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
  526. }
  527. this.setVerticesData(temp, BABYLON.VertexBuffer.NormalKind, this._vertexBuffers[BABYLON.VertexBuffer.NormalKind].isUpdatable());
  528. };
  529. Mesh.prototype.lookAt = function (targetPoint, yawCor, pitchCor, rollCor) {
  530. /// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
  531. /// <param name="targetPoint" type="BABYLON.Vector3">The position (must be in same space as current mesh) to look at</param>
  532. /// <param name="yawCor" type="Number">optional yaw (y-axis) correction in radians</param>
  533. /// <param name="pitchCor" type="Number">optional pitch (x-axis) correction in radians</param>
  534. /// <param name="rollCor" type="Number">optional roll (z-axis) correction in radians</param>
  535. /// <returns>Mesh oriented towards targetMesh</returns>
  536. yawCor = yawCor || 0; // default to zero if undefined
  537. pitchCor = pitchCor || 0;
  538. rollCor = rollCor || 0;
  539. var dv = targetPoint.subtract(this.position);
  540. var yaw = -Math.atan2(dv.z, dv.x) - Math.PI / 2;
  541. var len = Math.sqrt(dv.x * dv.x + dv.z * dv.z);
  542. var pitch = Math.atan2(dv.y, len);
  543. this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
  544. };
  545. // Cache
  546. Mesh.prototype._resetPointsArrayCache = function () {
  547. this._positions = null;
  548. };
  549. Mesh.prototype._generatePointsArray = function () {
  550. if (this._positions)
  551. return;
  552. this._positions = [];
  553. var data = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].getData();
  554. for (var index = 0; index < data.length; index += 3) {
  555. this._positions.push(BABYLON.Vector3.FromArray(data, index));
  556. }
  557. };
  558. // Collisions
  559. Mesh.prototype._collideForSubMesh = function (subMesh, transformMatrix, collider) {
  560. this._generatePointsArray();
  561. // Transformation
  562. if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
  563. subMesh._lastColliderTransformMatrix = transformMatrix.clone();
  564. subMesh._lastColliderWorldVertices = [];
  565. subMesh._trianglePlanes = [];
  566. var start = subMesh.verticesStart;
  567. var end = (subMesh.verticesStart + subMesh.verticesCount);
  568. for (var i = start; i < end; i++) {
  569. subMesh._lastColliderWorldVertices.push(BABYLON.Vector3.TransformCoordinates(this._positions[i], transformMatrix));
  570. }
  571. }
  572. // Collide
  573. collider._collide(subMesh, subMesh._lastColliderWorldVertices, this._indices, subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart);
  574. };
  575. Mesh.prototype._processCollisionsForSubModels = function (collider, transformMatrix) {
  576. for (var index = 0; index < this.subMeshes.length; index++) {
  577. var subMesh = this.subMeshes[index];
  578. // Bounding test
  579. if (this.subMeshes.length > 1 && !subMesh._checkCollision(collider))
  580. continue;
  581. this._collideForSubMesh(subMesh, transformMatrix, collider);
  582. }
  583. };
  584. Mesh.prototype._checkCollision = function (collider) {
  585. // Bounding box test
  586. if (!this._boundingInfo._checkCollision(collider))
  587. return;
  588. // Transformation matrix
  589. BABYLON.Matrix.ScalingToRef(1.0 / collider.radius.x, 1.0 / collider.radius.y, 1.0 / collider.radius.z, this._collisionsScalingMatrix);
  590. this._worldMatrix.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
  591. this._processCollisionsForSubModels(collider, this._collisionsTransformMatrix);
  592. };
  593. Mesh.prototype.intersectsMesh = function (mesh, precise) {
  594. if (!this._boundingInfo || !mesh._boundingInfo) {
  595. return false;
  596. }
  597. return this._boundingInfo.intersects(mesh._boundingInfo, precise);
  598. };
  599. Mesh.prototype.intersectsPoint = function (point) {
  600. if (!this._boundingInfo) {
  601. return false;
  602. }
  603. return this._boundingInfo.intersectsPoint(point);
  604. };
  605. // Picking
  606. Mesh.prototype.intersects = function (ray, fastCheck) {
  607. var pickingInfo = new BABYLON.PickingInfo();
  608. if (!this._boundingInfo || !ray.intersectsSphere(this._boundingInfo.boundingSphere) || !ray.intersectsBox(this._boundingInfo.boundingBox)) {
  609. return pickingInfo;
  610. }
  611. this._generatePointsArray();
  612. var intersectInfo = null;
  613. for (var index = 0; index < this.subMeshes.length; index++) {
  614. var subMesh = this.subMeshes[index];
  615. // Bounding test
  616. if (this.subMeshes.length > 1 && !subMesh.canIntersects(ray))
  617. continue;
  618. var currentIntersectInfo = subMesh.intersects(ray, this._positions, this._indices, fastCheck);
  619. if (currentIntersectInfo) {
  620. if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
  621. intersectInfo = currentIntersectInfo;
  622. if (fastCheck) {
  623. break;
  624. }
  625. }
  626. }
  627. }
  628. if (intersectInfo) {
  629. // Get picked point
  630. var world = this.getWorldMatrix();
  631. var worldOrigin = BABYLON.Vector3.TransformCoordinates(ray.origin, world);
  632. var direction = ray.direction.clone();
  633. direction.normalize();
  634. direction = direction.scale(intersectInfo.distance);
  635. var worldDirection = BABYLON.Vector3.TransformNormal(direction, world);
  636. var pickedPoint = worldOrigin.add(worldDirection);
  637. // Return result
  638. pickingInfo.hit = true;
  639. pickingInfo.distance = BABYLON.Vector3.Distance(worldOrigin, pickedPoint);
  640. pickingInfo.pickedPoint = pickedPoint;
  641. pickingInfo.pickedMesh = this;
  642. pickingInfo.bu = intersectInfo.bu;
  643. pickingInfo.bv = intersectInfo.bv;
  644. pickingInfo.faceId = intersectInfo.faceId;
  645. return pickingInfo;
  646. }
  647. return pickingInfo;
  648. };
  649. // Clone
  650. Mesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  651. var result = new BABYLON.Mesh(name, this.getScene());
  652. // Buffers
  653. result._vertexBuffers = this._vertexBuffers;
  654. for (var kind in result._vertexBuffers) {
  655. result._vertexBuffers[kind]._buffer.references++;
  656. }
  657. result._indexBuffer = this._indexBuffer;
  658. this._indexBuffer.references++;
  659. // Deep copy
  660. BABYLON.Tools.DeepCopy(this, result, ["name", "material", "skeleton"], ["_indices", "_totalVertices"]);
  661. // Bounding info
  662. var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this._totalVertices);
  663. result._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
  664. // Material
  665. result.material = this.material;
  666. // Parent
  667. if (newParent) {
  668. result.parent = newParent;
  669. }
  670. if (!doNotCloneChildren) {
  671. for (var index = 0; index < this.getScene().meshes.length; index++) {
  672. var mesh = this.getScene().meshes[index];
  673. if (mesh.parent == this) {
  674. mesh.clone(mesh.name, result);
  675. }
  676. }
  677. }
  678. for (index = 0; index < this.getScene().particleSystems.length; index++) {
  679. var system = this.getScene().particleSystems[index];
  680. if (system.emitter == this) {
  681. system.clone(system.name, result);
  682. }
  683. }
  684. result.computeWorldMatrix(true);
  685. return result;
  686. };
  687. // Dispose
  688. Mesh.prototype.dispose = function (doNotRecurse) {
  689. if (this._vertexBuffers) {
  690. for (var vbKind in this._vertexBuffers) {
  691. this._vertexBuffers[vbKind].dispose();
  692. }
  693. this._vertexBuffers = null;
  694. }
  695. if (this._indexBuffer) {
  696. this.getScene().getEngine()._releaseBuffer(this._indexBuffer);
  697. this._indexBuffer = null;
  698. }
  699. // Physics
  700. if (this.getPhysicsImpostor() != BABYLON.PhysicsEngine.NoImpostor) {
  701. this.setPhysicsState({ impostor: BABYLON.PhysicsEngine.NoImpostor });
  702. }
  703. // Remove from scene
  704. var index = this.getScene().meshes.indexOf(this);
  705. this.getScene().meshes.splice(index, 1);
  706. if (!doNotRecurse) {
  707. for (index = 0; index < this.getScene().particleSystems.length; index++) {
  708. if (this.getScene().particleSystems[index].emitter == this) {
  709. this.getScene().particleSystems[index].dispose();
  710. index--;
  711. }
  712. }
  713. // Children
  714. var objects = this.getScene().meshes.slice(0);
  715. for (index = 0; index < objects.length; index++) {
  716. if (objects[index].parent == this) {
  717. objects[index].dispose();
  718. }
  719. }
  720. } else {
  721. for (index = 0; index < this.getScene().meshes.length; index++) {
  722. var obj = this.getScene().meshes[index];
  723. if (obj.parent === this) {
  724. obj.parent = null;
  725. obj.computeWorldMatrix(true);
  726. }
  727. }
  728. }
  729. this._isDisposed = true;
  730. // Callback
  731. if (this.onDispose) {
  732. this.onDispose();
  733. }
  734. };
  735. // Physics
  736. Mesh.prototype.setPhysicsState = function (options) {
  737. if (!this.getScene()._physicsEngine) {
  738. return;
  739. }
  740. options.impostor = options.impostor || BABYLON.PhysicsEngine.NoImpostor;
  741. options.mass = options.mass || 0;
  742. options.friction = options.friction || 0.2;
  743. options.restitution = options.restitution || 0.9;
  744. this._physicImpostor = options.impostor;
  745. this._physicsMass = options.mass;
  746. this._physicsFriction = options.friction;
  747. this._physicRestitution = options.restitution;
  748. if (options.impostor === BABYLON.PhysicsEngine.NoImpostor) {
  749. this.getScene()._physicsEngine._unregisterMesh(this);
  750. return;
  751. }
  752. this.getScene()._physicsEngine._registerMesh(this, options);
  753. };
  754. Mesh.prototype.getPhysicsImpostor = function () {
  755. if (!this._physicImpostor) {
  756. return BABYLON.PhysicsEngine.NoImpostor;
  757. }
  758. return this._physicImpostor;
  759. };
  760. Mesh.prototype.getPhysicsMass = function () {
  761. if (!this._physicsMass) {
  762. return 0;
  763. }
  764. return this._physicsMass;
  765. };
  766. Mesh.prototype.getPhysicsFriction = function () {
  767. if (!this._physicsFriction) {
  768. return 0;
  769. }
  770. return this._physicsFriction;
  771. };
  772. Mesh.prototype.getPhysicsRestitution = function () {
  773. if (!this._physicRestitution) {
  774. return 0;
  775. }
  776. return this._physicRestitution;
  777. };
  778. Mesh.prototype.applyImpulse = function (force, contactPoint) {
  779. if (!this._physicImpostor) {
  780. return;
  781. }
  782. this.getScene()._physicsEngine._applyImpulse(this, force, contactPoint);
  783. };
  784. Mesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2) {
  785. if (!this._physicImpostor) {
  786. return;
  787. }
  788. this.getScene()._physicsEngine._createLink(this, otherMesh, pivot1, pivot2);
  789. };
  790. // Geometric tools
  791. Mesh.prototype.convertToFlatShadedMesh = function () {
  792. /// <summary>Update normals and vertices to get a flat shading rendering.</summary>
  793. /// <summary>Warning: This may imply adding vertices to the mesh in order to get exactly 3 vertices per face</summary>
  794. var kinds = this.getVerticesDataKinds();
  795. var vbs = [];
  796. var data = [];
  797. var newdata = [];
  798. var updatableNormals = false;
  799. for (var kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  800. var kind = kinds[kindIndex];
  801. if (kind === BABYLON.VertexBuffer.NormalKind) {
  802. updatableNormals = this.getVertexBuffer(kind).isUpdatable();
  803. kinds.splice(kindIndex, 1);
  804. kindIndex--;
  805. continue;
  806. }
  807. vbs[kind] = this.getVertexBuffer(kind);
  808. data[kind] = vbs[kind].getData();
  809. newdata[kind] = [];
  810. }
  811. // Save previous submeshes
  812. var previousSubmeshes = this.subMeshes.slice(0);
  813. var indices = this.getIndices();
  814. for (index = 0; index < indices.length; index++) {
  815. var vertexIndex = indices[index];
  816. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  817. kind = kinds[kindIndex];
  818. var stride = vbs[kind].getStrideSize();
  819. for (var offset = 0; offset < stride; offset++) {
  820. newdata[kind].push(data[kind][vertexIndex * stride + offset]);
  821. }
  822. }
  823. }
  824. // Updating faces & normal
  825. var normals = [];
  826. var positions = newdata[BABYLON.VertexBuffer.PositionKind];
  827. for (var index = 0; index < indices.length; index += 3) {
  828. indices[index] = index;
  829. indices[index + 1] = index + 1;
  830. indices[index + 2] = index + 2;
  831. var p1 = BABYLON.Vector3.FromArray(positions, index * 3);
  832. var p2 = BABYLON.Vector3.FromArray(positions, (index + 1) * 3);
  833. var p3 = BABYLON.Vector3.FromArray(positions, (index + 2) * 3);
  834. var p1p2 = p1.subtract(p2);
  835. var p3p2 = p3.subtract(p2);
  836. var normal = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(p1p2, p3p2));
  837. for (var localIndex = 0; localIndex < 3; localIndex++) {
  838. normals.push(normal.x);
  839. normals.push(normal.y);
  840. normals.push(normal.z);
  841. }
  842. }
  843. this.setIndices(indices);
  844. this.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatableNormals);
  845. for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
  846. kind = kinds[kindIndex];
  847. this.setVerticesData(newdata[kind], kind, vbs[kind].isUpdatable());
  848. }
  849. // Updating submeshes
  850. this.subMeshes = [];
  851. for (var submeshIndex = 0; submeshIndex < previousSubmeshes.length; submeshIndex++) {
  852. var previousOne = previousSubmeshes[submeshIndex];
  853. var subMesh = new BABYLON.SubMesh(previousOne.materialIndex, previousOne.indexStart, previousOne.indexCount, previousOne.indexStart, previousOne.indexCount, this);
  854. }
  855. };
  856. // Statics
  857. //ANY
  858. Mesh.CreateBox = function (name, size, scene, updatable) {
  859. var box = new BABYLON.Mesh(name, scene);
  860. var vertexData = BABYLON.VertexData.CreateBox(size);
  861. vertexData.applyToMesh(box, updatable);
  862. return box;
  863. };
  864. //ANY
  865. Mesh.CreateSphere = function (name, segments, diameter, scene, updatable) {
  866. var sphere = new BABYLON.Mesh(name, scene);
  867. var vertexData = BABYLON.VertexData.CreateSphere(segments, diameter);
  868. vertexData.applyToMesh(sphere, updatable);
  869. return sphere;
  870. };
  871. // Cylinder and cone (Code inspired by SharpDX.org)
  872. //ANY
  873. Mesh.CreateCylinder = function (name, height, diameterTop, diameterBottom, tessellation, scene, updatable) {
  874. var cylinder = new BABYLON.Mesh(name, scene);
  875. var vertexData = BABYLON.VertexData.CreateCylinder(height, diameterTop, diameterBottom, tessellation);
  876. vertexData.applyToMesh(cylinder, updatable);
  877. return cylinder;
  878. };
  879. // Torus (Code from SharpDX.org)
  880. //ANY
  881. Mesh.CreateTorus = function (name, diameter, thickness, tessellation, scene, updatable) {
  882. var torus = new BABYLON.Mesh(name, scene);
  883. var vertexData = BABYLON.VertexData.CreateTorus(diameter, thickness, tessellation);
  884. vertexData.applyToMesh(torus, updatable);
  885. return torus;
  886. };
  887. //ANY
  888. Mesh.CreateTorusKnot = function (name, radius, tube, radialSegments, tubularSegments, p, q, scene, updatable) {
  889. var torusKnot = new BABYLON.Mesh(name, scene);
  890. var vertexData = BABYLON.VertexData.CreateTorusKnot(radius, tube, radialSegments, tubularSegments, p, q);
  891. vertexData.applyToMesh(torusKnot, updatable);
  892. return torusKnot;
  893. };
  894. // Plane & ground
  895. //ANY
  896. Mesh.CreatePlane = function (name, size, scene, updatable) {
  897. var plane = new BABYLON.Mesh(name, scene);
  898. var vertexData = BABYLON.VertexData.CreatePlane(size);
  899. vertexData.applyToMesh(plane, updatable);
  900. return plane;
  901. };
  902. //ANY
  903. Mesh.CreateGround = function (name, width, height, subdivisions, scene, updatable) {
  904. var ground = new BABYLON.Mesh(name, scene);
  905. var vertexData = BABYLON.VertexData.CreateGround(width, height, subdivisions);
  906. vertexData.applyToMesh(ground, updatable);
  907. return ground;
  908. };
  909. //ANY
  910. Mesh.CreateGroundFromHeightMap = function (name, url, width, height, subdivisions, minHeight, maxHeight, scene, updatable) {
  911. var ground = new BABYLON.Mesh(name, scene);
  912. var onload = function (img) {
  913. var indices = [];
  914. var positions = [];
  915. var normals = [];
  916. var uvs = [];
  917. var row, col;
  918. // Getting height map data
  919. var canvas = document.createElement("canvas");
  920. var context = canvas.getContext("2d");
  921. var heightMapWidth = img.width;
  922. var heightMapHeight = img.height;
  923. canvas.width = heightMapWidth;
  924. canvas.height = heightMapHeight;
  925. context.drawImage(img, 0, 0);
  926. var buffer = context.getImageData(0, 0, heightMapWidth, heightMapHeight).data;
  927. for (row = 0; row <= subdivisions; row++) {
  928. for (col = 0; col <= subdivisions; col++) {
  929. var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
  930. // Compute height
  931. var heightMapX = (((position.x + width / 2) / width) * (heightMapWidth - 1)) | 0;
  932. var heightMapY = ((1.0 - (position.z + height / 2) / height) * (heightMapHeight - 1)) | 0;
  933. var pos = (heightMapX + heightMapY * heightMapWidth) * 4;
  934. var r = buffer[pos] / 255.0;
  935. var g = buffer[pos + 1] / 255.0;
  936. var b = buffer[pos + 2] / 255.0;
  937. var gradient = r * 0.3 + g * 0.59 + b * 0.11;
  938. position.y = minHeight + (maxHeight - minHeight) * gradient;
  939. // Add vertex
  940. positions.push(position.x, position.y, position.z);
  941. normals.push(0, 0, 0);
  942. uvs.push(col / subdivisions, 1.0 - row / subdivisions);
  943. }
  944. }
  945. for (row = 0; row < subdivisions; row++) {
  946. for (col = 0; col < subdivisions; col++) {
  947. indices.push(col + 1 + (row + 1) * (subdivisions + 1));
  948. indices.push(col + 1 + row * (subdivisions + 1));
  949. indices.push(col + row * (subdivisions + 1));
  950. indices.push(col + (row + 1) * (subdivisions + 1));
  951. indices.push(col + 1 + (row + 1) * (subdivisions + 1));
  952. indices.push(col + row * (subdivisions + 1));
  953. }
  954. }
  955. // Normals
  956. BABYLON.VertexData.ComputeNormals(positions, indices, normals);
  957. // Transfer
  958. ground.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable);
  959. ground.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable);
  960. ground.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable);
  961. ground.setIndices(indices);
  962. ground._isReady = true;
  963. };
  964. BABYLON.Tools.LoadImage(url, onload, function () {
  965. }, scene.database);
  966. ground._isReady = false;
  967. return ground;
  968. };
  969. // Tools
  970. Mesh.MinMax = function (meshes) {
  971. var minVector;
  972. var maxVector;
  973. for (var i in meshes) {
  974. var mesh = meshes[i];
  975. var boundingBox = mesh.getBoundingInfo().boundingBox;
  976. if (!minVector) {
  977. minVector = boundingBox.minimumWorld;
  978. maxVector = boundingBox.maximumWorld;
  979. continue;
  980. }
  981. minVector.MinimizeInPlace(boundingBox.minimumWorld);
  982. maxVector.MaximizeInPlace(boundingBox.maximumWorld);
  983. }
  984. return {
  985. min: minVector,
  986. max: maxVector
  987. };
  988. };
  989. Mesh.Center = function (meshesOrMinMaxVector) {
  990. var minMaxVector = meshesOrMinMaxVector.min !== undefined ? meshesOrMinMaxVector : BABYLON.Mesh.MinMax(meshesOrMinMaxVector);
  991. return BABYLON.Vector3.Center(minMaxVector.min, minMaxVector.max);
  992. };
  993. Mesh.BILLBOARDMODE_NONE = 0;
  994. Mesh.BILLBOARDMODE_X = 1;
  995. Mesh.BILLBOARDMODE_Y = 2;
  996. Mesh.BILLBOARDMODE_Z = 4;
  997. Mesh.BILLBOARDMODE_ALL = 7;
  998. return Mesh;
  999. })(BABYLON.Node);
  1000. BABYLON.Mesh = Mesh;
  1001. })(BABYLON || (BABYLON = {}));
  1002. //# sourceMappingURL=babylon.mesh.js.map