Skip to content

[FIX] Correct vertex format mismatch when decoding Draco meshes#8394

Merged
willeastcott merged 3 commits into
mainfrom
draco-stride
Jan 21, 2026
Merged

[FIX] Correct vertex format mismatch when decoding Draco meshes#8394
willeastcott merged 3 commits into
mainfrom
draco-stride

Conversation

@willeastcott

@willeastcott willeastcott commented Jan 21, 2026

Copy link
Copy Markdown
Contributor
image

Summary

  • Fix incorrect mesh rendering when loading Draco-compressed GLB files
  • Draco worker now returns vertex format metadata (stride, data types, offsets) instead of just unique IDs
  • GLB parser uses worker-provided metadata to correctly interpret vertex data

Technical Details

The root cause was a mismatch between how the Draco worker produces vertex data and how the GLB parser interprets it:

  1. Stride mismatch: The Draco worker processes ALL attributes from the mesh and calculates stride based on all of them. The GLB parser only knew about attributes listed in primitive.attributes, causing incorrect vertex count calculations when extra attributes existed.

  2. Data type mismatch: The parser was using glTF accessor componentType which may differ from Draco's actual decoded data type.

Changes

draco-worker.js:

  • Add toEngineDataType() to convert Draco types to PlayCanvas TYPE_* constants
  • Return detailed attribute metadata: { id, dataType, numComponents, offset } for each attribute
  • Return stride (actual vertex buffer stride) in the result

draco-decoder.js:

  • Pass new stride field through the callback

glb-parser.js:

  • Build vertex description from worker metadata instead of glTF accessor data
  • Use worker's stride for vertex count: numVertices = vertices.byteLength / stride
  • Pass offset and stride to VertexFormat for correct data interpretation

Fixed #7370

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug in the rendering of Draco-compressed GLB files caused by vertex format mismatches between the Draco worker and GLB parser. The issue occurred when Draco meshes contained additional attributes not listed in the glTF primitive.attributes, leading to incorrect stride calculations and vertex data interpretation.

Changes:

  • Draco worker now returns detailed attribute metadata (data type, component count, offset) and the actual vertex buffer stride
  • GLB parser builds vertex descriptions from worker-provided metadata instead of glTF accessor data
  • Added validation to prevent crashes when primitive.indices is undefined

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/framework/parsers/draco-worker.js Added toEngineDataType() function and modified attribute metadata to include data types, offsets, and stride; improved handling of generated normals
src/framework/parsers/glb-parser.js Refactored vertex description building to use worker metadata; fixed vertex count calculation using worker stride; added defensive check for undefined indices
src/framework/parsers/draco-decoder.js Added stride field passthrough from worker to callback

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/framework/parsers/draco-worker.js Outdated
willeastcott and others added 2 commits January 21, 2026 16:43
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@willeastcott willeastcott merged commit 97c825f into main Jan 21, 2026
7 checks passed
@willeastcott willeastcott deleted the draco-stride branch January 21, 2026 16:48
willeastcott added a commit that referenced this pull request Jan 26, 2026
* [FIX] Correct vertex format mismatch when decoding Draco compressed meshes

* Update src/framework/parsers/draco-worker.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Draco mesh imported incorrectly when loading draco compressed .glb

3 participants