ModelUtility.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. import BoundingSphere from "../Core/BoundingSphere.js";
  2. import Cartesian2 from "../Core/Cartesian2.js";
  3. import Cartesian3 from "../Core/Cartesian3.js";
  4. import Cartesian4 from "../Core/Cartesian4.js";
  5. import clone from "../Core/clone.js";
  6. import defined from "../Core/defined.js";
  7. import Matrix2 from "../Core/Matrix2.js";
  8. import Matrix3 from "../Core/Matrix3.js";
  9. import Matrix4 from "../Core/Matrix4.js";
  10. import Quaternion from "../Core/Quaternion.js";
  11. import RuntimeError from "../Core/RuntimeError.js";
  12. import WebGLConstants from "../Core/WebGLConstants.js";
  13. import ShaderSource from "../Renderer/ShaderSource.js";
  14. import addToArray from "../ThirdParty/GltfPipeline/addToArray.js";
  15. import ForEach from "../ThirdParty/GltfPipeline/ForEach.js";
  16. import hasExtension from "../ThirdParty/GltfPipeline/hasExtension.js";
  17. import AttributeType from "./AttributeType.js";
  18. import Axis from "./Axis.js";
  19. /**
  20. * @private
  21. */
  22. var ModelUtility = {};
  23. /**
  24. * Updates the model's forward axis if the model is not a 2.0 model.
  25. *
  26. * @param {Object} model The model to update.
  27. */
  28. ModelUtility.updateForwardAxis = function (model) {
  29. var cachedSourceVersion = model.gltf.extras.sourceVersion;
  30. if (
  31. (defined(cachedSourceVersion) && cachedSourceVersion !== "2.0") ||
  32. ModelUtility.getAssetVersion(model.gltf) !== "2.0"
  33. ) {
  34. model._gltfForwardAxis = Axis.X;
  35. }
  36. };
  37. /**
  38. * Gets the string representing the glTF asset version.
  39. *
  40. * @param {Object} gltf A javascript object containing a glTF asset.
  41. * @returns {String} The glTF asset version string.
  42. */
  43. ModelUtility.getAssetVersion = function (gltf) {
  44. // In glTF 1.0 it was valid to omit the version number.
  45. if (!defined(gltf.asset) || !defined(gltf.asset.version)) {
  46. return "1.0";
  47. }
  48. return gltf.asset.version;
  49. };
  50. /**
  51. * Splits primitive materials with values incompatible for generating techniques.
  52. *
  53. * @param {Object} gltf A javascript object containing a glTF asset.
  54. * @returns {Object} The glTF asset with modified materials.
  55. */
  56. ModelUtility.splitIncompatibleMaterials = function (gltf) {
  57. var accessors = gltf.accessors;
  58. var materials = gltf.materials;
  59. var primitiveInfoByMaterial = {};
  60. ForEach.mesh(gltf, function (mesh) {
  61. ForEach.meshPrimitive(mesh, function (primitive) {
  62. var materialIndex = primitive.material;
  63. var material = materials[materialIndex];
  64. var jointAccessorId = primitive.attributes.JOINTS_0;
  65. var componentType;
  66. var accessorType;
  67. if (defined(jointAccessorId)) {
  68. var jointAccessor = accessors[jointAccessorId];
  69. componentType = jointAccessor.componentType;
  70. accessorType = jointAccessor.type;
  71. }
  72. var isSkinned = defined(jointAccessorId) && accessorType === "VEC4";
  73. var hasVertexColors = defined(primitive.attributes.COLOR_0);
  74. var hasMorphTargets = defined(primitive.targets);
  75. var hasNormals = defined(primitive.attributes.NORMAL);
  76. var hasTangents = defined(primitive.attributes.TANGENT);
  77. var hasTexCoords = defined(primitive.attributes.TEXCOORD_0);
  78. var hasTexCoord1 =
  79. hasTexCoords && defined(primitive.attributes.TEXCOORD_1);
  80. var hasOutline =
  81. defined(primitive.extensions) &&
  82. defined(primitive.extensions.CESIUM_primitive_outline);
  83. var primitiveInfo = primitiveInfoByMaterial[materialIndex];
  84. if (!defined(primitiveInfo)) {
  85. primitiveInfoByMaterial[materialIndex] = {
  86. skinning: {
  87. skinned: isSkinned,
  88. componentType: componentType,
  89. },
  90. hasVertexColors: hasVertexColors,
  91. hasMorphTargets: hasMorphTargets,
  92. hasNormals: hasNormals,
  93. hasTangents: hasTangents,
  94. hasTexCoords: hasTexCoords,
  95. hasTexCoord1: hasTexCoord1,
  96. hasOutline: hasOutline,
  97. };
  98. } else if (
  99. primitiveInfo.skinning.skinned !== isSkinned ||
  100. primitiveInfo.hasVertexColors !== hasVertexColors ||
  101. primitiveInfo.hasMorphTargets !== hasMorphTargets ||
  102. primitiveInfo.hasNormals !== hasNormals ||
  103. primitiveInfo.hasTangents !== hasTangents ||
  104. primitiveInfo.hasTexCoords !== hasTexCoords ||
  105. primitiveInfo.hasTexCoord1 !== hasTexCoord1 ||
  106. primitiveInfo.hasOutline !== hasOutline
  107. ) {
  108. // This primitive uses the same material as another one that either:
  109. // * Isn't skinned
  110. // * Uses a different type to store joints and weights
  111. // * Doesn't have vertex colors, morph targets, normals, tangents, or texCoords
  112. // * Doesn't have a CESIUM_primitive_outline extension.
  113. var clonedMaterial = clone(material, true);
  114. // Split this off as a separate material
  115. materialIndex = addToArray(materials, clonedMaterial);
  116. primitive.material = materialIndex;
  117. primitiveInfoByMaterial[materialIndex] = {
  118. skinning: {
  119. skinned: isSkinned,
  120. componentType: componentType,
  121. },
  122. hasVertexColors: hasVertexColors,
  123. hasMorphTargets: hasMorphTargets,
  124. hasNormals: hasNormals,
  125. hasTangents: hasTangents,
  126. hasTexCoords: hasTexCoords,
  127. hasTexCoord1: hasTexCoord1,
  128. hasOutline: hasOutline,
  129. };
  130. }
  131. });
  132. });
  133. return primitiveInfoByMaterial;
  134. };
  135. ModelUtility.getShaderVariable = function (type) {
  136. if (type === "SCALAR") {
  137. return "float";
  138. }
  139. return type.toLowerCase();
  140. };
  141. ModelUtility.ModelState = {
  142. NEEDS_LOAD: 0,
  143. LOADING: 1,
  144. LOADED: 2, // Renderable, but textures can still be pending when incrementallyLoadTextures is true.
  145. FAILED: 3,
  146. };
  147. ModelUtility.getFailedLoadFunction = function (model, type, path) {
  148. return function (error) {
  149. model._state = ModelUtility.ModelState.FAILED;
  150. var message = "Failed to load " + type + ": " + path;
  151. if (defined(error)) {
  152. message += "\n" + error.message;
  153. }
  154. model._readyPromise.reject(new RuntimeError(message));
  155. };
  156. };
  157. ModelUtility.parseBuffers = function (model, bufferLoad) {
  158. var loadResources = model._loadResources;
  159. ForEach.buffer(model.gltf, function (buffer, bufferViewId) {
  160. if (defined(buffer.extras._pipeline.source)) {
  161. loadResources.buffers[bufferViewId] = buffer.extras._pipeline.source;
  162. } else if (defined(bufferLoad)) {
  163. var bufferResource = model._resource.getDerivedResource({
  164. url: buffer.uri,
  165. });
  166. ++loadResources.pendingBufferLoads;
  167. bufferResource
  168. .fetchArrayBuffer()
  169. .then(bufferLoad(model, bufferViewId))
  170. .otherwise(
  171. ModelUtility.getFailedLoadFunction(
  172. model,
  173. "buffer",
  174. bufferResource.url
  175. )
  176. );
  177. }
  178. });
  179. };
  180. var aMinScratch = new Cartesian3();
  181. var aMaxScratch = new Cartesian3();
  182. ModelUtility.computeBoundingSphere = function (model) {
  183. var gltf = model.gltf;
  184. var gltfNodes = gltf.nodes;
  185. var gltfMeshes = gltf.meshes;
  186. var rootNodes = gltf.scenes[gltf.scene].nodes;
  187. var rootNodesLength = rootNodes.length;
  188. var nodeStack = [];
  189. var min = new Cartesian3(
  190. Number.MAX_VALUE,
  191. Number.MAX_VALUE,
  192. Number.MAX_VALUE
  193. );
  194. var max = new Cartesian3(
  195. -Number.MAX_VALUE,
  196. -Number.MAX_VALUE,
  197. -Number.MAX_VALUE
  198. );
  199. for (var i = 0; i < rootNodesLength; ++i) {
  200. var n = gltfNodes[rootNodes[i]];
  201. n._transformToRoot = ModelUtility.getTransform(n);
  202. nodeStack.push(n);
  203. while (nodeStack.length > 0) {
  204. n = nodeStack.pop();
  205. var transformToRoot = n._transformToRoot;
  206. var meshId = n.mesh;
  207. if (defined(meshId)) {
  208. var mesh = gltfMeshes[meshId];
  209. var primitives = mesh.primitives;
  210. var primitivesLength = primitives.length;
  211. for (var m = 0; m < primitivesLength; ++m) {
  212. var positionAccessor = primitives[m].attributes.POSITION;
  213. if (defined(positionAccessor)) {
  214. var minMax = ModelUtility.getAccessorMinMax(gltf, positionAccessor);
  215. if (defined(minMax.min) && defined(minMax.max)) {
  216. var aMin = Cartesian3.fromArray(minMax.min, 0, aMinScratch);
  217. var aMax = Cartesian3.fromArray(minMax.max, 0, aMaxScratch);
  218. Matrix4.multiplyByPoint(transformToRoot, aMin, aMin);
  219. Matrix4.multiplyByPoint(transformToRoot, aMax, aMax);
  220. Cartesian3.minimumByComponent(min, aMin, min);
  221. Cartesian3.maximumByComponent(max, aMax, max);
  222. }
  223. }
  224. }
  225. }
  226. var children = n.children;
  227. if (defined(children)) {
  228. var childrenLength = children.length;
  229. for (var k = 0; k < childrenLength; ++k) {
  230. var child = gltfNodes[children[k]];
  231. child._transformToRoot = ModelUtility.getTransform(child);
  232. Matrix4.multiplyTransformation(
  233. transformToRoot,
  234. child._transformToRoot,
  235. child._transformToRoot
  236. );
  237. nodeStack.push(child);
  238. }
  239. }
  240. delete n._transformToRoot;
  241. }
  242. }
  243. var boundingSphere = BoundingSphere.fromCornerPoints(min, max);
  244. if (model._forwardAxis === Axis.Z) {
  245. // glTF 2.0 has a Z-forward convention that must be adapted here to X-forward.
  246. BoundingSphere.transformWithoutScale(
  247. boundingSphere,
  248. Axis.Z_UP_TO_X_UP,
  249. boundingSphere
  250. );
  251. }
  252. if (model._upAxis === Axis.Y) {
  253. BoundingSphere.transformWithoutScale(
  254. boundingSphere,
  255. Axis.Y_UP_TO_Z_UP,
  256. boundingSphere
  257. );
  258. } else if (model._upAxis === Axis.X) {
  259. BoundingSphere.transformWithoutScale(
  260. boundingSphere,
  261. Axis.X_UP_TO_Z_UP,
  262. boundingSphere
  263. );
  264. }
  265. return boundingSphere;
  266. };
  267. function techniqueAttributeForSemantic(technique, semantic) {
  268. return ForEach.techniqueAttribute(technique, function (
  269. attribute,
  270. attributeName
  271. ) {
  272. if (attribute.semantic === semantic) {
  273. return attributeName;
  274. }
  275. });
  276. }
  277. function ensureSemanticExistenceForPrimitive(gltf, primitive) {
  278. var accessors = gltf.accessors;
  279. var materials = gltf.materials;
  280. var techniquesWebgl = gltf.extensions.KHR_techniques_webgl;
  281. var techniques = techniquesWebgl.techniques;
  282. var programs = techniquesWebgl.programs;
  283. var shaders = techniquesWebgl.shaders;
  284. var targets = primitive.targets;
  285. var attributes = primitive.attributes;
  286. for (var target in targets) {
  287. if (targets.hasOwnProperty(target)) {
  288. var targetAttributes = targets[target];
  289. for (var attribute in targetAttributes) {
  290. if (attribute !== "extras") {
  291. attributes[attribute + "_" + target] = targetAttributes[attribute];
  292. }
  293. }
  294. }
  295. }
  296. var material = materials[primitive.material];
  297. var technique =
  298. techniques[material.extensions.KHR_techniques_webgl.technique];
  299. var program = programs[technique.program];
  300. var vertexShader = shaders[program.vertexShader];
  301. for (var semantic in attributes) {
  302. if (attributes.hasOwnProperty(semantic)) {
  303. if (!defined(techniqueAttributeForSemantic(technique, semantic))) {
  304. var accessorId = attributes[semantic];
  305. var accessor = accessors[accessorId];
  306. var lowerCase = semantic.toLowerCase();
  307. if (lowerCase.charAt(0) === "_") {
  308. lowerCase = lowerCase.slice(1);
  309. }
  310. var attributeName = "a_" + lowerCase;
  311. technique.attributes[attributeName] = {
  312. semantic: semantic,
  313. type: accessor.componentType,
  314. };
  315. var pipelineExtras = vertexShader.extras._pipeline;
  316. var shaderText = pipelineExtras.source;
  317. shaderText =
  318. "attribute " +
  319. ModelUtility.getShaderVariable(accessor.type) +
  320. " " +
  321. attributeName +
  322. ";\n" +
  323. shaderText;
  324. pipelineExtras.source = shaderText;
  325. }
  326. }
  327. }
  328. }
  329. /**
  330. * Ensures all attributes present on the primitive are present in the technique and
  331. * vertex shader.
  332. *
  333. * @param {Object} gltf A javascript object containing a glTF asset.
  334. * @returns {Object} The glTF asset, including any additional attributes.
  335. */
  336. ModelUtility.ensureSemanticExistence = function (gltf) {
  337. ForEach.mesh(gltf, function (mesh) {
  338. ForEach.meshPrimitive(mesh, function (primitive) {
  339. ensureSemanticExistenceForPrimitive(gltf, primitive);
  340. });
  341. });
  342. return gltf;
  343. };
  344. /**
  345. * Creates attribute location for all attributes required by a technique.
  346. *
  347. * @param {Object} technique A glTF KHR_techniques_webgl technique object.
  348. * @param {Object} precreatedAttributes A dictionary object of pre-created attributes for which to also create locations.
  349. * @returns {Object} A dictionary object containing attribute names and their locations.
  350. */
  351. ModelUtility.createAttributeLocations = function (
  352. technique,
  353. precreatedAttributes
  354. ) {
  355. var attributeLocations = {};
  356. var hasIndex0 = false;
  357. var i = 1;
  358. ForEach.techniqueAttribute(technique, function (attribute, attributeName) {
  359. // Set the position attribute to the 0th index. In some WebGL implementations the shader
  360. // will not work correctly if the 0th attribute is not active. For example, some glTF models
  361. // list the normal attribute first but derived shaders like the cast-shadows shader do not use
  362. // the normal attribute.
  363. if (/pos/i.test(attributeName) && !hasIndex0) {
  364. attributeLocations[attributeName] = 0;
  365. hasIndex0 = true;
  366. } else {
  367. attributeLocations[attributeName] = i++;
  368. }
  369. });
  370. if (defined(precreatedAttributes)) {
  371. for (var attributeName in precreatedAttributes) {
  372. if (precreatedAttributes.hasOwnProperty(attributeName)) {
  373. attributeLocations[attributeName] = i++;
  374. }
  375. }
  376. }
  377. return attributeLocations;
  378. };
  379. ModelUtility.getAccessorMinMax = function (gltf, accessorId) {
  380. var accessor = gltf.accessors[accessorId];
  381. var extensions = accessor.extensions;
  382. var accessorMin = accessor.min;
  383. var accessorMax = accessor.max;
  384. // If this accessor is quantized, we should use the decoded min and max
  385. if (defined(extensions)) {
  386. var quantizedAttributes = extensions.WEB3D_quantized_attributes;
  387. if (defined(quantizedAttributes)) {
  388. accessorMin = quantizedAttributes.decodedMin;
  389. accessorMax = quantizedAttributes.decodedMax;
  390. }
  391. }
  392. return {
  393. min: accessorMin,
  394. max: accessorMax,
  395. };
  396. };
  397. function getTechniqueAttributeOrUniformFunction(
  398. gltf,
  399. technique,
  400. semantic,
  401. ignoreNodes
  402. ) {
  403. if (hasExtension(gltf, "KHR_techniques_webgl")) {
  404. return function (attributeOrUniform, attributeOrUniformName) {
  405. if (
  406. attributeOrUniform.semantic === semantic &&
  407. (!ignoreNodes || !defined(attributeOrUniform.node))
  408. ) {
  409. return attributeOrUniformName;
  410. }
  411. };
  412. }
  413. return function (parameterName, attributeOrUniformName) {
  414. var attributeOrUniform = technique.parameters[parameterName];
  415. if (
  416. attributeOrUniform.semantic === semantic &&
  417. (!ignoreNodes || !defined(attributeOrUniform.node))
  418. ) {
  419. return attributeOrUniformName;
  420. }
  421. };
  422. }
  423. ModelUtility.getAttributeOrUniformBySemantic = function (
  424. gltf,
  425. semantic,
  426. programId,
  427. ignoreNodes
  428. ) {
  429. return ForEach.technique(gltf, function (technique) {
  430. if (defined(programId) && technique.program !== programId) {
  431. return;
  432. }
  433. var value = ForEach.techniqueAttribute(
  434. technique,
  435. getTechniqueAttributeOrUniformFunction(
  436. gltf,
  437. technique,
  438. semantic,
  439. ignoreNodes
  440. )
  441. );
  442. if (defined(value)) {
  443. return value;
  444. }
  445. return ForEach.techniqueUniform(
  446. technique,
  447. getTechniqueAttributeOrUniformFunction(
  448. gltf,
  449. technique,
  450. semantic,
  451. ignoreNodes
  452. )
  453. );
  454. });
  455. };
  456. ModelUtility.getDiffuseAttributeOrUniform = function (gltf, programId) {
  457. var diffuseUniformName = ModelUtility.getAttributeOrUniformBySemantic(
  458. gltf,
  459. "COLOR_0",
  460. programId
  461. );
  462. if (!defined(diffuseUniformName)) {
  463. diffuseUniformName = ModelUtility.getAttributeOrUniformBySemantic(
  464. gltf,
  465. "_3DTILESDIFFUSE",
  466. programId
  467. );
  468. }
  469. return diffuseUniformName;
  470. };
  471. var nodeTranslationScratch = new Cartesian3();
  472. var nodeQuaternionScratch = new Quaternion();
  473. var nodeScaleScratch = new Cartesian3();
  474. ModelUtility.getTransform = function (node, result) {
  475. if (defined(node.matrix)) {
  476. return Matrix4.fromColumnMajorArray(node.matrix, result);
  477. }
  478. return Matrix4.fromTranslationQuaternionRotationScale(
  479. Cartesian3.fromArray(node.translation, 0, nodeTranslationScratch),
  480. Quaternion.unpack(node.rotation, 0, nodeQuaternionScratch),
  481. Cartesian3.fromArray(node.scale, 0, nodeScaleScratch),
  482. result
  483. );
  484. };
  485. ModelUtility.getUsedExtensions = function (gltf) {
  486. var extensionsUsed = gltf.extensionsUsed;
  487. var cachedExtensionsUsed = {};
  488. if (defined(extensionsUsed)) {
  489. var extensionsUsedLength = extensionsUsed.length;
  490. for (var i = 0; i < extensionsUsedLength; i++) {
  491. var extension = extensionsUsed[i];
  492. cachedExtensionsUsed[extension] = true;
  493. }
  494. }
  495. return cachedExtensionsUsed;
  496. };
  497. ModelUtility.getRequiredExtensions = function (gltf) {
  498. var extensionsRequired = gltf.extensionsRequired;
  499. var cachedExtensionsRequired = {};
  500. if (defined(extensionsRequired)) {
  501. var extensionsRequiredLength = extensionsRequired.length;
  502. for (var i = 0; i < extensionsRequiredLength; i++) {
  503. var extension = extensionsRequired[i];
  504. cachedExtensionsRequired[extension] = true;
  505. }
  506. }
  507. return cachedExtensionsRequired;
  508. };
  509. ModelUtility.supportedExtensions = {
  510. AGI_articulations: true,
  511. CESIUM_RTC: true,
  512. EXT_texture_webp: true,
  513. KHR_blend: true,
  514. KHR_binary_glTF: true,
  515. KHR_draco_mesh_compression: true,
  516. KHR_materials_common: true,
  517. KHR_techniques_webgl: true,
  518. KHR_materials_unlit: true,
  519. KHR_materials_pbrSpecularGlossiness: true,
  520. KHR_texture_transform: true,
  521. WEB3D_quantized_attributes: true,
  522. };
  523. ModelUtility.checkSupportedExtensions = function (
  524. extensionsRequired,
  525. browserSupportsWebp
  526. ) {
  527. for (var extension in extensionsRequired) {
  528. if (extensionsRequired.hasOwnProperty(extension)) {
  529. if (!ModelUtility.supportedExtensions[extension]) {
  530. throw new RuntimeError("Unsupported glTF Extension: " + extension);
  531. }
  532. if (extension === "EXT_texture_webp" && browserSupportsWebp === false) {
  533. throw new RuntimeError(
  534. "Loaded model requires WebP but browser does not support it."
  535. );
  536. }
  537. }
  538. }
  539. };
  540. ModelUtility.checkSupportedGlExtensions = function (extensionsUsed, context) {
  541. if (defined(extensionsUsed)) {
  542. var glExtensionsUsedLength = extensionsUsed.length;
  543. for (var i = 0; i < glExtensionsUsedLength; i++) {
  544. var extension = extensionsUsed[i];
  545. if (extension !== "OES_element_index_uint") {
  546. throw new RuntimeError("Unsupported WebGL Extension: " + extension);
  547. } else if (!context.elementIndexUint) {
  548. throw new RuntimeError(
  549. "OES_element_index_uint WebGL extension is not enabled."
  550. );
  551. }
  552. }
  553. }
  554. };
  555. function replaceAllButFirstInString(string, find, replace) {
  556. // Limit search to strings that are not a subset of other tokens.
  557. find += "(?!\\w)";
  558. find = new RegExp(find, "g");
  559. var index = string.search(find);
  560. return string.replace(find, function (match, offset) {
  561. return index === offset ? match : replace;
  562. });
  563. }
  564. function getQuantizedAttributes(gltf, accessorId) {
  565. var accessor = gltf.accessors[accessorId];
  566. var extensions = accessor.extensions;
  567. if (defined(extensions)) {
  568. return extensions.WEB3D_quantized_attributes;
  569. }
  570. return undefined;
  571. }
  572. function getAttributeVariableName(gltf, primitive, attributeSemantic) {
  573. var materialId = primitive.material;
  574. var material = gltf.materials[materialId];
  575. if (
  576. !hasExtension(gltf, "KHR_techniques_webgl") ||
  577. !defined(material.extensions) ||
  578. !defined(material.extensions.KHR_techniques_webgl)
  579. ) {
  580. return;
  581. }
  582. var techniqueId = material.extensions.KHR_techniques_webgl.technique;
  583. var techniquesWebgl = gltf.extensions.KHR_techniques_webgl;
  584. var technique = techniquesWebgl.techniques[techniqueId];
  585. return ForEach.techniqueAttribute(technique, function (
  586. attribute,
  587. attributeName
  588. ) {
  589. var semantic = attribute.semantic;
  590. if (semantic === attributeSemantic) {
  591. return attributeName;
  592. }
  593. });
  594. }
  595. ModelUtility.modifyShaderForDracoQuantizedAttributes = function (
  596. gltf,
  597. primitive,
  598. shader,
  599. decodedAttributes
  600. ) {
  601. var quantizedUniforms = {};
  602. for (var attributeSemantic in decodedAttributes) {
  603. if (decodedAttributes.hasOwnProperty(attributeSemantic)) {
  604. var attribute = decodedAttributes[attributeSemantic];
  605. var quantization = attribute.quantization;
  606. if (!defined(quantization)) {
  607. continue;
  608. }
  609. var attributeVarName = getAttributeVariableName(
  610. gltf,
  611. primitive,
  612. attributeSemantic
  613. );
  614. if (attributeSemantic.charAt(0) === "_") {
  615. attributeSemantic = attributeSemantic.substring(1);
  616. }
  617. var decodeUniformVarName =
  618. "gltf_u_dec_" + attributeSemantic.toLowerCase();
  619. if (!defined(quantizedUniforms[decodeUniformVarName])) {
  620. var newMain = "gltf_decoded_" + attributeSemantic;
  621. var decodedAttributeVarName = attributeVarName.replace(
  622. "a_",
  623. "gltf_a_dec_"
  624. );
  625. var size = attribute.componentsPerAttribute;
  626. // replace usages of the original attribute with the decoded version, but not the declaration
  627. shader = replaceAllButFirstInString(
  628. shader,
  629. attributeVarName,
  630. decodedAttributeVarName
  631. );
  632. // declare decoded attribute
  633. var variableType;
  634. if (quantization.octEncoded) {
  635. variableType = "vec3";
  636. } else if (size > 1) {
  637. variableType = "vec" + size;
  638. } else {
  639. variableType = "float";
  640. }
  641. shader = variableType + " " + decodedAttributeVarName + ";\n" + shader;
  642. // The gltf 2.0 COLOR_0 vertex attribute can be VEC4 or VEC3
  643. var vec3Color = size === 3 && attributeSemantic === "COLOR_0";
  644. if (vec3Color) {
  645. shader = replaceAllButFirstInString(
  646. shader,
  647. decodedAttributeVarName,
  648. "vec4(" + decodedAttributeVarName + ", 1.0)"
  649. );
  650. }
  651. // splice decode function into the shader
  652. var decode = "";
  653. if (quantization.octEncoded) {
  654. var decodeUniformVarNameRangeConstant =
  655. decodeUniformVarName + "_rangeConstant";
  656. shader =
  657. "uniform float " +
  658. decodeUniformVarNameRangeConstant +
  659. ";\n" +
  660. shader;
  661. decode =
  662. "\n" +
  663. "void main() {\n" +
  664. // Draco oct-encoding decodes to zxy order
  665. " " +
  666. decodedAttributeVarName +
  667. " = czm_octDecode(" +
  668. attributeVarName +
  669. ".xy, " +
  670. decodeUniformVarNameRangeConstant +
  671. ").zxy;\n" +
  672. " " +
  673. newMain +
  674. "();\n" +
  675. "}\n";
  676. } else {
  677. var decodeUniformVarNameNormConstant =
  678. decodeUniformVarName + "_normConstant";
  679. var decodeUniformVarNameMin = decodeUniformVarName + "_min";
  680. shader =
  681. "uniform float " +
  682. decodeUniformVarNameNormConstant +
  683. ";\n" +
  684. "uniform " +
  685. variableType +
  686. " " +
  687. decodeUniformVarNameMin +
  688. ";\n" +
  689. shader;
  690. var attributeVarAccess = vec3Color ? ".xyz" : "";
  691. decode =
  692. "\n" +
  693. "void main() {\n" +
  694. " " +
  695. decodedAttributeVarName +
  696. " = " +
  697. decodeUniformVarNameMin +
  698. " + " +
  699. attributeVarName +
  700. attributeVarAccess +
  701. " * " +
  702. decodeUniformVarNameNormConstant +
  703. ";\n" +
  704. " " +
  705. newMain +
  706. "();\n" +
  707. "}\n";
  708. }
  709. shader = ShaderSource.replaceMain(shader, newMain);
  710. shader += decode;
  711. }
  712. }
  713. }
  714. return {
  715. shader: shader,
  716. };
  717. };
  718. ModelUtility.modifyShaderForQuantizedAttributes = function (
  719. gltf,
  720. primitive,
  721. shader
  722. ) {
  723. var quantizedUniforms = {};
  724. var attributes = primitive.attributes;
  725. for (var attributeSemantic in attributes) {
  726. if (attributes.hasOwnProperty(attributeSemantic)) {
  727. var attributeVarName = getAttributeVariableName(
  728. gltf,
  729. primitive,
  730. attributeSemantic
  731. );
  732. var accessorId = primitive.attributes[attributeSemantic];
  733. if (attributeSemantic.charAt(0) === "_") {
  734. attributeSemantic = attributeSemantic.substring(1);
  735. }
  736. var decodeUniformVarName =
  737. "gltf_u_dec_" + attributeSemantic.toLowerCase();
  738. var decodeUniformVarNameScale = decodeUniformVarName + "_scale";
  739. var decodeUniformVarNameTranslate = decodeUniformVarName + "_translate";
  740. if (
  741. !defined(quantizedUniforms[decodeUniformVarName]) &&
  742. !defined(quantizedUniforms[decodeUniformVarNameScale])
  743. ) {
  744. var quantizedAttributes = getQuantizedAttributes(gltf, accessorId);
  745. if (defined(quantizedAttributes)) {
  746. var decodeMatrix = quantizedAttributes.decodeMatrix;
  747. var newMain = "gltf_decoded_" + attributeSemantic;
  748. var decodedAttributeVarName = attributeVarName.replace(
  749. "a_",
  750. "gltf_a_dec_"
  751. );
  752. var size = Math.floor(Math.sqrt(decodeMatrix.length));
  753. // replace usages of the original attribute with the decoded version, but not the declaration
  754. shader = replaceAllButFirstInString(
  755. shader,
  756. attributeVarName,
  757. decodedAttributeVarName
  758. );
  759. // declare decoded attribute
  760. var variableType;
  761. if (size > 2) {
  762. variableType = "vec" + (size - 1);
  763. } else {
  764. variableType = "float";
  765. }
  766. shader =
  767. variableType + " " + decodedAttributeVarName + ";\n" + shader;
  768. // splice decode function into the shader - attributes are pre-multiplied with the decode matrix
  769. // uniform in the shader (32-bit floating point)
  770. var decode = "";
  771. if (size === 5) {
  772. // separate scale and translate since glsl doesn't have mat5
  773. shader =
  774. "uniform mat4 " + decodeUniformVarNameScale + ";\n" + shader;
  775. shader =
  776. "uniform vec4 " + decodeUniformVarNameTranslate + ";\n" + shader;
  777. decode =
  778. "\n" +
  779. "void main() {\n" +
  780. " " +
  781. decodedAttributeVarName +
  782. " = " +
  783. decodeUniformVarNameScale +
  784. " * " +
  785. attributeVarName +
  786. " + " +
  787. decodeUniformVarNameTranslate +
  788. ";\n" +
  789. " " +
  790. newMain +
  791. "();\n" +
  792. "}\n";
  793. quantizedUniforms[decodeUniformVarNameScale] = { mat: 4 };
  794. quantizedUniforms[decodeUniformVarNameTranslate] = { vec: 4 };
  795. } else {
  796. shader =
  797. "uniform mat" +
  798. size +
  799. " " +
  800. decodeUniformVarName +
  801. ";\n" +
  802. shader;
  803. decode =
  804. "\n" +
  805. "void main() {\n" +
  806. " " +
  807. decodedAttributeVarName +
  808. " = " +
  809. variableType +
  810. "(" +
  811. decodeUniformVarName +
  812. " * vec" +
  813. size +
  814. "(" +
  815. attributeVarName +
  816. ",1.0));\n" +
  817. " " +
  818. newMain +
  819. "();\n" +
  820. "}\n";
  821. quantizedUniforms[decodeUniformVarName] = { mat: size };
  822. }
  823. shader = ShaderSource.replaceMain(shader, newMain);
  824. shader += decode;
  825. }
  826. }
  827. }
  828. }
  829. return {
  830. shader: shader,
  831. uniforms: quantizedUniforms,
  832. };
  833. };
  834. function getScalarUniformFunction(value) {
  835. var that = {
  836. value: value,
  837. clone: function (source, result) {
  838. return source;
  839. },
  840. func: function () {
  841. return that.value;
  842. },
  843. };
  844. return that;
  845. }
  846. function getVec2UniformFunction(value) {
  847. var that = {
  848. value: Cartesian2.fromArray(value),
  849. clone: Cartesian2.clone,
  850. func: function () {
  851. return that.value;
  852. },
  853. };
  854. return that;
  855. }
  856. function getVec3UniformFunction(value) {
  857. var that = {
  858. value: Cartesian3.fromArray(value),
  859. clone: Cartesian3.clone,
  860. func: function () {
  861. return that.value;
  862. },
  863. };
  864. return that;
  865. }
  866. function getVec4UniformFunction(value) {
  867. var that = {
  868. value: Cartesian4.fromArray(value),
  869. clone: Cartesian4.clone,
  870. func: function () {
  871. return that.value;
  872. },
  873. };
  874. return that;
  875. }
  876. function getMat2UniformFunction(value) {
  877. var that = {
  878. value: Matrix2.fromColumnMajorArray(value),
  879. clone: Matrix2.clone,
  880. func: function () {
  881. return that.value;
  882. },
  883. };
  884. return that;
  885. }
  886. function getMat3UniformFunction(value) {
  887. var that = {
  888. value: Matrix3.fromColumnMajorArray(value),
  889. clone: Matrix3.clone,
  890. func: function () {
  891. return that.value;
  892. },
  893. };
  894. return that;
  895. }
  896. function getMat4UniformFunction(value) {
  897. var that = {
  898. value: Matrix4.fromColumnMajorArray(value),
  899. clone: Matrix4.clone,
  900. func: function () {
  901. return that.value;
  902. },
  903. };
  904. return that;
  905. }
  906. ///////////////////////////////////////////////////////////////////////////
  907. function DelayLoadedTextureUniform(value, textures, defaultTexture) {
  908. this._value = undefined;
  909. this._textureId = value.index;
  910. this._textures = textures;
  911. this._defaultTexture = defaultTexture;
  912. }
  913. Object.defineProperties(DelayLoadedTextureUniform.prototype, {
  914. value: {
  915. get: function () {
  916. // Use the default texture (1x1 white) until the model's texture is loaded
  917. if (!defined(this._value)) {
  918. var texture = this._textures[this._textureId];
  919. if (defined(texture)) {
  920. this._value = texture;
  921. } else {
  922. return this._defaultTexture;
  923. }
  924. }
  925. return this._value;
  926. },
  927. set: function (value) {
  928. this._value = value;
  929. },
  930. },
  931. });
  932. DelayLoadedTextureUniform.prototype.clone = function (source) {
  933. return source;
  934. };
  935. DelayLoadedTextureUniform.prototype.func = undefined;
  936. ///////////////////////////////////////////////////////////////////////////
  937. function getTextureUniformFunction(value, textures, defaultTexture) {
  938. var uniform = new DelayLoadedTextureUniform(value, textures, defaultTexture);
  939. // Define function here to access closure since 'this' can't be
  940. // used when the Renderer sets uniforms.
  941. uniform.func = function () {
  942. return uniform.value;
  943. };
  944. return uniform;
  945. }
  946. var gltfUniformFunctions = {};
  947. gltfUniformFunctions[WebGLConstants.FLOAT] = getScalarUniformFunction;
  948. gltfUniformFunctions[WebGLConstants.FLOAT_VEC2] = getVec2UniformFunction;
  949. gltfUniformFunctions[WebGLConstants.FLOAT_VEC3] = getVec3UniformFunction;
  950. gltfUniformFunctions[WebGLConstants.FLOAT_VEC4] = getVec4UniformFunction;
  951. gltfUniformFunctions[WebGLConstants.INT] = getScalarUniformFunction;
  952. gltfUniformFunctions[WebGLConstants.INT_VEC2] = getVec2UniformFunction;
  953. gltfUniformFunctions[WebGLConstants.INT_VEC3] = getVec3UniformFunction;
  954. gltfUniformFunctions[WebGLConstants.INT_VEC4] = getVec4UniformFunction;
  955. gltfUniformFunctions[WebGLConstants.BOOL] = getScalarUniformFunction;
  956. gltfUniformFunctions[WebGLConstants.BOOL_VEC2] = getVec2UniformFunction;
  957. gltfUniformFunctions[WebGLConstants.BOOL_VEC3] = getVec3UniformFunction;
  958. gltfUniformFunctions[WebGLConstants.BOOL_VEC4] = getVec4UniformFunction;
  959. gltfUniformFunctions[WebGLConstants.FLOAT_MAT2] = getMat2UniformFunction;
  960. gltfUniformFunctions[WebGLConstants.FLOAT_MAT3] = getMat3UniformFunction;
  961. gltfUniformFunctions[WebGLConstants.FLOAT_MAT4] = getMat4UniformFunction;
  962. gltfUniformFunctions[WebGLConstants.SAMPLER_2D] = getTextureUniformFunction;
  963. // GLTF_SPEC: Support SAMPLER_CUBE. https://github.com/KhronosGroup/glTF/issues/40
  964. ModelUtility.createUniformFunction = function (
  965. type,
  966. value,
  967. textures,
  968. defaultTexture
  969. ) {
  970. return gltfUniformFunctions[type](value, textures, defaultTexture);
  971. };
  972. function scaleFromMatrix5Array(matrix) {
  973. return [
  974. matrix[0],
  975. matrix[1],
  976. matrix[2],
  977. matrix[3],
  978. matrix[5],
  979. matrix[6],
  980. matrix[7],
  981. matrix[8],
  982. matrix[10],
  983. matrix[11],
  984. matrix[12],
  985. matrix[13],
  986. matrix[15],
  987. matrix[16],
  988. matrix[17],
  989. matrix[18],
  990. ];
  991. }
  992. function translateFromMatrix5Array(matrix) {
  993. return [matrix[20], matrix[21], matrix[22], matrix[23]];
  994. }
  995. ModelUtility.createUniformsForDracoQuantizedAttributes = function (
  996. decodedAttributes
  997. ) {
  998. var uniformMap = {};
  999. for (var attribute in decodedAttributes) {
  1000. if (decodedAttributes.hasOwnProperty(attribute)) {
  1001. var decodedData = decodedAttributes[attribute];
  1002. var quantization = decodedData.quantization;
  1003. if (!defined(quantization)) {
  1004. continue;
  1005. }
  1006. if (attribute.charAt(0) === "_") {
  1007. attribute = attribute.substring(1);
  1008. }
  1009. var uniformVarName = "gltf_u_dec_" + attribute.toLowerCase();
  1010. if (quantization.octEncoded) {
  1011. var uniformVarNameRangeConstant = uniformVarName + "_rangeConstant";
  1012. var rangeConstant = (1 << quantization.quantizationBits) - 1.0;
  1013. uniformMap[uniformVarNameRangeConstant] = getScalarUniformFunction(
  1014. rangeConstant
  1015. ).func;
  1016. continue;
  1017. }
  1018. var uniformVarNameNormConstant = uniformVarName + "_normConstant";
  1019. var normConstant =
  1020. quantization.range / (1 << quantization.quantizationBits);
  1021. uniformMap[uniformVarNameNormConstant] = getScalarUniformFunction(
  1022. normConstant
  1023. ).func;
  1024. var uniformVarNameMin = uniformVarName + "_min";
  1025. switch (decodedData.componentsPerAttribute) {
  1026. case 1:
  1027. uniformMap[uniformVarNameMin] = getScalarUniformFunction(
  1028. quantization.minValues
  1029. ).func;
  1030. break;
  1031. case 2:
  1032. uniformMap[uniformVarNameMin] = getVec2UniformFunction(
  1033. quantization.minValues
  1034. ).func;
  1035. break;
  1036. case 3:
  1037. uniformMap[uniformVarNameMin] = getVec3UniformFunction(
  1038. quantization.minValues
  1039. ).func;
  1040. break;
  1041. case 4:
  1042. uniformMap[uniformVarNameMin] = getVec4UniformFunction(
  1043. quantization.minValues
  1044. ).func;
  1045. break;
  1046. }
  1047. }
  1048. }
  1049. return uniformMap;
  1050. };
  1051. ModelUtility.createUniformsForQuantizedAttributes = function (
  1052. gltf,
  1053. primitive,
  1054. quantizedUniforms
  1055. ) {
  1056. var accessors = gltf.accessors;
  1057. var setUniforms = {};
  1058. var uniformMap = {};
  1059. var attributes = primitive.attributes;
  1060. for (var attribute in attributes) {
  1061. if (attributes.hasOwnProperty(attribute)) {
  1062. var accessorId = attributes[attribute];
  1063. var a = accessors[accessorId];
  1064. var extensions = a.extensions;
  1065. if (attribute.charAt(0) === "_") {
  1066. attribute = attribute.substring(1);
  1067. }
  1068. if (defined(extensions)) {
  1069. var quantizedAttributes = extensions.WEB3D_quantized_attributes;
  1070. if (defined(quantizedAttributes)) {
  1071. var decodeMatrix = quantizedAttributes.decodeMatrix;
  1072. var uniformVariable = "gltf_u_dec_" + attribute.toLowerCase();
  1073. switch (a.type) {
  1074. case AttributeType.SCALAR:
  1075. uniformMap[uniformVariable] = getMat2UniformFunction(
  1076. decodeMatrix
  1077. ).func;
  1078. setUniforms[uniformVariable] = true;
  1079. break;
  1080. case AttributeType.VEC2:
  1081. uniformMap[uniformVariable] = getMat3UniformFunction(
  1082. decodeMatrix
  1083. ).func;
  1084. setUniforms[uniformVariable] = true;
  1085. break;
  1086. case AttributeType.VEC3:
  1087. uniformMap[uniformVariable] = getMat4UniformFunction(
  1088. decodeMatrix
  1089. ).func;
  1090. setUniforms[uniformVariable] = true;
  1091. break;
  1092. case AttributeType.VEC4:
  1093. // VEC4 attributes are split into scale and translate because there is no mat5 in GLSL
  1094. var uniformVariableScale = uniformVariable + "_scale";
  1095. var uniformVariableTranslate = uniformVariable + "_translate";
  1096. uniformMap[uniformVariableScale] = getMat4UniformFunction(
  1097. scaleFromMatrix5Array(decodeMatrix)
  1098. ).func;
  1099. uniformMap[uniformVariableTranslate] = getVec4UniformFunction(
  1100. translateFromMatrix5Array(decodeMatrix)
  1101. ).func;
  1102. setUniforms[uniformVariableScale] = true;
  1103. setUniforms[uniformVariableTranslate] = true;
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. // If there are any unset quantized uniforms in this program, they should be set to the identity
  1111. for (var quantizedUniform in quantizedUniforms) {
  1112. if (quantizedUniforms.hasOwnProperty(quantizedUniform)) {
  1113. if (!setUniforms[quantizedUniform]) {
  1114. var properties = quantizedUniforms[quantizedUniform];
  1115. if (defined(properties.mat)) {
  1116. if (properties.mat === 2) {
  1117. uniformMap[quantizedUniform] = getMat2UniformFunction(
  1118. Matrix2.IDENTITY
  1119. ).func;
  1120. } else if (properties.mat === 3) {
  1121. uniformMap[quantizedUniform] = getMat3UniformFunction(
  1122. Matrix3.IDENTITY
  1123. ).func;
  1124. } else if (properties.mat === 4) {
  1125. uniformMap[quantizedUniform] = getMat4UniformFunction(
  1126. Matrix4.IDENTITY
  1127. ).func;
  1128. }
  1129. }
  1130. if (defined(properties.vec)) {
  1131. if (properties.vec === 4) {
  1132. uniformMap[quantizedUniform] = getVec4UniformFunction([
  1133. 0,
  1134. 0,
  1135. 0,
  1136. 0,
  1137. ]).func;
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. return uniformMap;
  1144. };
  1145. // This doesn't support LOCAL, which we could add if it is ever used.
  1146. var scratchTranslationRtc = new Cartesian3();
  1147. var gltfSemanticUniforms = {
  1148. MODEL: function (uniformState, model) {
  1149. return function () {
  1150. return uniformState.model;
  1151. };
  1152. },
  1153. VIEW: function (uniformState, model) {
  1154. return function () {
  1155. return uniformState.view;
  1156. };
  1157. },
  1158. PROJECTION: function (uniformState, model) {
  1159. return function () {
  1160. return uniformState.projection;
  1161. };
  1162. },
  1163. MODELVIEW: function (uniformState, model) {
  1164. return function () {
  1165. return uniformState.modelView;
  1166. };
  1167. },
  1168. CESIUM_RTC_MODELVIEW: function (uniformState, model) {
  1169. // CESIUM_RTC extension
  1170. var mvRtc = new Matrix4();
  1171. return function () {
  1172. if (defined(model._rtcCenter)) {
  1173. Matrix4.getTranslation(uniformState.model, scratchTranslationRtc);
  1174. Cartesian3.add(
  1175. scratchTranslationRtc,
  1176. model._rtcCenter,
  1177. scratchTranslationRtc
  1178. );
  1179. Matrix4.multiplyByPoint(
  1180. uniformState.view,
  1181. scratchTranslationRtc,
  1182. scratchTranslationRtc
  1183. );
  1184. return Matrix4.setTranslation(
  1185. uniformState.modelView,
  1186. scratchTranslationRtc,
  1187. mvRtc
  1188. );
  1189. }
  1190. return uniformState.modelView;
  1191. };
  1192. },
  1193. MODELVIEWPROJECTION: function (uniformState, model) {
  1194. return function () {
  1195. return uniformState.modelViewProjection;
  1196. };
  1197. },
  1198. MODELINVERSE: function (uniformState, model) {
  1199. return function () {
  1200. return uniformState.inverseModel;
  1201. };
  1202. },
  1203. VIEWINVERSE: function (uniformState, model) {
  1204. return function () {
  1205. return uniformState.inverseView;
  1206. };
  1207. },
  1208. PROJECTIONINVERSE: function (uniformState, model) {
  1209. return function () {
  1210. return uniformState.inverseProjection;
  1211. };
  1212. },
  1213. MODELVIEWINVERSE: function (uniformState, model) {
  1214. return function () {
  1215. return uniformState.inverseModelView;
  1216. };
  1217. },
  1218. MODELVIEWPROJECTIONINVERSE: function (uniformState, model) {
  1219. return function () {
  1220. return uniformState.inverseModelViewProjection;
  1221. };
  1222. },
  1223. MODELINVERSETRANSPOSE: function (uniformState, model) {
  1224. return function () {
  1225. return uniformState.inverseTransposeModel;
  1226. };
  1227. },
  1228. MODELVIEWINVERSETRANSPOSE: function (uniformState, model) {
  1229. return function () {
  1230. return uniformState.normal;
  1231. };
  1232. },
  1233. VIEWPORT: function (uniformState, model) {
  1234. return function () {
  1235. return uniformState.viewportCartesian4;
  1236. };
  1237. },
  1238. // JOINTMATRIX created in createCommand()
  1239. };
  1240. ModelUtility.getGltfSemanticUniforms = function () {
  1241. return gltfSemanticUniforms;
  1242. };
  1243. export default ModelUtility;