Skip to main content

DrawingLayers

Manages the named layers of a TechnicalDrawing.

Extends

Constructors

new DrawingLayers()

new DrawingLayers(container): DrawingLayers

Accessible via drawing.layers. Each layer owns a THREE.LineBasicMaterial that is shared across all projection LineSegments assigned to it — mutating the material (e.g. via setColor) is reflected on every line immediately without any scene traversal. Annotation systems always use their own style material and are not affected by layer materials.

Extends DataMap<string, DrawingLayer> so consumers get reactive events (onItemSet, onItemDeleted, …) directly on drawing.layers.

Layer "0" always exists and cannot be removed.

drawing.layers.create("walls", { material: new THREE.LineBasicMaterial({ color: 0x333333 }) });
drawing.layers.setColor("walls", 0x888888);
drawing.layers.setVisibility("walls", false);

Parameters

ParameterType
containerGroup<Object3DEventMap>

Returns

DrawingLayers

Overrides

FRAGS.DataMap<string, DrawingLayer>.constructor

Methods

assign()

assign(object, name): void

Assigns an object to a named layer, applies the layer's material (if the object is a LineSegments), and immediately reflects the layer's current visibility state.

Use this instead of setting object.userData.layer directly so that the material and visibility are always in sync at insertion time.

Does nothing if the layer does not exist.

Parameters

ParameterTypeDescription
objectObject3D<Object3DEventMap>The Three.js object to assign.
namestringLayer name.

Returns

void


create()

create(name, options?): DrawingLayer

Creates a new layer. If a layer with the same name already exists, returns the existing one without modifying it.

Parameters

ParameterTypeDescription
namestringUnique layer name.
options?object

Optional material and visibility. If no material is given,

a default black LineBasicMaterial is created. Visibility defaults to true.

options.material?LineBasicMaterial-
options.visible?boolean-

Returns

DrawingLayer

The (possibly pre-existing) layer object.


resolveColor()

Internal

resolveColor(name): undefined | number

Used by DxfExporter to read the layer color for DXF output.

Parameters

ParameterType
namestring

Returns

undefined | number


setColor()

setColor(name, color): void

Updates the color of a layer's material and fires reactive events.

Because all LineSegments on the same layer share the same material instance, the change is reflected immediately on all of them — no scene traversal is required.

Does nothing if the layer does not exist.

Parameters

ParameterTypeDescription
namestringLayer name.
colornumberHex color (e.g. 0xff0000).

Returns

void


setMaterial()

setMaterial(name, material): void

Replaces the material of a layer and updates all LineSegments currently assigned to it. The previous material is disposed.

Does nothing if the layer does not exist.

Parameters

ParameterTypeDescription
namestringLayer name.
materialLineBasicMaterialNew material to assign.

Returns

void


setVisibility()

setVisibility(name, visible): void

Shows or hides all objects assigned to the given layer.

Does nothing if the layer does not exist.

Parameters

ParameterTypeDescription
namestringLayer name.
visiblebooleantrue to show, false to hide.

Returns

void