Skip to content

Commit

Permalink
Merge pull request #631 from javagl/primitive-outline-support
Browse files Browse the repository at this point in the history
Basic CESIUM_primitive_outline support
  • Loading branch information
lilleyse authored Mar 30, 2023
2 parents dc21311 + f812302 commit 8751527
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ processGltf(gltf, options).then(function (results) {
| `--stats` | Print statistics to console for output glTF file. | No, default `false` |
| `--keepUnusedElements` | Keep unused materials, nodes and meshes. | No, default `false` |
| `--keepLegacyExtensions` | When false, materials with `KHR_techniques_webgl`, `KHR_blend`, or `KHR_materials_common` will be converted to PBR. | No, default `false` |
| `--draco.compressMeshes`, `-d` | Compress the meshes using Draco. Adds the KHR_draco_mesh_compression extension. | No, default `false` |
| `--draco.compressMeshes`, `-d` | Compress the meshes using Draco. Adds the `KHR_draco_mesh_compression` extension. | No, default `false` |
| `--draco.compressionLevel` | Draco compression level [0-10], most is 10, least is 0. A value of 0 will apply sequential encoding and preserve face order. | No, default `7` |
| `--draco.quantizePositionBits` | Quantization bits for position attribute when using Draco compression. | No, default `14` |
| `--draco.quantizeNormalBits` | Quantization bits for normal attribute when using Draco compression. | No, default `10` |
| `--draco.quantizeTexcoordBits` | Quantization bits for texture coordinate attribute when using Draco compression. | No, default `12` |
| `--draco.quantizePositionBits` | Quantization bits for position attribute when using Draco compression. | No, default `11` |
| `--draco.quantizeNormalBits` | Quantization bits for normal attribute when using Draco compression. | No, default `8` |
| `--draco.quantizeTexcoordBits` | Quantization bits for texture coordinate attribute when using Draco compression. | No, default `10` |
| `--draco.quantizeColorBits` | Quantization bits for color attribute when using Draco compression. | No, default `8` |
| `--draco.quantizeGenericBits` | Quantization bits for skinning attribute (joint indices and joint weights) and custom attributes when using Draco compression. | No, default `12` |
| `--draco.quantizeGenericBits` | Quantization bits for skinning attribute (joint indices and joint weights) and custom attributes when using Draco compression. | No, default `8` |
| `--draco.unifiedQuantization` | Quantize positions of all primitives using the same quantization grid. If not set, quantization is applied separately. | No, default `false` |
| `--draco.uncompressedFallback` | Adds uncompressed fallback versions of the compressed meshes. | No, default `false` |

## Build Instructions

Expand Down
27 changes: 27 additions & 0 deletions lib/removeUnusedElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ Remove.accessor = function (gltf, accessorId) {
if (defined(indices) && indices > accessorId) {
primitive.indices--;
}

const ext = primitive.extensions;
if (
defined(ext) &&
defined(ext.CESIUM_primitive_outline) &&
ext.CESIUM_primitive_outline.indices > accessorId
) {
--ext.CESIUM_primitive_outline.indices;
}
});
});

Expand Down Expand Up @@ -551,6 +560,24 @@ getListOfElementsIdsInUse.accessor = function (gltf) {
});
}

if (usesExtension(gltf, "CESIUM_primitive_outline")) {
ForEach.mesh(gltf, function (mesh) {
ForEach.meshPrimitive(mesh, function (primitive) {
const extensions = primitive.extensions;
if (
defined(extensions) &&
defined(extensions.CESIUM_primitive_outline)
) {
const extension = extensions.CESIUM_primitive_outline;
const indicesAccessorId = extension.indices;
if (defined(indicesAccessorId)) {
usedAccessorIds[indicesAccessorId] = true;
}
}
});
});
}

return usedAccessorIds;
};

Expand Down
61 changes: 61 additions & 0 deletions specs/lib/removeUnusedElementsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,67 @@ describe("removes unused materials, textures, images, samplers", () => {
expect(gltf.accessors[2].name).toEqual("S");
});

it("does not remove CESIUM_primitive_outline accessors", () => {
const gltf = {
accessors: [
{
name: "unused",
},
{
name: "position",
},
{
name: "outlineIndices",
},
{
name: "normal",
},
{
name: "indices",
},
{
name: "unused",
},
],
meshes: [
{
primitives: [
{
attributes: {
POSITION: 1,
NORMAL: 3,
},
indices: 4,
extensions: {
CESIUM_primitive_outline: {
indices: 2,
},
},
},
],
},
],
nodes: [
{
mesh: 0,
},
],
extensionsUsed: ["CESIUM_primitive_outline"],
};

removeUnusedElements(gltf, ["accessor"]);

expect(gltf.accessors.length).toEqual(4);
expect(gltf.accessors[0].name).toEqual("position");
expect(gltf.accessors[1].name).toEqual("outlineIndices");
expect(gltf.accessors[2].name).toEqual("normal");
expect(gltf.accessors[3].name).toEqual("indices");

expect(
gltf.meshes[0].primitives[0].extensions.CESIUM_primitive_outline.indices
).toEqual(1);
});

it("does not remove EXT_feature_metadata buffer views and textures", () => {
const gltf = {
asset: {
Expand Down

0 comments on commit 8751527

Please sign in to comment.