es6.js 137 KB

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