Class: ModelManager

PD. ModelManager

Manages the 3D building model and all its elements.


new ModelManager( [config])

Creates a new building model manager.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
project BIM.Project <optional>

An optional BIM project to manage, defaults to a new project.

structure BIM.Project <optional>

An optional structure within the BIM project to edit.

level BIM.Level <optional>

An optional level within the current structure to edit.

site BIM.Site <optional>

An optional site within the current project to edit.

view BIM.DrawingView <optional>

An optional drawing view within the current project to show.

Author:
  • drajmarsh

Members


:boolean

animateViewWithFloorLevel

Whether or not to animate the view together with the floor level offset.

Type
  • boolean

:BIM.Level

currentLevel

The current level within the structure being edited.

Type

:BIM.Site

currentSite

The current site within the project.

Type

:BIM.Project

currentStructure

The current structure being edited.

Type

:BIM.DrawingView

currentView

The current stored view.

Type

:Array

elementList <readonly>

The list of spaces that make up the current level.

Type
  • Array

:THREE.Box3

expandedExtents

Stores the extents of the current level.

Type
  • THREE.Box3

:boolean

hasChanged

Whether or not the model has changed and needs an update.

Type
  • boolean

:boolean

isModelManager <readonly>

A flag identifying this object as a model manager.

Type
  • boolean

:PD.PolyMesh

meshFloorAnnotation

A dynamic mesh for displaying annotations that always move and align with the floor height of the current level.

This includes annotations such as the base north arrow and the current level selection indicator.

Type

:PD.PolyMesh

meshModelAnnotation

A dynamic mesh for displaying annotations that always move and align with the model as a whole.

This includes annotations such as the level height grid, etc.

Type

:PD.PolyMesh

meshOverlap

The dynamic mesh used to render overlaps and errors.

Type

:PD.PolyMesh

meshSnapLevel

A semi-transparent dynamic mesh for indicating the current snap level.

Type

:THREE.Group

meshes

Stores the meshes required to display the current model.

Type
  • THREE.Group

:BIM.Project

project

Stores the BIM project currently being edited.

Type

:BIM.SceneManager|null

sceneManager

Stores the scene manager this is connected to.

This value is set in the PD.ModelManager.connectTo method.

Type
  • BIM.SceneManager | null

:BIM.Level|null

snapLevel

An upper or lower level to snap to.

Type

Methods


addElement(element)

Adds a new element to the current level if it doesn't already exist.

Parameters:
Name Type Description
element BIM.Element

The new element to add.

Returns:

Returns true if the element was added and the model changed.

Type
boolean

addLevel(level)

Adds a new level to the current structure if it doesn't already exist.

Parameters:
Name Type Description
level BIM.Level

The new level to add.

Returns:

Returns true if the level was added and the model changed.

Type
boolean

addLevelMeshes(level)

Adds the meshes of the given level from the displayed model.

Parameters:
Name Type Description
level BIM.Level

The new level to make current.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

animateFloorLevelOffset(newOffset)

Animates the floor level offset for the current model.

Parameters:
Name Type Description
newOffset number

The new floor grid offset to animate to.

Returns:

Returns true the animation started.

Type
boolean

animateFloorLevelPos(new_pos)

Animates levels to their new positions within the current model.

Parameters:
Name Type Description
new_pos THREE.Vector3

The new floor grid position to animate to.

Returns:

Returns true the animation started.

Type
boolean

closestPoint3D(snapper, point, ray [, selection])

Finds the closest element in the element list to the given 3D ray.

Parameters:
Name Type Argument Description
snapper PD.Snapper

The snap helper object.

point THREE.Vector3

The point to snap.

ray THREE.Ray

The 3D ray to check points.

selection PD.SelectionSet | BIM.Element <optional>

The current selection set or element, defaults to null.

Returns:

Returns true if a point in the model was found and the selection updated, otherwise false.

Type
boolean

closestPointOnAperture(snapper, point, ray [, selected_aperture])

Finds the closest aperture point to the given 3D ray.

Parameters:
Name Type Argument Description
snapper PD.Snapper

The snap helper object.

point THREE.Vector3

The point to snap.

ray THREE.Ray

The 3D ray to check points.

selected_aperture BIM.Aperture <optional>

The currently selected aperture, defaults to null.

Returns:

Returns true if an aperture point in the model was found and the snapper updated, otherwise false.

Type
boolean

closestPointXY(snapper, point [, selection])

Finds the closest element in the element list to the given point in plan.

Parameters:
Name Type Argument Default Description
snapper PD.Snapper

The snap helper object.

point THREE.Vector3

The point to snap.

selection PD.SelectionSet | BIM.Element <optional>
null

The current selection set or element, defaults to null.

Returns:

Returns true if a point in the model was found and the selection updated, otherwise false.

Type
boolean

computeExpandedExtents()

Computes a bounding box that is slightly expanded around the current structure.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

computeExtents()

Calculates the extents of the entire project with all its structures.

This computes the extents using the PD.Project#computeExtents method and then updates any currently visible annotations on the current structure.

Returns:

Returns the newly computed bounding box.

Type
THREE.Box3

connectTo(sceneManager)

Add the model meshes to the given scene.

Parameters:
Name Type Description
sceneManager PD.SceneManager

The scene manager to display meshes in.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

dispose()

Cleans up the scene viewer and removes all event listeners.

NOTE: Only call this method when the scene viewer is no longer needed and you wish to free all its resources.


fadeInLevel(level)

This method is used by levels to determine whether they need to fade in at the same time as scaling in when displayed in 3D.

Parameters:
Name Type Description
level BIM.Level

The level to check.

Returns:

Returns true if the level should fade in to the current view.

Type
boolean

findAperturesByFrustum(selection, event)

Search for apertures inside the given selection frustum.

This method first checks that the PD.GlobalState.selectComponents value is set to true before iterating through the model. If so, it then fills out the selection.foundItems map with information on each aperture that is inside the frustum, if any.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findByUUID(uuid [, currentOnly])

Search through structures within the project for a matching entity.

This method always gives priority to the current structure being edited by searching it first. If the second argument if truthy, only the current structure will be searched.

Parameters:
Name Type Argument Default Description
uuid string

The UUID of the entity to search for.

currentOnly boolean <optional>
false

When true, only search the current structure.

Returns:

Returns the found entity or null.

Type
PD.Base | null

findClosestChildOrSiblingByRay(selection, element)

Finds the closest child or sibling of the given element.

If the element has children, it first checks them. If the element is the child of another element, it then checks for sibling.

This method fills out the selection object with information on the closest child/sibling element found, if any.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

element BIM.Element

The composite or child element to check.

Returns:

Returns true if a child or sibling of the element was found and the selection updated, otherwise false.

Type
boolean

findClosestElementByRay(selection, event [, selectedType])

Finds the closest element in the element list.

This method fills out the selection object with information on the closest element, if found.

Parameters:
Name Type Argument Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

selectedType PD.SELECTED <optional>

The current model selection type, defaults to PD.SELECTED.NONE.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findClosestFeatureByRay(selection, event [, selectedType])

Finds the closest feature in the element list.

This method fills out the selection object with information on the closest junction, path segment or element. If the selection.currentElement value is not null, then priority for selection is given to this element.

Parameters:
Name Type Argument Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

selectedType PD.SELECTED <optional>

The current model selection type, defaults to PD.SELECTED.NONE.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findClosestFeatureInElementByRay(selection, element, selectedType)

Finds the closest feature within the given element.

This method fills out the selection object with information on the closest junction, path segment or child element.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

element BIM.Element

The element to check.

selectedType PD.SELECTED

The current model selection type.

Returns:

Returns true if something in the element was selected and the selection updated, otherwise false.

Type
boolean

findClosestSurfaceByRay(selection)

Finds the closest surface of a space, wall or slab in the current level.

This method fills out the selection object with information on the closest line segment or element. If the selected element is not null, then priority for selection is given to this element.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findClosestWallSurfaceByRay(selection, event)

Finds the closest segment or element in the current level.

This method fills out the selection object with information on the closest line segment or element. If the selected element is not null, then priority for selection is given to this element.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findElementsByFrustum(selection, event)

Search for elements inside the given selection frustum.

This method first checks that the PD.GlobalState.selectElements value is set to true before iterating through the model. If so, it then fills out the selection.foundItems map with information on each element that is inside the frustum, if any.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findFeaturesByFrustum(selection, event)

Search for features inside the given selection frustum.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findJunctionsByFrustum(selection, event)

Search for junctions inside the given selection frustum.

This method first checks that the PD.GlobalState.selectJunctions value is set to true before iterating through the model. If so, it then fills out the selection.foundItems map with information on each junction that is inside the frustum, if any.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

findSameSelectionTypeByRay(type, selection)

Searches for the closest element, segment, junction or aperture based on the given type.

If something is found. this method fills out the selection object with information on the closest item.

Parameters:
Name Type Description
type PD.SELECTED

The selection type to find more of.

selection PD.Selection

The interactive selection accumulator.

Returns:

Returns true if something in the model was found and the selection set updated, otherwise false.

Type
boolean

findSegmentsByFrustum(selection, event)

Search for path segments inside the given selection frustum.

This method first checks that the PD.GlobalState.selectSegments value is set to true before iterating through the model. If so, it then fills out the selection.foundItems map with information on each segment that is inside the frustum, if any.

Parameters:
Name Type Description
selection PD.Selection

The interactive selection accumulator.

event Event

The DOM event that triggered this selection.

Returns:

Returns true if something in the model was selected and the selection updated, otherwise false.

Type
boolean

getAllElements(filterFn)

Retrieves a list of all elements in the model that match the filter function.

Parameters:
Name Type Description
filterFn function

A callback function suitable for use with Array.filter().

Returns:

Returns an array of visible elements.

Type
Array

getLevelsWithSameElevation(level)

Retrieves an array of levels with the same elevation in adjacent structures.

Parameters:
Name Type Description
level BIM.Level

The level to get the reference elevation from.

Returns:

Returns an array of zero or more adjacent levels.

Type
Array

getModelAsJSONObject()

Generates a JSON object from the current model.

The returned object has a single property PD:BIM:MODEL that contains the current model data as well as relevant global state information.

Returns:

Returns the current model as simplified JSON.

Type
string

getModelAsJSONString()

Generates a JSON string from the current model.

The returned string is a stringified object with a single property PD:BIM:MODEL that contains the current model data as well as relevant global state information.

Returns:

Returns the current model as a JSON string.

Type
string

getVisibleElements(filterFn)

Retrieves a list of visible elements in the model that match the filter function.

Parameters:
Name Type Description
filterFn function

A callback function suitable for use with Array.filter().

Returns:

Returns an array of visible elements.

Type
Array

hideSpaceOverlap()

Hides the error mesh at the start of an edit.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

highlightSpaceOverlap()

Checks both spatial relationships and highlight areas of overlap.

Returns:

Returns true if overlaps were detected.

Type
boolean

intersectLightRay(ray, result)

Handles the intersection of a light or shading ray with this element.

This method typically intersects the ray with the BIM.Element#shell if it has one. Override this method in your custom element if it needs to handle light ray intersections differently.

Parameters:
Name Type Description
ray THREE.Ray

The ray defining the origin and direction of the light ray.

result object

An object containing information about the light ray.

Properties of result:
Name Type Description
intersection THREE.Vector3

Stores the octree triangle intersection point as a {x,y,z} vector.

transmittance number

Stores the accumulated transmittance of all intersected surfaces.

reflectance number

Stores the accumulated reflectance from all intersected surfaces.

color number

Stores the color of the primary intersected surface.

Returns:

Returns true if the light ray hit an opaque surface and updated results.

Type
boolean

isInsideAnySpace(element)

Determines if the given element is inside a space on the current level.

Parameters:
Name Type Description
element BIM.Element

The element to check for a host space.

Returns:

Returns the space that the element is in, or null.

Type
BIM.Space

levelImageLoad(image_url, callback)

Loads in and displays a level floor plan image.

Parameters:
Name Type Description
image_url string

The url of the image to load.

callback function

The callback function once loaded.

Returns:

Returns this model manager to support method chaining.

Type
PD.SceneManager

levelImageSet(image)

Assigns a DOM element as the level floor plan image.

Parameters:
Name Type Description
image object

The DOM img element to use.

Returns:

Returns this model manager to support method chaining.

Type
PD.SceneManager

levelImageVisible(show)

Shows or hides the currently level floor plan image.

Parameters:
Name Type Description
show boolean

Whether or not to show the floor plan.

Returns:

Returns this model manager to support method chaining.

Type
PD.SceneManager

loadFromXML(xmlDoc)

Generates a new model from a gbXML document file.

Parameters:
Name Type Description
xmlDoc XMLDocument

An XML document obtained from 'DOMParser().parseFromString()'.

Returns:

Returns true if the current model was regenerated.

Type
boolean

loadJSON_ScannedData(json)

Reads JSON data resulting from a scanned building.

Parameters:
Name Type Description
json object

A JSON data object from the scanning tool.

Returns:

Returns true if a new model was created.

Type
boolean

loadModelFromJSON(json)

Generates a new model from a given JSON string/object.

The provided JSON data can either be a string or parsed object, and can be a BIM project file, a CityJSON file, or a PassiveLogic scanned model file.

Parameters:
Name Type Description
json object

A JSON data object.

Returns:

Returns true if the current model was regenerated.

Type
boolean

loadWeatherData(data)

Attempts to read in data from an EnergyPlus weather data file (.EPW).

Parameters:
Name Type Description
data string

The textual data from an .EPW file.


newProject( [project] [, no_undo])

Passes the current model to global undo and creates a brand new one.

Parameters:
Name Type Argument Description
project BIM.Project <optional>

An optional new model project.

no_undo boolean <optional>

When true, prevents recursive undo/redo entries.

Returns:

Returns true if a new model was created.

Type
boolean

rebuild( [forceUpdate])

Rebuilds the model mesh based on recent changes to the current level.

Parameters:
Name Type Argument Default Description
forceUpdate boolean <optional>
false

Whether or not to rebuild level(s) even if unchanged, defaults to false.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

rebuildAll( [forceUpdate] [, all])

Rebuilds the whole model mesh based on recent changes to the model.

Parameters:
Name Type Argument Default Description
forceUpdate boolean <optional>
false

Whether or not to rebuild visible level(s) even if unchanged, defaults to false.

all boolean <optional>
false

Whether or not to rebuild all level(s) even if not visible, defaults to false.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

removeElement(element)

Removes an existing element from the current level.

Parameters:
Name Type Description
element BIM.Element

The element to remove from the model.

Returns:

Returns the previous index of the element within the current level, or -1 if not removed.

Type
number

removeLevel(level)

Removes an existing level from the current structure.

Parameters:
Name Type Description
level BIM.Level

The level to remove from the model.

Returns:

Returns the previous index of the level within the current structure, or -1 if not removed.

Type
number

removeLevelMeshes(level [, force])

Removes the meshes of the given level from the displayed model.

Parameters:
Name Type Argument Description
level BIM.Level

The new level to remove.

force boolean <optional>

when true, removes even the current level.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

removeMeshes(container [, force])

Removes the meshes of the given child container from the displayed model.

Parameters:
Name Type Argument Description
container BIM.Level

The new level or view to remove.

force boolean <optional>

when true, removes even the current level.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

renderElementPaths(mesh)

Renders the paths of visible element to the given mesh.

Parameters:
Name Type Description
mesh PD.PolyMesh

the mesh to render paths to.


setCurrentLevel(level [, instant])

Sets the given level as the current level.

Parameters:
Name Type Argument Default Description
level BIM.Level

The new level to make current.

instant boolean <optional>
false

When true, no fade in/out animations are used, defaults to false.

Returns:

Returns true if animating, otherwise false if instant.

Type
boolean

setCurrentStructure(structure, level [, instant])

Sets the given structure (and level) as the current structure.

Parameters:
Name Type Argument Default Description
structure BIM.Structure

The new structure to make current.

level BIM.Level

The new level within the structure to make current.

instant boolean <optional>
false

When true, no fade in/out animations are used, defaults to false.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

setCurrentView(level [, instant])

Sets the given view as the current view.

Parameters:
Name Type Argument Description
level BIM.DrawingView

The new view to make current.

instant boolean <optional>

When true, no fade in/out animations are used, defaults to false.

Returns:

Returns true if animating, otherwise false if instant.

Type
boolean

setLevelDisplayPositions(animate)

Sets the target level positions to be animated to.

When the animate argument is false, the actual level mesh positions are also set.

Parameters:
Name Type Description
animate boolean

Whether or not to just set target position ready for animation.


setSnapLevel(level)

Makes the given level the snap level.

Parameters:
Name Type Description
level BIM.Level

The new level to make current.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

showLevel(level [, show])

Toggles the visibility of meshes for the given level from the displayed model.

Parameters:
Name Type Argument Description
level BIM.Level

The level to make current.

show boolean <optional>

The new level to make current.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

showLevelsWithSameElevation(level, speed, rebuild)

Displays levels with the same elevation in adjacent structures.

Parameters:
Name Type Description
level BIM.Level

The level to check the elevation of.

speed number

The animation speed in milliseconds.

rebuild boolean

Whether or not to rebuild the level due to a mode change.


snapLineToNearestElement(snapper, point [, selection])

Checks for points to snap the end point of a line to.

If given, the selected element is ignored as it should not be snapped to itself.

Parameters:
Name Type Argument Default Description
snapper PD.Snapper

The snap helper object.

point THREE.Vector3

The point to find the closest snap.

selection PD.SelectionSet | BIM.Element <optional>
null

The current selection set or element, defaults to null.

Returns:

Returns true if a features in the space list was found and added to the snapper, otherwise false.

Type
boolean

snapPointToNearestElement(snapper, point [, selection] [, selected_index])

Checks for points to snap to in the element list.

Parameters:
Name Type Argument Default Description
snapper PD.Snapper

The snap helper object.

point THREE.Vector3

The point to find the closest snap.

selection PD.SelectionSet | BIM.Element <optional>
null

The current selection set or element, defaults to null.

selected_index number <optional>

The currently selected vertex index within the selected element.

Returns:

Returns true if a features in the space list was found and added to the snapper, otherwise false.

Type
boolean

syncProjectHierarchy(array)

Synchronises a simplified version of the project hierarchy.

To ensure complete separation between the model data and its UI representation, this method synchronises a simple list that only contains strings, booleans and numbers. This allows a reactive or observable array to be passed in and updated, without any reactivity or observability leaking into the model itself.

In order to support observable arrays in Knockout and reactive arrays in Vue, the splice() array method is applied to reuse and (re)assign items, and to trim the lengths of each array.

Parameters:
Name Type Description
array Array

The array to update with project hierarchy.

Returns:

Returns the passed in array.

Type
Array

toggleShowLevel(level)

Toggles the visibility of meshes for the given level from the displayed model.

Parameters:
Name Type Description
level BIM.Level

The new level to toggle.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

update()

Checks if the model has changed and, if so, rebuilds the model mesh.

Returns:

Returns true if the model mesh was rebuilt, otherwise false.

Type
boolean

updateAfterDisplayModeChange( [forceUpdate])

Updates the model display based on the current display mode change.

Parameters:
Name Type Argument Default Description
forceUpdate boolean <optional>
false

An optional flag to force an update, defaults to false.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateAfterExplode()

Check the current explode levels setting to either show all structures or just current structure.


updateAfterLevelChange(oldLevel, newLevel, instant)

Updates the model display after the current level has been changed.

Parameters:
Name Type Description
oldLevel BIM.Level

The previously selected level.

newLevel BIM.Level

The newly selected level.

instant boolean

An optional flag to bypass animations.


updateAfterMajorModelChange()

Updates the model display based on the current display mode.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateAnnotations()

Regenerates the annotations mesh with any changed model annotations.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateLevelOpacities()

Updates the model when display opacity or colours change.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateLevelPositions()

Updates the height of all levels in each structure.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateLevelSidedness()

Updates the model when material double-sided values change.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateMeshGroupNames()

Updates the names of the BIM.Meshes in each level and drawing view in the current model.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateModelAnnotations()

Regenerates the model annotations mesh.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager

updateOctrees( [force_rebuild])

Rebuilds the octrees or each level if required.

Parameters:
Name Type Argument Description
force_rebuild boolean <optional>

When true, the octrees are forcibly rebuilt, defaults to false.

Returns:

Returns this model manager to support method chaining.

Type
PD.ModelManager