-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overriding IfcElements render colors on loading file (#595)
* basic elements coloring * implementing view settings * Linting and adjusting viewer mockup
- Loading branch information
Showing
6 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* create an ifc color object | ||
* | ||
* @param {number} r the red component of the color as a fraction between 0 and 1 | ||
* @param {number} g the green component of the color as a fraction between 0 and 1 | ||
* @param {number} b the blue component of the color as a fraction between 0 and 1 | ||
* @param {number} o the opacity component of the color as a fraction between 0 and 1 | ||
*/ | ||
export default function IfcColor(r = 0, g = 0, b = 0, o = 1) { | ||
this.x = r | ||
this.y = g | ||
this.z = b | ||
this.w = o | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import IfcColor from './IfcColor' | ||
|
||
|
||
/** | ||
* Object containig the coloring settings | ||
* | ||
* @param {IfcColor} defaultColor the color to be used if the id wasn't found in the provided map, | ||
* if undefined the original element color will be used instead | ||
* @param {object} idsToColorMap an object containing pairs of {[expressId]:[IfcColor]} to be used for those elements | ||
*/ | ||
export default function IfcCustomViewSettings(defaultColor, idsToColorMap = {}) { | ||
this.defaultColor = defaultColor | ||
this.idsToColorMap = idsToColorMap | ||
|
||
this.getElementColor = (expressId) => { | ||
return this.idsToColorMap[expressId] ? this.idsToColorMap[expressId] : this.defaultColor | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import IfcCustomViewSettings from './IfcCustomViewSettings' | ||
|
||
|
||
/* eslint-disable jsdoc/no-undefined-types */ | ||
/** | ||
* Overrides the default render functionality in the viewer | ||
* and adds a postprocessing effect (outlining selected elements) | ||
*/ | ||
export default class IfcElementsStyleManager { | ||
/** | ||
* constructs new class | ||
* | ||
* @param {IfcParser} the parser of the viewer | ||
*/ | ||
constructor(parser) { | ||
this.parser = parser | ||
parser._overrideStyles = {} | ||
parser.streamMesh = newStreamMeshFunction(parser) | ||
} | ||
|
||
|
||
/** | ||
* Applys view settings to the next load call | ||
* | ||
* @param {IfcCustomViewSettings} settings an object containing expressId:IfcColor pairs | ||
*/ | ||
setViewSettings(settings) { | ||
this.parser._overrideStyles = settings ? settings : new IfcCustomViewSettings() | ||
} | ||
} | ||
|
||
|
||
/* eslint-disable no-invalid-this */ | ||
/** | ||
* Returns a new stream mesh function that uses | ||
* the custom coloring provided | ||
* | ||
* @param {IfcParser} parser | ||
* @return {Function} the new render function | ||
*/ | ||
function newStreamMeshFunction(parser) { | ||
/** | ||
* Overrides the default stream function in the ifc parser | ||
* | ||
*/ | ||
function streamMesh(modelID, mesh) { | ||
const placedGeometries = mesh.geometries | ||
const size = placedGeometries.size() | ||
for (let i = 0; i < size; i++) { | ||
const placedGeometry = placedGeometries.get(i) | ||
const itemMesh = this.getPlacedGeometry(modelID, mesh.expressID, placedGeometry) | ||
const geom = itemMesh.geometry.applyMatrix4(itemMesh.matrix) | ||
const overrideStyle = this._overrideStyles.getElementColor(mesh.expressID) | ||
const color = overrideStyle !== undefined ? overrideStyle : placedGeometry.color | ||
this.storeGeometryByMaterial(color, geom) | ||
} | ||
} | ||
|
||
return streamMesh.bind(parser) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters