ModelComponents.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. import AlphaMode from "./AlphaMode.js";
  2. import Cartesian3 from "../Core/Cartesian3.js";
  3. import Cartesian4 from "../Core/Cartesian4.js";
  4. import Matrix3 from "../Core/Matrix3.js";
  5. import Matrix4 from "../Core/Matrix4.js";
  6. /**
  7. * Components for building models.
  8. *
  9. * @namespace ModelComponents
  10. *
  11. * @private
  12. */
  13. const ModelComponents = {};
  14. /**
  15. * Information about the quantized attribute.
  16. *
  17. * @alias ModelComponents.Quantization
  18. * @constructor
  19. *
  20. * @private
  21. */
  22. function Quantization() {
  23. /**
  24. * Whether the quantized attribute is oct-encoded.
  25. *
  26. * @type {boolean}
  27. * @private
  28. */
  29. this.octEncoded = false;
  30. /**
  31. * Whether the oct-encoded values are stored as ZXY instead of XYZ. This is true when decoding from Draco.
  32. *
  33. * @type {boolean}
  34. * @private
  35. */
  36. this.octEncodedZXY = false;
  37. /**
  38. * The range used to convert buffer values to normalized values [0.0, 1.0]
  39. * This is typically computed as (1 << quantizationBits) - 1.
  40. * For oct-encoded values this value is a single Number.
  41. *
  42. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  43. * @private
  44. */
  45. this.normalizationRange = undefined;
  46. /**
  47. * The bottom-left corner of the quantization volume. Not applicable for oct encoded attributes.
  48. * The type should match the attribute type - e.g. if the attribute type
  49. * is AttributeType.VEC4 the offset should be a Cartesian4.
  50. *
  51. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  52. * @private
  53. */
  54. this.quantizedVolumeOffset = undefined;
  55. /**
  56. * The dimensions of the quantization volume. Not applicable for oct encoded attributes.
  57. * The type should match the attribute type - e.g. if the attribute type
  58. * is AttributeType.VEC4 the dimensions should be a Cartesian4.
  59. *
  60. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  61. * @private
  62. */
  63. this.quantizedVolumeDimensions = undefined;
  64. /**
  65. * The step size of the quantization volume, equal to
  66. * quantizedVolumeDimensions / normalizationRange (component-wise).
  67. * Not applicable for oct encoded attributes.
  68. * The type should match the attribute type - e.g. if the attribute type
  69. * is AttributeType.VEC4 the dimensions should be a Cartesian4.
  70. *
  71. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  72. * @private
  73. */
  74. this.quantizedVolumeStepSize = undefined;
  75. /**
  76. * The component data type of the quantized attribute, e.g. ComponentDatatype.UNSIGNED_SHORT.
  77. *
  78. * <p>
  79. * The following component datatypes are not supported:
  80. * <ul>
  81. * <li>ComponentDatatype.INT</li>
  82. * <li>ComponentDatatype.UNSIGNED_INT</li>
  83. * <li>ComponentDatatype.DOUBLE</li>
  84. * </ul>
  85. * </p>
  86. *
  87. * @type {ComponentDatatype}
  88. * @private
  89. */
  90. this.componentDatatype = undefined;
  91. /**
  92. * The type of the quantized attribute, e.g. AttributeType.VEC2 for oct-encoded normals.
  93. *
  94. * @type {AttributeType}
  95. * @private
  96. */
  97. this.type = undefined;
  98. }
  99. /**
  100. * A per-vertex or per-instance attribute.
  101. *
  102. * @alias ModelComponents.Attribute
  103. * @constructor
  104. *
  105. * @private
  106. */
  107. function Attribute() {
  108. /**
  109. * The attribute name. Must be unique within the attributes array.
  110. *
  111. * @type {string}
  112. * @private
  113. */
  114. this.name = undefined;
  115. /**
  116. * The attribute semantic. The combination of semantic and setIndex must be
  117. * unique within the attributes array.
  118. *
  119. * @type {VertexAttributeSemantic|InstanceAttributeSemantic}
  120. * @private
  121. */
  122. this.semantic = undefined;
  123. /**
  124. * The set index of the attribute. Only applicable when the attribute has one
  125. * of the following semantics:
  126. *
  127. * <ul>
  128. * <li>{@link VertexAttributeSemantic.TEXCOORD}</li>
  129. * <li>{@link VertexAttributeSemantic.COLOR}</li>
  130. * <li>{@link VertexAttributeSemantic.JOINTS}</li>
  131. * <li>{@link VertexAttributeSemantic.WEIGHTS}</li>
  132. * <li>{@link VertexAttributeSemantic.FEATURE_ID}</li>
  133. * <li>{@link InstanceAttributeSemantic.FEATURE_ID}</li>
  134. * </ul>
  135. */
  136. this.setIndex = undefined;
  137. /**
  138. * The component data type of the attribute.
  139. * <p>
  140. * When the data is quantized the componentDatatype should match the
  141. * dequantized data, which is typically ComponentDatatype.FLOAT.
  142. * </p>
  143. * <p>
  144. * The following component datatypes are not supported:
  145. * <ul>
  146. * <li>ComponentDatatype.INT</li>
  147. * <li>ComponentDatatype.UNSIGNED_INT</li>
  148. * <li>ComponentDatatype.DOUBLE</li>
  149. * </ul>
  150. * </p>
  151. *
  152. * @type {ComponentDatatype}
  153. * @private
  154. */
  155. this.componentDatatype = undefined;
  156. /**
  157. * The type of the attribute.
  158. * <p>
  159. * When the data is oct-encoded the type should match the decoded data, which
  160. * is typically AttributeType.VEC3.
  161. * </p>
  162. *
  163. * @type {AttributeType}
  164. * @private
  165. */
  166. this.type = undefined;
  167. /**
  168. * Whether the attribute is normalized.
  169. *
  170. * @type {boolean}
  171. * @default false
  172. * @private
  173. */
  174. this.normalized = false;
  175. /**
  176. * The number of elements.
  177. *
  178. * @type {number}
  179. * @private
  180. */
  181. this.count = undefined;
  182. /**
  183. * Minimum value of each component in the attribute.
  184. * <p>
  185. * When the data is quantized the min should match the dequantized data.
  186. * The normalized property has no effect on these values.
  187. * </p>
  188. * <p>
  189. * Must be defined for POSITION attributes.
  190. * </p>
  191. *
  192. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  193. * @private
  194. */
  195. this.min = undefined;
  196. /**
  197. * Maximum value of each component in the attribute.
  198. * <p>
  199. * When the data is quantized the max should match the dequantized data.
  200. * The normalized property has no effect on these values.
  201. * </p>
  202. * <p>
  203. * Must be defined for POSITION attributes.
  204. * </p>
  205. *
  206. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  207. * @private
  208. */
  209. this.max = undefined;
  210. /**
  211. * A constant value used for all elements when typed array and buffer are undefined.
  212. *
  213. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  214. * @private
  215. */
  216. this.constant = undefined;
  217. /**
  218. * Information about the quantized attribute.
  219. *
  220. * @type {ModelComponents.Quantization}
  221. * @private
  222. */
  223. this.quantization = undefined;
  224. /**
  225. * A typed array containing tightly-packed attribute values, as they appear
  226. * in the model file.
  227. *
  228. * @type {Uint8Array|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array}
  229. * @private
  230. */
  231. this.typedArray = undefined;
  232. /**
  233. * A vertex buffer. Attribute values are accessed using byteOffset and byteStride.
  234. *
  235. * @type {Buffer}
  236. * @private
  237. */
  238. this.buffer = undefined;
  239. /**
  240. * The byte offset of elements in the buffer.
  241. *
  242. * @type {number}
  243. * @default 0
  244. * @private
  245. */
  246. this.byteOffset = 0;
  247. /**
  248. * The byte stride of elements in the buffer. When undefined the elements are tightly packed.
  249. *
  250. * @type {number}
  251. * @private
  252. */
  253. this.byteStride = undefined;
  254. }
  255. /**
  256. * Indices used to select vertices for rendering.
  257. *
  258. * @alias ModelComponents.Indices
  259. * @constructor
  260. *
  261. * @private
  262. */
  263. function Indices() {
  264. /**
  265. * The index data type of the attribute, e.g. IndexDatatype.UNSIGNED_SHORT.
  266. *
  267. * @type {IndexDatatype}
  268. * @private
  269. */
  270. this.indexDatatype = undefined;
  271. /**
  272. * The number of indices.
  273. *
  274. * @type {number}
  275. * @private
  276. */
  277. this.count = undefined;
  278. /**
  279. * An index buffer containing indices.
  280. *
  281. * @type {Buffer}
  282. * @private
  283. */
  284. this.buffer = undefined;
  285. /**
  286. * A typed array containing indices.
  287. *
  288. * @type {Uint8Array|Uint16Array|Uint32Array}
  289. * @private
  290. */
  291. this.typedArray = undefined;
  292. }
  293. /**
  294. * Maps per-vertex or per-instance feature IDs to a property table. Feature
  295. * IDs are stored in an accessor.
  296. *
  297. * @alias ModelComponents.FeatureIdAttribute
  298. * @constructor
  299. *
  300. * @private
  301. */
  302. function FeatureIdAttribute() {
  303. /**
  304. * How many unique features are defined in this set of feature IDs
  305. *
  306. * @type {number}
  307. * @private
  308. */
  309. this.featureCount = undefined;
  310. /**
  311. * This value indicates that no feature is indicated with this vertex
  312. *
  313. * @type {number}
  314. * @private
  315. */
  316. this.nullFeatureId = undefined;
  317. /**
  318. * The ID of the property table that feature IDs index into. If undefined,
  319. * feature IDs are used for classification, but no metadata is associated.
  320. *
  321. *
  322. * @type {number}
  323. * @private
  324. */
  325. this.propertyTableId = undefined;
  326. /**
  327. * The set index of feature ID attribute containing feature IDs.
  328. *
  329. * @type {number}
  330. * @private
  331. */
  332. this.setIndex = undefined;
  333. /**
  334. * The label to identify this set of feature IDs. This is used in picking,
  335. * styling and shaders.
  336. *
  337. * @type {string}
  338. * @private
  339. */
  340. this.label = undefined;
  341. /**
  342. * Label to identify this set of feature IDs by its position in the array.
  343. * This will always be either "featureId_N" for primitives or
  344. * "instanceFeatureId_N" for instances.
  345. *
  346. * @type {string}
  347. * @private
  348. */
  349. this.positionalLabel = undefined;
  350. }
  351. /**
  352. * Defines a range of implicitly-defined feature IDs, one for each vertex or
  353. * instance. Such feature IDs may optionally be associated with a property table
  354. * storing metadata
  355. *
  356. * @alias ModelComponents.FeatureIdImplicitRange
  357. * @constructor
  358. *
  359. * @private
  360. */
  361. function FeatureIdImplicitRange() {
  362. /**
  363. * How many unique features are defined in this set of feature IDs
  364. *
  365. * @type {number}
  366. * @private
  367. */
  368. this.featureCount = undefined;
  369. /**
  370. * This value indicates that no feature is indicated with this vertex
  371. *
  372. * @type {number}
  373. * @private
  374. */
  375. this.nullFeatureId = undefined;
  376. /**
  377. * The ID of the property table that feature IDs index into. If undefined,
  378. * feature IDs are used for classification, but no metadata is associated.
  379. *
  380. * @type {number}
  381. * @private
  382. */
  383. this.propertyTableId = undefined;
  384. /**
  385. * The first feature ID to use when setIndex is undefined
  386. *
  387. * @type {number}
  388. * @default 0
  389. * @private
  390. */
  391. this.offset = 0;
  392. /**
  393. * Number of times each feature ID is repeated before being incremented.
  394. *
  395. * @type {number}
  396. * @private
  397. */
  398. this.repeat = undefined;
  399. /**
  400. * The label to identify this set of feature IDs. This is used in picking,
  401. * styling and shaders.
  402. *
  403. * @type {string}
  404. * @private
  405. */
  406. this.label = undefined;
  407. /**
  408. * Label to identify this set of feature IDs by its position in the array.
  409. * This will always be either "featureId_N" for primitives or
  410. * "instanceFeatureId_N" for instances.
  411. *
  412. * @type {string}
  413. * @private
  414. */
  415. this.positionalLabel = undefined;
  416. }
  417. /**
  418. * A texture that contains per-texel feature IDs that index into a property table.
  419. *
  420. * @alias ModelComponents.FeatureIdTexture
  421. * @constructor
  422. *
  423. * @private
  424. */
  425. function FeatureIdTexture() {
  426. /**
  427. * How many unique features are defined in this set of feature IDs
  428. *
  429. * @type {number}
  430. * @private
  431. */
  432. this.featureCount = undefined;
  433. /**
  434. * This value indicates that no feature is indicated with this texel
  435. *
  436. * @type {number}
  437. * @private
  438. */
  439. this.nullFeatureId = undefined;
  440. /**
  441. * The ID of the property table that feature IDs index into. If undefined,
  442. * feature IDs are used for classification, but no metadata is associated.
  443. *
  444. * @type {string}
  445. * @private
  446. */
  447. this.propertyTableId = undefined;
  448. /**
  449. * The texture reader containing feature IDs.
  450. *
  451. * @type {ModelComponents.TextureReader}
  452. * @private
  453. */
  454. this.textureReader = undefined;
  455. /**
  456. * The label to identify this set of feature IDs. This is used in picking,
  457. * styling and shaders.
  458. *
  459. * @type {string}
  460. * @private
  461. */
  462. this.label = undefined;
  463. /**
  464. * Label to identify this set of feature IDs by its position in the array.
  465. * This will always be either "featureId_N" for primitives or
  466. * "instanceFeatureId_N" for instances.
  467. *
  468. * @type {string}
  469. * @private
  470. */
  471. this.positionalLabel = undefined;
  472. }
  473. /**
  474. * A morph target where each attribute contains attribute displacement data.
  475. *
  476. * @alias ModelComponents.MorphTarget
  477. * @constructor
  478. *
  479. * @private
  480. */
  481. function MorphTarget() {
  482. /**
  483. * Attributes that are part of the morph target, e.g. positions, normals, and tangents.
  484. *
  485. * @type {ModelComponents.Attribute[]}
  486. * @private
  487. */
  488. this.attributes = [];
  489. }
  490. /**
  491. * Geometry to be rendered with a material.
  492. *
  493. * @alias ModelComponents.Primitive
  494. * @constructor
  495. *
  496. * @private
  497. */
  498. function Primitive() {
  499. /**
  500. * The vertex attributes, e.g. positions, normals, etc.
  501. *
  502. * @type {ModelComponents.Attribute[]}
  503. * @private
  504. */
  505. this.attributes = [];
  506. /**
  507. * The morph targets.
  508. *
  509. * @type {ModelComponents.MorphTarget[]}
  510. * @private
  511. */
  512. this.morphTargets = [];
  513. /**
  514. * The indices.
  515. *
  516. * @type {ModelComponents.Indices}
  517. * @private
  518. */
  519. this.indices = undefined;
  520. /**
  521. * The material.
  522. *
  523. * @type {ModelComponents.Material}
  524. * @private
  525. */
  526. this.material = undefined;
  527. /**
  528. * The primitive type, e.g. PrimitiveType.TRIANGLES.
  529. *
  530. * @type {PrimitiveType}
  531. * @private
  532. */
  533. this.primitiveType = undefined;
  534. /**
  535. * The feature IDs associated with this primitive. Feature ID types may
  536. * be interleaved
  537. *
  538. * @type {Array<ModelComponents.FeatureIdAttribute|ModelComponents.FeatureIdImplicitRange|ModelComponents.FeatureIdTexture>}
  539. * @private
  540. */
  541. this.featureIds = [];
  542. /**
  543. * The property texture IDs. These indices correspond to the array of
  544. * property textures.
  545. *
  546. * @type {number[]}
  547. * @private
  548. */
  549. this.propertyTextureIds = [];
  550. /**
  551. * The property attribute IDs. These indices correspond to the array of
  552. * property attributes in the EXT_structural_metadata extension.
  553. *
  554. * @type {number[]}
  555. * @private
  556. */
  557. this.propertyAttributeIds = [];
  558. /**
  559. * If the CESIUM_primitive_outline glTF extension is used, this property
  560. * stores an additional attribute storing outline coordinates.
  561. *
  562. * @type {Attribute}
  563. * @private
  564. */
  565. this.outlineCoordinates = undefined;
  566. }
  567. /**
  568. * Position and metadata information for instances of a node.
  569. *
  570. * @alias ModelComponents.Instances
  571. * @constructor
  572. *
  573. * @private
  574. */
  575. function Instances() {
  576. /**
  577. * The instance attributes, e.g. translation, rotation, scale, feature id, etc.
  578. *
  579. * @type {ModelComponents.Attribute[]}
  580. * @private
  581. */
  582. this.attributes = [];
  583. /**
  584. * The feature ID attributes associated with this set of instances.
  585. * Feature ID attribute types may be interleaved.
  586. *
  587. * @type {Array<ModelComponents.FeatureIdAttribute|ModelComponents.FeatureIdImplicitRange>}
  588. * @private
  589. */
  590. this.featureIds = [];
  591. /**
  592. * Whether the instancing transforms are applied in world space. For glTF models that
  593. * use EXT_mesh_gpu_instancing, the transform is applied in object space. For i3dm files,
  594. * the instance transform is in world space.
  595. *
  596. * @type {boolean}
  597. * @private
  598. */
  599. this.transformInWorldSpace = false;
  600. }
  601. /**
  602. * Joints and matrices defining a skin.
  603. *
  604. * @alias ModelComponents.Skin
  605. * @constructor
  606. *
  607. * @private
  608. */
  609. function Skin() {
  610. /**
  611. * The index of the skin in the glTF. This is useful for finding the skin
  612. * that applies to a node after the skin is instantiated at runtime.
  613. *
  614. * @type {number}
  615. * @private
  616. */
  617. this.index = undefined;
  618. /**
  619. * The joints.
  620. *
  621. * @type {ModelComponents.Node[]}
  622. * @private
  623. */
  624. this.joints = [];
  625. /**
  626. * The inverse bind matrices of the joints.
  627. *
  628. * @type {Matrix4[]}
  629. * @private
  630. */
  631. this.inverseBindMatrices = [];
  632. }
  633. /**
  634. * A node in the node hierarchy.
  635. *
  636. * @alias ModelComponents.Node
  637. * @constructor
  638. *
  639. * @private
  640. */
  641. function Node() {
  642. /**
  643. * The name of the node.
  644. *
  645. * @type {string}
  646. * @private
  647. */
  648. this.name = undefined;
  649. /**
  650. * The index of the node in the glTF. This is useful for finding the nodes
  651. * that belong to a skin after they have been instantiated at runtime.
  652. *
  653. * @type {number}
  654. * @private
  655. */
  656. this.index = undefined;
  657. /**
  658. * The children nodes.
  659. *
  660. * @type {ModelComponents.Node[]}
  661. * @private
  662. */
  663. this.children = [];
  664. /**
  665. * The mesh primitives.
  666. *
  667. * @type {ModelComponents.Primitive[]}
  668. * @private
  669. */
  670. this.primitives = [];
  671. /**
  672. * Instances of this node.
  673. *
  674. * @type {ModelComponents.Instances}
  675. * @private
  676. */
  677. this.instances = undefined;
  678. /**
  679. * The skin.
  680. *
  681. * @type {ModelComponents.Skin}
  682. * @private
  683. */
  684. this.skin = undefined;
  685. /**
  686. * The local transformation matrix. When matrix is defined translation,
  687. * rotation, and scale must be undefined. When matrix is undefined
  688. * translation, rotation, and scale must all be defined.
  689. *
  690. * @type {Matrix4}
  691. * @private
  692. */
  693. this.matrix = undefined;
  694. /**
  695. * The local translation.
  696. *
  697. * @type {Cartesian3}
  698. * @private
  699. */
  700. this.translation = undefined;
  701. /**
  702. * The local rotation.
  703. *
  704. * @type {Quaternion}
  705. * @private
  706. */
  707. this.rotation = undefined;
  708. /**
  709. * The local scale.
  710. *
  711. * @type {Cartesian3}
  712. * @private
  713. */
  714. this.scale = undefined;
  715. /**
  716. * An array of weights to be applied to the primitives' morph targets.
  717. * These are supplied by either the node or its mesh.
  718. *
  719. * @type {number[]}
  720. * @private
  721. */
  722. this.morphWeights = [];
  723. /**
  724. * The name of the articulation affecting this node, as defined by the
  725. * AGI_articulations extension.
  726. *
  727. * @type {string}
  728. * @private
  729. */
  730. this.articulationName = undefined;
  731. }
  732. /**
  733. * A scene containing nodes.
  734. *
  735. * @alias ModelComponents.Scene
  736. * @constructor
  737. *
  738. * @private
  739. */
  740. function Scene() {
  741. /**
  742. * The nodes belonging to the scene.
  743. *
  744. * @type {ModelComponents.Node[]}
  745. * @private
  746. */
  747. this.nodes = [];
  748. }
  749. /**
  750. * The property of the node that is targeted by an animation. The values of
  751. * this enum are used to look up the appropriate property on the runtime node.
  752. *
  753. * @alias {ModelComponents.AnimatedPropertyType}
  754. * @enum {string}
  755. *
  756. * @private
  757. */
  758. const AnimatedPropertyType = {
  759. TRANSLATION: "translation",
  760. ROTATION: "rotation",
  761. SCALE: "scale",
  762. WEIGHTS: "weights",
  763. };
  764. /**
  765. * An animation sampler that describes the sources of animated keyframe data
  766. * and their interpolation.
  767. *
  768. * @alias {ModelComponents.AnimationSampler}
  769. * @constructor
  770. *
  771. * @private
  772. */
  773. function AnimationSampler() {
  774. /**
  775. * The timesteps of the animation.
  776. *
  777. * @type {number[]}
  778. * @private
  779. */
  780. this.input = [];
  781. /**
  782. * The method used to interpolate between the animation's keyframe data.
  783. *
  784. * @type {InterpolationType}
  785. * @private
  786. */
  787. this.interpolation = undefined;
  788. /**
  789. * The keyframe data of the animation.
  790. *
  791. * @type {number[]|Cartesian3[]|Quaternion[]}
  792. * @private
  793. */
  794. this.output = [];
  795. }
  796. /**
  797. * An animation target, which specifies the node and property to animate.
  798. *
  799. * @alias {ModelComponents.AnimationTarget}
  800. * @constructor
  801. *
  802. * @private
  803. */
  804. function AnimationTarget() {
  805. /**
  806. * The node that will be affected by the animation.
  807. *
  808. * @type {ModelComponents.Node}
  809. * @private
  810. */
  811. this.node = undefined;
  812. /**
  813. * The property of the node to be animated.
  814. *
  815. * @type {ModelComponents.AnimatedPropertyType}
  816. * @private
  817. */
  818. this.path = undefined;
  819. }
  820. /**
  821. * An animation channel linking an animation sampler and the target it animates.
  822. *
  823. * @alias {ModelComponents.AnimationChannel}
  824. * @constructor
  825. *
  826. * @private
  827. */
  828. function AnimationChannel() {
  829. /**
  830. * The sampler used as the source of the animation data.
  831. *
  832. * @type {ModelComponents.AnimationSampler}
  833. * @private
  834. */
  835. this.sampler = undefined;
  836. /**
  837. * The target of the animation.
  838. *
  839. * @type {ModelComponents.AnimationTarget}
  840. * @private
  841. */
  842. this.target = undefined;
  843. }
  844. /**
  845. * An animation in the model.
  846. *
  847. * @alias {ModelComponents.Animation}
  848. * @constructor
  849. *
  850. * @private
  851. */
  852. function Animation() {
  853. /**
  854. * The name of the animation.
  855. *
  856. * @type {string}
  857. * @private
  858. */
  859. this.name = undefined;
  860. /**
  861. * The samplers used in this animation.
  862. *
  863. * @type {ModelComponents.AnimationSampler[]}
  864. * @private
  865. */
  866. this.samplers = [];
  867. /**
  868. * The channels used in this animation.
  869. *
  870. * @type {ModelComponents.AnimationChannel[]}
  871. * @private
  872. */
  873. this.channels = [];
  874. }
  875. /**
  876. * An articulation stage belonging to an articulation from the
  877. * AGI_articulations extension.
  878. *
  879. * @alias {ModelComponents.ArticulationStage}
  880. * @constructor
  881. *
  882. * @private
  883. */
  884. function ArticulationStage() {
  885. /**
  886. * The name of the articulation stage.
  887. *
  888. * @type {string}
  889. * @private
  890. */
  891. this.name = undefined;
  892. /**
  893. * The type of the articulation stage, defined by the type of motion it modifies.
  894. *
  895. * @type {ArticulationStageType}
  896. * @private
  897. */
  898. this.type = undefined;
  899. /**
  900. * The minimum value for the range of motion of this articulation stage.
  901. *
  902. * @type {number}
  903. * @private
  904. */
  905. this.minimumValue = undefined;
  906. /**
  907. * The maximum value for the range of motion of this articulation stage.
  908. *
  909. * @type {number}
  910. * @private
  911. */
  912. this.maximumValue = undefined;
  913. /**
  914. * The initial value for this articulation stage.
  915. *
  916. * @type {number}
  917. * @private
  918. */
  919. this.initialValue = undefined;
  920. }
  921. /**
  922. * An articulation for the model, as defined by the AGI_articulations extension.
  923. *
  924. * @alias {ModelComponents.Articulation}
  925. * @constructor
  926. *
  927. * @private
  928. */
  929. function Articulation() {
  930. /**
  931. * The name of the articulation.
  932. *
  933. * @type {string}
  934. * @private
  935. */
  936. this.name = undefined;
  937. /**
  938. * The stages belonging to this articulation. The stages are applied to
  939. * the model in order of appearance.
  940. *
  941. * @type {ModelComponents.ArticulationStage[]}
  942. * @private
  943. */
  944. this.stages = [];
  945. }
  946. /**
  947. * The asset of the model.
  948. *
  949. * @alias {ModelComponents.Asset}
  950. * @constructor
  951. *
  952. * @private
  953. */
  954. function Asset() {
  955. /**
  956. * The credits of the model.
  957. *
  958. * @type {Credit[]}
  959. * @private
  960. */
  961. this.credits = [];
  962. }
  963. /**
  964. * The components that make up a model.
  965. *
  966. * @alias ModelComponents.Components
  967. * @constructor
  968. *
  969. * @private
  970. */
  971. function Components() {
  972. /**
  973. * The asset of the model.
  974. *
  975. * @type {ModelComponents.Asset}
  976. * @private
  977. */
  978. this.asset = new Asset();
  979. /**
  980. * The default scene.
  981. *
  982. * @type {ModelComponents.Scene}
  983. * @private
  984. */
  985. this.scene = undefined;
  986. /**
  987. * All nodes in the model.
  988. *
  989. * @type {ModelComponents.Node[]}
  990. */
  991. this.nodes = [];
  992. /**
  993. * All skins in the model.
  994. *
  995. * @type {ModelComponents.Skin[]}
  996. */
  997. this.skins = [];
  998. /**
  999. * All animations in the model.
  1000. *
  1001. * @type {ModelComponents.Animation[]}
  1002. */
  1003. this.animations = [];
  1004. /**
  1005. * All articulations in the model as defined by the AGI_articulations extension.
  1006. *
  1007. * @type {ModelComponents.Articulation[]}
  1008. */
  1009. this.articulations = [];
  1010. /**
  1011. * Structural metadata containing the schema, property tables, property
  1012. * textures and property mappings
  1013. *
  1014. * @type {StructuralMetadata}
  1015. * @private
  1016. */
  1017. this.structuralMetadata = undefined;
  1018. /**
  1019. * The model's up axis.
  1020. *
  1021. * @type {Axis}
  1022. * @private
  1023. */
  1024. this.upAxis = undefined;
  1025. /**
  1026. * The model's forward axis.
  1027. *
  1028. * @type {Axis}
  1029. * @private
  1030. */
  1031. this.forwardAxis = undefined;
  1032. /**
  1033. * A world-space transform to apply to the primitives.
  1034. *
  1035. * @type {Matrix4}
  1036. * @private
  1037. */
  1038. this.transform = Matrix4.clone(Matrix4.IDENTITY);
  1039. }
  1040. /**
  1041. * Information about a GPU texture, including the texture itself
  1042. *
  1043. * @alias ModelComponents.TextureReader
  1044. * @constructor
  1045. *
  1046. * @private
  1047. */
  1048. function TextureReader() {
  1049. /**
  1050. * The underlying GPU texture. The {@link Texture} contains the sampler.
  1051. *
  1052. * @type {Texture}
  1053. * @private
  1054. */
  1055. this.texture = undefined;
  1056. /**
  1057. * The index of the texture in the glTF. This is useful for determining
  1058. * when textures are shared to avoid attaching a texture in multiple uniform
  1059. * slots in the shader.
  1060. *
  1061. * @type {number}
  1062. * @private
  1063. */
  1064. this.index = undefined;
  1065. /**
  1066. * The texture coordinate set.
  1067. *
  1068. * @type {number}
  1069. * @default 0
  1070. * @private
  1071. */
  1072. this.texCoord = 0;
  1073. /**
  1074. * Transformation matrix to apply to texture coordinates.
  1075. *
  1076. * @type {Matrix3}
  1077. * @default Matrix3.IDENTITY
  1078. */
  1079. this.transform = Matrix3.clone(Matrix3.IDENTITY);
  1080. /**
  1081. * The texture channels to read from. When undefined all channels are read.
  1082. *
  1083. * @type {string}
  1084. */
  1085. this.channels = undefined;
  1086. }
  1087. /**
  1088. * Material properties for the PBR metallic roughness shading model.
  1089. *
  1090. * @alias ModelComponents.MetallicRoughness
  1091. * @constructor
  1092. *
  1093. * @private
  1094. */
  1095. function MetallicRoughness() {
  1096. /**
  1097. * The base color texture reader.
  1098. *
  1099. * @type {ModelComponents.TextureReader}
  1100. * @private
  1101. */
  1102. this.baseColorTexture = undefined;
  1103. /**
  1104. * The metallic roughness texture reader.
  1105. *
  1106. * @type {ModelComponents.TextureReader}
  1107. * @private
  1108. */
  1109. this.metallicRoughnessTexture = undefined;
  1110. /**
  1111. * The base color factor.
  1112. *
  1113. * @type {Cartesian4}
  1114. * @default new Cartesian4(1.0, 1.0, 1.0, 1.0)
  1115. * @private
  1116. */
  1117. this.baseColorFactor = Cartesian4.clone(
  1118. MetallicRoughness.DEFAULT_BASE_COLOR_FACTOR
  1119. );
  1120. /**
  1121. * The metallic factor.
  1122. *
  1123. * @type {number}
  1124. * @default 1.0
  1125. * @private
  1126. */
  1127. this.metallicFactor = MetallicRoughness.DEFAULT_METALLIC_FACTOR;
  1128. /**
  1129. * The roughness factor.
  1130. *
  1131. * @type {number}
  1132. * @default 1.0
  1133. * @private
  1134. */
  1135. this.roughnessFactor = MetallicRoughness.DEFAULT_ROUGHNESS_FACTOR;
  1136. }
  1137. /**
  1138. * @private
  1139. */
  1140. MetallicRoughness.DEFAULT_BASE_COLOR_FACTOR = Cartesian4.ONE;
  1141. /**
  1142. * @private
  1143. */
  1144. MetallicRoughness.DEFAULT_METALLIC_FACTOR = 1.0;
  1145. /**
  1146. * @private
  1147. */
  1148. MetallicRoughness.DEFAULT_ROUGHNESS_FACTOR = 1.0;
  1149. /**
  1150. * Material properties for the PBR specular glossiness shading model.
  1151. *
  1152. * @alias ModelComponents.SpecularGlossiness
  1153. * @constructor
  1154. *
  1155. * @private
  1156. */
  1157. function SpecularGlossiness() {
  1158. /**
  1159. * The diffuse texture reader.
  1160. *
  1161. * @type {ModelComponents.TextureReader}
  1162. * @private
  1163. */
  1164. this.diffuseTexture = undefined;
  1165. /**
  1166. * The specular glossiness texture reader.
  1167. *
  1168. * @type {ModelComponents.TextureReader}
  1169. * @private
  1170. */
  1171. this.specularGlossinessTexture = undefined;
  1172. /**
  1173. * The diffuse factor.
  1174. *
  1175. * @type {Cartesian4}
  1176. * @default new Cartesian4(1.0, 1.0, 1.0, 1.0)
  1177. * @private
  1178. */
  1179. this.diffuseFactor = Cartesian4.clone(
  1180. SpecularGlossiness.DEFAULT_DIFFUSE_FACTOR
  1181. );
  1182. /**
  1183. * The specular factor.
  1184. *
  1185. * @type {Cartesian3}
  1186. * @default new Cartesian3(1.0, 1.0, 1.0)
  1187. * @private
  1188. */
  1189. this.specularFactor = Cartesian3.clone(
  1190. SpecularGlossiness.DEFAULT_SPECULAR_FACTOR
  1191. );
  1192. /**
  1193. * The glossiness factor.
  1194. *
  1195. * @type {number}
  1196. * @default 1.0
  1197. * @private
  1198. */
  1199. this.glossinessFactor = SpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR;
  1200. }
  1201. /**
  1202. * @private
  1203. */
  1204. SpecularGlossiness.DEFAULT_DIFFUSE_FACTOR = Cartesian4.ONE;
  1205. /**
  1206. * @private
  1207. */
  1208. SpecularGlossiness.DEFAULT_SPECULAR_FACTOR = Cartesian3.ONE;
  1209. /**
  1210. * @private
  1211. */
  1212. SpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR = 1.0;
  1213. /**
  1214. * The material appearance of a primitive.
  1215. *
  1216. * @alias ModelComponent.Material
  1217. * @constructor
  1218. *
  1219. * @private
  1220. */
  1221. function Material() {
  1222. /**
  1223. * Material properties for the PBR metallic roughness shading model.
  1224. *
  1225. * @type {ModelComponents.MetallicRoughness}
  1226. * @private
  1227. */
  1228. this.metallicRoughness = new MetallicRoughness();
  1229. /**
  1230. * Material properties for the PBR specular glossiness shading model.
  1231. *
  1232. * @type {ModelComponents.SpecularGlossiness}
  1233. * @private
  1234. */
  1235. this.specularGlossiness = undefined;
  1236. /**
  1237. * The emissive texture reader.
  1238. *
  1239. * @type {ModelComponents.TextureReader}
  1240. * @private
  1241. */
  1242. this.emissiveTexture = undefined;
  1243. /**
  1244. * The normal texture reader.
  1245. *
  1246. * @type {ModelComponents.TextureReader}
  1247. * @private
  1248. */
  1249. this.normalTexture = undefined;
  1250. /**
  1251. * The occlusion texture reader.
  1252. *
  1253. * @type {ModelComponents.TextureReader}
  1254. * @private
  1255. */
  1256. this.occlusionTexture = undefined;
  1257. /**
  1258. * The emissive factor.
  1259. *
  1260. * @type {Cartesian3}
  1261. * @default Cartesian3.ZERO
  1262. * @private
  1263. */
  1264. this.emissiveFactor = Cartesian3.clone(Material.DEFAULT_EMISSIVE_FACTOR);
  1265. /**
  1266. * The alpha mode.
  1267. *
  1268. * @type {AlphaMode}
  1269. * @default AlphaMode.OPAQUE
  1270. * @private
  1271. */
  1272. this.alphaMode = AlphaMode.OPAQUE;
  1273. /**
  1274. * The alpha cutoff value of the material for the MASK alpha mode.
  1275. *
  1276. * @type {number}
  1277. * @default 0.5
  1278. * @private
  1279. */
  1280. this.alphaCutoff = 0.5;
  1281. /**
  1282. * Specifies whether the material is double sided.
  1283. *
  1284. * @type {boolean}
  1285. * @default false
  1286. * @private
  1287. */
  1288. this.doubleSided = false;
  1289. /**
  1290. * Specifies whether the material is unlit.
  1291. *
  1292. * @type {boolean}
  1293. * @default false
  1294. * @private
  1295. */
  1296. this.unlit = false;
  1297. }
  1298. /**
  1299. * @private
  1300. */
  1301. Material.DEFAULT_EMISSIVE_FACTOR = Cartesian3.ZERO;
  1302. ModelComponents.Quantization = Quantization;
  1303. ModelComponents.Attribute = Attribute;
  1304. ModelComponents.Indices = Indices;
  1305. ModelComponents.FeatureIdAttribute = FeatureIdAttribute;
  1306. ModelComponents.FeatureIdTexture = FeatureIdTexture;
  1307. ModelComponents.FeatureIdImplicitRange = FeatureIdImplicitRange;
  1308. ModelComponents.MorphTarget = MorphTarget;
  1309. ModelComponents.Primitive = Primitive;
  1310. ModelComponents.Instances = Instances;
  1311. ModelComponents.Skin = Skin;
  1312. ModelComponents.Node = Node;
  1313. ModelComponents.Scene = Scene;
  1314. ModelComponents.AnimatedPropertyType = Object.freeze(AnimatedPropertyType);
  1315. ModelComponents.AnimationSampler = AnimationSampler;
  1316. ModelComponents.AnimationTarget = AnimationTarget;
  1317. ModelComponents.AnimationChannel = AnimationChannel;
  1318. ModelComponents.Animation = Animation;
  1319. ModelComponents.ArticulationStage = ArticulationStage;
  1320. ModelComponents.Articulation = Articulation;
  1321. ModelComponents.Asset = Asset;
  1322. ModelComponents.Components = Components;
  1323. ModelComponents.TextureReader = TextureReader;
  1324. ModelComponents.MetallicRoughness = MetallicRoughness;
  1325. ModelComponents.SpecularGlossiness = SpecularGlossiness;
  1326. ModelComponents.Material = Material;
  1327. export default ModelComponents;