Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdgeMeasurement does not work when you load multiple models #534

Open
5 tasks done
rgarciade opened this issue Nov 18, 2024 · 0 comments
Open
5 tasks done

EdgeMeasurement does not work when you load multiple models #534

rgarciade opened this issue Nov 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rgarciade
Copy link

Describe the bug 📝

I am using EdgeMeasurement after loading 2 or more linked ifc models and it only returns correct values for the first ifc model loaded.

The problem is that it fails to locate the center as it is shifted in the second and subsequent models loaded.

How to solve it?
I made a couple of changes in the “updateSelection” function of “EdgeMeasurement”.

create new method

private meshIsDesplaced(mesh: THREE.Mesh | THREE.InstancedMesh) {
    return (
      mesh &&
      mesh.parent &&
      mesh.parent.position.x !== 0 &&
      mesh.parent.position.y !== 0 &&
      mesh.parent.position.z !== 0
    );
}

// update "updateSelection"

 private updateSelection(
  mesh: THREE.Mesh | THREE.InstancedMesh,
  point: THREE.Vector3,
  faceIndex: number,
  instance?: number
) {
  if (!this.preview) {
    return;
  }
  if (!mesh.geometry.index) {
    return;
  }
  if (this.meshIsDesplaced(mesh)) {
    const parentPosition = (mesh.parent = mesh.parent as THREE.Mesh);
    point.x -= parentPosition.position.x;
    point.y -= parentPosition.position.y;
    point.z -= parentPosition.position.z;
  }

  const measurements = this.components.get(OBC.MeasurementUtils);
  const result = measurements.getFace(mesh, faceIndex, instance);
  if (!result) return;
  const { edges } = result;

  let minDistance = Number.MAX_VALUE;
  let currentEdge: THREE.Vector3[] = [];
  for (const edge of edges) {
    const [v1, v2] = edge.points;

    const distance = OBC.MeasurementUtils.distanceFromPointToLine(
      point,
      v1,
      v2,
      true
    );

    if (distance < this.tolerance && distance < minDistance) {
      minDistance = distance;
      currentEdge = edge.points;
    }
  }

  if (!currentEdge.length) {
    this.preview.visible = false;
    return;
  }
  let [start, end] = currentEdge;

  if (this.meshIsDesplaced(mesh)) {
    const parentPosition = (mesh.parent = mesh.parent as THREE.Mesh);
    const startX = start.x + parentPosition.position.x;
    const startY = start.y + parentPosition.position.y;
    const startZ = start.z + parentPosition.position.z;
    const endX = end.x + parentPosition.position.x;
    const endY = end.y + parentPosition.position.y;
    const endZ = end.z + parentPosition.position.z;
    start = new THREE.Vector3(startX, startY, startZ);
    end = new THREE.Vector3(endX, endY, endZ);
  }

  this.preview.startPoint = start;
  this.preview.endPoint = end;

  // const scene = this.components.scene.get();
  this.preview.visible = true;

}`

Reproduction ▶️

No response

Steps to reproduce 🔢

  1. Load more than one model
    2.Enable EdgeMeasurement
  2. Detect that in the second model we do not see the edgelines

System Info 💻

System:
    OS: macOS 15.0.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 112.83 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.2.0 - ~/.nvm/versions/node/v21.2.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v21.2.0/bin/npm
  Browsers:
    Chrome: 130.0.6723.117
    Edge: 130.0.2849.68
    Safari: 18.0.1

Used Package Manager 📦

npm

Error Trace/Logs 📃

No response

Validations ✅

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.
@rgarciade rgarciade added the bug Something isn't working label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant