Skip to content

Commit

Permalink
feat: load iosSrc
Browse files Browse the repository at this point in the history
* feat: change iosSrc on loading new model

* test: add TC for view3d#load

* feat: add iosSrc setter
  • Loading branch information
WoodNeck committed Jan 17, 2023
1 parent 612aa7c commit bcb4b8f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/view3d/src/View3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ class View3D extends Component<View3DEvents> implements OptionGetters<Omit<View3
*/
public get maxDeltaTime() { return this._maxDeltaTime; }

public set iosSrc(val: View3DOptions["iosSrc"]) { this._iosSrc = val; }
public set variant(val: View3DOptions["variant"]) {
if (this._model) {
this._model.selectVariant(val)
Expand Down Expand Up @@ -956,8 +957,14 @@ class View3D extends Component<View3DEvents> implements OptionGetters<Omit<View3
/**
* Load a new 3D model and replace it with the current one
* @param {string | string[]} src Source URL to fetch 3D model from
* @param {object} [options={}] Options
* @param {string | null} [options.iosSrc] Source URL to fetch 3D model in iOS AR Quick Look. `usdz` models are supported.
*/
public async load(src: string | string[]) {
public async load(src: string | string[], {
iosSrc = null
}: Partial<{
iosSrc: string | null;
}> = {}) {
if (this._initialized) {
const loadModel = this._loadModel(src);
void this._resetLoadingContextOnFinish(loadModel);
Expand All @@ -966,8 +973,10 @@ class View3D extends Component<View3DEvents> implements OptionGetters<Omit<View3

// Change the src later as an error can occur while loading the model
this._src = src;
this._iosSrc = iosSrc;
} else {
this._src = src;
this._iosSrc = iosSrc;

await this.init();
}
Expand Down
32 changes: 32 additions & 0 deletions packages/view3d/test/suite/View3D.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ describe("View3D", () => {
it("should have 'null' as a default value", async () => {
expect((await createView3D()).iosSrc).to.be.null;
});

it("can be change at anytime", async () => {
const view3D = await createView3D();

expect(view3D.iosSrc).to.be.null;

view3D.iosSrc = "/ios.usdz";

expect(view3D.iosSrc).to.equal("/ios.usdz");
});
});

describe("dracoPath", () => {
Expand Down Expand Up @@ -489,5 +499,27 @@ describe("View3D", () => {

expect(view3D.model).not.to.be.null;
});

it("should set iosSrc to `null` when loading a new model", async () => {
const view3D = await createView3D({
iosSrc: "some_ios_src.usdz"
});

await view3D.load("/cube.glb");

expect(view3D.iosSrc).to.be.null;
});

it("should set iosSrc to given option value when loading a new model", async () => {
const view3D = await createView3D({
iosSrc: "some_ios_src.usdz"
});

await view3D.load("/cube.glb", {
iosSrc: "/cube.usdz"
});

expect(view3D.iosSrc).to.equal("/cube.usdz");
});
});
});

0 comments on commit bcb4b8f

Please sign in to comment.