@kupcad/ui 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,7 @@ import { disposeObject } from './dispose.js';
43
43
  import { axesOf, environmentOf } from './environment.js';
44
44
  import { faceAt } from './faces.js';
45
45
  import { HoverMark } from './hover-mark.js';
46
+ import { intersectMeshes } from './hits.js';
46
47
  import { disposeScene, isDracoCompressed, sceneOf } from './model.js';
47
48
  import { CameraMove, MOTION_MS, sameDirection, unit } from './motion.js';
48
49
  import { RENDER_ORDER, SectionView } from './section.js';
@@ -124,7 +125,8 @@ export class Viewer extends EventTarget {
124
125
  #sectionView;
125
126
  #raycaster = new Raycaster();
126
127
  /** The selected part's edges, in the selection's colour. */
127
- #selectionEdges = new LineBasicMaterial();
128
+ // See-through to three.js, as a drawing's outlines are, so a selected one keeps its order
129
+ #selectionEdges = new LineBasicMaterial({ transparent: true });
128
130
  /** What the pointer is over, marked. */
129
131
  #hoverMark = new HoverMark(LIGHT.selection);
130
132
  /** @type {SceneModel | null} */
@@ -305,7 +307,10 @@ export class Viewer extends EventTarget {
305
307
  }
306
308
  this.#model = built;
307
309
  if (built) {
308
- for (const shape of built.shapes) shape.mesh.renderOrder = RENDER_ORDER.model;
310
+ // A drawing's shapes keep their own order (model.js); a section cuts solids alone
311
+ if (built.kind === '3d') {
312
+ for (const shape of built.shapes) shape.mesh.renderOrder = RENDER_ORDER.model;
313
+ }
309
314
  this.#content.add(built.root);
310
315
  }
311
316
  const dropped =
@@ -866,16 +871,15 @@ export class Viewer extends EventTarget {
866
871
  this.#camera.updateMatrixWorld();
867
872
  const pointer = new Vector2((x / this.#width) * 2 - 1, 1 - (y / this.#height) * 2);
868
873
  this.#raycaster.setFromCamera(pointer, this.#camera);
874
+ const solid = this.#model.shapes.filter((shape) => !shape.ghost);
869
875
  /** @type {Map<import('three').Object3D, Shape>} */
870
- const solid = new Map();
871
- for (const shape of this.#model.shapes) {
872
- if (!shape.ghost) solid.set(shape.mesh, shape);
873
- }
874
- for (const hit of this.#raycaster.intersectObjects([...solid.keys()], false)) {
876
+ const shapeOf = new Map(solid.map((shape) => [shape.mesh, shape]));
877
+ const meshes = solid.map((shape) => shape.mesh);
878
+ for (const hit of intersectMeshes(this.#raycaster, meshes)) {
875
879
  if (this.#sectionView.clipping && this.#sectionView.plane.distanceToPoint(hit.point) < 0) {
876
880
  continue;
877
881
  }
878
- const shape = /** @type {Shape} */ (solid.get(hit.object));
882
+ const shape = /** @type {Shape} */ (shapeOf.get(hit.object));
879
883
  return { shape, triangle: hit.faceIndex ?? null };
880
884
  }
881
885
  return null;