-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
244 lines (208 loc) · 7.92 KB
/
index.html
File metadata and controls
244 lines (208 loc) · 7.92 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html class="h-full">
<head>
<title>Zea 4D Schedule Viewer</title>
<link
rel="shortcut icon"
type="image/png"
href="./data/favicon-32x32.png"
/>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.9/tailwind.min.css"
/>
<link rel="stylesheet" href="./src/styles.css"/>
<script src="https://cdn.jsdelivr.net/npm/@zeainc/zea-engine@4.12.0/dist/index.umd.js"></script>
<script src="./src/zea-fps-display.js" type="module"></script>
<script src="./src/schedule-view.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/@zeainc/zea-tree-view@0.1.0/dist/index.umd.development.js"></script>
<script src="./src/third-party/xlsx.js"></script>
<script src="./src/third-party/jszip.js"></script>
<script src="./src/third-party/moment.min.js"></script>
</head>
<body class="overflow-hidden h-full">
<div class="h-full flex flex-col">
<header class="p-2">
<img src="./data/logo-zea.svg" id="logo"></img>
</header>
<div class="flex" id="topPanel">
<div id="leftPanel">
<zea-tree-view
id="tree"
class="select-none"
></zea-tree-view>
</div>
<div class="separator" id="separatorV"></div>
<div id="mainPanel" class="flex-1">
<div id="canvas-holder">
<canvas id="canvas" > </canvas>
</div>
<div class="xr-button hidden" id="xr-button"></div>
<zea-fps-display class="fps-display" id="fps"></zea-fps-display>
<progress class="progress-display" id="progress" value="0" max="100">
0%
</progress>
</div>
</div>
<div class="separator" id="separatorH"></div>
<div id="bottomPanel">
<schedule-view id="schedule-viewer" class="w-full"></schedule-view>
</div>
</div>
<script type="module">
import { dragElement } from './src/panels.js'
const separatorV = document.getElementById("separatorV");
const leftPanel = document.getElementById("leftPanel");
const mainPanel = document.getElementById("mainPanel");
dragElement(separatorV, leftPanel, mainPanel, "H");
const separatorH = document.getElementById("separatorH");
const topPanel = document.getElementById("topPanel");
const bottomPanel = document.getElementById("bottomPanel");
dragElement(separatorH, topPanel, bottomPanel, "V");
</script>
<script type="module">
const {
Color,
Vec3,
EulerAngles,
Xfo,
ObjAsset,
Scene,
GLRenderer,
EnvMap,
resourceLoader,
GeomItem,
MeshProxy,
LinesProxy,CADAsset, CADBody
} = zeaEngine;
import init from "./src/init.js";
document.addEventListener('contextmenu', (event) => {
event.stopPropagation()
event.preventDefault()
})
function setupSceneAndRenderer() {
const urlParams = new URLSearchParams(window.location.search);
const scene = new Scene();
// scene.setupGrid(100.0, 10);
const renderer = new GLRenderer(document.getElementById("canvas"), {
debugGeomIds: false,
enableFrustumCulling: true,
enableOcclusionCulling: true,
debugOcclusionBuffer: false,
});
// //////////////////////////////////////////////////////
// Temporary fix till the next point release comes out.
// This code will be part of 3.11.2
let lastResize = performance.now();
let timoutId = 0;
const handleResize = renderer.handleResize.bind(renderer);
renderer.handleResize = (width, height) => {
// Note: Rapid resize events would cause WebGL to render black.
// There appeared nothing to indicate why we get black, but throttling
// the resizing of our canvas and buffers seems to work.
const now = performance.now();
if (now - lastResize > 100) {
lastResize = now;
// If a delayed resize is scheduled, cancel it.
if (timoutId) {
clearTimeout(timoutId);
timoutId = 0;
}
handleResize(width, height);
} else {
// Set a timer to see if we can delay this resize by a few ms.
// If a resize happens in the meantime that succeeds, then skip this one.
// This ensures that after a drag to resize, the final resize event
// should always eventually apply.
timoutId = setTimeout(() => {
const now = performance.now();
if (now - lastResize > 100) {
lastResize = now;
handleResize(width, height);
}
}, 100);
}
};
// //////////////////////////////////////////////////////
// renderer.outlineThickness = 0.75
// renderer.outlineSensitivity = 5
// renderer.solidAngleLimit = 0.0;
renderer.setScene(scene);
renderer
.getViewport()
.getCamera()
.setPositionAndTarget(new Vec3(12, 12, 10), new Vec3(0, 0, 1.5));
const envMap = new EnvMap();
envMap.load("./data/StudioG.zenv");
scene.setEnvMap(envMap);
// renderer.on("resized", (event) => {
// console.log("resized:", event)
// });
// renderer.on("redrawOccurred", () => {
// console.log("redrawOccurred")
// });
renderer.getViewport().backgroundColorParam.value = new Color('#87CEEB')
// .getViewport().setBackgroundColor(new Color('#87CEEB'))
renderer
.getViewport()
.getCamera()
.setPositionAndTarget(new Vec3(-80, -40, 20), new Vec3(40, 80, 10))
const schedule = init(scene)
// Setup TreeView Display
const treeElement = document.getElementById("tree");
treeElement.setTreeItem(scene.getRoot());
// Setup Schedule view
const scheduleViewer = document.getElementById("schedule-viewer");
scheduleViewer.schedule = schedule
// Setup FPS Display
const fpsElement = document.getElementById("fps");
fpsElement.renderer = renderer;
const filterItem = (item) => item
renderer.getViewport().on("pointerDown", (event) => {
if (event.intersectionData) {
const geomItem = filterItem(event.intersectionData.geomItem);
console.log(geomItem.getPath());
}
});
resourceLoader.on("progressIncremented", (event) => {
const pct = document.getElementById("progress");
pct.value = event.percent;
if (event.percent >= 100) {
setTimeout(() => pct.classList.add("hidden"), 1000);
}
});
renderer.getXRViewport().then((xrvp) => {
fpsElement.style.bottom = "70px";
const xrButton = document.getElementById("xr-button");
xrButton.textContent = "Launch VR";
xrButton.classList.remove("hidden");
xrvp.on("presentingChanged", (event) => {
const { state } = event;
if (state) {
xrButton.textContent = "Exit VR";
} else {
xrButton.textContent = "Launch VR";
}
});
xrButton.addEventListener("click", function (event) {
xrvp.togglePresenting();
});
document.addEventListener("keydown", (event) => {
if (event.key == " ") {
xrvp.togglePresenting();
}
});
});
if (urlParams.has("profile")) {
renderer.startContinuousDrawing();
}
}
const { IndexDBCache } = zeaEngine
resourceLoader.cache = new IndexDBCache('zcad-viewer', 'zcad')
resourceLoader.cache.init().then(() => {
setupSceneAndRenderer()
})
</script>
</body>
</html>