-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.ts
99 lines (77 loc) · 2.54 KB
/
index2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import * as BUI from "../engine_ui-components/packages/core/src"
import * as OBC from "../engine_components/packages/components/src"
BUI.UIManager.registerComponents()
const grid = document.querySelector<BUI.Grid>("bim-grid")!
grid.layouts = {
main: `
"c-toolbars-ribbon" 80px
"c-viewports-center" 1fr
`
}
grid.layout = "main"
const viewport3D = grid.querySelector<BUI.Viewport>("bim-viewport[name='view-3d']")!
viewport3D.remove()
const viewerA = new OBC.Components()
viewerA.uiEnabled = false
const sceneComponentA = new OBC.SimpleScene(viewerA)
sceneComponentA.setup()
viewerA.scene = sceneComponentA
const rendererComponentA = new OBC.PostproductionRenderer(viewerA, viewport3D)
viewerA.renderer = rendererComponentA
const cameraComponentA = new OBC.OrthoPerspectiveCamera(viewerA)
viewerA.camera = cameraComponentA
await viewerA.init()
viewport3D.addEventListener("resize", () => {
rendererComponentA.resize()
cameraComponentA.updateAspect()
})
new OBC.SimpleGrid(viewerA)
// ------
const viewport2D = grid.querySelector<BUI.Viewport>("bim-viewport[name='view-2d']")!
viewport2D.remove()
const viewerB = new OBC.Components()
viewerB.uiEnabled = false
const sceneComponentB = new OBC.SimpleScene(viewerB)
sceneComponentB.setup()
viewerB.scene = sceneComponentB
const rendererComponentB = new OBC.PostproductionRenderer(viewerB, viewport2D)
viewerB.renderer = rendererComponentB
const cameraComponentB = new OBC.OrthoPerspectiveCamera(viewerB)
viewerB.camera = cameraComponentB
await viewerB.init()
viewport2D.addEventListener("resize", () => {
rendererComponentB.resize()
cameraComponentB.updateAspect()
})
new OBC.SimpleGrid(viewerB)
// Tab switcher
const tabs = {
A: viewport2D,
B: viewport3D,
}
const [view, updateView] = BUI.UIComponent.create((state: { tabs: Record<string, HTMLElement>, tab: string }) => {
const { tabs, tab } = state
const element = tabs[tab]
return BUI.html`<div style="height: 100%">${element}</div>`
}, {tabs, tab: "A"})
const switcher = BUI.UIComponent.create(() => {
const selector = document.createElement("bim-selector-input")
selector.style.width = "10rem"
for (const key in tabs) {
const option = document.createElement("bim-option")
option.label = key
selector.append(option)
}
selector.value = "A"
selector.addEventListener("change", () => {
updateView({tab: selector.value})
})
return BUI.html`
<div style="height: 100%">
${selector}
${view}
</div>
`
})
const viewportsContainer = grid.getContainer("viewports", "center")
viewportsContainer.append(switcher)