Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/Contributors/BuildGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Here's the full set of scripts and what they do.
- `eslint` - Runs [ESLint](http://eslint.org/), a static code analysis tool, on the entire source tree
- `prettier` - Formats the code base using [Prettier](https://prettier.io/)
- `prettier-check` - Verifies prettier formatting, but does not write the output
- `download-schemas` and `generate-types` in `@cesium/gltf` (run with `-w @cesium/gltf`) - Download the glTF JSON Schemas and generate TypeScript types for glTF JSON from them. See [Generated glTF types](../../../packages/gltf/README.md#generated-gltf-types).
- **Testing scripts** -- build and run the unit tests
- `test` - Runs all tests with [Karma](http://karma-runner.github.io/0.13/index.html) using the default browser specified in the Karma config file.
- `test-all` - Runs all tests with Karma using all browsers installed on the current system
Expand Down
7 changes: 7 additions & 0 deletions Documentation/Contributors/CodingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ When referencing external documentation and examples — including TypeScript do
const x = "hello world"; // good
const x = /** @type {string} */ ("hello world"); // bad
```
7. **Use the generated glTF types for glTF JSON.** `@cesium/gltf` exports types generated from the glTF JSON Schemas, such as `Gltf2`, `Gltf2.Accessor`, and `EXT_structural_metadata.Mesh.Primitive`. Use them for glTF JSON in place of `object` or a hand-written type:

```javascript
/** @import { Gltf2 } from "@cesium/gltf"; */
```

If code reads an extension that has no generated type, add the extension to the generated types. See [Generated glTF types](../../../packages/gltf/README.md#generated-gltf-types).

## Units

Expand Down

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,20 @@ export default [
},
{
// The core rule reports parameter names in function types as unused.
files: ["packages/*/Source/**/*.ts", "packages/gltf/gltf.entry.d.ts"],
// The core rule also reports interfaces and namespaces that share a name.
files: [
"packages/*/Source/**/*.ts",
"packages/gltf/SchemaTypes/**/*.ts",
"packages/gltf/gltf.entry.d.ts",
],
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ vars: "all", args: "none", caughtErrors: "none" },
],
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "error",
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4394,6 +4394,8 @@ Cesium3DTileset.checkSupportedExtensions = function (extensionsRequired) {
}
};

// Add each extension to the glTF types in @cesium/gltf; see the "Generated glTF types"
// section of packages/gltf/README.md.
Cesium3DTileset.supportedGltfExtensions = {
"3DTILES_tileset": true,
"3DTILES_implicit_tiling": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/Source/Scene/Model/ModelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ ModelUtility.sanitizeGlslIdentifier = function (identifier) {
};

// Keep the list of supported extensions in the Model.js class docstring in sync with this object.
// Also add each extension to the glTF types in @cesium/gltf; see the "Generated glTF types"
// section of packages/gltf/README.md.
ModelUtility.supportedExtensions = {
AGI_articulations: true,
CESIUM_mesh_vector: true,
Expand Down
51 changes: 51 additions & 0 deletions packages/gltf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,57 @@ Or, install with yarn:
yarn add @cesium/gltf
```

## Generated glTF types

`SchemaTypes` contains TypeScript types for glTF JSON, generated from the [glTF JSON Schemas](https://github.com/KhronosGroup/glTF/tree/main/specification/2.0/schema): `Gltf1` for glTF 1.0, `Gltf2` for glTF 2.0 and 2.1, and a namespace for each extension, such as `EXT_structural_metadata`. Don't edit them by hand; regenerate them as described below.

`scripts/gltfSchemaSources.json` lists where each schema comes from. `npm run download-schemas -w @cesium/gltf` downloads the listed schemas into `Build/Schemas`, and `npm run generate-types -w @cesium/gltf` generates the types from them.

### Adding an extension

When CesiumJS adds support for a glTF extension, add the extension to the generated types:

1. Add an entry for the extension to `scripts/gltfSchemaSources.json`, as described below.
2. Run `npm run download-schemas -w @cesium/gltf`.
3. Run `npm run generate-types -w @cesium/gltf`.
4. Run `npm run tsc -w @cesium/gltf`.
5. Commit `gltfSchemaSources.json` with the regenerated files in `SchemaTypes`.

For example, this entry adds `3DTILES_shape_ellipsoid_region`, whose schema appears in a glTF 2.1 shape's `extensions`:

```json
"3DTILES_shape_ellipsoid_region": {
"repository": "CesiumGS/glTF",
"branch": "3d-tiles-2.0",
"commit": "e68efc9086f60743c331a2c757a1ffadcdb5d532",
"schemaDirectory": "extensions/2.1/Vendor/3DTILES_shape_ellipsoid_region/schema",
"core": ["2.1"],
"extends": {
"shape.3DTILES_shape_ellipsoid_region.schema.json": ["shape"]
}
}
```

### Updating a schema

To use a newer version of a schema, change its `commit`, and its `branch` if needed, then follow steps 2 to 5 above. In the pull request, link the upstream changes, such as `https://github.com/KhronosGroup/glTF/compare/<old commit>...<new commit>`.

### Entries in `gltfSchemaSources.json`

`core` has an entry for each glTF version: `1.0`, `2.0`, and `2.1`. `extensions` has an entry for each extension, with these properties:

- `repository`: The GitHub repository with the schemas.
- `branch`: The branch that `commit` is from. The scripts don't read it; it records where to look for newer versions.
- `commit`: The commit to download the schemas from.
- `schemaDirectory`: The directory in the repository with the extension's `*.schema.json` files.
- `core`: The glTF versions the extension applies to: `1.0`, `2.x` for glTF 2.0 and later, or `2.1` for an extension that uses anything glTF 2.1 adds, such as shapes.
- `extends`: For each of the extension's schemas that can appear in an object's `extensions`, the objects it can appear in. List every such schema: a schema left out still gets a type, but no object's `extensions` refers to it. Name an object by its schema file name without `.schema.json`:
- a glTF object, like `node` or `material.textureInfo`, or `glTF` for the root object;
- `*` for any glTF object;
- an object of another extension, as `<extension name>/<schema>`, like `EXT_geospatial_crs/EXT_geospatial_crs`.

An extension without a published schema, like `KHR_mesh_quantization`, has only `core`, and gets no types.

## Community

Have questions? Ask them on the [community forum](https://community.cesium.com/).
Expand Down
47 changes: 47 additions & 0 deletions packages/gltf/SchemaTypes/Extensions/3DTILES_implicit_tiling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Generated from the glTF JSON schemas at:
// https://github.com/CesiumGS/glTF/tree/e68efc9086f60743c331a2c757a1ffadcdb5d532/extensions/2.1/Vendor/3DTILES_implicit_tiling/schema
// Do not edit; rerun `npm run generate-types -w @cesium/gltf` instead.
// See packages/gltf/README.md#generated-gltf-types.

import type { Gltf2 } from "../Gltf2.js";

/** @internal */
export namespace _3DTILES_implicit_tiling {
/**
* Implicit tiling defines a concise representation of quadtrees and octrees
* in 3D Tiles.
*/
export interface Node extends Gltf2.Property {
/**
* A template URI pointing to tile content. It contains placeholders
* `{level}`, `{x}`, `{y}`, and optionally `{z}` (for OCTREE subdivision
* scheme) that are substituted with a tile's coordinate to resolve the
* actual file. Example: `content/{level}/{x}/{y}.glb`.
*/
contentUri: string;
/**
* A template URI pointing to subtree files. It contains placeholders
* `{level}`, `{x}`, `{y}`, and optionally `{z}` (for OCTREE subdivision
* scheme) that are substituted with a subtree's coordinate to resolve the
* actual file. Example: `subtrees/{level}/{x}/{y}.json`.
*/
subtreeUri: string;
/**
* Either QUADTREE or OCTREE. See Subdivision scheme.
*
* Allowed values:
*
* - `"QUADTREE"`
* - `"OCTREE"`
*/
subdivisionScheme: string;
/**
* How many levels there are in the tree with available tiles.
*/
availableLevels: number;
/**
* How many levels there are in each subtree.
*/
subtreeLevels: number;
}
}
101 changes: 101 additions & 0 deletions packages/gltf/SchemaTypes/Extensions/3DTILES_subtree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Generated from the glTF JSON schemas at:
// https://github.com/CesiumGS/glTF/tree/e68efc9086f60743c331a2c757a1ffadcdb5d532/extensions/2.1/Vendor/3DTILES_subtree/schema
// Do not edit; rerun `npm run generate-types -w @cesium/gltf` instead.
// See packages/gltf/README.md#generated-gltf-types.

import type { Gltf2 } from "../Gltf2.js";

/** @internal */
export namespace _3DTILES_subtree {
/**
* An object describing the availability of a set of elements.
*/
export interface Availability extends Gltf2.Property {
/**
* Index of a buffer view that contains availability bits. If an element is
* available, its bit is 1, and if it is unavailable, its bit is 0.
*/
bitstream?: number;
/**
* A number indicating how many 1 bits exist in the availability bitstream.
*/
availableCount?: number;
/**
* Integer indicating whether all of the elements are available (1) or all
* are unavailable (0).
*
* Allowed values:
*
* - `0`: UNAVAILABLE
* - `1`: AVAILABLE
*/
constant?: number;
}
/**
* An object describing the availability of tiles and content in a subtree, as
* well as availability of children subtrees. May also store attributes and
* application-specific properties for available tiles and contents.
*/
export interface Gltf extends Gltf2.Property {
/**
* The availability of tiles in the subtree. The availability bitstream is a
* 1D boolean array where tiles are ordered by their level in the subtree
* and Morton index within that level. A tile's availability is determined
* by a single bit, 1 meaning a tile exists at that spatial index, and 0
* meaning it does not. The number of elements in the array is
* `(N^subtreeLevels - 1)/(N - 1)` where N is 4 for subdivision scheme
* `QUADTREE` and 8 for `OCTREE`. Availability may be stored in a buffer
* view or as a constant value that applies to all tiles. If a non-root
* tile's availability is 1 its parent tile's availability must also be 1.
* `tileAvailability.constant: 0` is disallowed, as subtrees must have at
* least one tile.
*/
tileAvailability: _3DTILES_subtree.Availability;
/**
* The availability of contents in the subtree.
*/
contentAvailability?: _3DTILES_subtree.Availability;
/**
* The availability of children subtrees. The availability bitstream is a 1D
* boolean array where subtrees are ordered by their Morton index in the
* level of the tree immediately below the bottom row of the subtree. A
* child subtree's availability is determined by a single bit, 1 meaning a
* subtree exists at that spatial index, and 0 meaning it does not. The
* number of elements in the array is `N^subtreeLevels` where N is 4 for
* subdivision scheme `QUADTREE` and 8 for `OCTREE`. Availability may be
* stored in a buffer view or as a constant value that applies to all child
* subtrees. If availability is 0 for all child subtrees, then the tileset
* does not subdivide further.
*/
childSubtreeAvailability: _3DTILES_subtree.Availability;
/**
* A plain JSON object, where each key corresponds to a tile attribute
* semantic and each value is the index of the accessor containing
* attribute's data. Attribute values only exists for available tiles and
* are ordered by increasing tile index.
*/
tileAttributes?: Record<string, number>;
/**
* A plain JSON object, where each key corresponds to a content attribute
* semantic and each value is the index of the accessor containing
* attribute's data. Attribute values only exists for available contents and
* are ordered by increasing tile index.
*/
contentAttributes?: Record<string, number>;
/**
* Index of the property table containing tile properties. Tile properties
* only exist for available tiles and are tightly packed by increasing tile
* index. To access individual tile properties, implementations may create a
* mapping from tile indices to tile property indices.
*/
tileProperties?: number;
/**
* Index of the property table containing content properties. Content
* properties only exist for available contents and are tightly packed by
* increasing tile index. To access individual content properties,
* implementations may create a mapping from tile indices to content
* property indices.
*/
contentProperties?: number;
}
}
67 changes: 67 additions & 0 deletions packages/gltf/SchemaTypes/Extensions/3DTILES_tileset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Generated from the glTF JSON schemas at:
// https://github.com/CesiumGS/glTF/tree/e68efc9086f60743c331a2c757a1ffadcdb5d532/extensions/2.1/Vendor/3DTILES_tileset/schema
// Do not edit; rerun `npm run generate-types -w @cesium/gltf` instead.
// See packages/gltf/README.md#generated-gltf-types.

import type { Gltf2 } from "../Gltf2.js";

/** @internal */
export namespace _3DTILES_tileset {
/**
* Content object in node-level 3DTILES_tileset extension.
*/
export interface Content extends Gltf2.Property {
/**
* The content bounding volume.
*/
boundingVolume?: Gltf2.Node.BoundingVolume;
}
/**
* glTF-level 3DTILES_tileset extension.
*/
export interface Gltf extends Gltf2.Property {
/**
* The tileset geometric error. A nonnegative number that defines the error,
* in meters, that determines if the tileset is rendered. At runtime, the
* geometric error is used to compute Screen-Space Error (SSE), the error
* measured in pixels. If the SSE does not exceed a required minimum, the
* tileset should not be rendered, and none of its tiles should be
* considered for rendering.
*/
geometricError: number;
}
/**
* Node-level 3DTILES_tileset extension.
*/
export interface Node extends Gltf2.Property {
/**
* The tile geometric error. A nonnegative number that defines the error, in
* meters, introduced if this tile is rendered and its children are not. At
* runtime, the geometric error is used to compute Screen-Space Error (SSE),
* the error measured in pixels. The SSE determines if a tile is
* sufficiently detailed for the current view or if its children should be
* considered.
*/
geometricError: number;
/**
* Specifies the refinement type. A string that is either "REPLACE" for
* replacement refinement or "ADD" for additive refinement. It is required
* for the root tile of a tileset; it is optional for all other tiles. A
* tileset can use any combination of additive and replacement refinement.
* When the refine property is omitted, it is inherited from the parent
* tile.
*
* Allowed values:
*
* - `"REPLACE"`
* - `"ADD"`
*/
refine?: string;
/**
* An object that provides additional information about the tile's content.
* If the tile does not have content (i.e. the node's `externalAsset`
* property is not defined) then `content` **MUST** be omitted.
*/
content?: _3DTILES_tileset.Content;
}
}
41 changes: 41 additions & 0 deletions packages/gltf/SchemaTypes/Extensions/3DTILES_tileset_voxels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Generated from the glTF JSON schemas at:
// https://github.com/CesiumGS/glTF/tree/e68efc9086f60743c331a2c757a1ffadcdb5d532/extensions/2.1/Vendor/3DTILES_tileset_voxels/schema
// Do not edit; rerun `npm run generate-types -w @cesium/gltf` instead.
// See packages/gltf/README.md#generated-gltf-types.

import type { Gltf2 } from "../Gltf2.js";

/** @internal */
export namespace _3DTILES_tileset_voxels {
/**
* Voxels are stored as glTFs with the EXT_voxels extension and are paired
* with EXT_structural_metadata to unify the schema between a tileset and its
* tiles. This extension is paired with Implicit Tiling for efficient
* representation of massive sparse voxel datasets. This extension lets
* runtimes detect voxel content in advance to allocate necessary resources
* before tiles load.
*/
export interface Gltf extends Gltf2.Property {
/**
* Dimensions of the voxel grid.
*/
dimensions: [number, number, number];
/**
* The optional padding of the voxels.
*/
padding?: _3DTILES_tileset_voxels.Padding;
/**
* The class that property values conform to. The value shall be a class ID
* declared in the `classes` dictionary.
*/
class: string;
}
/**
* The padding around a voxel grid. Specifies how many rows of attribute data
* come from neighboring grids in each dimension.
*/
export interface Padding extends Gltf2.Property {
before: [number, number, number];
after: [number, number, number];
}
}
Loading