ModelUtility.js 39 KB

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