Skip to content

Commit

Permalink
rename BoundingZone to WorldZone (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostatni5 committed Nov 19, 2021
1 parent d22d830 commit 625f88a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const bodyTypeOptions = {



export function BoundingZonePanel(editor, boundingZone) {
export function WorldZonePanel(editor, worldZone) {

const strings = editor.strings;

Expand All @@ -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);

Expand Down Expand Up @@ -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'));
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -139,7 +139,7 @@ export function BoundingZonePanel(editor, boundingZone) {

editor.signals.objectChanged.add((object) => {

if (object.isBoundingZone) {
if (object.isWorldZone) {
updateUI();
}

Expand Down
6 changes: 3 additions & 3 deletions src/ThreeEditor/js/Sidebar.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');

Expand Down
6 changes: 3 additions & 3 deletions src/ThreeEditor/js/Sidebar.Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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)
}

Expand Down
14 changes: 7 additions & 7 deletions src/ThreeEditor/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -428,7 +428,7 @@ export function Viewport(

function canBeTransformed(object) {

function notTransformable(object){
function notTransformable(object) {
switch (transformControls.getMode()) {
case 'translate':
return object.notMovable;
Expand All @@ -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);
}

Expand Down
28 changes: 14 additions & 14 deletions src/ThreeEditor/util/CSG/CSGZoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -14,7 +14,7 @@ interface ZoneManagerJSON {
uuid: string,
name: string,
zones: ZoneJSON[],
boundingZone: BoundingZoneJSON
worldZone: WorldZoneJSON
}

export class ZonesContainer extends THREE.Group implements ISimulationObject {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class ZoneManager extends THREE.Scene implements ISimulationObject {

editor: Editor;
worker: Comlink.Remote<IZoneWorker>;
boundingZone: BoundingZone;
worldZone: WorldZone;
zonesContainer: ZonesContainer;
private signals: {
objectAdded: Signal<THREE.Object3D>;
Expand All @@ -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));

Expand Down Expand Up @@ -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
};
}

Expand All @@ -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;
}
Expand All @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ 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;
}

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

const _sphereGeometry = new THREE.SphereGeometry(1, 16, 8, 0, Math.PI * 2, 0, Math.PI);

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;
Expand All @@ -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<THREE.CylinderGeometry, MeshBasicMaterial>;
private sphereMesh: THREE.Mesh<THREE.SphereGeometry, MeshBasicMaterial>;
Expand All @@ -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;

Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;

0 comments on commit 625f88a

Please sign in to comment.