KHR_animation_pointer.data.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* eslint-disable @typescript-eslint/naming-convention */
  2. import { Animation } from "@babylonjs/core/Animations/animation.js";
  3. import { AnimationPropertyInfo, nodeAnimationData } from "../glTFLoaderAnimation.js";
  4. import { Color3 } from "@babylonjs/core/Maths/math.color.js";
  5. function getColor3(_target, source, offset, scale) {
  6. return Color3.FromArray(source, offset).scale(scale);
  7. }
  8. function getAlpha(_target, source, offset, scale) {
  9. return source[offset + 3] * scale;
  10. }
  11. function getFloat(_target, source, offset, scale) {
  12. return source[offset] * scale;
  13. }
  14. function getMinusFloat(_target, source, offset, scale) {
  15. return -source[offset] * scale;
  16. }
  17. function getNextFloat(_target, source, offset, scale) {
  18. return source[offset + 1] * scale;
  19. }
  20. function getFloatBy2(_target, source, offset, scale) {
  21. return source[offset] * scale * 2;
  22. }
  23. function getTextureTransformTree(textureName) {
  24. return {
  25. scale: [
  26. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, `${textureName}.uScale`, getFloat, () => 2),
  27. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, `${textureName}.vScale`, getNextFloat, () => 2),
  28. ],
  29. offset: [
  30. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, `${textureName}.uOffset`, getFloat, () => 2),
  31. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, `${textureName}.vOffset`, getNextFloat, () => 2),
  32. ],
  33. rotation: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, `${textureName}.wAng`, getMinusFloat, () => 1)],
  34. };
  35. }
  36. class CameraAnimationPropertyInfo extends AnimationPropertyInfo {
  37. /** @internal */
  38. buildAnimations(target, name, fps, keys, callback) {
  39. callback(target._babylonCamera, this._buildAnimation(name, fps, keys));
  40. }
  41. }
  42. class MaterialAnimationPropertyInfo extends AnimationPropertyInfo {
  43. /** @internal */
  44. buildAnimations(target, name, fps, keys, callback) {
  45. for (const fillMode in target._data) {
  46. callback(target._data[fillMode].babylonMaterial, this._buildAnimation(name, fps, keys));
  47. }
  48. }
  49. }
  50. class LightAnimationPropertyInfo extends AnimationPropertyInfo {
  51. /** @internal */
  52. buildAnimations(target, name, fps, keys, callback) {
  53. callback(target._babylonLight, this._buildAnimation(name, fps, keys));
  54. }
  55. }
  56. const nodesTree = {
  57. __array__: {
  58. __target__: true,
  59. ...nodeAnimationData,
  60. },
  61. };
  62. const camerasTree = {
  63. __array__: {
  64. __target__: true,
  65. orthographic: {
  66. xmag: [
  67. new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "orthoLeft", getMinusFloat, () => 1),
  68. new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "orthoRight", getNextFloat, () => 1),
  69. ],
  70. ymag: [
  71. new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "orthoBottom", getMinusFloat, () => 1),
  72. new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "orthoTop", getNextFloat, () => 1),
  73. ],
  74. zfar: [new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "maxZ", getFloat, () => 1)],
  75. znear: [new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "minZ", getFloat, () => 1)],
  76. },
  77. perspective: {
  78. yfov: [new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "fov", getFloat, () => 1)],
  79. zfar: [new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "maxZ", getFloat, () => 1)],
  80. znear: [new CameraAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "minZ", getFloat, () => 1)],
  81. },
  82. },
  83. };
  84. const materialsTree = {
  85. __array__: {
  86. __target__: true,
  87. pbrMetallicRoughness: {
  88. baseColorFactor: [
  89. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "albedoColor", getColor3, () => 4),
  90. new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "alpha", getAlpha, () => 4),
  91. ],
  92. metallicFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "metallic", getFloat, () => 1)],
  93. roughnessFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "roughness", getFloat, () => 1)],
  94. baseColorTexture: {
  95. extensions: {
  96. KHR_texture_transform: getTextureTransformTree("albedoTexture"),
  97. },
  98. },
  99. metallicRoughnessTexture: {
  100. extensions: {
  101. KHR_texture_transform: getTextureTransformTree("metallicTexture"),
  102. },
  103. },
  104. },
  105. emissiveFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "emissiveColor", getColor3, () => 3)],
  106. normalTexture: {
  107. scale: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "bumpTexture.level", getFloat, () => 1)],
  108. extensions: {
  109. KHR_texture_transform: getTextureTransformTree("bumpTexture"),
  110. },
  111. },
  112. occlusionTexture: {
  113. strength: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "ambientTextureStrength", getFloat, () => 1)],
  114. extensions: {
  115. KHR_texture_transform: getTextureTransformTree("ambientTexture"),
  116. },
  117. },
  118. emissiveTexture: {
  119. extensions: {
  120. KHR_texture_transform: getTextureTransformTree("emissiveTexture"),
  121. },
  122. },
  123. extensions: {
  124. KHR_materials_anisotropy: {
  125. anisotropyStrength: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "anisotropy.intensity", getFloat, () => 1)],
  126. anisotropyRotation: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "anisotropy.angle", getFloat, () => 1)],
  127. anisotropyTexture: {
  128. extensions: {
  129. KHR_texture_transform: getTextureTransformTree("anisotropy.texture"),
  130. },
  131. },
  132. },
  133. KHR_materials_clearcoat: {
  134. clearcoatFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "clearCoat.intensity", getFloat, () => 1)],
  135. clearcoatRoughnessFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "clearCoat.roughness", getFloat, () => 1)],
  136. clearcoatTexture: {
  137. extensions: {
  138. KHR_texture_transform: getTextureTransformTree("clearCoat.texture"),
  139. },
  140. },
  141. clearcoatNormalTexture: {
  142. scale: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "clearCoat.bumpTexture.level", getFloat, () => 1)],
  143. extensions: {
  144. KHR_texture_transform: getTextureTransformTree("clearCoat.bumpTexture"),
  145. },
  146. },
  147. clearcoatRoughnessTexture: {
  148. extensions: {
  149. KHR_texture_transform: getTextureTransformTree("clearCoat.textureRoughness"),
  150. },
  151. },
  152. },
  153. KHR_materials_dispersion: {
  154. dispersion: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "subSurface.dispersion", getFloat, () => 1)],
  155. },
  156. KHR_materials_emissive_strength: {
  157. emissiveStrength: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "emissiveIntensity", getFloat, () => 1)],
  158. },
  159. KHR_materials_ior: {
  160. ior: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "indexOfRefraction", getFloat, () => 1)],
  161. },
  162. KHR_materials_iridescence: {
  163. iridescenceFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "iridescence.intensity", getFloat, () => 1)],
  164. iridescenceIor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "iridescence.indexOfRefraction", getFloat, () => 1)],
  165. iridescenceThicknessMinimum: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "iridescence.minimumThickness", getFloat, () => 1)],
  166. iridescenceThicknessMaximum: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "iridescence.maximumThickness", getFloat, () => 1)],
  167. iridescenceTexture: {
  168. extensions: {
  169. KHR_texture_transform: getTextureTransformTree("iridescence.texture"),
  170. },
  171. },
  172. iridescenceThicknessTexture: {
  173. extensions: {
  174. KHR_texture_transform: getTextureTransformTree("iridescence.thicknessTexture"),
  175. },
  176. },
  177. },
  178. KHR_materials_sheen: {
  179. sheenColorFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "sheen.color", getColor3, () => 3)],
  180. sheenRoughnessFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "sheen.roughness", getFloat, () => 1)],
  181. sheenColorTexture: {
  182. extensions: {
  183. KHR_texture_transform: getTextureTransformTree("sheen.texture"),
  184. },
  185. },
  186. sheenRoughnessTexture: {
  187. extensions: {
  188. KHR_texture_transform: getTextureTransformTree("sheen.textureRoughness"),
  189. },
  190. },
  191. },
  192. KHR_materials_specular: {
  193. specularFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "metallicF0Factor", getFloat, () => 1)],
  194. specularColorFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "metallicReflectanceColor", getColor3, () => 3)],
  195. specularTexture: {
  196. extensions: {
  197. KHR_texture_transform: getTextureTransformTree("metallicReflectanceTexture"),
  198. },
  199. },
  200. specularColorTexture: {
  201. extensions: {
  202. KHR_texture_transform: getTextureTransformTree("reflectanceTexture"),
  203. },
  204. },
  205. },
  206. KHR_materials_transmission: {
  207. transmissionFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "subSurface.refractionIntensity", getFloat, () => 1)],
  208. transmissionTexture: {
  209. extensions: {
  210. KHR_texture_transform: getTextureTransformTree("subSurface.refractionIntensityTexture"),
  211. },
  212. },
  213. },
  214. KHR_materials_volume: {
  215. attenuationColor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "subSurface.tintColor", getColor3, () => 3)],
  216. attenuationDistance: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "subSurface.tintColorAtDistance", getFloat, () => 1)],
  217. thicknessFactor: [new MaterialAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "subSurface.maximumThickness", getFloat, () => 1)],
  218. thicknessTexture: {
  219. extensions: {
  220. KHR_texture_transform: getTextureTransformTree("subSurface.thicknessTexture"),
  221. },
  222. },
  223. },
  224. },
  225. },
  226. };
  227. const extensionsTree = {
  228. KHR_lights_punctual: {
  229. lights: {
  230. __array__: {
  231. __target__: true,
  232. color: [new LightAnimationPropertyInfo(Animation.ANIMATIONTYPE_COLOR3, "diffuse", getColor3, () => 3)],
  233. intensity: [new LightAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "intensity", getFloat, () => 1)],
  234. range: [new LightAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "range", getFloat, () => 1)],
  235. spot: {
  236. innerConeAngle: [new LightAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "innerAngle", getFloatBy2, () => 1)],
  237. outerConeAngle: [new LightAnimationPropertyInfo(Animation.ANIMATIONTYPE_FLOAT, "angle", getFloatBy2, () => 1)],
  238. },
  239. },
  240. },
  241. },
  242. };
  243. /** @internal */
  244. export const animationPointerTree = {
  245. nodes: nodesTree,
  246. materials: materialsTree,
  247. cameras: camerasTree,
  248. extensions: extensionsTree,
  249. };
  250. //# sourceMappingURL=KHR_animation_pointer.data.js.map