Skip to content

Commit

Permalink
add ar-usdz-max-texture-size (related google#4984 issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadbaghaei committed Jan 30, 2025
1 parent 51ff5d3 commit 5763db9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/model-viewer/src/features/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export declare interface ARInterface {
arPlacement: string;
iosSrc: string|null;
xrEnvironment: boolean;
arUsdzMaxTextureSize: string;
readonly canActivateAR: boolean;
activateAR(): Promise<void>;
}
Expand All @@ -83,6 +84,9 @@ export const ARMixin = <T extends Constructor<ModelViewerElementBase>>(

@property({type: String, attribute: 'ar-scale'}) arScale: string = 'auto';

@property({type: String, attribute: 'ar-usdz-max-texture-size'})
arUsdzMaxTextureSize: string = 'auto';

@property({type: String, attribute: 'ar-placement'})
arPlacement: string = 'floor';

Expand Down Expand Up @@ -182,7 +186,8 @@ export const ARMixin = <T extends Constructor<ModelViewerElementBase>>(
}

if (changedProperties.has('ar') || changedProperties.has('arModes') ||
changedProperties.has('src') || changedProperties.has('iosSrc')) {
changedProperties.has('src') || changedProperties.has('iosSrc') ||
changedProperties.has('arUsdzMaxTextureSize')) {
this[$selectARMode]();
}
}
Expand Down Expand Up @@ -446,7 +451,11 @@ configuration or device capabilities');
model.position.copy(target.position);
model.updateWorldMatrix(false, true);

const arraybuffer = await exporter.parseAsync(model);
const arraybuffer = await exporter.parseAsync(model, {
maxTextureSize: isNaN(this.arUsdzMaxTextureSize as any) ?
Infinity :
Math.max(parseInt(this.arUsdzMaxTextureSize), 16),
});

model.position.set(0, 0, 0);
target.add(model);
Expand Down
9 changes: 9 additions & 0 deletions packages/modelviewer.dev/data/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@
"<a href=\"../examples/augmentedreality/#ar\"><span class='attribute'>ios-src</span> example</a>"
]
},
{
"name": "ar-usdz-max-texture-size",
"htmlName": "arUsdzMaxTextureSize",
"description": "Set texture max resolution for Quick Look auto generated USDZ model.",
"default": {
"default": "Infinity (no limits for maximum texture resolution)",
"options": "Number greater than or equal to 16"
}
},
{
"name": "xr-environment",
"htmlName": "xrEnvironment",
Expand Down

0 comments on commit 5763db9

Please sign in to comment.