API Docs for: 2.0.0
Show:

Viewer Class

Module: BIMSURFER

A Viewer is a WebGL-based 3D viewer for the visualisation and evaluation of BIM models.

Overview

Example

In the example below we'll create a Viewer with a Camera, a CameraControl and a TeapotGeometry, which is used by an Object.
Finally, we make the Camera orbit on each "tick" event emitted by the Viewer.

// Create a Viewer
var viewer = new BIMSURFER.Viewer({

   // ID of the DIV element
   element: "myDiv"
});

// Create a Camera
var camera = new BIMSURFER.Camera(viewer, {
       eye: [5, 5, -5]
   });

// Create a CameraControl to control our Camera with mouse and keyboard
var cameraControl = new BIMSURFER.CameraControl(viewer, {
       camera: camera
   });

// Create a Geometry
var geometry = new BIMSURFER.TeapotGeometry(viewer, {
       id: "myGeometry"
   });

// Create an Object that uses the Geometry
var object1 = new BIMSURFER.Object(viewer, {
       id: "myObject1",
       type: "IfcCovering",
       geometries: [ geometry ]
   });

// Spin the camera
viewer.on("tick", function () {
       camera.rotateEyeY(0.2);
   });

Constructor

Viewer

(
  • [cfg]
)

Parameters:

  • [cfg] optional

    Configs

    • [id] String optional

      Optional ID, unique among all components in the parent viewer, generated automatically when omitted.

    • [meta] String:Object optional

      Optional map of user-defined metadata to attach to this Object.

    • element String | HTMLElement

      ID or instance of a DIV element in the page.

    • bimServerApi

      The BIMServer API.

Methods

error

(
  • message
)

Logs an error for this View to the JavaScript console.

The console message will have this format: [ERROR] BIMSERVER.Viewer: <message>

Parameters:

  • message String

    The message to log

fire

(
  • event
  • value
  • [forget=false]
)

Fires an event on this Viewer.

Notifies existing subscribers to the event, retains the event to give to any subsequent notifications on that location as they are made.

Parameters:

  • event String

    The event type name

  • value Object

    The event

  • [forget=false] Boolean optional

    When true, does not retain for subsequent subscribers

log

(
  • message
)

Logs a console debugging message for this View.

The console message will have this format: [LOG] BIMSERVER.Viewer: <message>

Parameters:

  • message String

    The message to log

off

(
  • handle
)

Cancels an event subscription that was previously made with on or once.

Parameters:

  • handle String

    Publication handle

on

(
  • event
  • callback
  • [scope=this]
)
String

Subscribes to an event on this Viewer.

The callback is be called with this Viewer as scope.

Parameters:

  • event String

    Publication event

  • callback Function

    Called when fresh data is available at the event

  • [scope=this] Object optional

    Scope for the callback

Returns:

String:

Handle to the subscription, which may be used to unsubscribe with {@link #off}.

once

(
  • event
  • callback
  • [scope=this]
)

Subscribes to the next occurrence of the given event on this Viewer, then un-subscribes as soon as the event is handled.

Parameters:

  • event String

    Data event to listen to

  • callback Function(data)

    Called when fresh data is available at the event

  • [scope=this] Object optional

    Scope for the callback

Properties

bimServerApi

Object final

The BIMServer API

boundary

final

Boundary of all bounded components in this Viewer.

camera

BIMSURFER.Camera final

The default Camera for this Viewer.

This Camera is active by default, and becomes inactive as soon as you activate some other Camera in this Viewer.

Any components that you create for this Viewer, that require a Camera, will fall back on this one by default.

canvas

BIMSURFER.Canvas final

Canvas manager for this Viewer.

canvas

HTMLCanvasElement final

The HTML Canvas that this Viewer renders to. This is inserted into the element we configured this Viewer with.

center

final

Center of all bounded components in this Viewer.

classes

String:String:Component final

The Components within this Viewer, mapped to their class names.

components

String:Component final

The Components within this Viewer, mapped to their IDs.

cursor

BIMSURFER.Cursor final

Cursor icon control for this Viewer.

element

HTMLElement final

The HTML element ocupied by the Viewer

geometryLoaders

Array of final

Geometry loaders

id

String final

ID of this Viewer

input

BIMSURFER.Input final

Input handling for this Viewer.

numObjects

Number

The number of Objects within this ObjectSet.

origin

final

World-space origin.

projMatrix

Array of Number final

This Viewer's projection transformation matrix.

Default: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]

scene

SceneJS.Scene final

The SceneJS scene graph that renders 3D content for this Viewer.

types

String:String:Component final

The Components within this Viewer, mapped to their IFC type names.

viewMatrix

Array of Number final

This Viewer's view transformation matrix.

Default: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]

Events

componentCreated

Fired whenever a Component has been created within this Viewer.

Event Payload:

  • value Component

    The component that was created

componentDestroyed

Fired whenever a component within this Viewer has been destroyed.

Event Payload:

  • value Component

    The component that was destroyed