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

Fix breaking viewHelper while changing camera #469

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,29 +362,38 @@ export class MainView extends React.Component<IProps, IStates> {

this._transformControls.enabled = false;
this._transformControls.visible = false;
this._createViewHelper();
}
};

// ViewHelper setup
this._viewHelper = new ViewHelper(
this._camera,
this._renderer.domElement
);
this._viewHelper.center = this._controls.target;
private _createViewHelper() {
// Remove the existing ViewHelperDiv if it already exists
if (
this._viewHelperDiv &&
this.divRef.current?.contains(this._viewHelperDiv)
) {
this.divRef.current.removeChild(this._viewHelperDiv);
}

const viewHelperDiv = document.createElement('div');
viewHelperDiv.id = 'viewHelper';
viewHelperDiv.style.position = 'absolute';
viewHelperDiv.style.right = '0px';
viewHelperDiv.style.bottom = '0px';
viewHelperDiv.style.height = '128px';
viewHelperDiv.style.width = '128px';
// Create new ViewHelper
this._viewHelper = new ViewHelper(this._camera, this._renderer.domElement);
this._viewHelper.center = this._controls.target;

this.divRef.current.appendChild(viewHelperDiv);
const viewHelperDiv = document.createElement('div');
viewHelperDiv.style.position = 'absolute';
viewHelperDiv.style.right = '0px';
viewHelperDiv.style.bottom = '0px';
viewHelperDiv.style.height = '128px';
viewHelperDiv.style.width = '128px';

viewHelperDiv.addEventListener('pointerup', event =>
this._viewHelper.handleClick(event)
);
}
};
this._viewHelperDiv = viewHelperDiv;

this.divRef.current?.appendChild(this._viewHelperDiv);
Copy link
Member

Choose a reason for hiding this comment

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

Just a question, how are we removing the old one now?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're not removing it now as it was not necessary, just updating it with updateCamera works.

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is that you re-create a new this._viewHelperDiv in updateCamera, that you append to this.divRef.current.

Don't we need to remove the old this._viewHelperDiv that was created before?

Copy link
Member Author

Choose a reason for hiding this comment

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

image

Yes you're right, I just verified. Sorry that I overlooked, I'll be omw to fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 4602e00

Thank You for pointing this out :)


this._viewHelperDiv.addEventListener('pointerup', event =>
this._viewHelper.handleClick(event)
);
}

animate = (): void => {
this._requestID = window.requestAnimationFrame(this.animate);
Expand Down Expand Up @@ -1312,6 +1321,7 @@ export class MainView extends React.Component<IProps, IStates> {
}

this._camera.add(this._cameraLight);
this._createViewHelper();

this._scene.add(this._camera);
this._controls.object = this._camera;
Expand Down Expand Up @@ -1476,6 +1486,7 @@ export class MainView extends React.Component<IProps, IStates> {
private _pointer3D: IPointer | null = null;
private _clock: THREE.Clock;
private _viewHelper: ViewHelper;
private _viewHelperDiv: HTMLDivElement | null = null;
private _collaboratorPointers: IDict<IPointer>;
private _pointerGeometry: THREE.SphereGeometry;
private _contextMenu: ContextMenu;
Expand Down
Loading