Skip to content

Commit

Permalink
Remove getRootContainer from MMLScene (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir authored Jan 29, 2025
1 parent 66f808a commit 61dcc35
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Interaction,
Matr4,
MMLGraphicsInterface,
StandaloneGraphicsAdapter,
TransformableElement,
Vect3,
} from "@mml-io/mml-web";
Expand Down Expand Up @@ -33,7 +34,9 @@ export type StandalonePlayCanvasAdapterOptions = {
controlsType?: StandalonePlayCanvasAdapterControlsType;
};

export class StandalonePlayCanvasAdapter implements PlayCanvasGraphicsAdapter {
export class StandalonePlayCanvasAdapter
implements PlayCanvasGraphicsAdapter, StandaloneGraphicsAdapter
{
containerType: playcanvas.Entity;
collisionType: playcanvas.Entity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PlayCanvasMElement extends MElementGraphics<PlayCanvasGraphicsAdapt
// If none of the ancestors are MElements then this element may be directly connected to the body (without a wrapper).
// Attempt to use a global scene that has been configured to attach this element to.
const scene = this.element.getScene();
this.currentParentContainer = scene.getRootContainer();
this.currentParentContainer = scene.getGraphicsAdapter().getRootContainer();
this.currentParentContainer.addChild(this.container);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Interaction, MElement, MMLGraphicsInterface, radToDeg } from "@mml-io/mml-web";
import {
Interaction,
MElement,
MMLGraphicsInterface,
radToDeg,
StandaloneGraphicsAdapter,
} from "@mml-io/mml-web";
import {
ThreeJSClickTrigger,
ThreeJSGraphicsAdapter,
Expand All @@ -21,7 +27,7 @@ export type StandaloneThreeJSAdapterOptions = {
controlsType?: StandaloneThreeJSAdapterControlsType;
};

export class StandaloneThreeJSAdapter implements ThreeJSGraphicsAdapter {
export class StandaloneThreeJSAdapter implements ThreeJSGraphicsAdapter, StandaloneGraphicsAdapter {
collisionType: THREE.Object3D;
containerType: THREE.Object3D;

Expand Down
2 changes: 1 addition & 1 deletion packages/mml-web-threejs/src/elements/ThreeJSMElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ThreeJSMElement extends MElementGraphics<ThreeJSGraphicsAdapter> {
// If none of the ancestors are MElements then this element may be directly connected to the body (without a wrapper).
// Attempt to use a global scene that has been configured to attach this element to.
const scene = this.element.getScene();
this.currentParentContainer = scene.getRootContainer();
this.currentParentContainer = scene.getGraphicsAdapter().getRootContainer();
this.currentParentContainer.add(this.container);
}

Expand Down
3 changes: 0 additions & 3 deletions packages/mml-web/src/frame/CreateWrappedScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export function createWrappedScene<G extends GraphicsAdapter = GraphicsAdapter>(
) {
scene.link(linkProps, abortSignal, windowCallback);
},
getRootContainer: () => {
throw new Error("Wrapped scenes do not have a root container");
},
getUserPositionAndRotation: () => {
return scene.getUserPositionAndRotation();
},
Expand Down
14 changes: 3 additions & 11 deletions packages/mml-web/src/scene/MMLScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
CylinderGraphics,
DebugHelperGraphics,
FrameGraphics,
GraphicsAdapter,
ImageGraphics,
InteractionGraphics,
LabelGraphics,
Expand All @@ -39,10 +40,10 @@ import {
PromptGraphics,
RemoteDocumentGraphics,
SphereGraphics,
StandaloneGraphicsAdapter,
TransformableGraphics,
VideoGraphics,
} from "../graphics";
import { GraphicsAdapter, StandaloneGraphicsAdapter } from "../graphics";
import { InteractionManager } from "../interaction-ui";
import { LoadingProgressManager } from "../loading";
import { PromptManager } from "../prompt-ui";
Expand Down Expand Up @@ -118,8 +119,6 @@ export type IMMLScene<G extends GraphicsAdapter = GraphicsAdapter> = {
getGraphicsAdapter: () => G;
hasGraphicsAdapter: () => boolean;

getRootContainer: () => ReturnType<G["getRootContainer"]>;

addCollider?: (collider: unknown, element: MElement<G>) => void;
updateCollider?: (collider: unknown, element: MElement<G>) => void;
removeCollider?: (collider: unknown, element: MElement<G>) => void;
Expand Down Expand Up @@ -155,7 +154,7 @@ export type IMMLScene<G extends GraphicsAdapter = GraphicsAdapter> = {
*
* It is the default implementation of the IMMLScene interface and presents a fly camera with drag controls.
*/
export class MMLScene<G extends StandaloneGraphicsAdapter<any, any, any>> implements IMMLScene<G> {
export class MMLScene<G extends StandaloneGraphicsAdapter> implements IMMLScene<G> {
private colliders = new Set<unknown>();

private interactions = new Set<Interaction<G>>();
Expand Down Expand Up @@ -212,13 +211,6 @@ export class MMLScene<G extends StandaloneGraphicsAdapter<any, any, any>> implem
return this.graphicsAdapter;
}

public getRootContainer(): G["containerType"] {
if (!this.graphicsAdapter) {
throw new Error("MMLScene not initialized with a graphics adapter");
}
return this.graphicsAdapter.getRootContainer();
}

public getUserPositionAndRotation(): PositionAndRotation {
if (!this.graphicsAdapter) {
throw new Error("MMLScene not initialized with a graphics adapter");
Expand Down
6 changes: 4 additions & 2 deletions packages/mml-web/src/tag-debug-adapter/TagDebugMElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TagDebugMElement implements MElementGraphics<TagDebugGraphicsAdapte
// Attempt to use a global scene that has been configured to attach this element to.
const scene = this.mElement.getScene();
this.currentParent = scene;
(scene.getRootContainer() as HTMLElement).append(this.container);
(scene.getGraphicsAdapter().getRootContainer() as HTMLElement).append(this.container);
this.indentLevel = 0;
}

Expand Down Expand Up @@ -181,7 +181,9 @@ export class TagDebugMElement implements MElementGraphics<TagDebugGraphicsAdapte
this.currentParent.childElementHolder.removeChild(this.container);
this.currentParent = null;
} else {
(this.currentParent.getRootContainer() as HTMLElement).removeChild(this.container);
(this.currentParent.getGraphicsAdapter().getRootContainer() as HTMLElement).removeChild(
this.container,
);
this.currentParent = null;
}
}
Expand Down

0 comments on commit 61dcc35

Please sign in to comment.