Skip to content

quantizePrimitive() #1636

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

Open
samevision opened this issue Apr 8, 2025 · 1 comment
Open

quantizePrimitive() #1636

samevision opened this issue Apr 8, 2025 · 1 comment
Labels
feature New enhancement or request package:functions

Comments

@samevision
Copy link

Is it possible to quantize single objects?

The idea is to use different settings for each object.

Best

@samevision samevision added the feature New enhancement or request label Apr 8, 2025
@donmccurdy
Copy link
Owner

Yes and no. When quantizing primitives, their vertex data is translated and scaled to a 3D quantization grid. The inverse of that translation and scale must be applied to objects referencing the primitive (nodes, skins, volumetric materials). As a result, all of a particular mesh's primitives must share the same transform.

You can find the internal code responsible for quantizing a primitive here:

function quantizePrimitive(
document: Document,
prim: Primitive | PrimitiveTarget,
nodeTransform: VectorTransform<vec3>,
options: Required<QuantizeOptions>,
): void {
const isTarget = prim instanceof PrimitiveTarget;
const logger = document.getLogger();
for (const semantic of prim.listSemantics()) {
if (!isTarget && !options.pattern.test(semantic)) continue;
if (isTarget && !options.patternTargets.test(semantic)) continue;
const srcAttribute = prim.getAttribute(semantic)!;

It's not exposed as a public API because computing the transform for the mesh, and applying that to all references to the mesh, is not trivial and would need to be done by the caller.

If a quantizeNode(node, settings) function would work just as well for you, that might be easier to create and expose in the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New enhancement or request package:functions
Projects
None yet
Development

No branches or pull requests

2 participants