ModelComponents.js 28 KB

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