Fix wireframe mode for cap meshes
This commit is contained in:
parent
419b58fe56
commit
c20b682d33
3 changed files with 40 additions and 7 deletions
|
@ -3,7 +3,10 @@ import { buildMeshes } from "./utils/build-meshes";
|
||||||
import { Extent, buildScene } from "./utils/build-scene";
|
import { Extent, buildScene } from "./utils/build-scene";
|
||||||
import { getMetadata } from "./utils/utils";
|
import { getMetadata } from "./utils/utils";
|
||||||
import { MODEL_ID, SERVICE_URL } from "./config";
|
import { MODEL_ID, SERVICE_URL } from "./config";
|
||||||
import { buildClippingplanes } from "./utils/build-clipping-planes";
|
import {
|
||||||
|
Orientation,
|
||||||
|
buildClippingplanes,
|
||||||
|
} from "./utils/build-clipping-planes";
|
||||||
import { buildCoordinateGrid } from "./utils/build-coordinate-grid";
|
import { buildCoordinateGrid } from "./utils/build-coordinate-grid";
|
||||||
import { DragControls } from "three/examples/jsm/Addons.js";
|
import { DragControls } from "three/examples/jsm/Addons.js";
|
||||||
|
|
||||||
|
@ -60,11 +63,30 @@ export class SceneView {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleWireFrame() {
|
toggleWireFrame() {
|
||||||
|
// Set global wireframe mode data
|
||||||
|
this._scene.userData.wireframe = !this._scene.userData.wireframe;
|
||||||
|
|
||||||
|
// Set wireframe for model
|
||||||
const model = this._model;
|
const model = this._model;
|
||||||
model.children.forEach((child) => {
|
model.children.forEach((child) => {
|
||||||
const material = (child as Mesh).material as MeshStandardMaterial;
|
const material = (child as Mesh).material as MeshStandardMaterial;
|
||||||
material.wireframe = !material.wireframe;
|
material.wireframe = !material.wireframe;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set wireframe for any existing cap meshes
|
||||||
|
for (const key of Object.values(Orientation)) {
|
||||||
|
const name = `cap-mesh-group-${key}`;
|
||||||
|
const capMeshGroup = this._scene.getObjectByName(name);
|
||||||
|
|
||||||
|
if (capMeshGroup) {
|
||||||
|
capMeshGroup.children.forEach((mesh) => {
|
||||||
|
const material = (mesh as Mesh).material as MeshStandardMaterial;
|
||||||
|
if (material) {
|
||||||
|
material.wireframe = !material.wireframe;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { DragControls, OrbitControls } from "three/examples/jsm/Addons.js";
|
||||||
import { Extent } from "./build-scene";
|
import { Extent } from "./build-scene";
|
||||||
import earcut from "earcut";
|
import earcut from "earcut";
|
||||||
|
|
||||||
enum Orientation {
|
export enum Orientation {
|
||||||
X = "x",
|
X = "x",
|
||||||
Y = "y",
|
Y = "y",
|
||||||
Z = "z",
|
Z = "z",
|
||||||
|
@ -317,7 +317,13 @@ export function buildClippingplanes(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate new cap meshes
|
// Generate new cap meshes
|
||||||
const capMeshes = generateCapMeshes(meshes, plane, planes, orientation);
|
const capMeshes = generateCapMeshes(
|
||||||
|
meshes,
|
||||||
|
plane,
|
||||||
|
planes,
|
||||||
|
orientation,
|
||||||
|
scene
|
||||||
|
);
|
||||||
|
|
||||||
// Add new cap meshes
|
// Add new cap meshes
|
||||||
if (capMeshes.length > 0) {
|
if (capMeshes.length > 0) {
|
||||||
|
@ -456,7 +462,8 @@ function generateCapMeshes(
|
||||||
meshes: Mesh[],
|
meshes: Mesh[],
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
planes: Plane[],
|
planes: Plane[],
|
||||||
orientation: Orientation
|
orientation: Orientation,
|
||||||
|
scene: Scene
|
||||||
) {
|
) {
|
||||||
const capMeshes: Mesh[] = [];
|
const capMeshes: Mesh[] = [];
|
||||||
|
|
||||||
|
@ -526,6 +533,7 @@ function generateCapMeshes(
|
||||||
polygonOffsetFactor: offset,
|
polygonOffsetFactor: offset,
|
||||||
polygonOffsetUnits: offset,
|
polygonOffsetUnits: offset,
|
||||||
clippingPlanes,
|
clippingPlanes,
|
||||||
|
wireframe: scene.userData.wireframe,
|
||||||
});
|
});
|
||||||
|
|
||||||
const localMeshes = polygons.map((polygon) => {
|
const localMeshes = polygons.map((polygon) => {
|
||||||
|
@ -560,7 +568,7 @@ function buildPolygons(edges: Array<[Vector3, Vector3]>): Vector3[][] {
|
||||||
const polygons: Vector3[][] = [];
|
const polygons: Vector3[][] = [];
|
||||||
const edgeMap = new Map<string, [Vector3, Vector3]>();
|
const edgeMap = new Map<string, [Vector3, Vector3]>();
|
||||||
|
|
||||||
// Populate the edgeMap for fast lookups
|
// Populate the edgeMap
|
||||||
for (const [v1, v2] of edges) {
|
for (const [v1, v2] of edges) {
|
||||||
edgeMap.set(`${v1.x},${v1.y},${v1.z}-${v2.x},${v2.y},${v2.z}`, [v1, v2]);
|
edgeMap.set(`${v1.x},${v1.y},${v1.z}-${v2.x},${v2.y},${v2.z}`, [v1, v2]);
|
||||||
}
|
}
|
||||||
|
@ -604,10 +612,12 @@ function buildPolygons(edges: Array<[Vector3, Vector3]>): Vector3[][] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundNextEdge) break; // Stop if no connected edge is found
|
// Stop if no connected edge is found
|
||||||
|
if (!foundNextEdge) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (polygon.length >= 3) polygons.push(polygon); // Ensure valid polygon with at least 3 vertices
|
// Ensure valid polygon with at least 3 vertices
|
||||||
|
if (polygon.length >= 3) polygons.push(polygon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return polygons;
|
return polygons;
|
||||||
|
|
|
@ -92,6 +92,7 @@ export function buildScene(container: HTMLElement, extent: Extent) {
|
||||||
|
|
||||||
// Scene will hold all our elements such as objects, cameras and lights
|
// Scene will hold all our elements such as objects, cameras and lights
|
||||||
scene = new Scene();
|
scene = new Scene();
|
||||||
|
scene.userData.wireframe = false;
|
||||||
|
|
||||||
// Add lights to the scene
|
// Add lights to the scene
|
||||||
const lights = buildDefaultLights();
|
const lights = buildDefaultLights();
|
||||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue