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

Drag and drop ability on viewer #9

Merged
merged 15 commits into from
Nov 11, 2024
Merged

Drag and drop ability on viewer #9

merged 15 commits into from
Nov 11, 2024

Conversation

parveshneedhoo
Copy link
Collaborator

Right now, on the 3D-viewer measurement, we can place two spheres to measure the distance between two points. In this PR, we will add the ability to drag the sphere once it is placed.

Copy link
Member

@ombr ombr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Table should not be displayed when loading
  • We should use a # instead of a query param ?
  • when we drag we should stay on the surface
  • Nice to have but may be done a another pull-request (Bonus) save the lines added to the url ?

Copy link
Member

@zfir zfir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove all spheres when clearing all - when adding the first and not the second one, it does not clear all spheres

src/measurements.ts Outdated Show resolved Hide resolved
Copy link
Member

@ombr ombr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test url is not working ?

@parveshneedhoo
Copy link
Collaborator Author

Test url is not working ?

Oops no @ombr

I forgot to replace the "?" by "#" one the url.

It works now

However for the 3D file, I think it has been moved, I need to check with @zfir to change the value in the environment variable

Copy link
Member

@zfir zfir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parveshneedhoo Can we check if we can move the controls to another class

src/measurements.ts Outdated Show resolved Hide resolved
src/measurements.ts Outdated Show resolved Hide resolved
src/measurements.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@@ -28,11 +28,11 @@
<tbody id="measurements"></tbody>
</table>
</div>
<div id="loading">
<div id="loading" style="display: none;">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use inline styling?

import { Measurements } from "./measurements";

export class DragControlHandler {
private control: DragControls;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private control: DragControls;
private controls: DragControls;

Copy link
Member

@ombr ombr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior is good for me, I did not check all the code.

src/drag-control-handler.ts Show resolved Hide resolved
src/drag-control-handler.ts Show resolved Hide resolved
src/drag-control-handler.ts Outdated Show resolved Hide resolved
src/drag-control-handler.ts Outdated Show resolved Hide resolved
src/drag-control-handler.ts Outdated Show resolved Hide resolved
src/measurements.ts Show resolved Hide resolved
new THREE.BufferGeometry().setFromPoints([sphere1.position, sphere2.position]),
new THREE.LineBasicMaterial({ color })
),
color,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color,
this.generatedColor,

src/measurements.ts Outdated Show resolved Hide resolved
src/measurements.ts Outdated Show resolved Hide resolved
Comment on lines 62 to +63
window.addEventListener("unload", this.cleanup.bind(this));
container.addEventListener("click", this.onMouseClick.bind(this), false);
container.addEventListener("mousedown", this.onMouseDown.bind(this), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if better to use Arrow funcctions here. Can be done in another PR

Copy link
Member

@zfir zfir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should be handle all the events from loader and measurement in Drag Control Handler?
  • Loader -> Measurement -> DragControlHandler : I think we handle the classes like and for example DragControlHandler should not have loader as a global variable

I will merge it like this. The comments can be handled in the next PR.

Reviewed with @parveshneedhoo

renderer: THREE.WebGLRenderer,
private loader: Loader,
private onDrag: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>) => void,
private onDragEnd: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>, event: any) => void,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private onDragEnd: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>, event: any) => void,
private onDragEnd: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>, event: Event) => void,

private loader: Loader,
private onDrag: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>) => void,
private onDragEnd: (object: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial>, event: any) => void,
measurements: Measurements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
measurements: Measurements
measurements: Measurements

Move above privates

window.addEventListener('mousedown', this.onMouseDown);
this.loader.lockRotationAndClick();

measurement.lastIntersectedPosition = event.object.position.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use callback in measurement


private handleDragEnd(event: THREE.Event, measurement: Measurements) {
const onMouseUp = (mouseEvent: MouseEvent) => {
measurement.updateMouse(mouseEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
measurement.updateMouse(mouseEvent);
measurement.updateMouse(mouseEvent);

use measurement in measurement

@@ -54,11 +56,45 @@ export class Loader {

container.appendChild(this.renderer.domElement);

this.measurement = new Measurements(this.scene);
this.measurement = new Measurements(this.scene, this.camera, this.renderer, this.group, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.measurement = new Measurements(this.scene, this.camera, this.renderer, this.group, this);
this.measurement = new Measurements(this.scene, this.camera, this.renderer, this.group);

Handle all events in drag-control-handler

sphere2,
line: new THREE.Line(
new THREE.BufferGeometry().setFromPoints([sphere1.position, sphere2.position]),
new THREE.LineBasicMaterial({ color })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new THREE.LineBasicMaterial({ color })
new THREE.LineBasicMaterial({ color: this.generatedColor })

Comment on lines +141 to +143
this.spherePairs = [];
this.currentSpheres = [];
this.generatedColor = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplication should we move that to a new function

@zfir zfir merged commit 4e1b25c into main Nov 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants