index.js 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. if(typeof require !== 'undefined'){
  12. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  13. var BABYLON = globalObject["BABYLON"] || {};
  14. var BABYLON0 = require('babylonjs/core');
  15. if(BABYLON !== BABYLON0) __extends(BABYLON, BABYLON0);
  16. var BABYLON;
  17. (function (BABYLON) {
  18. var Bone = /** @class */ (function (_super) {
  19. __extends(Bone, _super);
  20. function Bone(name, skeleton, parentBone, localMatrix, restPose, baseMatrix, index) {
  21. if (parentBone === void 0) { parentBone = null; }
  22. if (localMatrix === void 0) { localMatrix = null; }
  23. if (restPose === void 0) { restPose = null; }
  24. if (baseMatrix === void 0) { baseMatrix = null; }
  25. if (index === void 0) { index = null; }
  26. var _this = _super.call(this, name, skeleton.getScene()) || this;
  27. _this.name = name;
  28. _this.children = new Array();
  29. _this.animations = new Array();
  30. // Set this value to map this bone to a different index in the transform matrices.
  31. // Set this value to -1 to exclude the bone from the transform matrices.
  32. _this._index = null;
  33. _this._worldTransform = new BABYLON.Matrix();
  34. _this._absoluteTransform = new BABYLON.Matrix();
  35. _this._invertedAbsoluteTransform = new BABYLON.Matrix();
  36. _this._scaleMatrix = BABYLON.Matrix.Identity();
  37. _this._scaleVector = BABYLON.Vector3.One();
  38. _this._negateScaleChildren = BABYLON.Vector3.One();
  39. _this._scalingDeterminant = 1;
  40. _this._skeleton = skeleton;
  41. _this._localMatrix = localMatrix ? localMatrix : BABYLON.Matrix.Identity();
  42. _this._restPose = restPose ? restPose : _this._localMatrix.clone();
  43. _this._baseMatrix = baseMatrix ? baseMatrix : _this._localMatrix.clone();
  44. _this._index = index;
  45. skeleton.bones.push(_this);
  46. _this.setParent(parentBone, false);
  47. _this._updateDifferenceMatrix();
  48. return _this;
  49. }
  50. Object.defineProperty(Bone.prototype, "_matrix", {
  51. get: function () {
  52. return this._localMatrix;
  53. },
  54. set: function (val) {
  55. if (this._localMatrix) {
  56. this._localMatrix.copyFrom(val);
  57. }
  58. else {
  59. this._localMatrix = val;
  60. }
  61. },
  62. enumerable: true,
  63. configurable: true
  64. });
  65. // Members
  66. Bone.prototype.getSkeleton = function () {
  67. return this._skeleton;
  68. };
  69. Bone.prototype.getParent = function () {
  70. return this._parent;
  71. };
  72. Bone.prototype.setParent = function (parent, updateDifferenceMatrix) {
  73. if (updateDifferenceMatrix === void 0) { updateDifferenceMatrix = true; }
  74. if (this._parent === parent) {
  75. return;
  76. }
  77. if (this._parent) {
  78. var index = this._parent.children.indexOf(this);
  79. if (index !== -1) {
  80. this._parent.children.splice(index, 1);
  81. }
  82. }
  83. this._parent = parent;
  84. if (this._parent) {
  85. this._parent.children.push(this);
  86. }
  87. if (updateDifferenceMatrix) {
  88. this._updateDifferenceMatrix();
  89. }
  90. };
  91. Bone.prototype.getLocalMatrix = function () {
  92. return this._localMatrix;
  93. };
  94. Bone.prototype.getBaseMatrix = function () {
  95. return this._baseMatrix;
  96. };
  97. Bone.prototype.getRestPose = function () {
  98. return this._restPose;
  99. };
  100. Bone.prototype.returnToRest = function () {
  101. this.updateMatrix(this._restPose.clone());
  102. };
  103. Bone.prototype.getWorldMatrix = function () {
  104. return this._worldTransform;
  105. };
  106. Bone.prototype.getInvertedAbsoluteTransform = function () {
  107. return this._invertedAbsoluteTransform;
  108. };
  109. Bone.prototype.getAbsoluteTransform = function () {
  110. return this._absoluteTransform;
  111. };
  112. Object.defineProperty(Bone.prototype, "position", {
  113. // Properties (matches AbstractMesh properties)
  114. get: function () {
  115. return this.getPosition();
  116. },
  117. set: function (newPosition) {
  118. this.setPosition(newPosition);
  119. },
  120. enumerable: true,
  121. configurable: true
  122. });
  123. Object.defineProperty(Bone.prototype, "rotation", {
  124. get: function () {
  125. return this.getRotation();
  126. },
  127. set: function (newRotation) {
  128. this.setRotation(newRotation);
  129. },
  130. enumerable: true,
  131. configurable: true
  132. });
  133. Object.defineProperty(Bone.prototype, "rotationQuaternion", {
  134. get: function () {
  135. return this.getRotationQuaternion();
  136. },
  137. set: function (newRotation) {
  138. this.setRotationQuaternion(newRotation);
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(Bone.prototype, "scaling", {
  144. get: function () {
  145. return this.getScale();
  146. },
  147. set: function (newScaling) {
  148. this.setScale(newScaling.x, newScaling.y, newScaling.z);
  149. },
  150. enumerable: true,
  151. configurable: true
  152. });
  153. // Methods
  154. Bone.prototype.updateMatrix = function (matrix, updateDifferenceMatrix) {
  155. if (updateDifferenceMatrix === void 0) { updateDifferenceMatrix = true; }
  156. this._baseMatrix = matrix.clone();
  157. this._localMatrix = matrix.clone();
  158. this._skeleton._markAsDirty();
  159. if (updateDifferenceMatrix) {
  160. this._updateDifferenceMatrix();
  161. }
  162. };
  163. Bone.prototype._updateDifferenceMatrix = function (rootMatrix) {
  164. if (!rootMatrix) {
  165. rootMatrix = this._baseMatrix;
  166. }
  167. if (this._parent) {
  168. rootMatrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
  169. }
  170. else {
  171. this._absoluteTransform.copyFrom(rootMatrix);
  172. }
  173. this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);
  174. for (var index = 0; index < this.children.length; index++) {
  175. this.children[index]._updateDifferenceMatrix();
  176. }
  177. this._scalingDeterminant = (this._absoluteTransform.determinant() < 0 ? -1 : 1);
  178. };
  179. Bone.prototype.markAsDirty = function () {
  180. this._currentRenderId++;
  181. this._skeleton._markAsDirty();
  182. };
  183. Bone.prototype.copyAnimationRange = function (source, rangeName, frameOffset, rescaleAsRequired, skelDimensionsRatio) {
  184. if (rescaleAsRequired === void 0) { rescaleAsRequired = false; }
  185. if (skelDimensionsRatio === void 0) { skelDimensionsRatio = null; }
  186. // all animation may be coming from a library skeleton, so may need to create animation
  187. if (this.animations.length === 0) {
  188. this.animations.push(new BABYLON.Animation(this.name, "_matrix", source.animations[0].framePerSecond, BABYLON.Animation.ANIMATIONTYPE_MATRIX, 0));
  189. this.animations[0].setKeys([]);
  190. }
  191. // get animation info / verify there is such a range from the source bone
  192. var sourceRange = source.animations[0].getRange(rangeName);
  193. if (!sourceRange) {
  194. return false;
  195. }
  196. var from = sourceRange.from;
  197. var to = sourceRange.to;
  198. var sourceKeys = source.animations[0].getKeys();
  199. // rescaling prep
  200. var sourceBoneLength = source.length;
  201. var sourceParent = source.getParent();
  202. var parent = this.getParent();
  203. var parentScalingReqd = rescaleAsRequired && sourceParent && sourceBoneLength && this.length && sourceBoneLength !== this.length;
  204. var parentRatio = parentScalingReqd && parent && sourceParent ? parent.length / sourceParent.length : 1;
  205. var dimensionsScalingReqd = rescaleAsRequired && !parent && skelDimensionsRatio && (skelDimensionsRatio.x !== 1 || skelDimensionsRatio.y !== 1 || skelDimensionsRatio.z !== 1);
  206. var destKeys = this.animations[0].getKeys();
  207. // loop vars declaration
  208. var orig;
  209. var origTranslation;
  210. var mat;
  211. for (var key = 0, nKeys = sourceKeys.length; key < nKeys; key++) {
  212. orig = sourceKeys[key];
  213. if (orig.frame >= from && orig.frame <= to) {
  214. if (rescaleAsRequired) {
  215. mat = orig.value.clone();
  216. // scale based on parent ratio, when bone has parent
  217. if (parentScalingReqd) {
  218. origTranslation = mat.getTranslation();
  219. mat.setTranslation(origTranslation.scaleInPlace(parentRatio));
  220. // scale based on skeleton dimension ratio when root bone, and value is passed
  221. }
  222. else if (dimensionsScalingReqd && skelDimensionsRatio) {
  223. origTranslation = mat.getTranslation();
  224. mat.setTranslation(origTranslation.multiplyInPlace(skelDimensionsRatio));
  225. // use original when root bone, and no data for skelDimensionsRatio
  226. }
  227. else {
  228. mat = orig.value;
  229. }
  230. }
  231. else {
  232. mat = orig.value;
  233. }
  234. destKeys.push({ frame: orig.frame + frameOffset, value: mat });
  235. }
  236. }
  237. this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
  238. return true;
  239. };
  240. /**
  241. * Translate the bone in local or world space.
  242. * @param vec The amount to translate the bone.
  243. * @param space The space that the translation is in.
  244. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  245. */
  246. Bone.prototype.translate = function (vec, space, mesh) {
  247. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  248. var lm = this.getLocalMatrix();
  249. if (space == BABYLON.Space.LOCAL) {
  250. lm.m[12] += vec.x;
  251. lm.m[13] += vec.y;
  252. lm.m[14] += vec.z;
  253. }
  254. else {
  255. var wm = null;
  256. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  257. if (mesh) {
  258. wm = mesh.getWorldMatrix();
  259. }
  260. this._skeleton.computeAbsoluteTransforms();
  261. var tmat = Bone._tmpMats[0];
  262. var tvec = Bone._tmpVecs[0];
  263. if (this._parent) {
  264. if (mesh && wm) {
  265. tmat.copyFrom(this._parent.getAbsoluteTransform());
  266. tmat.multiplyToRef(wm, tmat);
  267. }
  268. else {
  269. tmat.copyFrom(this._parent.getAbsoluteTransform());
  270. }
  271. }
  272. tmat.m[12] = 0;
  273. tmat.m[13] = 0;
  274. tmat.m[14] = 0;
  275. tmat.invert();
  276. BABYLON.Vector3.TransformCoordinatesToRef(vec, tmat, tvec);
  277. lm.m[12] += tvec.x;
  278. lm.m[13] += tvec.y;
  279. lm.m[14] += tvec.z;
  280. }
  281. this.markAsDirty();
  282. };
  283. /**
  284. * Set the postion of the bone in local or world space.
  285. * @param position The position to set the bone.
  286. * @param space The space that the position is in.
  287. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  288. */
  289. Bone.prototype.setPosition = function (position, space, mesh) {
  290. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  291. var lm = this.getLocalMatrix();
  292. if (space == BABYLON.Space.LOCAL) {
  293. lm.m[12] = position.x;
  294. lm.m[13] = position.y;
  295. lm.m[14] = position.z;
  296. }
  297. else {
  298. var wm = null;
  299. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  300. if (mesh) {
  301. wm = mesh.getWorldMatrix();
  302. }
  303. this._skeleton.computeAbsoluteTransforms();
  304. var tmat = Bone._tmpMats[0];
  305. var vec = Bone._tmpVecs[0];
  306. if (this._parent) {
  307. if (mesh && wm) {
  308. tmat.copyFrom(this._parent.getAbsoluteTransform());
  309. tmat.multiplyToRef(wm, tmat);
  310. }
  311. else {
  312. tmat.copyFrom(this._parent.getAbsoluteTransform());
  313. }
  314. }
  315. tmat.invert();
  316. BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, vec);
  317. lm.m[12] = vec.x;
  318. lm.m[13] = vec.y;
  319. lm.m[14] = vec.z;
  320. }
  321. this.markAsDirty();
  322. };
  323. /**
  324. * Set the absolute postion of the bone (world space).
  325. * @param position The position to set the bone.
  326. * @param mesh The mesh that this bone is attached to.
  327. */
  328. Bone.prototype.setAbsolutePosition = function (position, mesh) {
  329. this.setPosition(position, BABYLON.Space.WORLD, mesh);
  330. };
  331. /**
  332. * Set the scale of the bone on the x, y and z axes.
  333. * @param x The scale of the bone on the x axis.
  334. * @param x The scale of the bone on the y axis.
  335. * @param z The scale of the bone on the z axis.
  336. * @param scaleChildren Set this to true if children of the bone should be scaled.
  337. */
  338. Bone.prototype.setScale = function (x, y, z, scaleChildren) {
  339. if (scaleChildren === void 0) { scaleChildren = false; }
  340. if (this.animations[0] && !this.animations[0].hasRunningRuntimeAnimations) {
  341. if (!scaleChildren) {
  342. this._negateScaleChildren.x = 1 / x;
  343. this._negateScaleChildren.y = 1 / y;
  344. this._negateScaleChildren.z = 1 / z;
  345. }
  346. this._syncScaleVector();
  347. }
  348. this.scale(x / this._scaleVector.x, y / this._scaleVector.y, z / this._scaleVector.z, scaleChildren);
  349. };
  350. /**
  351. * Scale the bone on the x, y and z axes.
  352. * @param x The amount to scale the bone on the x axis.
  353. * @param x The amount to scale the bone on the y axis.
  354. * @param z The amount to scale the bone on the z axis.
  355. * @param scaleChildren Set this to true if children of the bone should be scaled.
  356. */
  357. Bone.prototype.scale = function (x, y, z, scaleChildren) {
  358. if (scaleChildren === void 0) { scaleChildren = false; }
  359. var locMat = this.getLocalMatrix();
  360. var origLocMat = Bone._tmpMats[0];
  361. origLocMat.copyFrom(locMat);
  362. var origLocMatInv = Bone._tmpMats[1];
  363. origLocMatInv.copyFrom(origLocMat);
  364. origLocMatInv.invert();
  365. var scaleMat = Bone._tmpMats[2];
  366. BABYLON.Matrix.FromValuesToRef(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1, scaleMat);
  367. this._scaleMatrix.multiplyToRef(scaleMat, this._scaleMatrix);
  368. this._scaleVector.x *= x;
  369. this._scaleVector.y *= y;
  370. this._scaleVector.z *= z;
  371. locMat.multiplyToRef(origLocMatInv, locMat);
  372. locMat.multiplyToRef(scaleMat, locMat);
  373. locMat.multiplyToRef(origLocMat, locMat);
  374. var parent = this.getParent();
  375. if (parent) {
  376. locMat.multiplyToRef(parent.getAbsoluteTransform(), this.getAbsoluteTransform());
  377. }
  378. else {
  379. this.getAbsoluteTransform().copyFrom(locMat);
  380. }
  381. var len = this.children.length;
  382. scaleMat.invert();
  383. for (var i = 0; i < len; i++) {
  384. var child = this.children[i];
  385. var cm = child.getLocalMatrix();
  386. cm.multiplyToRef(scaleMat, cm);
  387. var lm = child.getLocalMatrix();
  388. lm.m[12] *= x;
  389. lm.m[13] *= y;
  390. lm.m[14] *= z;
  391. }
  392. this.computeAbsoluteTransforms();
  393. if (scaleChildren) {
  394. for (var i = 0; i < len; i++) {
  395. this.children[i].scale(x, y, z, scaleChildren);
  396. }
  397. }
  398. this.markAsDirty();
  399. };
  400. /**
  401. * Set the yaw, pitch, and roll of the bone in local or world space.
  402. * @param yaw The rotation of the bone on the y axis.
  403. * @param pitch The rotation of the bone on the x axis.
  404. * @param roll The rotation of the bone on the z axis.
  405. * @param space The space that the axes of rotation are in.
  406. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  407. */
  408. Bone.prototype.setYawPitchRoll = function (yaw, pitch, roll, space, mesh) {
  409. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  410. var rotMat = Bone._tmpMats[0];
  411. BABYLON.Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
  412. var rotMatInv = Bone._tmpMats[1];
  413. this._getNegativeRotationToRef(rotMatInv, space, mesh);
  414. rotMatInv.multiplyToRef(rotMat, rotMat);
  415. this._rotateWithMatrix(rotMat, space, mesh);
  416. };
  417. /**
  418. * Rotate the bone on an axis in local or world space.
  419. * @param axis The axis to rotate the bone on.
  420. * @param amount The amount to rotate the bone.
  421. * @param space The space that the axis is in.
  422. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  423. */
  424. Bone.prototype.rotate = function (axis, amount, space, mesh) {
  425. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  426. var rmat = Bone._tmpMats[0];
  427. rmat.m[12] = 0;
  428. rmat.m[13] = 0;
  429. rmat.m[14] = 0;
  430. BABYLON.Matrix.RotationAxisToRef(axis, amount, rmat);
  431. this._rotateWithMatrix(rmat, space, mesh);
  432. };
  433. /**
  434. * Set the rotation of the bone to a particular axis angle in local or world space.
  435. * @param axis The axis to rotate the bone on.
  436. * @param angle The angle that the bone should be rotated to.
  437. * @param space The space that the axis is in.
  438. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  439. */
  440. Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
  441. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  442. var rotMat = Bone._tmpMats[0];
  443. BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
  444. var rotMatInv = Bone._tmpMats[1];
  445. this._getNegativeRotationToRef(rotMatInv, space, mesh);
  446. rotMatInv.multiplyToRef(rotMat, rotMat);
  447. this._rotateWithMatrix(rotMat, space, mesh);
  448. };
  449. /**
  450. * Set the euler rotation of the bone in local of world space.
  451. * @param rotation The euler rotation that the bone should be set to.
  452. * @param space The space that the rotation is in.
  453. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  454. */
  455. Bone.prototype.setRotation = function (rotation, space, mesh) {
  456. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  457. this.setYawPitchRoll(rotation.y, rotation.x, rotation.z, space, mesh);
  458. };
  459. /**
  460. * Set the quaternion rotation of the bone in local of world space.
  461. * @param quat The quaternion rotation that the bone should be set to.
  462. * @param space The space that the rotation is in.
  463. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  464. */
  465. Bone.prototype.setRotationQuaternion = function (quat, space, mesh) {
  466. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  467. var rotMatInv = Bone._tmpMats[0];
  468. this._getNegativeRotationToRef(rotMatInv, space, mesh);
  469. var rotMat = Bone._tmpMats[1];
  470. BABYLON.Matrix.FromQuaternionToRef(quat, rotMat);
  471. rotMatInv.multiplyToRef(rotMat, rotMat);
  472. this._rotateWithMatrix(rotMat, space, mesh);
  473. };
  474. /**
  475. * Set the rotation matrix of the bone in local of world space.
  476. * @param rotMat The rotation matrix that the bone should be set to.
  477. * @param space The space that the rotation is in.
  478. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  479. */
  480. Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
  481. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  482. var rotMatInv = Bone._tmpMats[0];
  483. this._getNegativeRotationToRef(rotMatInv, space, mesh);
  484. var rotMat2 = Bone._tmpMats[1];
  485. rotMat2.copyFrom(rotMat);
  486. rotMatInv.multiplyToRef(rotMat, rotMat2);
  487. this._rotateWithMatrix(rotMat2, space, mesh);
  488. };
  489. Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
  490. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  491. var lmat = this.getLocalMatrix();
  492. var lx = lmat.m[12];
  493. var ly = lmat.m[13];
  494. var lz = lmat.m[14];
  495. var parent = this.getParent();
  496. var parentScale = Bone._tmpMats[3];
  497. var parentScaleInv = Bone._tmpMats[4];
  498. if (parent) {
  499. if (space == BABYLON.Space.WORLD) {
  500. if (mesh) {
  501. parentScale.copyFrom(mesh.getWorldMatrix());
  502. parent.getAbsoluteTransform().multiplyToRef(parentScale, parentScale);
  503. }
  504. else {
  505. parentScale.copyFrom(parent.getAbsoluteTransform());
  506. }
  507. }
  508. else {
  509. parentScale = parent._scaleMatrix;
  510. }
  511. parentScaleInv.copyFrom(parentScale);
  512. parentScaleInv.invert();
  513. lmat.multiplyToRef(parentScale, lmat);
  514. lmat.multiplyToRef(rmat, lmat);
  515. lmat.multiplyToRef(parentScaleInv, lmat);
  516. }
  517. else {
  518. if (space == BABYLON.Space.WORLD && mesh) {
  519. parentScale.copyFrom(mesh.getWorldMatrix());
  520. parentScaleInv.copyFrom(parentScale);
  521. parentScaleInv.invert();
  522. lmat.multiplyToRef(parentScale, lmat);
  523. lmat.multiplyToRef(rmat, lmat);
  524. lmat.multiplyToRef(parentScaleInv, lmat);
  525. }
  526. else {
  527. lmat.multiplyToRef(rmat, lmat);
  528. }
  529. }
  530. lmat.m[12] = lx;
  531. lmat.m[13] = ly;
  532. lmat.m[14] = lz;
  533. this.computeAbsoluteTransforms();
  534. this.markAsDirty();
  535. };
  536. Bone.prototype._getNegativeRotationToRef = function (rotMatInv, space, mesh) {
  537. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  538. if (space == BABYLON.Space.WORLD) {
  539. var scaleMatrix = Bone._tmpMats[2];
  540. scaleMatrix.copyFrom(this._scaleMatrix);
  541. rotMatInv.copyFrom(this.getAbsoluteTransform());
  542. if (mesh) {
  543. rotMatInv.multiplyToRef(mesh.getWorldMatrix(), rotMatInv);
  544. var meshScale = Bone._tmpMats[3];
  545. BABYLON.Matrix.ScalingToRef(mesh.scaling.x, mesh.scaling.y, mesh.scaling.z, meshScale);
  546. scaleMatrix.multiplyToRef(meshScale, scaleMatrix);
  547. }
  548. rotMatInv.invert();
  549. scaleMatrix.m[0] *= this._scalingDeterminant;
  550. rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
  551. }
  552. else {
  553. rotMatInv.copyFrom(this.getLocalMatrix());
  554. rotMatInv.invert();
  555. var scaleMatrix = Bone._tmpMats[2];
  556. scaleMatrix.copyFrom(this._scaleMatrix);
  557. if (this._parent) {
  558. var pscaleMatrix = Bone._tmpMats[3];
  559. pscaleMatrix.copyFrom(this._parent._scaleMatrix);
  560. pscaleMatrix.invert();
  561. pscaleMatrix.multiplyToRef(rotMatInv, rotMatInv);
  562. }
  563. else {
  564. scaleMatrix.m[0] *= this._scalingDeterminant;
  565. }
  566. rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
  567. }
  568. };
  569. /**
  570. * Get the scale of the bone
  571. * @returns the scale of the bone
  572. */
  573. Bone.prototype.getScale = function () {
  574. return this._scaleVector.clone();
  575. };
  576. /**
  577. * Copy the scale of the bone to a vector3.
  578. * @param result The vector3 to copy the scale to
  579. */
  580. Bone.prototype.getScaleToRef = function (result) {
  581. result.copyFrom(this._scaleVector);
  582. };
  583. /**
  584. * Get the position of the bone in local or world space.
  585. * @param space The space that the returned position is in.
  586. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  587. * @returns The position of the bone
  588. */
  589. Bone.prototype.getPosition = function (space, mesh) {
  590. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  591. if (mesh === void 0) { mesh = null; }
  592. var pos = BABYLON.Vector3.Zero();
  593. this.getPositionToRef(space, mesh, pos);
  594. return pos;
  595. };
  596. /**
  597. * Copy the position of the bone to a vector3 in local or world space.
  598. * @param space The space that the returned position is in.
  599. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  600. * @param result The vector3 to copy the position to.
  601. */
  602. Bone.prototype.getPositionToRef = function (space, mesh, result) {
  603. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  604. if (space == BABYLON.Space.LOCAL) {
  605. var lm = this.getLocalMatrix();
  606. result.x = lm.m[12];
  607. result.y = lm.m[13];
  608. result.z = lm.m[14];
  609. }
  610. else {
  611. var wm = null;
  612. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  613. if (mesh) {
  614. wm = mesh.getWorldMatrix();
  615. }
  616. this._skeleton.computeAbsoluteTransforms();
  617. var tmat = Bone._tmpMats[0];
  618. if (mesh && wm) {
  619. tmat.copyFrom(this.getAbsoluteTransform());
  620. tmat.multiplyToRef(wm, tmat);
  621. }
  622. else {
  623. tmat = this.getAbsoluteTransform();
  624. }
  625. result.x = tmat.m[12];
  626. result.y = tmat.m[13];
  627. result.z = tmat.m[14];
  628. }
  629. };
  630. /**
  631. * Get the absolute position of the bone (world space).
  632. * @param mesh The mesh that this bone is attached to.
  633. * @returns The absolute position of the bone
  634. */
  635. Bone.prototype.getAbsolutePosition = function (mesh) {
  636. if (mesh === void 0) { mesh = null; }
  637. var pos = BABYLON.Vector3.Zero();
  638. this.getPositionToRef(BABYLON.Space.WORLD, mesh, pos);
  639. return pos;
  640. };
  641. /**
  642. * Copy the absolute position of the bone (world space) to the result param.
  643. * @param mesh The mesh that this bone is attached to.
  644. * @param result The vector3 to copy the absolute position to.
  645. */
  646. Bone.prototype.getAbsolutePositionToRef = function (mesh, result) {
  647. this.getPositionToRef(BABYLON.Space.WORLD, mesh, result);
  648. };
  649. /**
  650. * Compute the absolute transforms of this bone and its children.
  651. */
  652. Bone.prototype.computeAbsoluteTransforms = function () {
  653. if (this._parent) {
  654. this._localMatrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
  655. }
  656. else {
  657. this._absoluteTransform.copyFrom(this._localMatrix);
  658. var poseMatrix = this._skeleton.getPoseMatrix();
  659. if (poseMatrix) {
  660. this._absoluteTransform.multiplyToRef(poseMatrix, this._absoluteTransform);
  661. }
  662. }
  663. var children = this.children;
  664. var len = children.length;
  665. for (var i = 0; i < len; i++) {
  666. children[i].computeAbsoluteTransforms();
  667. }
  668. };
  669. Bone.prototype._syncScaleVector = function () {
  670. var lm = this.getLocalMatrix();
  671. var xsq = (lm.m[0] * lm.m[0] + lm.m[1] * lm.m[1] + lm.m[2] * lm.m[2]);
  672. var ysq = (lm.m[4] * lm.m[4] + lm.m[5] * lm.m[5] + lm.m[6] * lm.m[6]);
  673. var zsq = (lm.m[8] * lm.m[8] + lm.m[9] * lm.m[9] + lm.m[10] * lm.m[10]);
  674. var xs = lm.m[0] * lm.m[1] * lm.m[2] * lm.m[3] < 0 ? -1 : 1;
  675. var ys = lm.m[4] * lm.m[5] * lm.m[6] * lm.m[7] < 0 ? -1 : 1;
  676. var zs = lm.m[8] * lm.m[9] * lm.m[10] * lm.m[11] < 0 ? -1 : 1;
  677. this._scaleVector.x = xs * Math.sqrt(xsq);
  678. this._scaleVector.y = ys * Math.sqrt(ysq);
  679. this._scaleVector.z = zs * Math.sqrt(zsq);
  680. if (this._parent) {
  681. this._scaleVector.x /= this._parent._negateScaleChildren.x;
  682. this._scaleVector.y /= this._parent._negateScaleChildren.y;
  683. this._scaleVector.z /= this._parent._negateScaleChildren.z;
  684. }
  685. BABYLON.Matrix.FromValuesToRef(this._scaleVector.x, 0, 0, 0, 0, this._scaleVector.y, 0, 0, 0, 0, this._scaleVector.z, 0, 0, 0, 0, 1, this._scaleMatrix);
  686. };
  687. /**
  688. * Get the world direction from an axis that is in the local space of the bone.
  689. * @param localAxis The local direction that is used to compute the world direction.
  690. * @param mesh The mesh that this bone is attached to.
  691. * @returns The world direction
  692. */
  693. Bone.prototype.getDirection = function (localAxis, mesh) {
  694. if (mesh === void 0) { mesh = null; }
  695. var result = BABYLON.Vector3.Zero();
  696. this.getDirectionToRef(localAxis, mesh, result);
  697. return result;
  698. };
  699. /**
  700. * Copy the world direction to a vector3 from an axis that is in the local space of the bone.
  701. * @param localAxis The local direction that is used to compute the world direction.
  702. * @param mesh The mesh that this bone is attached to.
  703. * @param result The vector3 that the world direction will be copied to.
  704. */
  705. Bone.prototype.getDirectionToRef = function (localAxis, mesh, result) {
  706. if (mesh === void 0) { mesh = null; }
  707. var wm = null;
  708. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  709. if (mesh) {
  710. wm = mesh.getWorldMatrix();
  711. }
  712. this._skeleton.computeAbsoluteTransforms();
  713. var mat = Bone._tmpMats[0];
  714. mat.copyFrom(this.getAbsoluteTransform());
  715. if (mesh && wm) {
  716. mat.multiplyToRef(wm, mat);
  717. }
  718. BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
  719. result.normalize();
  720. };
  721. /**
  722. * Get the euler rotation of the bone in local or world space.
  723. * @param space The space that the rotation should be in.
  724. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  725. * @returns The euler rotation
  726. */
  727. Bone.prototype.getRotation = function (space, mesh) {
  728. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  729. if (mesh === void 0) { mesh = null; }
  730. var result = BABYLON.Vector3.Zero();
  731. this.getRotationToRef(space, mesh, result);
  732. return result;
  733. };
  734. /**
  735. * Copy the euler rotation of the bone to a vector3. The rotation can be in either local or world space.
  736. * @param space The space that the rotation should be in.
  737. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  738. * @param result The vector3 that the rotation should be copied to.
  739. */
  740. Bone.prototype.getRotationToRef = function (space, mesh, result) {
  741. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  742. if (mesh === void 0) { mesh = null; }
  743. var quat = Bone._tmpQuat;
  744. this.getRotationQuaternionToRef(space, mesh, quat);
  745. quat.toEulerAnglesToRef(result);
  746. };
  747. /**
  748. * Get the quaternion rotation of the bone in either local or world space.
  749. * @param space The space that the rotation should be in.
  750. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  751. * @returns The quaternion rotation
  752. */
  753. Bone.prototype.getRotationQuaternion = function (space, mesh) {
  754. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  755. if (mesh === void 0) { mesh = null; }
  756. var result = BABYLON.Quaternion.Identity();
  757. this.getRotationQuaternionToRef(space, mesh, result);
  758. return result;
  759. };
  760. /**
  761. * Copy the quaternion rotation of the bone to a quaternion. The rotation can be in either local or world space.
  762. * @param space The space that the rotation should be in.
  763. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  764. * @param result The quaternion that the rotation should be copied to.
  765. */
  766. Bone.prototype.getRotationQuaternionToRef = function (space, mesh, result) {
  767. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  768. if (mesh === void 0) { mesh = null; }
  769. if (space == BABYLON.Space.LOCAL) {
  770. this.getLocalMatrix().decompose(Bone._tmpVecs[0], result, Bone._tmpVecs[1]);
  771. }
  772. else {
  773. var mat = Bone._tmpMats[0];
  774. var amat = this.getAbsoluteTransform();
  775. if (mesh) {
  776. amat.multiplyToRef(mesh.getWorldMatrix(), mat);
  777. }
  778. else {
  779. mat.copyFrom(amat);
  780. }
  781. mat.m[0] *= this._scalingDeterminant;
  782. mat.m[1] *= this._scalingDeterminant;
  783. mat.m[2] *= this._scalingDeterminant;
  784. mat.decompose(Bone._tmpVecs[0], result, Bone._tmpVecs[1]);
  785. }
  786. };
  787. /**
  788. * Get the rotation matrix of the bone in local or world space.
  789. * @param space The space that the rotation should be in.
  790. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  791. * @returns The rotation matrix
  792. */
  793. Bone.prototype.getRotationMatrix = function (space, mesh) {
  794. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  795. var result = BABYLON.Matrix.Identity();
  796. this.getRotationMatrixToRef(space, mesh, result);
  797. return result;
  798. };
  799. /**
  800. * Copy the rotation matrix of the bone to a matrix. The rotation can be in either local or world space.
  801. * @param space The space that the rotation should be in.
  802. * @param mesh The mesh that this bone is attached to. This is only used in world space.
  803. * @param result The quaternion that the rotation should be copied to.
  804. */
  805. Bone.prototype.getRotationMatrixToRef = function (space, mesh, result) {
  806. if (space === void 0) { space = BABYLON.Space.LOCAL; }
  807. if (space == BABYLON.Space.LOCAL) {
  808. this.getLocalMatrix().getRotationMatrixToRef(result);
  809. }
  810. else {
  811. var mat = Bone._tmpMats[0];
  812. var amat = this.getAbsoluteTransform();
  813. if (mesh) {
  814. amat.multiplyToRef(mesh.getWorldMatrix(), mat);
  815. }
  816. else {
  817. mat.copyFrom(amat);
  818. }
  819. mat.m[0] *= this._scalingDeterminant;
  820. mat.m[1] *= this._scalingDeterminant;
  821. mat.m[2] *= this._scalingDeterminant;
  822. mat.getRotationMatrixToRef(result);
  823. }
  824. };
  825. /**
  826. * Get the world position of a point that is in the local space of the bone.
  827. * @param position The local position
  828. * @param mesh The mesh that this bone is attached to.
  829. * @returns The world position
  830. */
  831. Bone.prototype.getAbsolutePositionFromLocal = function (position, mesh) {
  832. if (mesh === void 0) { mesh = null; }
  833. var result = BABYLON.Vector3.Zero();
  834. this.getAbsolutePositionFromLocalToRef(position, mesh, result);
  835. return result;
  836. };
  837. /**
  838. * Get the world position of a point that is in the local space of the bone and copy it to the result param.
  839. * @param position The local position
  840. * @param mesh The mesh that this bone is attached to.
  841. * @param result The vector3 that the world position should be copied to.
  842. */
  843. Bone.prototype.getAbsolutePositionFromLocalToRef = function (position, mesh, result) {
  844. if (mesh === void 0) { mesh = null; }
  845. var wm = null;
  846. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  847. if (mesh) {
  848. wm = mesh.getWorldMatrix();
  849. }
  850. this._skeleton.computeAbsoluteTransforms();
  851. var tmat = Bone._tmpMats[0];
  852. if (mesh && wm) {
  853. tmat.copyFrom(this.getAbsoluteTransform());
  854. tmat.multiplyToRef(wm, tmat);
  855. }
  856. else {
  857. tmat = this.getAbsoluteTransform();
  858. }
  859. BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, result);
  860. };
  861. /**
  862. * Get the local position of a point that is in world space.
  863. * @param position The world position
  864. * @param mesh The mesh that this bone is attached to.
  865. * @returns The local position
  866. */
  867. Bone.prototype.getLocalPositionFromAbsolute = function (position, mesh) {
  868. if (mesh === void 0) { mesh = null; }
  869. var result = BABYLON.Vector3.Zero();
  870. this.getLocalPositionFromAbsoluteToRef(position, mesh, result);
  871. return result;
  872. };
  873. /**
  874. * Get the local position of a point that is in world space and copy it to the result param.
  875. * @param position The world position
  876. * @param mesh The mesh that this bone is attached to.
  877. * @param result The vector3 that the local position should be copied to.
  878. */
  879. Bone.prototype.getLocalPositionFromAbsoluteToRef = function (position, mesh, result) {
  880. if (mesh === void 0) { mesh = null; }
  881. var wm = null;
  882. //mesh.getWorldMatrix() needs to be called before skeleton.computeAbsoluteTransforms()
  883. if (mesh) {
  884. wm = mesh.getWorldMatrix();
  885. }
  886. this._skeleton.computeAbsoluteTransforms();
  887. var tmat = Bone._tmpMats[0];
  888. tmat.copyFrom(this.getAbsoluteTransform());
  889. if (mesh && wm) {
  890. tmat.multiplyToRef(wm, tmat);
  891. }
  892. tmat.invert();
  893. BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, result);
  894. };
  895. Bone._tmpVecs = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
  896. Bone._tmpQuat = BABYLON.Quaternion.Identity();
  897. Bone._tmpMats = [BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity()];
  898. return Bone;
  899. }(BABYLON.Node));
  900. BABYLON.Bone = Bone;
  901. })(BABYLON || (BABYLON = {}));
  902. //# sourceMappingURL=babylon.bone.js.map
  903. var BABYLON;
  904. (function (BABYLON) {
  905. var BoneIKController = /** @class */ (function () {
  906. function BoneIKController(mesh, bone, options) {
  907. this.targetPosition = BABYLON.Vector3.Zero();
  908. this.poleTargetPosition = BABYLON.Vector3.Zero();
  909. this.poleTargetLocalOffset = BABYLON.Vector3.Zero();
  910. this.poleAngle = 0;
  911. this.slerpAmount = 1;
  912. this._bone1Quat = BABYLON.Quaternion.Identity();
  913. this._bone1Mat = BABYLON.Matrix.Identity();
  914. this._bone2Ang = Math.PI;
  915. this._maxAngle = Math.PI;
  916. this._rightHandedSystem = false;
  917. this._bendAxis = BABYLON.Vector3.Right();
  918. this._slerping = false;
  919. this._adjustRoll = 0;
  920. this._bone2 = bone;
  921. this._bone1 = bone.getParent();
  922. if (!this._bone1) {
  923. return;
  924. }
  925. this.mesh = mesh;
  926. var bonePos = bone.getPosition();
  927. if (bone.getAbsoluteTransform().determinant() > 0) {
  928. this._rightHandedSystem = true;
  929. this._bendAxis.x = 0;
  930. this._bendAxis.y = 0;
  931. this._bendAxis.z = -1;
  932. if (bonePos.x > bonePos.y && bonePos.x > bonePos.z) {
  933. this._adjustRoll = Math.PI * .5;
  934. this._bendAxis.z = 1;
  935. }
  936. }
  937. if (this._bone1.length) {
  938. var boneScale1 = this._bone1.getScale();
  939. var boneScale2 = this._bone2.getScale();
  940. this._bone1Length = this._bone1.length * boneScale1.y * this.mesh.scaling.y;
  941. this._bone2Length = this._bone2.length * boneScale2.y * this.mesh.scaling.y;
  942. }
  943. else if (this._bone1.children[0]) {
  944. mesh.computeWorldMatrix(true);
  945. var pos1 = this._bone2.children[0].getAbsolutePosition(mesh);
  946. var pos2 = this._bone2.getAbsolutePosition(mesh);
  947. var pos3 = this._bone1.getAbsolutePosition(mesh);
  948. this._bone1Length = BABYLON.Vector3.Distance(pos1, pos2);
  949. this._bone2Length = BABYLON.Vector3.Distance(pos2, pos3);
  950. }
  951. this._bone1.getRotationMatrixToRef(BABYLON.Space.WORLD, mesh, this._bone1Mat);
  952. this.maxAngle = Math.PI;
  953. if (options) {
  954. if (options.targetMesh) {
  955. this.targetMesh = options.targetMesh;
  956. this.targetMesh.computeWorldMatrix(true);
  957. }
  958. if (options.poleTargetMesh) {
  959. this.poleTargetMesh = options.poleTargetMesh;
  960. this.poleTargetMesh.computeWorldMatrix(true);
  961. }
  962. else if (options.poleTargetBone) {
  963. this.poleTargetBone = options.poleTargetBone;
  964. }
  965. else if (this._bone1.getParent()) {
  966. this.poleTargetBone = this._bone1.getParent();
  967. }
  968. if (options.poleTargetLocalOffset) {
  969. this.poleTargetLocalOffset.copyFrom(options.poleTargetLocalOffset);
  970. }
  971. if (options.poleAngle) {
  972. this.poleAngle = options.poleAngle;
  973. }
  974. if (options.bendAxis) {
  975. this._bendAxis.copyFrom(options.bendAxis);
  976. }
  977. if (options.maxAngle) {
  978. this.maxAngle = options.maxAngle;
  979. }
  980. if (options.slerpAmount) {
  981. this.slerpAmount = options.slerpAmount;
  982. }
  983. }
  984. }
  985. Object.defineProperty(BoneIKController.prototype, "maxAngle", {
  986. get: function () {
  987. return this._maxAngle;
  988. },
  989. set: function (value) {
  990. this._setMaxAngle(value);
  991. },
  992. enumerable: true,
  993. configurable: true
  994. });
  995. BoneIKController.prototype._setMaxAngle = function (ang) {
  996. if (ang < 0) {
  997. ang = 0;
  998. }
  999. if (ang > Math.PI || ang == undefined) {
  1000. ang = Math.PI;
  1001. }
  1002. this._maxAngle = ang;
  1003. var a = this._bone1Length;
  1004. var b = this._bone2Length;
  1005. this._maxReach = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(ang));
  1006. };
  1007. BoneIKController.prototype.update = function () {
  1008. var bone1 = this._bone1;
  1009. if (!bone1) {
  1010. return;
  1011. }
  1012. var target = this.targetPosition;
  1013. var poleTarget = this.poleTargetPosition;
  1014. var mat1 = BoneIKController._tmpMats[0];
  1015. var mat2 = BoneIKController._tmpMats[1];
  1016. if (this.targetMesh) {
  1017. target.copyFrom(this.targetMesh.getAbsolutePosition());
  1018. }
  1019. if (this.poleTargetBone) {
  1020. this.poleTargetBone.getAbsolutePositionFromLocalToRef(this.poleTargetLocalOffset, this.mesh, poleTarget);
  1021. }
  1022. else if (this.poleTargetMesh) {
  1023. BABYLON.Vector3.TransformCoordinatesToRef(this.poleTargetLocalOffset, this.poleTargetMesh.getWorldMatrix(), poleTarget);
  1024. }
  1025. var bonePos = BoneIKController._tmpVecs[0];
  1026. var zaxis = BoneIKController._tmpVecs[1];
  1027. var xaxis = BoneIKController._tmpVecs[2];
  1028. var yaxis = BoneIKController._tmpVecs[3];
  1029. var upAxis = BoneIKController._tmpVecs[4];
  1030. var _tmpQuat = BoneIKController._tmpQuat;
  1031. bone1.getAbsolutePositionToRef(this.mesh, bonePos);
  1032. poleTarget.subtractToRef(bonePos, upAxis);
  1033. if (upAxis.x == 0 && upAxis.y == 0 && upAxis.z == 0) {
  1034. upAxis.y = 1;
  1035. }
  1036. else {
  1037. upAxis.normalize();
  1038. }
  1039. target.subtractToRef(bonePos, yaxis);
  1040. yaxis.normalize();
  1041. BABYLON.Vector3.CrossToRef(yaxis, upAxis, zaxis);
  1042. zaxis.normalize();
  1043. BABYLON.Vector3.CrossToRef(yaxis, zaxis, xaxis);
  1044. xaxis.normalize();
  1045. BABYLON.Matrix.FromXYZAxesToRef(xaxis, yaxis, zaxis, mat1);
  1046. var a = this._bone1Length;
  1047. var b = this._bone2Length;
  1048. var c = BABYLON.Vector3.Distance(bonePos, target);
  1049. if (this._maxReach > 0) {
  1050. c = Math.min(this._maxReach, c);
  1051. }
  1052. var acosa = (b * b + c * c - a * a) / (2 * b * c);
  1053. var acosb = (c * c + a * a - b * b) / (2 * c * a);
  1054. if (acosa > 1) {
  1055. acosa = 1;
  1056. }
  1057. if (acosb > 1) {
  1058. acosb = 1;
  1059. }
  1060. if (acosa < -1) {
  1061. acosa = -1;
  1062. }
  1063. if (acosb < -1) {
  1064. acosb = -1;
  1065. }
  1066. var angA = Math.acos(acosa);
  1067. var angB = Math.acos(acosb);
  1068. var angC = -angA - angB;
  1069. if (this._rightHandedSystem) {
  1070. BABYLON.Matrix.RotationYawPitchRollToRef(0, 0, this._adjustRoll, mat2);
  1071. mat2.multiplyToRef(mat1, mat1);
  1072. BABYLON.Matrix.RotationAxisToRef(this._bendAxis, angB, mat2);
  1073. mat2.multiplyToRef(mat1, mat1);
  1074. }
  1075. else {
  1076. var _tmpVec = BoneIKController._tmpVecs[5];
  1077. _tmpVec.copyFrom(this._bendAxis);
  1078. _tmpVec.x *= -1;
  1079. BABYLON.Matrix.RotationAxisToRef(_tmpVec, -angB, mat2);
  1080. mat2.multiplyToRef(mat1, mat1);
  1081. }
  1082. if (this.poleAngle) {
  1083. BABYLON.Matrix.RotationAxisToRef(yaxis, this.poleAngle, mat2);
  1084. mat1.multiplyToRef(mat2, mat1);
  1085. }
  1086. if (this._bone1) {
  1087. if (this.slerpAmount < 1) {
  1088. if (!this._slerping) {
  1089. BABYLON.Quaternion.FromRotationMatrixToRef(this._bone1Mat, this._bone1Quat);
  1090. }
  1091. BABYLON.Quaternion.FromRotationMatrixToRef(mat1, _tmpQuat);
  1092. BABYLON.Quaternion.SlerpToRef(this._bone1Quat, _tmpQuat, this.slerpAmount, this._bone1Quat);
  1093. angC = this._bone2Ang * (1.0 - this.slerpAmount) + angC * this.slerpAmount;
  1094. this._bone1.setRotationQuaternion(this._bone1Quat, BABYLON.Space.WORLD, this.mesh);
  1095. this._slerping = true;
  1096. }
  1097. else {
  1098. this._bone1.setRotationMatrix(mat1, BABYLON.Space.WORLD, this.mesh);
  1099. this._bone1Mat.copyFrom(mat1);
  1100. this._slerping = false;
  1101. }
  1102. }
  1103. this._bone2.setAxisAngle(this._bendAxis, angC, BABYLON.Space.LOCAL);
  1104. this._bone2Ang = angC;
  1105. };
  1106. BoneIKController._tmpVecs = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
  1107. BoneIKController._tmpQuat = BABYLON.Quaternion.Identity();
  1108. BoneIKController._tmpMats = [BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity()];
  1109. return BoneIKController;
  1110. }());
  1111. BABYLON.BoneIKController = BoneIKController;
  1112. })(BABYLON || (BABYLON = {}));
  1113. //# sourceMappingURL=babylon.boneIKController.js.map
  1114. BABYLON.Effect.ShadersStore['defaultVertexShader'] = "#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}";
  1115. BABYLON.Effect.ShadersStore['defaultPixelShader'] = "#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}";
  1116. var BABYLON;
  1117. (function (BABYLON) {
  1118. var BoneLookController = /** @class */ (function () {
  1119. /**
  1120. * Create a BoneLookController
  1121. * @param mesh the mesh that the bone belongs to
  1122. * @param bone the bone that will be looking to the target
  1123. * @param target the target Vector3 to look at
  1124. * @param settings optional settings:
  1125. * - maxYaw: the maximum angle the bone will yaw to
  1126. * - minYaw: the minimum angle the bone will yaw to
  1127. * - maxPitch: the maximum angle the bone will pitch to
  1128. * - minPitch: the minimum angle the bone will yaw to
  1129. * - slerpAmount: set the between 0 and 1 to make the bone slerp to the target.
  1130. * - upAxis: the up axis of the coordinate system
  1131. * - upAxisSpace: the space that the up axis is in - BABYLON.Space.BONE, BABYLON.Space.LOCAL (default), or BABYLON.Space.WORLD.
  1132. * - yawAxis: set yawAxis if the bone does not yaw on the y axis
  1133. * - pitchAxis: set pitchAxis if the bone does not pitch on the x axis
  1134. * - adjustYaw: used to make an adjustment to the yaw of the bone
  1135. * - adjustPitch: used to make an adjustment to the pitch of the bone
  1136. * - adjustRoll: used to make an adjustment to the roll of the bone
  1137. **/
  1138. function BoneLookController(mesh, bone, target, options) {
  1139. /**
  1140. * The up axis of the coordinate system that is used when the bone is rotated.
  1141. */
  1142. this.upAxis = BABYLON.Vector3.Up();
  1143. /**
  1144. * The space that the up axis is in - BABYLON.Space.BONE, BABYLON.Space.LOCAL (default), or BABYLON.Space.WORLD.
  1145. */
  1146. this.upAxisSpace = BABYLON.Space.LOCAL;
  1147. /**
  1148. * Used to make an adjustment to the yaw of the bone.
  1149. */
  1150. this.adjustYaw = 0;
  1151. /**
  1152. * Used to make an adjustment to the pitch of the bone.
  1153. */
  1154. this.adjustPitch = 0;
  1155. /**
  1156. * Used to make an adjustment to the roll of the bone.
  1157. */
  1158. this.adjustRoll = 0;
  1159. /**
  1160. * The amount to slerp (spherical linear interpolation) to the target. Set this to a value between 0 and 1 (a value of 1 disables slerp).
  1161. */
  1162. this.slerpAmount = 1;
  1163. this._boneQuat = BABYLON.Quaternion.Identity();
  1164. this._slerping = false;
  1165. this._firstFrameSkipped = false;
  1166. this._fowardAxis = BABYLON.Vector3.Forward();
  1167. this.mesh = mesh;
  1168. this.bone = bone;
  1169. this.target = target;
  1170. if (options) {
  1171. if (options.adjustYaw) {
  1172. this.adjustYaw = options.adjustYaw;
  1173. }
  1174. if (options.adjustPitch) {
  1175. this.adjustPitch = options.adjustPitch;
  1176. }
  1177. if (options.adjustRoll) {
  1178. this.adjustRoll = options.adjustRoll;
  1179. }
  1180. if (options.maxYaw != null) {
  1181. this.maxYaw = options.maxYaw;
  1182. }
  1183. else {
  1184. this.maxYaw = Math.PI;
  1185. }
  1186. if (options.minYaw != null) {
  1187. this.minYaw = options.minYaw;
  1188. }
  1189. else {
  1190. this.minYaw = -Math.PI;
  1191. }
  1192. if (options.maxPitch != null) {
  1193. this.maxPitch = options.maxPitch;
  1194. }
  1195. else {
  1196. this.maxPitch = Math.PI;
  1197. }
  1198. if (options.minPitch != null) {
  1199. this.minPitch = options.minPitch;
  1200. }
  1201. else {
  1202. this.minPitch = -Math.PI;
  1203. }
  1204. if (options.slerpAmount != null) {
  1205. this.slerpAmount = options.slerpAmount;
  1206. }
  1207. if (options.upAxis != null) {
  1208. this.upAxis = options.upAxis;
  1209. }
  1210. if (options.upAxisSpace != null) {
  1211. this.upAxisSpace = options.upAxisSpace;
  1212. }
  1213. if (options.yawAxis != null || options.pitchAxis != null) {
  1214. var newYawAxis = BABYLON.Axis.Y;
  1215. var newPitchAxis = BABYLON.Axis.X;
  1216. if (options.yawAxis != null) {
  1217. newYawAxis = options.yawAxis.clone();
  1218. newYawAxis.normalize();
  1219. }
  1220. if (options.pitchAxis != null) {
  1221. newPitchAxis = options.pitchAxis.clone();
  1222. newPitchAxis.normalize();
  1223. }
  1224. var newRollAxis = BABYLON.Vector3.Cross(newPitchAxis, newYawAxis);
  1225. this._transformYawPitch = BABYLON.Matrix.Identity();
  1226. BABYLON.Matrix.FromXYZAxesToRef(newPitchAxis, newYawAxis, newRollAxis, this._transformYawPitch);
  1227. this._transformYawPitchInv = this._transformYawPitch.clone();
  1228. this._transformYawPitch.invert();
  1229. }
  1230. }
  1231. if (!bone.getParent() && this.upAxisSpace == BABYLON.Space.BONE) {
  1232. this.upAxisSpace = BABYLON.Space.LOCAL;
  1233. }
  1234. }
  1235. Object.defineProperty(BoneLookController.prototype, "minYaw", {
  1236. /**
  1237. * Get/set the minimum yaw angle that the bone can look to.
  1238. */
  1239. get: function () {
  1240. return this._minYaw;
  1241. },
  1242. set: function (value) {
  1243. this._minYaw = value;
  1244. this._minYawSin = Math.sin(value);
  1245. this._minYawCos = Math.cos(value);
  1246. if (this._maxYaw != null) {
  1247. this._midYawConstraint = this._getAngleDiff(this._minYaw, this._maxYaw) * .5 + this._minYaw;
  1248. this._yawRange = this._maxYaw - this._minYaw;
  1249. }
  1250. },
  1251. enumerable: true,
  1252. configurable: true
  1253. });
  1254. Object.defineProperty(BoneLookController.prototype, "maxYaw", {
  1255. /**
  1256. * Get/set the maximum yaw angle that the bone can look to.
  1257. */
  1258. get: function () {
  1259. return this._maxYaw;
  1260. },
  1261. set: function (value) {
  1262. this._maxYaw = value;
  1263. this._maxYawSin = Math.sin(value);
  1264. this._maxYawCos = Math.cos(value);
  1265. if (this._minYaw != null) {
  1266. this._midYawConstraint = this._getAngleDiff(this._minYaw, this._maxYaw) * .5 + this._minYaw;
  1267. this._yawRange = this._maxYaw - this._minYaw;
  1268. }
  1269. },
  1270. enumerable: true,
  1271. configurable: true
  1272. });
  1273. Object.defineProperty(BoneLookController.prototype, "minPitch", {
  1274. /**
  1275. * Get/set the minimum pitch angle that the bone can look to.
  1276. */
  1277. get: function () {
  1278. return this._minPitch;
  1279. },
  1280. set: function (value) {
  1281. this._minPitch = value;
  1282. this._minPitchTan = Math.tan(value);
  1283. },
  1284. enumerable: true,
  1285. configurable: true
  1286. });
  1287. Object.defineProperty(BoneLookController.prototype, "maxPitch", {
  1288. /**
  1289. * Get/set the maximum pitch angle that the bone can look to.
  1290. */
  1291. get: function () {
  1292. return this._maxPitch;
  1293. },
  1294. set: function (value) {
  1295. this._maxPitch = value;
  1296. this._maxPitchTan = Math.tan(value);
  1297. },
  1298. enumerable: true,
  1299. configurable: true
  1300. });
  1301. /**
  1302. * Update the bone to look at the target. This should be called before the scene is rendered (use scene.registerBeforeRender()).
  1303. */
  1304. BoneLookController.prototype.update = function () {
  1305. //skip the first frame when slerping so that the mesh rotation is correct
  1306. if (this.slerpAmount < 1 && !this._firstFrameSkipped) {
  1307. this._firstFrameSkipped = true;
  1308. return;
  1309. }
  1310. var bone = this.bone;
  1311. var bonePos = BoneLookController._tmpVecs[0];
  1312. bone.getAbsolutePositionToRef(this.mesh, bonePos);
  1313. var target = this.target;
  1314. var _tmpMat1 = BoneLookController._tmpMats[0];
  1315. var _tmpMat2 = BoneLookController._tmpMats[1];
  1316. var mesh = this.mesh;
  1317. var parentBone = bone.getParent();
  1318. var upAxis = BoneLookController._tmpVecs[1];
  1319. upAxis.copyFrom(this.upAxis);
  1320. if (this.upAxisSpace == BABYLON.Space.BONE && parentBone) {
  1321. if (this._transformYawPitch) {
  1322. BABYLON.Vector3.TransformCoordinatesToRef(upAxis, this._transformYawPitchInv, upAxis);
  1323. }
  1324. parentBone.getDirectionToRef(upAxis, this.mesh, upAxis);
  1325. }
  1326. else if (this.upAxisSpace == BABYLON.Space.LOCAL) {
  1327. mesh.getDirectionToRef(upAxis, upAxis);
  1328. if (mesh.scaling.x != 1 || mesh.scaling.y != 1 || mesh.scaling.z != 1) {
  1329. upAxis.normalize();
  1330. }
  1331. }
  1332. var checkYaw = false;
  1333. var checkPitch = false;
  1334. if (this._maxYaw != Math.PI || this._minYaw != -Math.PI) {
  1335. checkYaw = true;
  1336. }
  1337. if (this._maxPitch != Math.PI || this._minPitch != -Math.PI) {
  1338. checkPitch = true;
  1339. }
  1340. if (checkYaw || checkPitch) {
  1341. var spaceMat = BoneLookController._tmpMats[2];
  1342. var spaceMatInv = BoneLookController._tmpMats[3];
  1343. if (this.upAxisSpace == BABYLON.Space.BONE && upAxis.y == 1 && parentBone) {
  1344. parentBone.getRotationMatrixToRef(BABYLON.Space.WORLD, this.mesh, spaceMat);
  1345. }
  1346. else if (this.upAxisSpace == BABYLON.Space.LOCAL && upAxis.y == 1 && !parentBone) {
  1347. spaceMat.copyFrom(mesh.getWorldMatrix());
  1348. }
  1349. else {
  1350. var forwardAxis = BoneLookController._tmpVecs[2];
  1351. forwardAxis.copyFrom(this._fowardAxis);
  1352. if (this._transformYawPitch) {
  1353. BABYLON.Vector3.TransformCoordinatesToRef(forwardAxis, this._transformYawPitchInv, forwardAxis);
  1354. }
  1355. if (parentBone) {
  1356. parentBone.getDirectionToRef(forwardAxis, this.mesh, forwardAxis);
  1357. }
  1358. else {
  1359. mesh.getDirectionToRef(forwardAxis, forwardAxis);
  1360. }
  1361. var rightAxis = BABYLON.Vector3.Cross(upAxis, forwardAxis);
  1362. rightAxis.normalize();
  1363. var forwardAxis = BABYLON.Vector3.Cross(rightAxis, upAxis);
  1364. BABYLON.Matrix.FromXYZAxesToRef(rightAxis, upAxis, forwardAxis, spaceMat);
  1365. }
  1366. spaceMat.invertToRef(spaceMatInv);
  1367. var xzlen = null;
  1368. if (checkPitch) {
  1369. var localTarget = BoneLookController._tmpVecs[3];
  1370. target.subtractToRef(bonePos, localTarget);
  1371. BABYLON.Vector3.TransformCoordinatesToRef(localTarget, spaceMatInv, localTarget);
  1372. xzlen = Math.sqrt(localTarget.x * localTarget.x + localTarget.z * localTarget.z);
  1373. var pitch = Math.atan2(localTarget.y, xzlen);
  1374. var newPitch = pitch;
  1375. if (pitch > this._maxPitch) {
  1376. localTarget.y = this._maxPitchTan * xzlen;
  1377. newPitch = this._maxPitch;
  1378. }
  1379. else if (pitch < this._minPitch) {
  1380. localTarget.y = this._minPitchTan * xzlen;
  1381. newPitch = this._minPitch;
  1382. }
  1383. if (pitch != newPitch) {
  1384. BABYLON.Vector3.TransformCoordinatesToRef(localTarget, spaceMat, localTarget);
  1385. localTarget.addInPlace(bonePos);
  1386. target = localTarget;
  1387. }
  1388. }
  1389. if (checkYaw) {
  1390. var localTarget = BoneLookController._tmpVecs[4];
  1391. target.subtractToRef(bonePos, localTarget);
  1392. BABYLON.Vector3.TransformCoordinatesToRef(localTarget, spaceMatInv, localTarget);
  1393. var yaw = Math.atan2(localTarget.x, localTarget.z);
  1394. var newYaw = yaw;
  1395. if (yaw > this._maxYaw || yaw < this._minYaw) {
  1396. if (xzlen == null) {
  1397. xzlen = Math.sqrt(localTarget.x * localTarget.x + localTarget.z * localTarget.z);
  1398. }
  1399. if (this._yawRange > Math.PI) {
  1400. if (this._isAngleBetween(yaw, this._maxYaw, this._midYawConstraint)) {
  1401. localTarget.z = this._maxYawCos * xzlen;
  1402. localTarget.x = this._maxYawSin * xzlen;
  1403. newYaw = this._maxYaw;
  1404. }
  1405. else if (this._isAngleBetween(yaw, this._midYawConstraint, this._minYaw)) {
  1406. localTarget.z = this._minYawCos * xzlen;
  1407. localTarget.x = this._minYawSin * xzlen;
  1408. newYaw = this._minYaw;
  1409. }
  1410. }
  1411. else {
  1412. if (yaw > this._maxYaw) {
  1413. localTarget.z = this._maxYawCos * xzlen;
  1414. localTarget.x = this._maxYawSin * xzlen;
  1415. newYaw = this._maxYaw;
  1416. }
  1417. else if (yaw < this._minYaw) {
  1418. localTarget.z = this._minYawCos * xzlen;
  1419. localTarget.x = this._minYawSin * xzlen;
  1420. newYaw = this._minYaw;
  1421. }
  1422. }
  1423. }
  1424. if (this._slerping && this._yawRange > Math.PI) {
  1425. //are we going to be crossing into the min/max region?
  1426. var boneFwd = BoneLookController._tmpVecs[8];
  1427. boneFwd.copyFrom(BABYLON.Axis.Z);
  1428. if (this._transformYawPitch) {
  1429. BABYLON.Vector3.TransformCoordinatesToRef(boneFwd, this._transformYawPitchInv, boneFwd);
  1430. }
  1431. var boneRotMat = BoneLookController._tmpMats[4];
  1432. this._boneQuat.toRotationMatrix(boneRotMat);
  1433. this.mesh.getWorldMatrix().multiplyToRef(boneRotMat, boneRotMat);
  1434. BABYLON.Vector3.TransformCoordinatesToRef(boneFwd, boneRotMat, boneFwd);
  1435. BABYLON.Vector3.TransformCoordinatesToRef(boneFwd, spaceMatInv, boneFwd);
  1436. var boneYaw = Math.atan2(boneFwd.x, boneFwd.z);
  1437. var angBtwTar = this._getAngleBetween(boneYaw, yaw);
  1438. var angBtwMidYaw = this._getAngleBetween(boneYaw, this._midYawConstraint);
  1439. if (angBtwTar > angBtwMidYaw) {
  1440. if (xzlen == null) {
  1441. xzlen = Math.sqrt(localTarget.x * localTarget.x + localTarget.z * localTarget.z);
  1442. }
  1443. var angBtwMax = this._getAngleBetween(boneYaw, this._maxYaw);
  1444. var angBtwMin = this._getAngleBetween(boneYaw, this._minYaw);
  1445. if (angBtwMin < angBtwMax) {
  1446. newYaw = boneYaw + Math.PI * .75;
  1447. localTarget.z = Math.cos(newYaw) * xzlen;
  1448. localTarget.x = Math.sin(newYaw) * xzlen;
  1449. }
  1450. else {
  1451. newYaw = boneYaw - Math.PI * .75;
  1452. localTarget.z = Math.cos(newYaw) * xzlen;
  1453. localTarget.x = Math.sin(newYaw) * xzlen;
  1454. }
  1455. }
  1456. }
  1457. if (yaw != newYaw) {
  1458. BABYLON.Vector3.TransformCoordinatesToRef(localTarget, spaceMat, localTarget);
  1459. localTarget.addInPlace(bonePos);
  1460. target = localTarget;
  1461. }
  1462. }
  1463. }
  1464. var zaxis = BoneLookController._tmpVecs[5];
  1465. var xaxis = BoneLookController._tmpVecs[6];
  1466. var yaxis = BoneLookController._tmpVecs[7];
  1467. var _tmpQuat = BoneLookController._tmpQuat;
  1468. target.subtractToRef(bonePos, zaxis);
  1469. zaxis.normalize();
  1470. BABYLON.Vector3.CrossToRef(upAxis, zaxis, xaxis);
  1471. xaxis.normalize();
  1472. BABYLON.Vector3.CrossToRef(zaxis, xaxis, yaxis);
  1473. yaxis.normalize();
  1474. BABYLON.Matrix.FromXYZAxesToRef(xaxis, yaxis, zaxis, _tmpMat1);
  1475. if (xaxis.x === 0 && xaxis.y === 0 && xaxis.z === 0) {
  1476. return;
  1477. }
  1478. if (yaxis.x === 0 && yaxis.y === 0 && yaxis.z === 0) {
  1479. return;
  1480. }
  1481. if (zaxis.x === 0 && zaxis.y === 0 && zaxis.z === 0) {
  1482. return;
  1483. }
  1484. if (this.adjustYaw || this.adjustPitch || this.adjustRoll) {
  1485. BABYLON.Matrix.RotationYawPitchRollToRef(this.adjustYaw, this.adjustPitch, this.adjustRoll, _tmpMat2);
  1486. _tmpMat2.multiplyToRef(_tmpMat1, _tmpMat1);
  1487. }
  1488. if (this.slerpAmount < 1) {
  1489. if (!this._slerping) {
  1490. this.bone.getRotationQuaternionToRef(BABYLON.Space.WORLD, this.mesh, this._boneQuat);
  1491. }
  1492. if (this._transformYawPitch) {
  1493. this._transformYawPitch.multiplyToRef(_tmpMat1, _tmpMat1);
  1494. }
  1495. BABYLON.Quaternion.FromRotationMatrixToRef(_tmpMat1, _tmpQuat);
  1496. BABYLON.Quaternion.SlerpToRef(this._boneQuat, _tmpQuat, this.slerpAmount, this._boneQuat);
  1497. this.bone.setRotationQuaternion(this._boneQuat, BABYLON.Space.WORLD, this.mesh);
  1498. this._slerping = true;
  1499. }
  1500. else {
  1501. if (this._transformYawPitch) {
  1502. this._transformYawPitch.multiplyToRef(_tmpMat1, _tmpMat1);
  1503. }
  1504. this.bone.setRotationMatrix(_tmpMat1, BABYLON.Space.WORLD, this.mesh);
  1505. this._slerping = false;
  1506. }
  1507. };
  1508. BoneLookController.prototype._getAngleDiff = function (ang1, ang2) {
  1509. var angDiff = ang2 - ang1;
  1510. angDiff %= Math.PI * 2;
  1511. if (angDiff > Math.PI) {
  1512. angDiff -= Math.PI * 2;
  1513. }
  1514. else if (angDiff < -Math.PI) {
  1515. angDiff += Math.PI * 2;
  1516. }
  1517. return angDiff;
  1518. };
  1519. BoneLookController.prototype._getAngleBetween = function (ang1, ang2) {
  1520. ang1 %= (2 * Math.PI);
  1521. ang1 = (ang1 < 0) ? ang1 + (2 * Math.PI) : ang1;
  1522. ang2 %= (2 * Math.PI);
  1523. ang2 = (ang2 < 0) ? ang2 + (2 * Math.PI) : ang2;
  1524. var ab = 0;
  1525. if (ang1 < ang2) {
  1526. ab = ang2 - ang1;
  1527. }
  1528. else {
  1529. ab = ang1 - ang2;
  1530. }
  1531. if (ab > Math.PI) {
  1532. ab = Math.PI * 2 - ab;
  1533. }
  1534. return ab;
  1535. };
  1536. BoneLookController.prototype._isAngleBetween = function (ang, ang1, ang2) {
  1537. ang %= (2 * Math.PI);
  1538. ang = (ang < 0) ? ang + (2 * Math.PI) : ang;
  1539. ang1 %= (2 * Math.PI);
  1540. ang1 = (ang1 < 0) ? ang1 + (2 * Math.PI) : ang1;
  1541. ang2 %= (2 * Math.PI);
  1542. ang2 = (ang2 < 0) ? ang2 + (2 * Math.PI) : ang2;
  1543. if (ang1 < ang2) {
  1544. if (ang > ang1 && ang < ang2) {
  1545. return true;
  1546. }
  1547. }
  1548. else {
  1549. if (ang > ang2 && ang < ang1) {
  1550. return true;
  1551. }
  1552. }
  1553. return false;
  1554. };
  1555. BoneLookController._tmpVecs = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
  1556. BoneLookController._tmpQuat = BABYLON.Quaternion.Identity();
  1557. BoneLookController._tmpMats = [BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity(), BABYLON.Matrix.Identity()];
  1558. return BoneLookController;
  1559. }());
  1560. BABYLON.BoneLookController = BoneLookController;
  1561. })(BABYLON || (BABYLON = {}));
  1562. //# sourceMappingURL=babylon.boneLookController.js.map
  1563. var BABYLON;
  1564. (function (BABYLON) {
  1565. var Skeleton = /** @class */ (function () {
  1566. function Skeleton(name, id, scene) {
  1567. this.name = name;
  1568. this.id = id;
  1569. this.bones = new Array();
  1570. this.needInitialSkinMatrix = false;
  1571. this._isDirty = true;
  1572. this._meshesWithPoseMatrix = new Array();
  1573. this._identity = BABYLON.Matrix.Identity();
  1574. this._ranges = {};
  1575. this._lastAbsoluteTransformsUpdateId = -1;
  1576. // Events
  1577. /**
  1578. * An event triggered before computing the skeleton's matrices
  1579. * @type {BABYLON.Observable}
  1580. */
  1581. this.onBeforeComputeObservable = new BABYLON.Observable();
  1582. this.bones = [];
  1583. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  1584. scene.skeletons.push(this);
  1585. //make sure it will recalculate the matrix next time prepare is called.
  1586. this._isDirty = true;
  1587. }
  1588. // Members
  1589. Skeleton.prototype.getTransformMatrices = function (mesh) {
  1590. if (this.needInitialSkinMatrix && mesh._bonesTransformMatrices) {
  1591. return mesh._bonesTransformMatrices;
  1592. }
  1593. if (!this._transformMatrices) {
  1594. this.prepare();
  1595. }
  1596. return this._transformMatrices;
  1597. };
  1598. Skeleton.prototype.getScene = function () {
  1599. return this._scene;
  1600. };
  1601. // Methods
  1602. /**
  1603. * @param {boolean} fullDetails - support for multiple levels of logging within scene loading
  1604. */
  1605. Skeleton.prototype.toString = function (fullDetails) {
  1606. var ret = "Name: " + this.name + ", nBones: " + this.bones.length;
  1607. ret += ", nAnimationRanges: " + (this._ranges ? Object.keys(this._ranges).length : "none");
  1608. if (fullDetails) {
  1609. ret += ", Ranges: {";
  1610. var first = true;
  1611. for (var name_1 in this._ranges) {
  1612. if (first) {
  1613. ret += ", ";
  1614. first = false;
  1615. }
  1616. ret += name_1;
  1617. }
  1618. ret += "}";
  1619. }
  1620. return ret;
  1621. };
  1622. /**
  1623. * Get bone's index searching by name
  1624. * @param {string} name is bone's name to search for
  1625. * @return {number} Indice of the bone. Returns -1 if not found
  1626. */
  1627. Skeleton.prototype.getBoneIndexByName = function (name) {
  1628. for (var boneIndex = 0, cache = this.bones.length; boneIndex < cache; boneIndex++) {
  1629. if (this.bones[boneIndex].name === name) {
  1630. return boneIndex;
  1631. }
  1632. }
  1633. return -1;
  1634. };
  1635. Skeleton.prototype.createAnimationRange = function (name, from, to) {
  1636. // check name not already in use
  1637. if (!this._ranges[name]) {
  1638. this._ranges[name] = new BABYLON.AnimationRange(name, from, to);
  1639. for (var i = 0, nBones = this.bones.length; i < nBones; i++) {
  1640. if (this.bones[i].animations[0]) {
  1641. this.bones[i].animations[0].createRange(name, from, to);
  1642. }
  1643. }
  1644. }
  1645. };
  1646. Skeleton.prototype.deleteAnimationRange = function (name, deleteFrames) {
  1647. if (deleteFrames === void 0) { deleteFrames = true; }
  1648. for (var i = 0, nBones = this.bones.length; i < nBones; i++) {
  1649. if (this.bones[i].animations[0]) {
  1650. this.bones[i].animations[0].deleteRange(name, deleteFrames);
  1651. }
  1652. }
  1653. this._ranges[name] = null; // said much faster than 'delete this._range[name]'
  1654. };
  1655. Skeleton.prototype.getAnimationRange = function (name) {
  1656. return this._ranges[name];
  1657. };
  1658. /**
  1659. * Returns as an Array, all AnimationRanges defined on this skeleton
  1660. */
  1661. Skeleton.prototype.getAnimationRanges = function () {
  1662. var animationRanges = [];
  1663. var name;
  1664. var i = 0;
  1665. for (name in this._ranges) {
  1666. animationRanges[i] = this._ranges[name];
  1667. i++;
  1668. }
  1669. return animationRanges;
  1670. };
  1671. /**
  1672. * note: This is not for a complete retargeting, only between very similar skeleton's with only possible bone length differences
  1673. */
  1674. Skeleton.prototype.copyAnimationRange = function (source, name, rescaleAsRequired) {
  1675. if (rescaleAsRequired === void 0) { rescaleAsRequired = false; }
  1676. if (this._ranges[name] || !source.getAnimationRange(name)) {
  1677. return false;
  1678. }
  1679. var ret = true;
  1680. var frameOffset = this._getHighestAnimationFrame() + 1;
  1681. // make a dictionary of source skeleton's bones, so exact same order or doublely nested loop is not required
  1682. var boneDict = {};
  1683. var sourceBones = source.bones;
  1684. var nBones;
  1685. var i;
  1686. for (i = 0, nBones = sourceBones.length; i < nBones; i++) {
  1687. boneDict[sourceBones[i].name] = sourceBones[i];
  1688. }
  1689. if (this.bones.length !== sourceBones.length) {
  1690. BABYLON.Tools.Warn("copyAnimationRange: this rig has " + this.bones.length + " bones, while source as " + sourceBones.length);
  1691. ret = false;
  1692. }
  1693. var skelDimensionsRatio = (rescaleAsRequired && this.dimensionsAtRest && source.dimensionsAtRest) ? this.dimensionsAtRest.divide(source.dimensionsAtRest) : null;
  1694. for (i = 0, nBones = this.bones.length; i < nBones; i++) {
  1695. var boneName = this.bones[i].name;
  1696. var sourceBone = boneDict[boneName];
  1697. if (sourceBone) {
  1698. ret = ret && this.bones[i].copyAnimationRange(sourceBone, name, frameOffset, rescaleAsRequired, skelDimensionsRatio);
  1699. }
  1700. else {
  1701. BABYLON.Tools.Warn("copyAnimationRange: not same rig, missing source bone " + boneName);
  1702. ret = false;
  1703. }
  1704. }
  1705. // do not call createAnimationRange(), since it also is done to bones, which was already done
  1706. var range = source.getAnimationRange(name);
  1707. if (range) {
  1708. this._ranges[name] = new BABYLON.AnimationRange(name, range.from + frameOffset, range.to + frameOffset);
  1709. }
  1710. return ret;
  1711. };
  1712. Skeleton.prototype.returnToRest = function () {
  1713. for (var index = 0; index < this.bones.length; index++) {
  1714. this.bones[index].returnToRest();
  1715. }
  1716. };
  1717. Skeleton.prototype._getHighestAnimationFrame = function () {
  1718. var ret = 0;
  1719. for (var i = 0, nBones = this.bones.length; i < nBones; i++) {
  1720. if (this.bones[i].animations[0]) {
  1721. var highest = this.bones[i].animations[0].getHighestFrame();
  1722. if (ret < highest) {
  1723. ret = highest;
  1724. }
  1725. }
  1726. }
  1727. return ret;
  1728. };
  1729. Skeleton.prototype.beginAnimation = function (name, loop, speedRatio, onAnimationEnd) {
  1730. var range = this.getAnimationRange(name);
  1731. if (!range) {
  1732. return null;
  1733. }
  1734. return this._scene.beginAnimation(this, range.from, range.to, loop, speedRatio, onAnimationEnd);
  1735. };
  1736. Skeleton.prototype._markAsDirty = function () {
  1737. this._isDirty = true;
  1738. };
  1739. Skeleton.prototype._registerMeshWithPoseMatrix = function (mesh) {
  1740. this._meshesWithPoseMatrix.push(mesh);
  1741. };
  1742. Skeleton.prototype._unregisterMeshWithPoseMatrix = function (mesh) {
  1743. var index = this._meshesWithPoseMatrix.indexOf(mesh);
  1744. if (index > -1) {
  1745. this._meshesWithPoseMatrix.splice(index, 1);
  1746. }
  1747. };
  1748. Skeleton.prototype._computeTransformMatrices = function (targetMatrix, initialSkinMatrix) {
  1749. this.onBeforeComputeObservable.notifyObservers(this);
  1750. for (var index = 0; index < this.bones.length; index++) {
  1751. var bone = this.bones[index];
  1752. var parentBone = bone.getParent();
  1753. if (parentBone) {
  1754. bone.getLocalMatrix().multiplyToRef(parentBone.getWorldMatrix(), bone.getWorldMatrix());
  1755. }
  1756. else {
  1757. if (initialSkinMatrix) {
  1758. bone.getLocalMatrix().multiplyToRef(initialSkinMatrix, bone.getWorldMatrix());
  1759. }
  1760. else {
  1761. bone.getWorldMatrix().copyFrom(bone.getLocalMatrix());
  1762. }
  1763. }
  1764. if (bone._index !== -1) {
  1765. var mappedIndex = bone._index === null ? index : bone._index;
  1766. bone.getInvertedAbsoluteTransform().multiplyToArray(bone.getWorldMatrix(), targetMatrix, mappedIndex * 16);
  1767. }
  1768. }
  1769. this._identity.copyToArray(targetMatrix, this.bones.length * 16);
  1770. };
  1771. Skeleton.prototype.prepare = function () {
  1772. if (!this._isDirty) {
  1773. return;
  1774. }
  1775. if (this.needInitialSkinMatrix) {
  1776. for (var index = 0; index < this._meshesWithPoseMatrix.length; index++) {
  1777. var mesh = this._meshesWithPoseMatrix[index];
  1778. var poseMatrix = mesh.getPoseMatrix();
  1779. if (!mesh._bonesTransformMatrices || mesh._bonesTransformMatrices.length !== 16 * (this.bones.length + 1)) {
  1780. mesh._bonesTransformMatrices = new Float32Array(16 * (this.bones.length + 1));
  1781. }
  1782. if (this._synchronizedWithMesh !== mesh) {
  1783. this._synchronizedWithMesh = mesh;
  1784. // Prepare bones
  1785. for (var boneIndex = 0; boneIndex < this.bones.length; boneIndex++) {
  1786. var bone = this.bones[boneIndex];
  1787. if (!bone.getParent()) {
  1788. var matrix = bone.getBaseMatrix();
  1789. matrix.multiplyToRef(poseMatrix, BABYLON.Tmp.Matrix[1]);
  1790. bone._updateDifferenceMatrix(BABYLON.Tmp.Matrix[1]);
  1791. }
  1792. }
  1793. }
  1794. this._computeTransformMatrices(mesh._bonesTransformMatrices, poseMatrix);
  1795. }
  1796. }
  1797. else {
  1798. if (!this._transformMatrices || this._transformMatrices.length !== 16 * (this.bones.length + 1)) {
  1799. this._transformMatrices = new Float32Array(16 * (this.bones.length + 1));
  1800. }
  1801. this._computeTransformMatrices(this._transformMatrices, null);
  1802. }
  1803. this._isDirty = false;
  1804. this._scene._activeBones.addCount(this.bones.length, false);
  1805. };
  1806. Skeleton.prototype.getAnimatables = function () {
  1807. if (!this._animatables || this._animatables.length !== this.bones.length) {
  1808. this._animatables = [];
  1809. for (var index = 0; index < this.bones.length; index++) {
  1810. this._animatables.push(this.bones[index]);
  1811. }
  1812. }
  1813. return this._animatables;
  1814. };
  1815. Skeleton.prototype.clone = function (name, id) {
  1816. var result = new Skeleton(name, id || name, this._scene);
  1817. result.needInitialSkinMatrix = this.needInitialSkinMatrix;
  1818. for (var index = 0; index < this.bones.length; index++) {
  1819. var source = this.bones[index];
  1820. var parentBone = null;
  1821. var parent_1 = source.getParent();
  1822. if (parent_1) {
  1823. var parentIndex = this.bones.indexOf(parent_1);
  1824. parentBone = result.bones[parentIndex];
  1825. }
  1826. var bone = new BABYLON.Bone(source.name, result, parentBone, source.getBaseMatrix().clone(), source.getRestPose().clone());
  1827. BABYLON.Tools.DeepCopy(source.animations, bone.animations);
  1828. }
  1829. if (this._ranges) {
  1830. result._ranges = {};
  1831. for (var rangeName in this._ranges) {
  1832. var range = this._ranges[rangeName];
  1833. if (range) {
  1834. result._ranges[rangeName] = range.clone();
  1835. }
  1836. }
  1837. }
  1838. this._isDirty = true;
  1839. return result;
  1840. };
  1841. Skeleton.prototype.enableBlending = function (blendingSpeed) {
  1842. if (blendingSpeed === void 0) { blendingSpeed = 0.01; }
  1843. this.bones.forEach(function (bone) {
  1844. bone.animations.forEach(function (animation) {
  1845. animation.enableBlending = true;
  1846. animation.blendingSpeed = blendingSpeed;
  1847. });
  1848. });
  1849. };
  1850. Skeleton.prototype.dispose = function () {
  1851. this._meshesWithPoseMatrix = [];
  1852. // Animations
  1853. this.getScene().stopAnimation(this);
  1854. // Remove from scene
  1855. this.getScene().removeSkeleton(this);
  1856. };
  1857. Skeleton.prototype.serialize = function () {
  1858. var serializationObject = {};
  1859. serializationObject.name = this.name;
  1860. serializationObject.id = this.id;
  1861. serializationObject.dimensionsAtRest = this.dimensionsAtRest;
  1862. serializationObject.bones = [];
  1863. serializationObject.needInitialSkinMatrix = this.needInitialSkinMatrix;
  1864. for (var index = 0; index < this.bones.length; index++) {
  1865. var bone = this.bones[index];
  1866. var parent_2 = bone.getParent();
  1867. var serializedBone = {
  1868. parentBoneIndex: parent_2 ? this.bones.indexOf(parent_2) : -1,
  1869. name: bone.name,
  1870. matrix: bone.getBaseMatrix().toArray(),
  1871. rest: bone.getRestPose().toArray()
  1872. };
  1873. serializationObject.bones.push(serializedBone);
  1874. if (bone.length) {
  1875. serializedBone.length = bone.length;
  1876. }
  1877. if (bone.animations && bone.animations.length > 0) {
  1878. serializedBone.animation = bone.animations[0].serialize();
  1879. }
  1880. serializationObject.ranges = [];
  1881. for (var name in this._ranges) {
  1882. var source = this._ranges[name];
  1883. if (!source) {
  1884. continue;
  1885. }
  1886. var range = {};
  1887. range.name = name;
  1888. range.from = source.from;
  1889. range.to = source.to;
  1890. serializationObject.ranges.push(range);
  1891. }
  1892. }
  1893. return serializationObject;
  1894. };
  1895. Skeleton.Parse = function (parsedSkeleton, scene) {
  1896. var skeleton = new Skeleton(parsedSkeleton.name, parsedSkeleton.id, scene);
  1897. if (parsedSkeleton.dimensionsAtRest) {
  1898. skeleton.dimensionsAtRest = BABYLON.Vector3.FromArray(parsedSkeleton.dimensionsAtRest);
  1899. }
  1900. skeleton.needInitialSkinMatrix = parsedSkeleton.needInitialSkinMatrix;
  1901. var index;
  1902. for (index = 0; index < parsedSkeleton.bones.length; index++) {
  1903. var parsedBone = parsedSkeleton.bones[index];
  1904. var parentBone = null;
  1905. if (parsedBone.parentBoneIndex > -1) {
  1906. parentBone = skeleton.bones[parsedBone.parentBoneIndex];
  1907. }
  1908. var rest = parsedBone.rest ? BABYLON.Matrix.FromArray(parsedBone.rest) : null;
  1909. var bone = new BABYLON.Bone(parsedBone.name, skeleton, parentBone, BABYLON.Matrix.FromArray(parsedBone.matrix), rest);
  1910. if (parsedBone.length) {
  1911. bone.length = parsedBone.length;
  1912. }
  1913. if (parsedBone.animation) {
  1914. bone.animations.push(BABYLON.Animation.Parse(parsedBone.animation));
  1915. }
  1916. }
  1917. // placed after bones, so createAnimationRange can cascade down
  1918. if (parsedSkeleton.ranges) {
  1919. for (index = 0; index < parsedSkeleton.ranges.length; index++) {
  1920. var data = parsedSkeleton.ranges[index];
  1921. skeleton.createAnimationRange(data.name, data.from, data.to);
  1922. }
  1923. }
  1924. return skeleton;
  1925. };
  1926. Skeleton.prototype.computeAbsoluteTransforms = function (forceUpdate) {
  1927. if (forceUpdate === void 0) { forceUpdate = false; }
  1928. var renderId = this._scene.getRenderId();
  1929. if (this._lastAbsoluteTransformsUpdateId != renderId || forceUpdate) {
  1930. this.bones[0].computeAbsoluteTransforms();
  1931. this._lastAbsoluteTransformsUpdateId = renderId;
  1932. }
  1933. };
  1934. Skeleton.prototype.getPoseMatrix = function () {
  1935. var poseMatrix = null;
  1936. if (this._meshesWithPoseMatrix.length > 0) {
  1937. poseMatrix = this._meshesWithPoseMatrix[0].getPoseMatrix();
  1938. }
  1939. return poseMatrix;
  1940. };
  1941. Skeleton.prototype.sortBones = function () {
  1942. var bones = new Array();
  1943. var visited = new Array(this.bones.length);
  1944. for (var index = 0; index < this.bones.length; index++) {
  1945. this._sortBones(index, bones, visited);
  1946. }
  1947. this.bones = bones;
  1948. };
  1949. Skeleton.prototype._sortBones = function (index, bones, visited) {
  1950. if (visited[index]) {
  1951. return;
  1952. }
  1953. visited[index] = true;
  1954. var bone = this.bones[index];
  1955. if (bone._index === undefined) {
  1956. bone._index = index;
  1957. }
  1958. var parentBone = bone.getParent();
  1959. if (parentBone) {
  1960. this._sortBones(this.bones.indexOf(parentBone), bones, visited);
  1961. }
  1962. bones.push(bone);
  1963. };
  1964. return Skeleton;
  1965. }());
  1966. BABYLON.Skeleton = Skeleton;
  1967. })(BABYLON || (BABYLON = {}));
  1968. //# sourceMappingURL=babylon.skeleton.js.map
  1969. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1970. BABYLON.Effect.IncludesShadersStore['bonesDeclaration'] = "#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif";
  1971. BABYLON.Effect.IncludesShadersStore['instancesDeclaration'] = "#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif";
  1972. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1973. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1974. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1975. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1976. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1977. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexDeclaration'] = "#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif";
  1978. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1979. BABYLON.Effect.IncludesShadersStore['morphTargetsVertex'] = "#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif";
  1980. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1981. BABYLON.Effect.IncludesShadersStore['bonesVertex'] = "#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif";
  1982. BABYLON.Effect.IncludesShadersStore['bumpVertex'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif";
  1983. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1984. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1985. BABYLON.Effect.IncludesShadersStore['shadowsVertex'] = "#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif";
  1986. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1987. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1988. BABYLON.Effect.IncludesShadersStore['helperFunctions'] = "const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nvec3 dither(vec2 seed,vec3 color) {\nfloat rand=getRand(seed);\ncolor+=mix(-0.5/255.0,0.5/255.0,rand);\ncolor=max(color,0.0);\nreturn color;\n}";
  1989. BABYLON.Effect.IncludesShadersStore['lightFragmentDeclaration'] = "#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif";
  1990. BABYLON.Effect.IncludesShadersStore['lightsFragmentFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n";
  1991. BABYLON.Effect.IncludesShadersStore['lightUboDeclaration'] = "#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif";
  1992. BABYLON.Effect.IncludesShadersStore['defaultVertexDeclaration'] = "\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  1993. BABYLON.Effect.IncludesShadersStore['defaultFragmentDeclaration'] = "uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif";
  1994. BABYLON.Effect.IncludesShadersStore['defaultUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  1995. BABYLON.Effect.IncludesShadersStore['shadowsFragmentFunctions'] = "#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n";
  1996. BABYLON.Effect.IncludesShadersStore['fresnelFunction'] = "#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif";
  1997. BABYLON.Effect.IncludesShadersStore['reflectionFunction'] = "vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}";
  1998. BABYLON.Effect.IncludesShadersStore['imageProcessingDeclaration'] = "#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif";
  1999. BABYLON.Effect.IncludesShadersStore['imageProcessingFunctions'] = "#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}";
  2000. BABYLON.Effect.IncludesShadersStore['bumpFragmentFunctions'] = "#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif";
  2001. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  2002. BABYLON.Effect.IncludesShadersStore['fogFragmentDeclaration'] = "#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif";
  2003. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  2004. BABYLON.Effect.IncludesShadersStore['bumpFragment'] = "vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif";
  2005. BABYLON.Effect.IncludesShadersStore['lightFragment'] = "#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif";
  2006. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  2007. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  2008. (function() {
  2009. var EXPORTS = {};EXPORTS['Bone'] = BABYLON['Bone'];EXPORTS['BoneIKController'] = BABYLON['BoneIKController'];EXPORTS['BoneLookController'] = BABYLON['BoneLookController'];EXPORTS['Skeleton'] = BABYLON['Skeleton'];
  2010. globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
  2011. module.exports = EXPORTS;
  2012. })();
  2013. }