From 625f88a0bd9247e965134f8600e8fb017e5270ee Mon Sep 17 00:00:00 2001 From: ostatni5 <26521377+ostatni5@users.noreply.github.com> Date: Fri, 19 Nov 2021 14:03:11 +0100 Subject: [PATCH] rename BoundingZone to WorldZone (#183) --- ...gZone.js => Sidebar.Geometry.WorldZone.js} | 30 ++++++++-------- src/ThreeEditor/js/Sidebar.Geometry.js | 6 ++-- src/ThreeEditor/js/Sidebar.Scene.js | 6 ++-- src/ThreeEditor/js/Viewport.js | 14 ++++---- src/ThreeEditor/util/CSG/CSGZoneManager.ts | 28 +++++++-------- .../util/{BoundingZone.ts => WorldZone.ts} | 34 +++++++++---------- 6 files changed, 59 insertions(+), 59 deletions(-) rename src/ThreeEditor/js/{Sidebar.Geometry.BoundingZone.js => Sidebar.Geometry.WorldZone.js} (77%) rename src/ThreeEditor/util/{BoundingZone.ts => WorldZone.ts} (87%) diff --git a/src/ThreeEditor/js/Sidebar.Geometry.BoundingZone.js b/src/ThreeEditor/js/Sidebar.Geometry.WorldZone.js similarity index 77% rename from src/ThreeEditor/js/Sidebar.Geometry.BoundingZone.js rename to src/ThreeEditor/js/Sidebar.Geometry.WorldZone.js index 12cafe135..772e8f972 100644 --- a/src/ThreeEditor/js/Sidebar.Geometry.BoundingZone.js +++ b/src/ThreeEditor/js/Sidebar.Geometry.WorldZone.js @@ -10,7 +10,7 @@ const bodyTypeOptions = { -export function BoundingZonePanel(editor, boundingZone) { +export function WorldZonePanel(editor, worldZone) { const strings = editor.strings; @@ -27,7 +27,7 @@ export function BoundingZonePanel(editor, boundingZone) { // geometry type - const [geometryTypeRow, geometryType] = createRowSelect({ text: 'Geometry Type', options: bodyTypeOptions, value: boundingZone.geometryType, update }) + const [geometryTypeRow, geometryType] = createRowSelect({ text: 'Geometry Type', options: bodyTypeOptions, value: worldZone.geometryType, update }) container.add(geometryTypeRow); @@ -55,9 +55,9 @@ export function BoundingZonePanel(editor, boundingZone) { // auto calculate checkbox const autoCalculateRow = new UIRow(); - const autoCalculate = new UICheckbox(boundingZone.autoCalculate).onChange(()=> { + const autoCalculate = new UICheckbox(worldZone.autoCalculate).onChange(()=> { update(); - editor.signals.objectSelected.dispatch(boundingZone); + editor.signals.objectSelected.dispatch(worldZone); }); autoCalculateRow.add(new UIText("Auto calculate").setWidth('90px')); @@ -69,7 +69,7 @@ export function BoundingZonePanel(editor, boundingZone) { const calculateButton = new UIButton("CALCULATE").setWidth('100%'); calculateButton.onClick(() => { - boundingZone.calculate(); + worldZone.calculate(); }); calculateContainer.add(calculateButton); @@ -82,19 +82,19 @@ export function BoundingZonePanel(editor, boundingZone) { const center = new THREE.Vector3(objectPositionX.getValue(), objectPositionY.getValue(), objectPositionZ.getValue()); const size = new THREE.Vector3(width.getValue(), height.getValue(), depth.getValue()); - boundingZone.setFromCenterAndSize(center, size); + worldZone.setFromCenterAndSize(center, size); - boundingZone.geometryType = geometryType.getValue(); // set before calling boundingZone.calculate() + worldZone.geometryType = geometryType.getValue(); // set before calling worldZone.calculate() - boundingZone.autoCalculate = autoCalculate.getValue(); - if (boundingZone.autoCalculate) boundingZone.calculate(); + worldZone.autoCalculate = autoCalculate.getValue(); + if (worldZone.autoCalculate) worldZone.calculate(); updateUI(); } function updateUI() { - const pos = boundingZone.box.getCenter(new THREE.Vector3()); - const size = boundingZone.box.getSize(new THREE.Vector3()); + const pos = worldZone.box.getCenter(new THREE.Vector3()); + const size = worldZone.box.getSize(new THREE.Vector3()); objectPositionX.setValue(pos.x); objectPositionZ.setValue(pos.z); @@ -103,9 +103,9 @@ export function BoundingZonePanel(editor, boundingZone) { [widthRow, heightRow, depthRow, calculateContainer].forEach(e => e.setDisplay('none')); - if (boundingZone.canCalculate()) calculateContainer.setDisplay('block'); + if (worldZone.canCalculate()) calculateContainer.setDisplay('block'); - switch (boundingZone.geometryType) { + switch (worldZone.geometryType) { case 'box': [widthRow, heightRow, depthRow].forEach(e => e.setDisplay('block')); widthText.setValue(strings.getKey('sidebar/geometry/box_geometry/width') + ' ' + editor.unit.name) @@ -125,7 +125,7 @@ export function BoundingZonePanel(editor, boundingZone) { break; default: - console.error("Unsupported geometry type: " + boundingZone.geometryType) + console.error("Unsupported geometry type: " + worldZone.geometryType) } width.setValue(size.x); @@ -139,7 +139,7 @@ export function BoundingZonePanel(editor, boundingZone) { editor.signals.objectChanged.add((object) => { - if (object.isBoundingZone) { + if (object.isWorldZone) { updateUI(); } diff --git a/src/ThreeEditor/js/Sidebar.Geometry.js b/src/ThreeEditor/js/Sidebar.Geometry.js index 0d847e18b..30b502204 100644 --- a/src/ThreeEditor/js/Sidebar.Geometry.js +++ b/src/ThreeEditor/js/Sidebar.Geometry.js @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'; import { VertexNormalsHelper } from 'three/examples/jsm/helpers/VertexNormalsHelper.js'; import ZoneManagerPanel from '../components/ZoneManagerPanel/ZoneManagerPanel'; import { UIButton, UIPanel, UIRow, UISpan, UIText } from './libs/ui.js'; -import { BoundingZonePanel } from './Sidebar.Geometry.BoundingZone'; +import { WorldZonePanel } from './Sidebar.Geometry.WorldZone'; import { BeamPanel } from './Sidebar.Geometry.Beam'; import { DetectPanel } from './Sidebar.Geometry.Detect'; @@ -87,10 +87,10 @@ function SidebarGeometry(editor) { vertexNormalsButton.setDisplay('none'); - } else if (object?.isBoundingZone) { + } else if (object?.isWorldZone) { parameters.clear(); - parameters.add(new BoundingZonePanel(editor, object)); + parameters.add(new WorldZonePanel(editor, object)); geometryType.setValue(object.type); container.setDisplay('block'); diff --git a/src/ThreeEditor/js/Sidebar.Scene.js b/src/ThreeEditor/js/Sidebar.Scene.js index 5dbf9a3fe..eaea92f03 100644 --- a/src/ThreeEditor/js/Sidebar.Scene.js +++ b/src/ThreeEditor/js/Sidebar.Scene.js @@ -263,7 +263,7 @@ function SidebarScene(editor) { const { scene } = editor; const { detectsContainer } = editor.detectManager; - const { zonesContainer, boundingZone } = editor.zonesManager; + const { zonesContainer, worldZone } = editor.zonesManager; const options = []; @@ -302,7 +302,7 @@ function SidebarScene(editor) { options.push(buildOption(detectsContainer, false)); addObjects(detectsContainer.children, 0); - options.push(buildOption(boundingZone, false)); + options.push(buildOption(worldZone, false)); options.push(buildOption(editor.beam, false)); @@ -385,7 +385,7 @@ function SidebarScene(editor) { let nextParent = object.parent; const reachedFinalParent = (parent) => { - const finalParents = [editor.scene, editor.zonesManager.zonesContainer, editor.zonesManager.boundingZones, editor.detectManager.detectsContainer] + const finalParents = [editor.scene, editor.zonesManager.zonesContainer, editor.zonesManager.worldZones, editor.detectManager.detectsContainer] return finalParents.some((finalParent) => finalParent === parent) } diff --git a/src/ThreeEditor/js/Viewport.js b/src/ThreeEditor/js/Viewport.js index 91df2d77f..6ad603e53 100644 --- a/src/ThreeEditor/js/Viewport.js +++ b/src/ThreeEditor/js/Viewport.js @@ -122,8 +122,8 @@ export function Viewport( if (config.showZones) renderer.render(zonesManager, camera); - - if (config.showDetect) + + if (config.showDetect) renderer.render(detectManager, camera); if (clipPlane) @@ -428,7 +428,7 @@ export function Viewport( function canBeTransformed(object) { - function notTransformable(object){ + function notTransformable(object) { switch (transformControls.getMode()) { case 'translate': return object.notMovable; @@ -443,16 +443,16 @@ export function Viewport( // Check if object can be transformed. // For our usage it would be only geometries included on the scene. // Amount of geometries can differ form project to project thus we check only if it isn't mesh. - // unionOperations is property unique to zones that shoudn't be transformed with controler. + // unionOperations is property unique to zones that shouldn't be transformed with controller. return object && !(object.isScene - || object.isCamera - || notTransformable(object)); + || object.isCamera + || object.isWorldZone + || notTransformable(object)); } function reattachTransformControls(object) { transformControls.detach(); - canBeTransformed(object) && transformControls.attach(object); } diff --git a/src/ThreeEditor/util/CSG/CSGZoneManager.ts b/src/ThreeEditor/util/CSG/CSGZoneManager.ts index ec3ebcb19..1221a8995 100644 --- a/src/ThreeEditor/util/CSG/CSGZoneManager.ts +++ b/src/ThreeEditor/util/CSG/CSGZoneManager.ts @@ -4,7 +4,7 @@ import * as THREE from 'three'; // eslint-disable-next-line import/no-webpack-loader-syntax import Worker from 'worker-loader!./CSGWorker'; import { Editor } from '../../js/Editor'; -import { BoundingZone, BoundingZoneJSON } from '../BoundingZone'; +import { WorldZone, WorldZoneJSON } from '../WorldZone'; import { ISimulationObject } from '../SimulationObject'; import { IZoneWorker } from './CSGWorker'; import { Zone, ZoneJSON } from './CSGZone'; @@ -14,7 +14,7 @@ interface ZoneManagerJSON { uuid: string, name: string, zones: ZoneJSON[], - boundingZone: BoundingZoneJSON + worldZone: WorldZoneJSON } export class ZonesContainer extends THREE.Group implements ISimulationObject { @@ -45,7 +45,7 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject { editor: Editor; worker: Comlink.Remote; - boundingZone: BoundingZone; + worldZone: WorldZone; zonesContainer: ZonesContainer; private signals: { objectAdded: Signal; @@ -69,11 +69,11 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject { this.editor = editor; this.signals = editor.signals; - this.boundingZone = new BoundingZone(editor); - this.boundingZone.addHelpersToSceneHelpers(); - this.boundingZone.name = "World Zone" + this.worldZone = new WorldZone(editor); + this.worldZone.addHelpersToSceneHelpers(); + this.worldZone.name = "World Zone" - this.add(this.boundingZone); + this.add(this.worldZone); this.signals.zoneEmpty.add((zone: Zone) => this.handleZoneEmpty(zone)); @@ -108,12 +108,12 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject { const zones = this.zonesContainer.children.map(zone => zone.toJSON()); const uuid = this.uuid; const name = this.name; - const boundingZone = this.boundingZone.toJSON(); + const worldZone = this.worldZone.toJSON(); return { zones, uuid, name, - boundingZone + worldZone }; } @@ -131,9 +131,9 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject { }); - this.boundingZone.removeHelpersFromSceneHelpers(); - this.boundingZone = BoundingZone.fromJSON(this.editor, data.boundingZone); - this.boundingZone.addHelpersToSceneHelpers(); + this.worldZone.removeHelpersFromSceneHelpers(); + this.worldZone = WorldZone.fromJSON(this.editor, data.worldZone); + this.worldZone.addHelpersToSceneHelpers(); return this; } @@ -156,13 +156,13 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject { this.zonesContainer.reset(); - this.boundingZone.reset(); + this.worldZone.reset(); return this; } getObjectById(id: number) { - return this.boundingZone.getObjectById(id) ?? super.getObjectById(id); + return this.worldZone.getObjectById(id) ?? super.getObjectById(id); } getZoneById(id: number): Zone | undefined{ diff --git a/src/ThreeEditor/util/BoundingZone.ts b/src/ThreeEditor/util/WorldZone.ts similarity index 87% rename from src/ThreeEditor/util/BoundingZone.ts rename to src/ThreeEditor/util/WorldZone.ts index f63b1eb93..da81d1b33 100644 --- a/src/ThreeEditor/util/BoundingZone.ts +++ b/src/ThreeEditor/util/WorldZone.ts @@ -7,11 +7,11 @@ import { Editor } from '../js/Editor'; import { ISimulationObject } from './SimulationObject'; -export interface BoundingZoneJSON { +export interface WorldZoneJSON { type: string; center: THREE.Vector3; size: THREE.Vector3; - geometryType: BoundingZoneType; + geometryType: WorldZoneType; name: string; color: THREE.ColorRepresentation; marginMultiplier: number; @@ -19,7 +19,7 @@ export interface BoundingZoneJSON { export const BOUNDING_ZONE_TYPE = ['sphere', 'cylinder', 'box'] as const; -export type BoundingZoneType = (typeof BOUNDING_ZONE_TYPE)[number]; +export type WorldZoneType = (typeof BOUNDING_ZONE_TYPE)[number]; const _cylinderGeometry = new THREE.CylinderGeometry(1, 1, 1, 16, 1, false, 0, Math.PI * 2); @@ -27,13 +27,13 @@ const _sphereGeometry = new THREE.SphereGeometry(1, 16, 8, 0, Math.PI * 2, 0, Ma const _material = new THREE.MeshBasicMaterial({ transparent: true, opacity: .5, wireframe: true }); -interface BoundingZoneParams { +interface WorldZoneParams { box?: THREE.Box3, color?: THREE.ColorRepresentation, marginMultiplier?: number } -export class BoundingZone extends THREE.Object3D implements ISimulationObject { +export class WorldZone extends THREE.Object3D implements ISimulationObject { readonly notRemovable = true; get notMovable() { // custom get function to conditionally return notMoveable property; @@ -48,9 +48,9 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { autoCalculate: boolean = true; material: MeshBasicMaterial; private _simulationMaterial?: MeshBasicMaterial; - readonly isBoundingZone: true = true; + readonly isWorldZone: true = true; - private _geometryType: BoundingZoneType = 'box'; + private _geometryType: WorldZoneType = 'box'; private boxHelper: THREE.Box3Helper; private cylinderMesh: THREE.Mesh; private sphereMesh: THREE.Mesh; @@ -60,9 +60,9 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { this.calculate() ); - constructor(editor: Editor, { box, color = 0xff0000, marginMultiplier = 1.1 }: BoundingZoneParams = {}) { + constructor(editor: Editor, { box, color = 0xff0000, marginMultiplier = 1.1 }: WorldZoneParams = {}) { super(); - this.type = 'BoundingZone'; + this.type = 'WorldZone'; this.name = 'World Zone'; this.editor = editor; @@ -96,7 +96,7 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { const handleSignal = (object: Object3D) => { - if (this.autoCalculate && !isBoundingZone(object)) this.debouncedCalculate(); + if (this.autoCalculate && !isWorldZone(object)) this.debouncedCalculate(); } this.editor.signals.objectChanged.add((object: Object3D) => handleSignal(object)); this.editor.signals.sceneGraphChanged.add((object: Object3D) => handleSignal(object)); @@ -118,7 +118,7 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { return this._geometryType; } - set geometryType(value: BoundingZoneType) { + set geometryType(value: WorldZoneType) { this._geometryType = value; this.getAllHelpers().forEach(e => e.visible = false); this.getHelper(value).visible = true; @@ -131,7 +131,7 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { return [this.boxHelper, this.sphereMesh, this.cylinderMesh]; } - private getHelper(geometryType: BoundingZoneType): Object3D { + private getHelper(geometryType: WorldZoneType): Object3D { const obj = { 'box': this.boxHelper, 'cylinder': this.cylinderMesh, @@ -207,7 +207,7 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { toJSON() { - const jsonObject: BoundingZoneJSON = { + const jsonObject: WorldZoneJSON = { center: this.box.getCenter(new Vector3()), size: this.box.getSize(new Vector3()), type: this.type, @@ -220,11 +220,11 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { return jsonObject; } - static fromJSON(editor: Editor, data: BoundingZoneJSON) { + static fromJSON(editor: Editor, data: WorldZoneJSON) { const box = new THREE.Box3(); box.setFromCenterAndSize(data.center, data.size); - const object = new BoundingZone(editor, { box, ...data }); + const object = new WorldZone(editor, { box, ...data }); object.geometryType = data.geometryType; object.name = data.name; @@ -240,10 +240,10 @@ export class BoundingZone extends THREE.Object3D implements ISimulationObject { } clone(recursive: boolean) { - return new BoundingZone(this.editor).copy(this, recursive) as this; + return new WorldZone(this.editor).copy(this, recursive) as this; } } -export const isBoundingZone = (x: unknown): x is BoundingZone => x instanceof BoundingZone; +export const isWorldZone = (x: unknown): x is WorldZone => x instanceof WorldZone;