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

Choosing mesh compression type per primitive #929

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ export class EXTMeshoptCompression extends Extension {
this._encoderBufferViewData = {};
this._encoderBufferViewAccessors = {};

const accessorsToUse = new Set<number>();
for (const mesh of this.document.getRoot().listMeshes()) {
mesh.listPrimitives().forEach((prim, index) => {
if(index % 2 === 0) return;
prim.listAttributes().forEach((accessor) => {
const index = context.accessorIndexMap.get(accessor);
if (index !== undefined)
accessorsToUse.add(index)
});
});
}

if (accessorsToUse.size === 0) {
console.log("NO ACCESSORS TO USE");
throw new Error("NO ACCESSORS TO USE");
}

for (const accessor of this.document.getRoot().listAccessors()) {
// See: https://github.com/donmccurdy/glTF-Transform/pull/323#issuecomment-898791251
// Example: https://skfb.ly/6qAD8
Expand All @@ -299,6 +316,14 @@ export class EXTMeshoptCompression extends Extension {
// See: https://github.com/donmccurdy/glTF-Transform/issues/289
if (accessor.getSparse()) continue;

// Test: skip every 2nd buffer view
const accessorIndex = context.accessorIndexMap.get(accessor);
if (accessorIndex !== undefined && !accessorsToUse.has(accessorIndex)) {
console.log("skipping accessor " + accessorIndex);
continue;
}
console.log("MESHOPT: compressing accessor " + accessorIndex);

const usage = context.getAccessorUsage(accessor);
const mode = getMeshoptMode(accessor, usage);
const filter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,17 @@ function listDracoPrimitives(doc: Document): Map<Primitive, string> {
const excluded = new Set<Primitive>();

// Support compressing only indexed, mode=TRIANGLES primitives.
let i = 0;
for (const mesh of doc.getRoot().listMeshes()) {
for (const prim of mesh.listPrimitives()) {

if(i++ % 2 !== 0)
{
logger.info(`[${NAME}] Skip Primitive ${i}.`);
continue;
}
logger.info(`[${NAME}] Select Primitive ${i}.`);

if (!prim.getIndices()) {
excluded.add(prim);
logger.warn(`[${NAME}] Skipping Draco compression on non-indexed primitive.`);
Expand Down