Skip to content

Commit

Permalink
Allow multiselection
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed May 10, 2022
1 parent 794e83c commit 1fb2a7e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 45 deletions.
62 changes: 37 additions & 25 deletions example/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90743,7 +90743,9 @@
this.context = context;
}
dispose() {
disposeMeshRecursively(this.grid);
if (this.grid) {
disposeMeshRecursively(this.grid);
}
this.grid = null;
}
setGrid(size, divisions, colorCenterLine, colorGrid) {
Expand All @@ -90765,7 +90767,9 @@
this.context = context;
}
dispose() {
disposeMeshRecursively(this.axes);
if (this.axes) {
disposeMeshRecursively(this.axes);
}
this.axes = null;
}
setAxes(size) {
Expand Down Expand Up @@ -99096,7 +99100,7 @@
super(context);
this.context = context;
this.mesh = null;
this.pick = async (item, focusSelection = false) => {
this.pick = async (item, focusSelection = false, removePrevious = true) => {
if (this.selected === item.faceIndex || item.faceIndex == null)
return null;
this.selected = item.faceIndex;
Expand All @@ -99106,23 +99110,23 @@
return null;
this.hideSelection(mesh);
this.modelID = mesh.modelID;
this.newSelection([id]);
this.newSelection([id], removePrevious);
if (focusSelection)
this.focusSelection();
return { modelID: this.modelID, id };
};
this.pickByID = async (modelID, ids, focusSelection = false) => {
this.pickByID = async (modelID, ids, focusSelection = false, removePrevious = true) => {
this.modelID = modelID;
this.newSelection(ids);
this.newSelection(ids, removePrevious);
if (focusSelection)
await this.focusSelection();
};
this.newSelection = (ids) => {
this.newSelection = (ids, removePrevious) => {
const mesh = this.loader.ifcManager.createSubset({
scene: this.scene,
modelID: this.modelID,
ids,
removePrevious: true,
removePrevious,
material: this.material
});
if (mesh) {
Expand Down Expand Up @@ -99205,27 +99209,29 @@
/**
* Highlights the item pointed by the cursor and gets is properties.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async pickIfcItem(focusSelection = false) {
async pickIfcItem(focusSelection = false, removePrevious = true) {
const found = this.context.castRayIfc();
if (!found)
return null;
const result = await this.selection.pick(found, focusSelection);
const result = await this.selection.pick(found, focusSelection, removePrevious);
if (result == null || result.modelID == null || result.id == null)
return null;
return result;
}
/**
* Highlights the item pointed by the cursor and gets is properties, without applying any material to it.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async highlightIfcItem(focusSelection = false) {
async highlightIfcItem(focusSelection = false, removePrevious = true) {
const found = this.context.castRayIfc();
if (!found)
return null;
const model = found.object;
this.fadeAwayModel(model);
const result = await this.highlight.pick(found, focusSelection);
const result = await this.highlight.pick(found, focusSelection, removePrevious);
if (result == null || result.modelID == null || result.id == null)
return null;
return result;
Expand All @@ -99235,30 +99241,33 @@
* @modelID ID of the IFC model.
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async pickIfcItemsByID(modelID, ids, focusSelection = false) {
await this.selection.pickByID(modelID, ids, focusSelection);
async pickIfcItemsByID(modelID, ids, focusSelection = false, removePrevious = true) {
await this.selection.pickByID(modelID, ids, focusSelection, removePrevious);
}
/**
* Highlights the item with the given ID with the prepicking material.
* @modelID ID of the IFC model.
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async prepickIfcItemsByID(modelID, ids, focusSelection = false) {
await this.preselection.pickByID(modelID, ids, focusSelection);
async prepickIfcItemsByID(modelID, ids, focusSelection = false, removePrevious = true) {
await this.preselection.pickByID(modelID, ids, focusSelection, removePrevious);
}
/**
* Highlights the item with the given ID and fades away the model.
* @modelID ID of the IFC model.
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @mesh Mesh to fade away. By default it's the IFCModel
* @removePrevious whether to remove the previous subset
*/
async highlightIfcItemsByID(modelID, ids, focusSelection = false, mesh) {
async highlightIfcItemsByID(modelID, ids, focusSelection = false, mesh, removePrevious = true) {
const model = mesh || this.context.items.ifcModels[modelID];
this.fadeAwayModel(model);
await this.highlight.pickByID(modelID, ids, focusSelection);
await this.highlight.pickByID(modelID, ids, focusSelection, removePrevious);
}
/**
* Unapplies the picking material.
Expand Down Expand Up @@ -101780,6 +101789,7 @@
this.restoreRendererBackgroundColor();
}
dispose() {
var _a, _b;
this.basicRenderer.domElement.remove();
this.basicRenderer.dispose();
this.postProductionRenderer.dispose();
Expand All @@ -101789,6 +101799,8 @@
this.renderer = null;
this.container = null;
this.context = null;
(_a = this.tempRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
(_b = this.tempCanvas) === null || _b === void 0 ? void 0 : _b.remove();
}
update(_delta) {
if (this.blocked)
Expand All @@ -101811,20 +101823,20 @@
const domElement = this.basicRenderer.domElement;
const tempCanvas = domElement.cloneNode(true);
// Using a new renderer to make screenshots without updating what the user sees in the canvas
const tempRenderer = new WebGLRenderer({ canvas: tempCanvas, antialias: true });
tempRenderer.localClippingEnabled = true;
if (!this.tempRenderer) {
this.tempRenderer = new WebGLRenderer({ canvas: tempCanvas, antialias: true });
this.tempRenderer.localClippingEnabled = true;
}
if (dimensions) {
tempRenderer.setSize(dimensions.x, dimensions.y);
this.tempRenderer.setSize(dimensions.x, dimensions.y);
this.context.ifcCamera.updateAspect(dimensions);
}
const scene = this.context.getScene();
const cameraToRender = camera || this.context.getCamera();
tempRenderer.render(scene, cameraToRender);
const result = tempRenderer.domElement.toDataURL();
this.tempRenderer.render(scene, cameraToRender);
const result = this.tempRenderer.domElement.toDataURL();
if (dimensions)
this.context.ifcCamera.updateAspect(previousDimensions);
tempRenderer.dispose();
tempCanvas.remove();
return result;
}
setupRenderers() {
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "web-ifc-viewer-basic-example",
"private": true,
"type": "module",
"version": "1.0.177",
"version": "1.0.178",
"description": "A basic html example for web-ifc-viewer",
"main": "main.js",
"scripts": {
Expand All @@ -29,6 +29,6 @@
"stats.js": "0.17.0",
"three": "0.135",
"web-ifc": "0.0.33",
"web-ifc-viewer": "1.0.177"
"web-ifc-viewer": "1.0.178"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-ifc-viewer-root",
"description": "IFC viewer",
"version": "1.0.177",
"version": "1.0.178",
"private": true,
"main": "viewer/src/ifc-viewer-api.ts",
"author": "agviegas",
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-ifc-viewer",
"version": "1.0.177",
"version": "1.0.178",
"description": "IFC viewer",
"main": "dist/index.js",
"scripts": {
Expand Down
17 changes: 11 additions & 6 deletions viewer/src/components/ifc/selection/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export class IfcSelection extends IfcComponent {
(this.context as any) = null;
}

pick = async (item: Intersection, focusSelection = false) => {
pick = async (item: Intersection, focusSelection = false, removePrevious = true) => {
if (this.selected === item.faceIndex || item.faceIndex == null) return null;
this.selected = item.faceIndex;
const mesh = item.object as IfcMesh;
const id = await this.loader.ifcManager.getExpressId(mesh.geometry, item.faceIndex);
if (id === undefined) return null;
this.hideSelection(mesh);
this.modelID = mesh.modelID;
this.newSelection([id]);
this.newSelection([id], removePrevious);
if (focusSelection) this.focusSelection();
return { modelID: this.modelID, id };
};
Expand All @@ -50,18 +50,23 @@ export class IfcSelection extends IfcComponent {
this.loader.ifcManager.removeSubset(this.modelID, this.material);
}

pickByID = async (modelID: number, ids: number[], focusSelection = false) => {
pickByID = async (
modelID: number,
ids: number[],
focusSelection = false,
removePrevious = true
) => {
this.modelID = modelID;
this.newSelection(ids);
this.newSelection(ids, removePrevious);
if (focusSelection) await this.focusSelection();
};

newSelection = (ids: number[]) => {
newSelection = (ids: number[], removePrevious: boolean) => {
const mesh = this.loader.ifcManager.createSubset({
scene: this.scene,
modelID: this.modelID,
ids,
removePrevious: true,
removePrevious,
material: this.material
});
if (mesh) {
Expand Down
41 changes: 31 additions & 10 deletions viewer/src/components/ifc/selection/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,29 @@ export class IfcSelector {
/**
* Highlights the item pointed by the cursor and gets is properties.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async pickIfcItem(focusSelection = false) {
async pickIfcItem(focusSelection = false, removePrevious = true) {
const found = this.context.castRayIfc();
if (!found) return null;
const result = await this.selection.pick(found, focusSelection);
const result = await this.selection.pick(found, focusSelection, removePrevious);
if (result == null || result.modelID == null || result.id == null) return null;
return result;
}

/**
* Highlights the item pointed by the cursor and gets is properties, without applying any material to it.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async highlightIfcItem(focusSelection = false) {
async highlightIfcItem(focusSelection = false, removePrevious = true) {
const found = this.context.castRayIfc();
if (!found) return null;

const model = found.object as IFCModel;
this.fadeAwayModel(model);

const result = await this.highlight.pick(found, focusSelection);
const result = await this.highlight.pick(found, focusSelection, removePrevious);
if (result == null || result.modelID == null || result.id == null) return null;
return result;
}
Expand All @@ -85,19 +87,31 @@ export class IfcSelector {
* @modelID ID of the IFC model.
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async pickIfcItemsByID(modelID: number, ids: number[], focusSelection = false) {
await this.selection.pickByID(modelID, ids, focusSelection);
async pickIfcItemsByID(
modelID: number,
ids: number[],
focusSelection = false,
removePrevious = true
) {
await this.selection.pickByID(modelID, ids, focusSelection, removePrevious);
}

/**
* Highlights the item with the given ID with the prepicking material.
* @modelID ID of the IFC model.
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @removePrevious whether to remove the previous subset
*/
async prepickIfcItemsByID(modelID: number, ids: number[], focusSelection = false) {
await this.preselection.pickByID(modelID, ids, focusSelection);
async prepickIfcItemsByID(
modelID: number,
ids: number[],
focusSelection = false,
removePrevious = true
) {
await this.preselection.pickByID(modelID, ids, focusSelection, removePrevious);
}

/**
Expand All @@ -106,11 +120,18 @@ export class IfcSelector {
* @id Express ID of the item.
* @focusSelection If true, animate the perspectiveCamera to focus the current selection
* @mesh Mesh to fade away. By default it's the IFCModel
* @removePrevious whether to remove the previous subset
*/
async highlightIfcItemsByID(modelID: number, ids: number[], focusSelection = false, mesh?: Mesh) {
async highlightIfcItemsByID(
modelID: number,
ids: number[],
focusSelection = false,
mesh?: Mesh,
removePrevious = true
) {
const model = (mesh as IFCModel) || this.context.items.ifcModels[modelID];
this.fadeAwayModel(model);
await this.highlight.pickByID(modelID, ids, focusSelection);
await this.highlight.pickByID(modelID, ids, focusSelection, removePrevious);
}

/**
Expand Down

0 comments on commit 1fb2a7e

Please sign in to comment.