Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imdl tiles meshopt compression #6956

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1a57cec
imdl tiles compression
mathieu-lemuzic Jul 11, 2024
1148224
add decoding time to DPTA statistics
mathieu-lemuzic Jul 16, 2024
a3fb39a
cleanup
mathieu-lemuzic Sep 25, 2024
a462e5a
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Sep 25, 2024
53651b1
PR suggestion
mathieu-lemuzic Sep 27, 2024
9b9a25e
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Sep 27, 2024
947b605
rush change
mathieu-lemuzic Sep 27, 2024
31d15fb
fix
mathieu-lemuzic Sep 27, 2024
ce01839
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Sep 30, 2024
eaefbb5
bump tile version
mathieu-lemuzic Sep 30, 2024
abcad9d
fix
mathieu-lemuzic Sep 30, 2024
f59831f
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Sep 30, 2024
5a16084
use index sequence compression
mathieu-lemuzic Oct 1, 2024
191e1aa
rush change + rush extract-api
mathieu-lemuzic Oct 1, 2024
f2653dd
cleanup
mathieu-lemuzic Oct 1, 2024
bbe108d
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Oct 1, 2024
20b9167
linto
mathieu-lemuzic Oct 1, 2024
1705b46
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Oct 3, 2024
23f7f15
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Oct 4, 2024
99c2d55
Merge branch 'master' into mlemuzic/imdl_tiles_compression
pmconne Oct 8, 2024
ab8ebcd
fix schema
mathieu-lemuzic Oct 9, 2024
aa0d90c
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Oct 9, 2024
d51bf0b
Merge branch 'master' into mlemuzic/imdl_tiles_compression
mathieu-lemuzic Oct 10, 2024
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
8 changes: 8 additions & 0 deletions core/frontend/src/common/imdl/ImdlSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export interface ImdlVertexTable {
readonly width: number;
/** The height of the lookup texture. */
readonly height: number;
/** True if vertex data is compressed. */
readonly isCompressed: boolean;
/** The size of the compressed data */
readonly compressedSize: number;
pmconne marked this conversation as resolved.
Show resolved Hide resolved
/** True if [[uniformColor]] has transparency or the embedded color table contains transparent colors. */
readonly hasTranslucency: boolean;
/** Describes the number (0, 1, or more than 1) of features contained in the vertex table. */
Expand Down Expand Up @@ -327,6 +331,10 @@ export interface ImdlSurface {
readonly type: SurfaceType;
/** The 24-bit indices into the [[ImdlVertexTable]] of each triangle's vertex. */
readonly indices: string;
/** Is the index data compressed. */
readonly isCompressed: boolean;
/** The number of indices, only set if data is compressed. */
readonly indexCount: number;
pmconne marked this conversation as resolved.
Show resolved Hide resolved
/** If true, the [[ImdlTextureMapping]] is applied regardless of [ViewFlags.textures]($common). */
readonly alwaysDisplayTexture?: boolean;
/** The quantization range for the UV coordinates. @see [QParams2d]($common). */
Expand Down
59 changes: 55 additions & 4 deletions core/frontend/src/common/imdl/ParseImdlDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { VertexTable } from "../render/primitives/VertexTable";
import { MaterialParams } from "../render/MaterialParams";
import { VertexIndices } from "../render/primitives/VertexIndices";
import { indexedEdgeParamsFromCompactEdges } from "./CompactEdges";
import {MeshoptDecoder} from "meshoptimizer/meshopt_decoder.module";

/** Timeline used to reassemble iMdl content into animatable nodes.
* @internal
Expand Down Expand Up @@ -889,10 +890,25 @@ class Parser {
if (!surf)
return undefined;

const indices = this.findBuffer(surf.indices);
let indices = this.findBuffer(surf.indices);
if (!indices)
return undefined;

if(surf.isCompressed){
const decompressedIndices = new Uint8Array(surf.indexCount * 4);
MeshoptDecoder.decodeIndexBuffer(decompressedIndices, surf.indexCount, 4, indices);

// reduce from 32 to 24 bits
indices = new Uint8Array(surf.indexCount * 3);
for (let i = 0; i < surf.indexCount; i++) {
const srcIndex = i * 4;
const dstIndex = i * 3;
indices[dstIndex + 0] = decompressedIndices[srcIndex + 0];
indices[dstIndex + 1] = decompressedIndices[srcIndex + 1];
indices[dstIndex + 2] = decompressedIndices[srcIndex + 2];
}
}

const type = surf.type;
if (!isValidSurfaceType(type))
return undefined;
Expand Down Expand Up @@ -959,9 +975,44 @@ class Parser {
if (!json)
return undefined;

const bytes = this.findBuffer(JsonUtils.asString(json.bufferView));
if (!bytes)
return undefined;
let bytes: Uint8Array | undefined;
if(json.isCompressed){

const bufferViewJson = this._document.bufferViews[JsonUtils.asString(json.bufferView)];
if (undefined === bufferViewJson)
return undefined;

const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);
const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);
if (0 === byteLength)
return undefined;

const compressedBytes = this._binaryData.subarray(byteOffset, byteOffset + json.compressedSize);
if (!compressedBytes)
return undefined;

bytes = new Uint8Array(json.width * json.height * 4);
MeshoptDecoder.decodeVertexBuffer(bytes, json.count, json.numRgbaPerVertex * 4, compressedBytes);

const remainingBytesSize = byteLength - json.compressedSize;

// if there are remaining bytes, copy the data that did not go through the compression
if(remainingBytesSize > 0){
const remainingBytes = this._binaryData.subarray(byteOffset + json.compressedSize, byteOffset + byteLength);
if (!remainingBytes)
return undefined;

const decompressedSize = json.count * json.numRgbaPerVertex * 4;
for(let i = 0; i < remainingBytesSize; i++){
bytes[decompressedSize + i] = remainingBytes[i];
}
}

} else{
bytes = this.findBuffer(JsonUtils.asString(json.bufferView));
if (!bytes)
return undefined;
}

const uniformFeatureID = undefined !== json.featureID ? JsonUtils.asInt(json.featureID) : undefined;

Expand Down
Loading