Skip to content

Commit

Permalink
update: isolate controls into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Aug 2, 2023
1 parent fdcfe77 commit 933d19f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/components/ThreejsEditorModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ThreejsEditorModal extends ModalDialog {
this.domElement = el;
this.setNumberFormat();
this.initializeEditor();
this.initializeControlsInEditor();
this.addEventListeners();
this.addSignalsListeners();
this.loadScene();
Expand Down Expand Up @@ -82,6 +83,17 @@ export class ThreejsEditorModal extends ModalDialog {
this.editor.scene.add(directionalLight);
}

initializeControlsInEditor() {
// initialize controls
this.editor.controls = new OrbitControls(this.editor.camera, this.viewport.dom);
this.editor.controls.up = new THREE.Vector3(0, 0, 1);

// set controls parameters
this.editor.controls.panSpeed = 0.006;
this.editor.controls.rotationSpeed = 0.015;
this.editor.controls.zoomSpeed = 0.2;
}

/**
* Initialize threejs editor and add it to the DOM.
*/
Expand All @@ -97,8 +109,8 @@ export class ThreejsEditorModal extends ModalDialog {
this.editor.onHide = this.onHide;

// initialize viewport and add it to the DOM
const viewport = new Viewport(this.editor);
this.domElement.appendChild(viewport.dom);
this.viewport = new Viewport(this.editor);
this.domElement.appendChild(this.viewport.dom);

// initialize UI elements and add them to the DOM
const script = new Script(this.editor);
Expand All @@ -112,15 +124,6 @@ export class ThreejsEditorModal extends ModalDialog {
const toolbar = new Toolbar(this.editor);
this.domElement.appendChild(toolbar.dom);

// initialize controls
this.editor.controls = new OrbitControls(this.editor.camera, viewport.dom);
this.editor.controls.up = new THREE.Vector3(0, 0, 1);

// set controls parameters
this.editor.controls.panSpeed = 0.006;
this.editor.controls.rotationSpeed = 0.015;
this.editor.controls.zoomSpeed = 0.2;

this.initializeLights();
}

Expand Down

0 comments on commit 933d19f

Please sign in to comment.