Skip to main content

Overview

The OpenPlans class is the core of the OpenPlans library. It provides a complete rendering environment with camera controls, scene management, and methods for creating architectural elements like lines, arcs, doors, windows, and more.

Constructor

OpenPlans()

Creates a new OpenPlans instance in the specified HTML container.
container
HTMLElement
required
The HTML element where the 3D scene will be rendered
const container = document.getElementById('viewport');
const op = new OpenPlans(container);

Initialization

setupOpenGeometry()

Initializes the OpenGeometry kernel and glyph rendering system. Must be called before using geometry methods.
wasmURL
string
Optional URL to the WebAssembly module
Promise<void>
Promise<void>
Returns a promise that resolves when initialization is complete
await op.setupOpenGeometry();
// or with custom WASM URL
await op.setupOpenGeometry('/path/to/opengeometry.wasm');

2D Primitives

line()

Creates a straight line primitive.
config
ILineOptions
Configuration object for the line
LinePrimitive
LinePrimitive
The created line object
const line = op.line({
  startPoint: [0, 0, 0],
  endPoint: [5, 0, 0],
  color: 0x000000
});

arc()

Creates an arc primitive.
config
IArcOptions
Configuration object for the arc
ArcPrimitive
ArcPrimitive
The created arc object
const arc = op.arc({
  center: [0, 0, 0],
  radius: 2,
  startAngle: 0,
  endAngle: Math.PI,
  segments: 32,
  color: 0x000000
});

rectangle()

Creates a rectangular primitive.
config
IRectangleOptions
Configuration object for the rectangle
RectanglePrimitive
RectanglePrimitive
The created rectangle object
const rect = op.rectangle({
  center: [0, 0, 0],
  width: 4,
  breadth: 2,
  color: 0x0000ff
});

polyline()

Creates a polyline (multi-segment line) primitive.
config
IPolylineOptions
Configuration object for the polyline
PolylinePrimitive
PolylinePrimitive
The created polyline object
const polyline = op.polyline({
  points: [
    [0, 0, 0],
    [1, 0, 0],
    [1, 0, 1],
    [2, 0, 1]
  ],
  color: 0x0000ff
});

3D Shapes

cuboid()

Creates a 3D cuboid (box) shape.
config
ICuboidOptions
Configuration object for the cuboid
CuboidShape
CuboidShape
The created cuboid object
import { Vector3 } from '@opengeometry/openplans';

const cuboid = op.cuboid({
  center: new Vector3(0, 1, 0),
  width: 2,
  height: 3,
  depth: 1,
  color: 0x8B4513
});

cylinder()

Creates a 3D cylinder shape.
config
ICylinderOptions
Configuration object for the cylinder
CylinderShape
CylinderShape
The created cylinder object
import { Vector3 } from '@opengeometry/openplans';

const cylinder = op.cylinder({
  center: new Vector3(0, 1.5, 0),
  radius: 0.5,
  height: 3,
  color: 0xCCCCCC
});

Architectural Elements

baseDoor()

Creates a door element with frame and panel.
config
OPDoor
Configuration object for the door
BaseDoor
BaseDoor
The created door object
const door = op.baseDoor({
  labelName: 'Main Entrance',
  doorPosition: [5, 0, 0],
  dimensions: {
    start: { x: -0.5, y: 0, z: 0 },
    end: { x: 0.5, y: 0, z: 0 },
    length: 1
  },
  doorHeight: 2.1,
  doorThickness: 0.1,
  frameThickness: 0.2,
  doorColor: 0x8B4513,
  frameColor: 0x000000,
  doorQuadrant: 1
});

baseSingleWindow()

Creates a single window element with frame and panel.
config
OPSingleWindow
Configuration object for the window
BaseSingleWindow
BaseSingleWindow
The created window object
const window = op.baseSingleWindow({
  labelName: 'Living Room Window',
  windowPosition: [3, 0, 0],
  dimensions: {
    start: { x: -0.6, y: 0, z: 0 },
    end: { x: 0.6, y: 0, z: 0 },
    length: 1.2
  },
  windowHeight: 1.2,
  sillHeight: 0.9,
  windowColor: 0x87CEEB,
  frameColor: 0x000000
});

baseDoubleWindow()

Creates a double window element.
config
OPDoubleWindow
Configuration object for the double window (similar structure to single window)
BaseDoubleWindow
BaseDoubleWindow
The created double window object
const doubleWindow = op.baseDoubleWindow({
  labelName: 'Large Window',
  windowPosition: [0, 0, 5],
  dimensions: {
    start: { x: -1.0, y: 0, z: 0 },
    end: { x: 1.0, y: 0, z: 0 },
    length: 2.0
  },
  windowHeight: 1.5,
  sillHeight: 0.9
});

baseSlab()

Creates a floor or ceiling slab element.
config
OPSlab
Configuration object for the slab
BaseSlab
BaseSlab
The created slab object
const slab = op.baseSlab({
  labelName: 'Ground Floor',
  slabPosition: [0, 0, 0],
  dimensions: {
    start: { x: -5, y: 0, z: -5 },
    end: { x: 5, y: 0, z: 5 },
    width: 10,
    length: 10
  },
  slabThickness: 0.2,
  slabColor: 0xCCCCCC,
  slabMaterial: 'concrete'
});

baseStair()

Creates a staircase element.
config
OPStair
Configuration object for the stair
BaseStair
BaseStair
The created stair object
const stair = op.baseStair({
  labelName: 'Main Stairs',
  stairPosition: [0, 0, 0],
  dimensions: {
    width: 1.2,
    totalHeight: 3.0,
    totalLength: 4.5
  },
  riserHeight: 0.17,
  treadDepth: 0.28,
  stairColor: 0x8B7355,
  stairMaterial: 'wood'
});

Drawing Elements

board()

Creates a drawing board for organizing elements.
config
BoardOptions
Configuration object for the board
Board
Board
The created board object
const board = op.board({
  labelName: 'Floor Plan',
  dimensions: {
    start: { x: 0, y: 0, z: 0 },
    end: { x: 20, y: -20, z: 0 },
    width: 20,
    height: 20
  },
  color: 0xffffff
});

paperFrame()

Creates a paper frame for technical drawings with standard paper sizes.
config
PaperFrameOptions
Configuration object for the paper frame
PaperFrame
PaperFrame
The created paper frame object
const paper = op.paperFrame({
  labelName: 'Sheet 1',
  format: 'A3',
  orientation: 'landscape',
  margin: 10,
  backgroundColor: 0xffffff,
  borderColor: 0x000000
});

Text and Glyphs

glyph()

Creates a text glyph (label) in the scene.
text
string
required
The text to display
size
number
required
Font size
color
number
required
Text color as hexadecimal
staticZoom
boolean
Whether the text size remains constant when zooming (default: true)
GlyphNode
GlyphNode
The created glyph object with unique ID
const label = op.glyph('Room A', 0.5, 0x000000, true);
label.position.set(5, 0, 5);

getGlyph()

Retrieves a glyph by its ID.
id
string
required
The unique ID of the glyph
GlyphNode
GlyphNode
The glyph object
const glyph = op.getGlyph('glyph-id');

updateGlyphText()

Updates the text content of a glyph.
id
string
required
The unique ID of the glyph
text
string
required
The new text content
op.updateGlyphText('glyph-id', 'Updated Text');

rotateGlyph()

Rotates a glyph by a specified angle.
id
string
required
The unique ID of the glyph
angle
number
required
Rotation angle in radians
op.rotateGlyph('glyph-id', Math.PI / 4);

selectGlyph()

Selects a glyph for editing.
id
string
required
The unique ID of the glyph
op.selectGlyph('glyph-id');

clearGlyphSelection()

Clears the current glyph selection.
op.clearGlyphSelection();

View Management

create2DView()

Creates a 2D orthographic view in a separate container.
container
HTMLElement
required
The HTML container for the 2D view
sectionHeight
number
Height at which to section the view (default: 0)
object
{camera: THREE.Camera, renderer: THREE.WebGLRenderer}
Object containing the camera and renderer for the 2D view
const view2DContainer = document.getElementById('plan-view');
const { camera, renderer } = op.create2DView(view2DContainer, 1.5);

update()

Updates the label renderer. Should be called in your render loop.
scene
THREE.Scene
required
The Three.js scene
camera
THREE.Camera
required
The Three.js camera
function animate() {
  requestAnimationFrame(animate);
  op.update(scene, camera);
}

Utility Methods

disposeElement()

Removes and disposes an element by its ID.
ogid
string
required
The unique ID of the element to dispose
op.disposeElement('element-id');

getEntitiesByType()

Retrieves all entities of a specific type.
type
string
required
The type of entities to retrieve (e.g., ‘LinePrimitive’, ‘BaseDoor’)
array
any[]
Array of entities matching the type
const allDoors = op.getEntitiesByType('DOOR');
const allLines = op.getEntitiesByType('LinePrimitive');

fit()

Fits the camera to show all elements of a specific type.
element
string
required
The type of elements to fit to
op.fit('BaseDoor');

Properties

showGrid

Setter to show or hide the grid.
op.showGrid = true;  // Show grid
op.showGrid = false; // Hide grid

glyphNodes

Getter that returns all glyph nodes in the scene.
Map
Map<string, GlyphNode>
Map of glyph IDs to glyph nodes
const allGlyphs = op.glyphNodes;
for (const [id, glyph] of allGlyphs) {
  console.log(`Glyph ${id}:`, glyph);
}

Static Methods

OpenPlans.toScreenPosition()

Converts a 3D world position to 2D screen coordinates.
pos
THREE.Vector3
required
The 3D world position
object
{x: number, y: number}
The 2D screen coordinates
import * as THREE from 'three';

const worldPos = new THREE.Vector3(5, 0, 5);
const screenPos = OpenPlans.toScreenPosition(worldPos);
console.log(`Screen position: ${screenPos.x}, ${screenPos.y}`);

Example: Complete Floor Plan

import { OpenPlans, Vector3 } from '@opengeometry/openplans';

const container = document.getElementById('viewport');
const op = new OpenPlans(container);

// Initialize OpenGeometry
await op.setupOpenGeometry();

// Create a floor slab
const floor = op.baseSlab({
  labelName: 'Ground Floor',
  slabPosition: [0, 0, 0],
  dimensions: {
    start: { x: -5, y: 0, z: -5 },
    end: { x: 5, y: 0, z: 5 },
    width: 10,
    length: 10
  },
  slabThickness: 0.2,
  slabColor: 0xEEEEEE
});

// Create walls using polylines
const wall1 = op.polyline({
  points: [
    [-5, 0, -5],
    [5, 0, -5],
    [5, 0, 5],
    [-5, 0, 5],
    [-5, 0, -5]
  ],
  color: 0x000000
});

// Add a door
const door = op.baseDoor({
  labelName: 'Main Entrance',
  doorPosition: [0, 0, -5],
  dimensions: {
    start: { x: -0.5, y: 0, z: 0 },
    end: { x: 0.5, y: 0, z: 0 },
    length: 1
  },
  doorHeight: 2.1,
  doorColor: 0x8B4513
});

// Add a window
const window = op.baseSingleWindow({
  labelName: 'Living Room Window',
  windowPosition: [5, 0, 0],
  dimensions: {
    start: { x: -0.6, y: 0, z: 0 },
    end: { x: 0.6, y: 0, z: 0 },
    length: 1.2
  },
  windowHeight: 1.2,
  sillHeight: 0.9
});

// Add labels
const roomLabel = op.glyph('Living Room', 0.3, 0x333333);
roomLabel.position.set(0, 0, 0);

// Show grid
op.showGrid = true;

// Fit camera to show all doors
op.fit('DOOR');
Last modified on March 7, 2026