openbim-components
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -114,3 +114,2 @@ import * as THREE from "three"; | ||
constructor(); | ||
private static setupBVH; | ||
/** | ||
@@ -158,2 +157,3 @@ * Initializes the library. It should be called at the start of the app after | ||
private static update; | ||
private static setupBVH; | ||
} |
@@ -146,7 +146,2 @@ import * as THREE from "three"; | ||
} | ||
static setupBVH() { | ||
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree; | ||
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree; | ||
THREE.Mesh.prototype.raycast = acceleratedRaycast; | ||
} | ||
/** | ||
@@ -203,3 +198,8 @@ * Initializes the library. It should be called at the start of the app after | ||
} | ||
static setupBVH() { | ||
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree; | ||
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree; | ||
THREE.Mesh.prototype.raycast = acceleratedRaycast; | ||
} | ||
} | ||
//# sourceMappingURL=components.js.map |
import * as THREE from "three"; | ||
import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer"; | ||
import { Disposer } from "../utils"; | ||
import { SimpleDimensions } from "./simple-dimensions"; | ||
import { DimensionLabelClassName } from "./types"; | ||
// TODO: Document + clean up this: way less parameters, clearer logic | ||
@@ -110,3 +110,3 @@ export class SimpleDimensionLine { | ||
const htmlText = document.createElement("div"); | ||
htmlText.className = SimpleDimensions.labelClassName; | ||
htmlText.className = DimensionLabelClassName; | ||
htmlText.textContent = this.getTextContent(); | ||
@@ -113,0 +113,0 @@ const label = new CSS2DObject(htmlText); |
@@ -25,6 +25,2 @@ import * as THREE from "three"; | ||
previewElement: CSS2DObject; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
static readonly labelClassName = "ifcjs-dimension-label"; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
static readonly previewClassName = "ifcjs-dimension-preview"; | ||
private _lineMaterial; | ||
@@ -31,0 +27,0 @@ private _endpointMesh; |
@@ -8,2 +8,3 @@ import * as THREE from "three"; | ||
import { Disposer } from "../utils"; | ||
import { DimensionPreviewClassName } from "./types"; | ||
/** | ||
@@ -46,3 +47,3 @@ * A basic dimension tool to measure distances between 2 points in 3D and | ||
const htmlPreview = document.createElement("div"); | ||
htmlPreview.className = SimpleDimensions.previewClassName; | ||
htmlPreview.className = DimensionPreviewClassName; | ||
this.previewElement = new CSS2DObject(htmlPreview); | ||
@@ -278,6 +279,2 @@ this.previewElement.visible = false; | ||
} | ||
/** The name of the CSS class that styles the dimension label. */ | ||
SimpleDimensions.labelClassName = "ifcjs-dimension-label"; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
SimpleDimensions.previewClassName = "ifcjs-dimension-preview"; | ||
//# sourceMappingURL=simple-dimensions.js.map |
import * as THREE from "three"; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
export declare const DimensionLabelClassName = "ifcjs-dimension-label"; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
export declare const DimensionPreviewClassName = "ifcjs-dimension-preview"; | ||
export interface DimensionData { | ||
@@ -3,0 +7,0 @@ start: THREE.Vector3; |
@@ -1,2 +0,5 @@ | ||
export {}; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
export const DimensionLabelClassName = "ifcjs-dimension-label"; | ||
/** The name of the CSS class that styles the dimension label. */ | ||
export const DimensionPreviewClassName = "ifcjs-dimension-preview"; | ||
//# sourceMappingURL=types.js.map |
@@ -19,8 +19,8 @@ import * as THREE from "three"; | ||
readonly worker: Worker; | ||
enabled: boolean; | ||
viewUpdated: Event<unknown>; | ||
needsUpdate: boolean; | ||
exclusions: Map<string, Fragment>; | ||
fragmentColorMap: Map<string, Fragment>; | ||
needsUpdate: boolean; | ||
alwaysForceUpdate: boolean; | ||
renderDebugFrame: boolean; | ||
viewUpdated: Event<unknown>; | ||
readonly meshes: Map<string, THREE.InstancedMesh<THREE.BufferGeometry, THREE.Material | THREE.Material[]>>; | ||
@@ -27,0 +27,0 @@ visibleFragments: Fragment[]; |
@@ -11,8 +11,8 @@ import * as THREE from "three"; | ||
this.autoUpdate = autoUpdate; | ||
this.enabled = true; | ||
this.viewUpdated = new Event(); | ||
this.needsUpdate = false; | ||
this.exclusions = new Map(); | ||
this.fragmentColorMap = new Map(); | ||
this.needsUpdate = false; | ||
this.alwaysForceUpdate = false; | ||
this.renderDebugFrame = false; | ||
this.viewUpdated = new Event(); | ||
this.meshes = new Map(); | ||
@@ -29,4 +29,6 @@ this.visibleFragments = []; | ||
this.updateVisibility = (force) => { | ||
if (!this.alwaysForceUpdate && !this.needsUpdate && !force) | ||
if (!this.enabled) | ||
return; | ||
if (!this.needsUpdate && !force) | ||
return; | ||
const camera = this.components.camera.get(); | ||
@@ -33,0 +35,0 @@ camera.updateMatrix(); |
@@ -11,2 +11,4 @@ import * as THREE from "three"; | ||
boundingBoxes: any; | ||
transparentBoundingBoxes: any; | ||
expressIDFragmentIDMap: any; | ||
} | ||
@@ -23,2 +25,3 @@ export interface GeometriesByMaterial { | ||
matrix: THREE.Matrix4; | ||
hasVoids: boolean; | ||
}[]; | ||
@@ -36,3 +39,6 @@ geometriesByMaterial: { | ||
[floor: string]: { | ||
[materialID: string]: THREE.BufferGeometry[]; | ||
[materialID: string]: { | ||
geoms: THREE.BufferGeometry[]; | ||
hasVoids: boolean; | ||
}; | ||
}; | ||
@@ -39,0 +45,0 @@ }; |
@@ -11,2 +11,5 @@ import * as WEBIFC from "web-ifc"; | ||
private _boundingBoxes; | ||
private _transparentBoundingBoxes; | ||
private _expressIDfragmentIDMap; | ||
private _transform; | ||
private readonly _items; | ||
@@ -28,3 +31,4 @@ private readonly _materials; | ||
private processInstancedItems; | ||
private getTransformHelper; | ||
private getBoxes; | ||
private areMatsTransparent; | ||
private setFragmentInstances; | ||
@@ -31,0 +35,0 @@ private createInstancedFragment; |
@@ -8,2 +8,3 @@ import * as THREE from "three"; | ||
import { FragmentGroup, } from "./base-types"; | ||
import { TransformHelper } from "./transform-helper"; | ||
export class DataConverter { | ||
@@ -17,2 +18,5 @@ constructor(items, materials, settings) { | ||
this._boundingBoxes = {}; | ||
this._transparentBoundingBoxes = {}; | ||
this._expressIDfragmentIDMap = {}; | ||
this._transform = new TransformHelper(); | ||
this._spatialStructure = new SpatialStructure(); | ||
@@ -27,2 +31,3 @@ this._items = items; | ||
this._boundingBoxes = {}; | ||
this._transparentBoundingBoxes = {}; | ||
} | ||
@@ -50,2 +55,4 @@ cleanUp() { | ||
this._model.boundingBoxes = this._boundingBoxes; | ||
this._model.transparentBoundingBoxes = this._transparentBoundingBoxes; | ||
this._model.expressIDFragmentIDMap = this._expressIDfragmentIDMap; | ||
this._model.levelRelationships = this._spatialStructure.itemsByFloor; | ||
@@ -83,3 +90,3 @@ this._model.floorsProperties = this._spatialStructure.floorProperties; | ||
const level = this._spatialStructure.itemsByFloor[instance.id]; | ||
this.initializeItem(category, level, matID); | ||
this.initializeItem(data, category, level, matID); | ||
this.applyTransformToMergedGeometries(data, category, level, matID); | ||
@@ -94,7 +101,7 @@ } | ||
geometry.userData.id = instance.id; | ||
this._uniqueItems[category][level][matID].push(geometry); | ||
this._uniqueItems[category][level][matID].geoms.push(geometry); | ||
geometry.applyMatrix4(instance.matrix); | ||
} | ||
} | ||
initializeItem(category, level, matID) { | ||
initializeItem(data, category, level, matID) { | ||
if (!this._uniqueItems[category]) { | ||
@@ -107,3 +114,6 @@ this._uniqueItems[category] = {}; | ||
if (!this._uniqueItems[category][level][matID]) { | ||
this._uniqueItems[category][level][matID] = []; | ||
this._uniqueItems[category][level][matID] = { | ||
geoms: [], | ||
hasVoids: data.instances[0].hasVoids, | ||
}; | ||
} | ||
@@ -117,14 +127,8 @@ } | ||
this._model.add(fragment.mesh); | ||
let isTransparent = false; | ||
const materialIDs = Object.keys(data.geometriesByMaterial); | ||
const mats = materialIDs.map((id) => this._materials[id]); | ||
for (const mat of mats) { | ||
if (mat.transparent) { | ||
isTransparent = true; | ||
} | ||
} | ||
if (isTransparent) { | ||
return; | ||
} | ||
const baseHelper = this.getTransformHelper([fragment.mesh.geometry]); | ||
const matsTransparent = this.areMatsTransparent(mats); | ||
const isTransparent = matsTransparent || data.instances[0].hasVoids; | ||
const boxes = this.getBoxes(isTransparent); | ||
const baseHelper = this._transform.getHelper([fragment.mesh.geometry]); | ||
for (let i = 0; i < fragment.mesh.count; i++) { | ||
@@ -138,27 +142,19 @@ const instanceTransform = new THREE.Matrix4(); | ||
const id = fragment.getItemID(i, 0); | ||
this._boundingBoxes[id] = instanceHelper.matrix.elements; | ||
boxes[id] = instanceHelper.matrix.elements; | ||
this._expressIDfragmentIDMap[id] = fragment.id; | ||
} | ||
} | ||
getTransformHelper(geometries) { | ||
const baseHelper = new THREE.Object3D(); | ||
const points = []; | ||
for (const geom of geometries) { | ||
geom.computeBoundingBox(); | ||
if (geom.boundingBox) { | ||
points.push(geom.boundingBox.min); | ||
points.push(geom.boundingBox.max); | ||
getBoxes(isTransparent) { | ||
const boxes = isTransparent | ||
? this._transparentBoundingBoxes | ||
: this._boundingBoxes; | ||
return boxes; | ||
} | ||
areMatsTransparent(mats) { | ||
for (const mat of mats) { | ||
if (mat.transparent) { | ||
return true; | ||
} | ||
} | ||
const bbox = new THREE.Box3(); | ||
bbox.setFromPoints(points); | ||
const width = bbox.max.x - bbox.min.x; | ||
const height = bbox.max.y - bbox.min.y; | ||
const depth = bbox.max.z - bbox.min.z; | ||
const positionX = bbox.min.x + width / 2; | ||
const positionY = bbox.min.y + height / 2; | ||
const positionZ = bbox.min.z + depth / 2; | ||
baseHelper.scale.set(width, height, depth); | ||
baseHelper.position.set(positionX, positionY, positionZ); | ||
baseHelper.updateMatrix(); | ||
return baseHelper; | ||
return false; | ||
} | ||
@@ -198,8 +194,14 @@ setFragmentInstances(data, fragment) { | ||
processUniqueItem(category, level) { | ||
const geometries = Object.values(this._uniqueItems[category][level]); | ||
const item = this._uniqueItems[category][level]; | ||
if (!item) | ||
return; | ||
const geometriesData = Object.values(item); | ||
const geometries = geometriesData.map((geom) => geom.geoms); | ||
const { buffer, ids } = this.processIDsAndBuffer(geometries); | ||
const mats = this.getUniqueItemMaterial(category, level); | ||
const items = {}; | ||
for (const geometryGroup of geometries) { | ||
for (const geom of geometryGroup) { | ||
let hasVoids = false; | ||
for (const geometryGroup of geometriesData) { | ||
hasVoids = hasVoids || geometryGroup.hasVoids; | ||
for (const geom of geometryGroup.geoms) { | ||
const id = geom.userData.id; | ||
@@ -212,6 +214,9 @@ if (!items[id]) { | ||
} | ||
const matsTransparent = this.areMatsTransparent(mats); | ||
const isTransparent = matsTransparent || hasVoids; | ||
const boxes = this.getBoxes(isTransparent); | ||
for (const id in items) { | ||
const geoms = items[id]; | ||
const helper = this.getTransformHelper(geoms); | ||
this._boundingBoxes[id] = helper.matrix.elements; | ||
const helper = this._transform.getHelper(geoms); | ||
boxes[id] = helper.matrix.elements; | ||
} | ||
@@ -222,2 +227,5 @@ const merged = GeometryUtils.merge(geometries); | ||
this._model.add(mergedFragment.mesh); | ||
for (const id in items) { | ||
this._expressIDfragmentIDMap[id] = mergedFragment.id; | ||
} | ||
} | ||
@@ -224,0 +232,0 @@ newMergedFragment(merged, buffer, mats, itemsIDs) { |
@@ -8,2 +8,3 @@ import * as WEBIFC from "web-ifc"; | ||
private _materials; | ||
private _voids; | ||
private _geometriesByMaterial; | ||
@@ -14,2 +15,3 @@ private readonly _items; | ||
cleanUp(): void; | ||
addVoid(voidID: number): void; | ||
private reset; | ||
@@ -16,0 +18,0 @@ private getGeometryTransformation; |
@@ -6,2 +6,3 @@ import * as THREE from "three"; | ||
this.isFirstMatrix = true; | ||
this._voids = new Set(); | ||
this._geometriesByMaterial = {}; | ||
@@ -26,3 +27,7 @@ this._items = {}; | ||
this._geometriesByMaterial = {}; | ||
this._voids.clear(); | ||
} | ||
addVoid(voidID) { | ||
this._voids.add(voidID); | ||
} | ||
reset(webifc) { | ||
@@ -42,2 +47,3 @@ this._geometriesByMaterial = {}; | ||
matrix: transform, | ||
hasVoids: this._voids.has(mesh.expressID), | ||
}); | ||
@@ -63,2 +69,3 @@ } | ||
matrix: new THREE.Matrix4(), | ||
hasVoids: this._voids.has(mesh.expressID), | ||
}, | ||
@@ -65,0 +72,0 @@ ], |
@@ -19,2 +19,3 @@ import { Settings } from "./settings"; | ||
private loadMainCategories; | ||
private setupVoids; | ||
private loadOptionalCategories; | ||
@@ -21,0 +22,0 @@ private cleanUp; |
@@ -36,3 +36,3 @@ import * as WEBIFC from "web-ifc"; | ||
await this._progress.setupLoadProgress(this._webIfc); | ||
this.loadAllCategories(); | ||
await this.loadAllCategories(); | ||
const model = await this._converter.generateFragmentData(this._webIfc); | ||
@@ -43,8 +43,9 @@ this._progress.updateLoadProgress(); | ||
} | ||
loadAllCategories() { | ||
async loadAllCategories() { | ||
this._converter.setupCategories(this._webIfc); | ||
this.loadOptionalCategories(); | ||
this.loadMainCategories(); | ||
await this.setupVoids(); | ||
await this.loadMainCategories(); | ||
} | ||
loadMainCategories() { | ||
async loadMainCategories() { | ||
this._webIfc.StreamAllMeshes(0, (mesh) => { | ||
@@ -55,2 +56,12 @@ this._progress.updateLoadProgress(); | ||
} | ||
async setupVoids() { | ||
const voids = this._webIfc.GetLineIDsWithType(0, WEBIFC.IFCRELVOIDSELEMENT); | ||
const props = this._webIfc.properties; | ||
const size = voids.size(); | ||
for (let i = 0; i < size; i++) { | ||
const voidsProperties = await props.getItemProperties(0, voids.get(i)); | ||
const voidID = voidsProperties.RelatingBuildingElement.value; | ||
this._geometry.addVoid(voidID); | ||
} | ||
} | ||
// Some categories (like IfcSpace) need to be set explicitly | ||
@@ -57,0 +68,0 @@ loadOptionalCategories() { |
@@ -13,5 +13,3 @@ import { FragmentLoader } from "bim-fragment/fragment-loader"; | ||
import { IfcFragmentLoader } from "./fragment-ifc-importer"; | ||
export interface FragmentConfig { | ||
culling: boolean; | ||
} | ||
import { MemoryCulling } from "./memory-culling"; | ||
export declare class Fragments { | ||
@@ -31,6 +29,7 @@ private components; | ||
materials: FragmentMaterials; | ||
culler?: FragmentCulling; | ||
constructor(components: Components, config?: FragmentConfig); | ||
culler: FragmentCulling; | ||
memoryCuller: MemoryCulling; | ||
constructor(components: Components); | ||
load(geometryURL: string, dataURL: string, matrix?: THREE.Matrix4): Promise<Fragment>; | ||
add(fragment: Fragment): void; | ||
} |
import { FragmentLoader } from "bim-fragment/fragment-loader"; | ||
import * as THREE from "three"; | ||
import { FragmentHighlighter } from "./fragment-highlighter"; | ||
@@ -10,4 +11,5 @@ import { FragmentCulling } from "./fragment-culling"; | ||
import { IfcFragmentLoader } from "./fragment-ifc-importer"; | ||
import { MemoryCulling } from "./memory-culling"; | ||
export class Fragments { | ||
constructor(components, config) { | ||
constructor(components) { | ||
this.components = components; | ||
@@ -24,7 +26,6 @@ this.fragments = {}; | ||
this.materials = new FragmentMaterials(this); | ||
if (!config || config.culling) { | ||
this.culler = new FragmentCulling(components, this); | ||
} | ||
this.culler = new FragmentCulling(components, this); | ||
this.memoryCuller = new MemoryCulling(components); | ||
} | ||
async load(geometryURL, dataURL, matrix) { | ||
async load(geometryURL, dataURL, matrix = new THREE.Matrix4()) { | ||
const fragment = await this.loader.load(geometryURL, dataURL); | ||
@@ -31,0 +32,0 @@ if (matrix) { |
{ | ||
"name": "openbim-components", | ||
"main": "dist/index.js", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"packageManager": "yarn@3.2.1", | ||
@@ -6,0 +6,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
548480
244
8601