-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(front): test platform component
- Loading branch information
Showing
7 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as OBC from "@thatopen/components"; | ||
|
||
export class PlatformComponents extends OBC.Component { | ||
/** | ||
* A unique identifier for the component. | ||
* This UUID is used to register the component within the Components system. | ||
*/ | ||
static readonly uuid = "74c0c370-1af8-4ca9-900a-4a4196c0f2f5" as const; | ||
|
||
enabled = true; | ||
|
||
private readonly _requestEventID = "thatOpenCompanyComponentRequested"; | ||
|
||
private readonly _createEventID = "thatOpenCompanyComponentCreated"; | ||
|
||
async import(componentSource: string) { | ||
return new Promise<OBC.ComponentWithUI>((resolve) => { | ||
const script = document.createElement("script"); | ||
|
||
const src = ` | ||
const { OBC, BUI } = window.ThatOpenCompany; | ||
${componentSource} | ||
const onComponentRequested = () => { | ||
window.removeEventListener("${this._requestEventID}", onComponentRequested); | ||
const event = new CustomEvent("${this._createEventID}", { detail: main }); | ||
window.dispatchEvent(event); | ||
}; | ||
window.addEventListener("${this._requestEventID}", onComponentRequested); | ||
`; | ||
|
||
const onCreated = (event: any) => { | ||
window.removeEventListener(this._createEventID, onCreated); | ||
|
||
const ComponentClass = event.detail as new ( | ||
components: OBC.Components, | ||
) => OBC.ComponentWithUI; | ||
|
||
const component = this.components.get(ComponentClass); | ||
script.remove(); | ||
resolve(component); | ||
}; | ||
|
||
script.addEventListener("load", () => { | ||
window.addEventListener(this._createEventID, onCreated); | ||
window.dispatchEvent(new Event(this._requestEventID)); | ||
}); | ||
|
||
script.src = URL.createObjectURL(new File([src], "temp.js")); | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | ||
<link rel="icon" type="image/x-icon" href="https://thatopen.github.io/engine_components/resources/favicon.ico"> | ||
<title>CloudComponents</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: "Plus Jakarta Sans", sans-serif; | ||
overflow: hidden; | ||
} | ||
|
||
.full-screen { | ||
width: 100vw; | ||
height: 100vh; | ||
position: relative; | ||
overflow: hidden; | ||
} | ||
|
||
.options-menu { | ||
position: fixed; | ||
min-width: unset; | ||
top: 5px; | ||
right: 5px; | ||
max-height: calc(100vh - 10px); | ||
} | ||
|
||
.phone-menu-toggler { | ||
visibility: hidden; | ||
} | ||
|
||
@media (max-width: 480px) { | ||
.options-menu { | ||
visibility: hidden; | ||
bottom: 5px; | ||
left: 5px; | ||
} | ||
|
||
.options-menu-visible { | ||
visibility: visible; | ||
} | ||
|
||
.phone-menu-toggler { | ||
visibility: visible; | ||
position: fixed; | ||
top: 5px; | ||
right: 5px; | ||
} | ||
} | ||
|
||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="full-screen" id="container"></div> | ||
<script type="module" src="./test.ts"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as OBC from "@thatopen/components"; | ||
import Stats from "stats.js"; | ||
import * as BUI from "@thatopen/ui"; | ||
import * as OBCF from "../.."; | ||
|
||
BUI.Manager.init(); | ||
|
||
const container = document.getElementById("container")!; | ||
|
||
const components = new OBC.Components(); | ||
|
||
const worlds = components.get(OBC.Worlds); | ||
|
||
const world = worlds.create< | ||
OBC.SimpleScene, | ||
OBC.SimpleCamera, | ||
OBCF.RendererWith2D | ||
>(); | ||
|
||
world.scene = new OBC.SimpleScene(components); | ||
world.renderer = new OBCF.RendererWith2D(components, container); | ||
world.camera = new OBC.SimpleCamera(components); | ||
|
||
components.init(); | ||
|
||
world.camera.controls.setLookAt(5, 5, 5, 0, 0, 0); | ||
|
||
container.appendChild(world.renderer.three2D.domElement); | ||
|
||
const grids = components.get(OBC.Grids); | ||
grids.create(world); | ||
|
||
world.scene.three.background = null; | ||
|
||
const stats = new Stats(); | ||
stats.showPanel(2); | ||
document.body.append(stats.dom); | ||
stats.dom.style.left = "0px"; | ||
stats.dom.style.zIndex = "unset"; | ||
world.renderer.onBeforeUpdate.add(() => stats.begin()); | ||
world.renderer.onAfterUpdate.add(() => stats.end()); | ||
|
||
(window as any).ThatOpenCompany = { OBC, BUI }; | ||
|
||
const cloudComponents = components.get(OBCF.PlatformComponents); | ||
const fetched = await fetch("../../../../../resources/mock-cloud-component.js"); | ||
const componentData = await fetched.text(); | ||
const test = await cloudComponents.import(componentData); | ||
const ui = test.getUI(); | ||
document.body.appendChild(ui[0].get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class PlatformComponent extends OBC.ComponentWithUI { | ||
static uuid = "392b7198-0193-4364-8b89-dfad1b386c50"; | ||
|
||
onDisposed = new OBC.Event(); | ||
|
||
enabled = true; | ||
|
||
name = "Mock Personal Component"; | ||
|
||
_uiElements = new Set(); | ||
|
||
constructor(components) { | ||
super(components); | ||
this.components.add(PlatformComponent.uuid, this); | ||
} | ||
|
||
getUI() { | ||
console.log("Hello from personal component!"); | ||
return [ | ||
{ | ||
name: "Panel", | ||
componentID: PlatformComponent.uuid, | ||
attributes: { | ||
label: "Hello" | ||
}, | ||
get: () => { | ||
const panel = BUI.Component.create(() => { | ||
return BUI.html` | ||
<bim-panel></bim-panel> | ||
`; | ||
}); | ||
this._uiElements.add(panel); | ||
return panel; | ||
} | ||
} | ||
]; | ||
} | ||
|
||
dispose() { | ||
for (const element of this._uiElements) { | ||
element.remove(); | ||
} | ||
this._uiElements.clear(); | ||
} | ||
} | ||
|
||
const main = PlatformComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters