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

Added first representation of cube selection state. #20

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,24 @@ In the following you find a list of all available actions to perform on DIVEComm
| Action | Description
| :--- | :---
| [GET_ALL_SCENE_DATA](./src/com/actions/scene/getallscenedata.ts) | Return all scene data that is currently set
| [GET_ALL_OBJECTS](./src/com/actions/object/getallobjects.ts) | Return a map of all objects
| [GET_OBJECTS](./src/com/actions/object/getobjects.ts) | Return an array of all objects with given ids
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor
| [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene
| [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object
| [DELETE_OBJECT](./src/com/actions/object/deleteobject.ts) | Delete an existing object
| [SELECT_OBJECT](./src/com/actions/object/selectobject.ts) | Select an existing object in the scene
| [DESELECT_OBJECT](./src/com/actions/object/deselectobject.ts) | Deselect an existing object in the scene
| [SET_BACKGROUND](./src/com/actions/scene/setbackground.ts) | Set a background color
| [UPDATE_SCENE](./src/com/actions/scene/updatescene.ts) | Update scene data
| [DROP_IT](./src/com/actions/object/model/dropit.ts) | Places the model onto the next underlying object's bounding box
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Places the model onto the floor (zero plane)
| [SET_CAMERA_TRANSFORM](./src/com/actions/camera/setcameratransform.ts) | Set camera transformation (w/o animation, used to initially set up camera)
| [GET_CAMERA_TRANSFORM](./src/com/actions/camera/getcameratransform.ts) | Return currenty camera transformation
| [MOVE_CAMERA](./src/com/actions/camera/movecamera.ts) | Move camera to a specific position or the position of a previously defined POV (with an animation)
| [RESET_CAMERA](./src/com/actions/camera/resetcamera.ts) | Reset camera to original position after MOVE_CAMERA was performed
| [SET_CAMERA_LAYER](./src/com/actions/camera/setcameralayer.ts) | Set camera layer to switch between live view and editor view
| [SET_CAMERA_TRANSFORM](./src/com/actions/camera/setcameratransform.ts) | Set camera transformation (w/o animation, used to initially set up camera)
| [ZOOM_CAMERA](./src/com/actions/camera/zoomcamera.ts) | Zoom in or out
| [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters
| [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded
| [DROP_IT](./src/com/actions/object/model/dropit.ts) | Places the model onto the nextg underlying object's bounding box
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor
| [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene
| [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object
| [DELETE_OBJECT](./src/com/actions/object/deleteobject.ts) | Delete an existing object
| [GET_ALL_OBJECTS](./src/com/actions/object/getallobjects.ts) | Return a map of all objects
| [GET_OBJECTS](./src/com/actions/object/getobjects.ts) | Return a map of all objects (with the opportunity to filter for ids)
| [SELECT_OBJECT](./src/com/actions/object/selectobject.ts) | Select an existing object in the scene
| [SET_GIZMO_MODE](./src/com/actions/toolbox/select/setgizmomode.ts) | Set gizmo mode
| [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded
| [UPDATE_SCENE](./src/com/actions/scene/updatescene.ts) | Update scene data
| [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters
2 changes: 1 addition & 1 deletion src/com/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default class DIVECommunication {
if (!('isSelectable' in sceneObject)) return false;

this.toolbox.UseTool('select');
(this.toolbox.GetActiveTool() as DIVESelectTool).DetachGizmo();
(this.toolbox.GetActiveTool() as DIVESelectTool).DetachGizmo(sceneObject as DIVESelectable);

// copy object to payload to use later
Object.assign(payload, object);
Expand Down
3 changes: 3 additions & 0 deletions src/dive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export default class DIVE {
console.log(this.scene);
},
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
console.log(`DIVE v${require('../package.json').version} initialized`);
}

// methods
Expand Down
4 changes: 2 additions & 2 deletions src/grid/Grid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GRID_SIDE_LINE_COLOR, GRID_CENTER_LINE_COLOR } from "../constant/GridColors.ts";
import { HELPER_LAYER_MASK } from "../constant/VisibilityLayerMask.ts";
import { UI_LAYER_MASK } from "../constant/VisibilityLayerMask.ts";
import { GridHelper, Object3D } from "three";

/**
Expand All @@ -15,7 +15,7 @@ export default class DIVEGrid extends Object3D {

const grid = new GridHelper(100, 100, GRID_CENTER_LINE_COLOR, GRID_SIDE_LINE_COLOR);
grid.material.depthTest = false;
grid.layers.mask = HELPER_LAYER_MASK;
grid.layers.mask = UI_LAYER_MASK;

this.add(grid);
}
Expand Down
93 changes: 93 additions & 0 deletions src/selections/cubeselection/CubeSelection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Box3, Object3D } from "three";
import { DIVECubeSelectionMesh } from "./mesh/CubeSelectionMesh";

export class DIVECubeSelection extends Object3D {
private _parents: { [id: string]: Object3D };
private _objectRoot: Object3D;

private _boundingBox: Box3;
private _boxMesh: DIVECubeSelectionMesh;

public get objects(): Object3D[] {
return this._objectRoot.children;
}

public set objects(objects: Object3D[]) {
this._objectRoot.children = objects;
this.calculateBoundingBox();
this._boxMesh.updateBox(this._boundingBox);
}

constructor() {
super();

this._parents = {};
this._objectRoot = new Object3D();
this.add(this._objectRoot);

this._boundingBox = new Box3()
this._boxMesh = new DIVECubeSelectionMesh();
this.add(this._boxMesh);

}

public Attach(object: Object3D): this {
if (object.parent !== null) {
this._parents[object.uuid] = object.parent;
}

this.addChild(object);

return this;
}

public Detach(object: Object3D): this;
public Detach(object: string): this;
public Detach(object: Object3D | string): this {
if (typeof object === 'string') {
const index = this.children.findIndex((child) => child.uuid === object);
if (index === -1) return this;

if (this._parents[object]) {
this.removeChild(this.children[index]);
this._parents[object].add(this.children[index]);
delete this._parents[object];
} else {
this.removeChild(this.children[index]);
}
} else {
if (this._parents[object.uuid]) {
this.removeChild(object);
this._parents[object.uuid].add(object);
delete this._parents[object.uuid];
} else {
this.removeChild(object);
}
}

return this;
}

private addChild(object: Object3D): this {
this._objectRoot.add(object);
this.calculateBoundingBox();
this._boxMesh.updateBox(this._boundingBox);

return this;
}

private removeChild(object: Object3D): this {
this._objectRoot.remove(object);
this.calculateBoundingBox();
this._boxMesh.updateBox(this._boundingBox);
return this;
}

private calculateBoundingBox(): void {
this._objectRoot.children.forEach((child) => {
child.updateMatrixWorld(true);
});

this._boundingBox.setFromObject(this._objectRoot);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Line2, LineGeometry, LineMaterial } from 'three/examples/jsm/Addons';
import { HELPER_LAYER_MASK } from '../../../../constant/VisibilityLayerMask';
import { Color } from 'three';

export class DIVECubeSelectionEdgeHandle extends Line2 {
readonly isCubeSelection = true;
readonly isCubeSelectionEdge = true;

private _color: number;
private _hoverColor: number = 0xff0000;

constructor(material: LineMaterial) {
super();

this.layers.mask = HELPER_LAYER_MASK;

this.geometry = new LineGeometry();
this.material = material.clone();
this._color = this.material.color.getHex();

const hsl = new Color(this._color).getHSL({ h: 0, s: 0, l: 0 });
this._hoverColor = new Color(this._color).setHSL(hsl.h, hsl.s, hsl.l * 1.3).getHex();
}

public setPoints(points: [number, number, number, number, number, number]): this {
this.geometry.setPositions(points);
this.geometry.computeBoundingBox();
return this;
}

public onPointerEnter(): void {
this.material.color.setHex(this._hoverColor);
}

public onPointerLeave(): void {
this.material.color.setHex(this._color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Color, Mesh, MeshBasicMaterial, PlaneGeometry, Vector3, HSL } from 'three';
import { HELPER_LAYER_MASK } from '../../../../constant/VisibilityLayerMask';

export class DIVECubeSelectionPlaneHandle extends Mesh {
readonly isCubeSelection = true;
readonly isCubeSelectionPlane = true;

private _color: number;
private _hoverColor: number = 0xff0000;

constructor(material: MeshBasicMaterial) {
super();

this.layers.mask = HELPER_LAYER_MASK;
this.geometry = new PlaneGeometry();

this.material = material.clone();
this._color = material.color.getHex();

const hsl: HSL = {
h: 0,
s: 0,
l: 0,
};
new Color(this._color).getHSL(hsl);
this._hoverColor = new Color(this._color).setHSL(hsl.h, hsl.s, hsl.l * 1.2).getHex();


}

public setPoints(points: [Vector3, Vector3, Vector3, Vector3]): this {
this.geometry.setFromPoints(points);
this.geometry.computeBoundingBox();
return this;
}

public onPointerEnter(): void {
(this.material as MeshBasicMaterial).color.setHex(this._hoverColor);
}

public onPointerLeave(): void {
(this.material as MeshBasicMaterial).color.setHex(this._color);
}
}
Loading
Loading