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

Add interactive axes helper #440

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
34 changes: 33 additions & 1 deletion packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js';
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js';
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader';
import { ViewHelper } from 'three/examples/jsm/helpers/ViewHelper';

import { FloatingAnnotation } from '../annotation';
import { getCSSVariableColor, isLightTheme, throttle } from '../tools';
Expand Down Expand Up @@ -221,7 +222,10 @@ export class MainView extends React.Component<IProps, IStates> {
antialias: true,
stencil: true
});

this._clock = new THREE.Clock();
// this._renderer.setPixelRatio(window.devicePixelRatio);
this._renderer.autoClear = false;
this._renderer.setClearColor(0x000000, 0);
this._renderer.setSize(500, 500, false);
this.divRef.current.appendChild(this._renderer.domElement); // mount using React ref
Expand Down Expand Up @@ -351,11 +355,33 @@ export class MainView extends React.Component<IProps, IStates> {

this._transformControls.enabled = false;
this._transformControls.visible = false;

// ViewHelper setup
this._viewHelper = new ViewHelper(
this._camera,
this._renderer.domElement
);
this._viewHelper.center = this._controls.target;

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';

this.divRef.current.appendChild(viewHelperDiv);

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

animate = (): void => {
this._requestID = window.requestAnimationFrame(this.animate);
const delta = this._clock.getDelta();

for (const material of this._edgeMaterials) {
material.resolution.set(
Expand All @@ -372,11 +398,15 @@ export class MainView extends React.Component<IProps, IStates> {
this._clippingPlaneMesh.position.z - this._clippingPlane.normal.z
);
}
if (this._viewHelper.animating) {
this._viewHelper.update(delta);
}

this._controls.update();
this._renderer.setRenderTarget(null);
this._renderer.clearDepth();
this._renderer.clear();
this._renderer.render(this._scene, this._camera);
this._viewHelper.render(this._renderer);
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
};

resizeCanvasToDisplaySize = (): void => {
Expand Down Expand Up @@ -1411,6 +1441,8 @@ export class MainView extends React.Component<IProps, IStates> {
private _controls: OrbitControls; // Mouse controls
private _transformControls: TransformControls; // Mesh position/rotation controls
private _pointer3D: IPointer | null = null;
private _clock: THREE.Clock;
private _viewHelper: ViewHelper;
private _collaboratorPointers: IDict<IPointer>;
private _pointerGeometry: THREE.SphereGeometry;
private _contextMenu: ContextMenu;
Expand Down
Binary file modified ui-tests/tests/ui.spec.ts-snapshots/JCAD-New-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ui-tests/tests/ui.spec.ts-snapshots/JCAD-Undo-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading