Spaces:
Running
Running
Commit
•
b95cc56
1
Parent(s):
c4d103b
improved wireframe
Browse files
src/routes/Vote.svelte
CHANGED
@@ -22,6 +22,10 @@
|
|
22 |
let containerB: HTMLDivElement;
|
23 |
let overlayA: HTMLDivElement;
|
24 |
let overlayB: HTMLDivElement;
|
|
|
|
|
|
|
|
|
25 |
let loadingBarFillA: HTMLDivElement;
|
26 |
let loadingBarFillB: HTMLDivElement;
|
27 |
let voteOverlay: boolean = false;
|
@@ -215,6 +219,7 @@
|
|
215 |
name="modeA"
|
216 |
value="default"
|
217 |
checked
|
|
|
218 |
on:change={() => setRenderMode(viewerA, "default")}
|
219 |
/>
|
220 |
<Cube class="mode-toggle-icon" />
|
@@ -224,6 +229,7 @@
|
|
224 |
type="radio"
|
225 |
name="modeA"
|
226 |
value="wireframe"
|
|
|
227 |
on:change={() => setRenderMode(viewerA, "wireframe")}
|
228 |
/>
|
229 |
<WatsonHealth3DPrintMesh class="mode-toggle-icon" />
|
@@ -250,6 +256,7 @@
|
|
250 |
name="modeB"
|
251 |
value="default"
|
252 |
checked
|
|
|
253 |
on:change={() => setRenderMode(viewerB, "default")}
|
254 |
/>
|
255 |
<Cube class="mode-toggle-icon" />
|
@@ -259,6 +266,7 @@
|
|
259 |
type="radio"
|
260 |
name="modeB"
|
261 |
value="wireframe"
|
|
|
262 |
on:change={() => setRenderMode(viewerB, "wireframe")}
|
263 |
/>
|
264 |
<WatsonHealth3DPrintMesh class="mode-toggle-icon" />
|
|
|
22 |
let containerB: HTMLDivElement;
|
23 |
let overlayA: HTMLDivElement;
|
24 |
let overlayB: HTMLDivElement;
|
25 |
+
let normalToggleA: HTMLInputElement;
|
26 |
+
let normalToggleB: HTMLInputElement;
|
27 |
+
let wireframeToggleA: HTMLInputElement;
|
28 |
+
let wireframeToggleB: HTMLInputElement;
|
29 |
let loadingBarFillA: HTMLDivElement;
|
30 |
let loadingBarFillB: HTMLDivElement;
|
31 |
let voteOverlay: boolean = false;
|
|
|
219 |
name="modeA"
|
220 |
value="default"
|
221 |
checked
|
222 |
+
bind:this={normalToggleA}
|
223 |
on:change={() => setRenderMode(viewerA, "default")}
|
224 |
/>
|
225 |
<Cube class="mode-toggle-icon" />
|
|
|
229 |
type="radio"
|
230 |
name="modeA"
|
231 |
value="wireframe"
|
232 |
+
bind:this={wireframeToggleA}
|
233 |
on:change={() => setRenderMode(viewerA, "wireframe")}
|
234 |
/>
|
235 |
<WatsonHealth3DPrintMesh class="mode-toggle-icon" />
|
|
|
256 |
name="modeB"
|
257 |
value="default"
|
258 |
checked
|
259 |
+
bind:this={normalToggleB}
|
260 |
on:change={() => setRenderMode(viewerB, "default")}
|
261 |
/>
|
262 |
<Cube class="mode-toggle-icon" />
|
|
|
266 |
type="radio"
|
267 |
name="modeB"
|
268 |
value="wireframe"
|
269 |
+
bind:this={wireframeToggleB}
|
270 |
on:change={() => setRenderMode(viewerB, "wireframe")}
|
271 |
/>
|
272 |
<WatsonHealth3DPrintMesh class="mode-toggle-icon" />
|
src/routes/viewers/BabylonViewer.ts
CHANGED
@@ -12,13 +12,13 @@ export class BabylonViewer implements IViewer {
|
|
12 |
|
13 |
vertexCount: number = 0;
|
14 |
|
15 |
-
private
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
constructor(canvas: HTMLCanvasElement) {
|
24 |
this.canvas = canvas;
|
@@ -51,6 +51,17 @@ export class BabylonViewer implements IViewer {
|
|
51 |
this.camera.panningSensibility = 10000 / this.camera.radius;
|
52 |
});
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
this.handleResize = this.handleResize.bind(this);
|
55 |
window.addEventListener("resize", this.handleResize);
|
56 |
this.canvas.addEventListener("wheel", (e) => e.preventDefault());
|
@@ -133,7 +144,7 @@ export class BabylonViewer implements IViewer {
|
|
133 |
if (this.engine) {
|
134 |
this.engine.dispose();
|
135 |
}
|
136 |
-
this.
|
137 |
window.removeEventListener("resize", this.handleResize);
|
138 |
this.canvas.removeEventListener("wheel", (e) => e.preventDefault());
|
139 |
}
|
@@ -152,28 +163,47 @@ export class BabylonViewer implements IViewer {
|
|
152 |
}
|
153 |
|
154 |
setRenderMode(mode: string) {
|
155 |
-
this.scene.forceWireframe = mode === "wireframe";
|
156 |
if (mode === "wireframe") {
|
157 |
this.scene.meshes.forEach((mesh) => {
|
158 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
if (material) {
|
160 |
-
this.
|
161 |
-
|
162 |
-
emissiveColor: material.emissiveColor,
|
163 |
-
});
|
164 |
-
material.albedoColor = new BABYLON.Color3(0, 0, 0);
|
165 |
-
material.emissiveColor = new BABYLON.Color3(1, 0.13, 0);
|
166 |
}
|
|
|
|
|
|
|
|
|
167 |
});
|
168 |
} else {
|
|
|
|
|
|
|
|
|
|
|
169 |
this.scene.meshes.forEach((mesh) => {
|
170 |
-
const
|
|
|
|
|
|
|
|
|
|
|
171 |
if (material) {
|
172 |
-
|
173 |
-
if (originalColors) {
|
174 |
-
material.albedoColor = originalColors.albedoColor;
|
175 |
-
material.emissiveColor = originalColors.emissiveColor;
|
176 |
-
}
|
177 |
}
|
178 |
});
|
179 |
}
|
|
|
12 |
|
13 |
vertexCount: number = 0;
|
14 |
|
15 |
+
private _originalMaterials: Map<BABYLON.AbstractMesh, BABYLON.Material> = new Map();
|
16 |
+
private _originalVertexColors: Map<BABYLON.AbstractMesh, BABYLON.Nullable<BABYLON.FloatArray>> = new Map();
|
17 |
+
private _wireframes: Array<BABYLON.Mesh> = [];
|
18 |
+
|
19 |
+
private _solidColor = new BABYLON.Color4(1, 1, 1, 1);
|
20 |
+
private _wireframeMaterial: BABYLON.StandardMaterial;
|
21 |
+
private _solidMaterial: BABYLON.StandardMaterial;
|
22 |
|
23 |
constructor(canvas: HTMLCanvasElement) {
|
24 |
this.canvas = canvas;
|
|
|
51 |
this.camera.panningSensibility = 10000 / this.camera.radius;
|
52 |
});
|
53 |
|
54 |
+
this._wireframeMaterial = new BABYLON.StandardMaterial("wireframe", this.scene);
|
55 |
+
this._wireframeMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
|
56 |
+
this._wireframeMaterial.emissiveColor = new BABYLON.Color3(0.7, 0.7, 0.7);
|
57 |
+
this._wireframeMaterial.zOffset = 1;
|
58 |
+
this._wireframeMaterial.disableLighting = true;
|
59 |
+
this._wireframeMaterial.wireframe = true;
|
60 |
+
|
61 |
+
this._solidMaterial = new BABYLON.StandardMaterial("solid", this.scene);
|
62 |
+
this._solidMaterial.diffuseColor = new BABYLON.Color3(0.8, 0.8, 0.8);
|
63 |
+
this._solidMaterial.alphaMode = 0;
|
64 |
+
|
65 |
this.handleResize = this.handleResize.bind(this);
|
66 |
window.addEventListener("resize", this.handleResize);
|
67 |
this.canvas.addEventListener("wheel", (e) => e.preventDefault());
|
|
|
144 |
if (this.engine) {
|
145 |
this.engine.dispose();
|
146 |
}
|
147 |
+
this._originalMaterials.clear();
|
148 |
window.removeEventListener("resize", this.handleResize);
|
149 |
this.canvas.removeEventListener("wheel", (e) => e.preventDefault());
|
150 |
}
|
|
|
163 |
}
|
164 |
|
165 |
setRenderMode(mode: string) {
|
|
|
166 |
if (mode === "wireframe") {
|
167 |
this.scene.meshes.forEach((mesh) => {
|
168 |
+
const vertexData = mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind);
|
169 |
+
if (vertexData) {
|
170 |
+
this._originalVertexColors.set(mesh, vertexData);
|
171 |
+
|
172 |
+
const newVertexData = new Array<number>(vertexData.length);
|
173 |
+
for (let i = 0; i < vertexData.length; i += 4) {
|
174 |
+
newVertexData[i] = this._solidColor.r;
|
175 |
+
newVertexData[i + 1] = this._solidColor.g;
|
176 |
+
newVertexData[i + 2] = this._solidColor.b;
|
177 |
+
newVertexData[i + 3] = this._solidColor.a;
|
178 |
+
}
|
179 |
+
mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, newVertexData);
|
180 |
+
}
|
181 |
+
|
182 |
+
const material = mesh.material as BABYLON.StandardMaterial;
|
183 |
if (material) {
|
184 |
+
this._originalMaterials.set(mesh, material);
|
185 |
+
mesh.material = this._solidMaterial;
|
|
|
|
|
|
|
|
|
186 |
}
|
187 |
+
|
188 |
+
const wireframeMesh = mesh.clone(mesh.name + "_wireframe", null) as BABYLON.Mesh;
|
189 |
+
wireframeMesh.material = this._wireframeMaterial;
|
190 |
+
this._wireframes.push(wireframeMesh);
|
191 |
});
|
192 |
} else {
|
193 |
+
this._wireframes.forEach((mesh) => {
|
194 |
+
mesh.dispose();
|
195 |
+
});
|
196 |
+
this._wireframes = [];
|
197 |
+
|
198 |
this.scene.meshes.forEach((mesh) => {
|
199 |
+
const vertexData = this._originalVertexColors.get(mesh);
|
200 |
+
if (vertexData) {
|
201 |
+
mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, vertexData);
|
202 |
+
}
|
203 |
+
|
204 |
+
const material = this._originalMaterials.get(mesh);
|
205 |
if (material) {
|
206 |
+
mesh.material = material;
|
|
|
|
|
|
|
|
|
207 |
}
|
208 |
});
|
209 |
}
|
src/routes/viewers/SplatViewer.ts
CHANGED
@@ -18,6 +18,8 @@ export class SplatViewer implements IViewer {
|
|
18 |
this.canvas = canvas;
|
19 |
|
20 |
this.renderer = new SPLAT.WebGLRenderer(canvas);
|
|
|
|
|
21 |
this.scene = new SPLAT.Scene();
|
22 |
this.camera = new SPLAT.Camera();
|
23 |
this.controls = new SPLAT.OrbitControls(this.camera, canvas);
|
|
|
18 |
this.canvas = canvas;
|
19 |
|
20 |
this.renderer = new SPLAT.WebGLRenderer(canvas);
|
21 |
+
this.renderer.renderProgram.outlineColor = new SPLAT.Color32(180, 180, 180);
|
22 |
+
|
23 |
this.scene = new SPLAT.Scene();
|
24 |
this.camera = new SPLAT.Camera();
|
25 |
this.controls = new SPLAT.OrbitControls(this.camera, canvas);
|