Reference Source
public class | source

OBJLoaderPlugin

Extends:

Plugin → OBJLoaderPlugin

Viewer plugin that loads models from OBJ files.

  • Creates an Entity representing each model it loads, which will have Entity#isModel set true and will be registered by Entity#id in Scene#models.
  • Creates an Entity for each object within the model, which will have Entity#isObject set true and will be registered by Entity#id in Scene#objects.
  • When loading, can set the World-space position, scale and rotation of each model within World space, along with initial properties for all the model's Entitys.

Metadata

OBJLoaderPlugin can also load an accompanying JSON metadata file with each model, which creates a MetaModel corresponding to the model Entity and a MetaObject corresponding to each object Entity.

Each MetaObject has a MetaObject#type, which indicates the classification of its corresponding Entity. When loading metadata, we can also provide GLTFModelLoaderPlugin with a custom lookup table of initial values to set on the properties of each type of Entity. By default, OBJLoaderPlugin uses its own map of standard default colors, visibilities and opacities for IFC element types.

Usage

[Run this example]

import {Viewer, OBJLoaderPlugin} from "xeokit-sdk.es.js";

// Create a xeokit Viewer and arrange the camera
const viewer = new Viewer({
     canvasId: "myCanvas",
     transparent: true
});

viewer.camera.orbitPitch(20);

// Add an OBJLoaderPlugin to the Viewer
const objLoader = new OBJLoaderPlugin(viewer);

// Load an OBJ model
var model = objLoader.load({ // Model is an Entity
     id: "myModel",
     src: "./models/obj/sportsCar/sportsCar.obj",
     edges: true
});

// When the model has loaded, fit it to view
model.on("loaded", () => {
     viewer.cameraFlight.flyTo(model);
})

// Find the model Entity by ID
model = viewer.scene.models["myModel"];

// Update properties of the model Entity
model.highlight = [1,0,0];

// Destroy the model
model.destroy();

Constructor Summary

Public Constructor
public

constructor(viewer: Viewer, cfg: Object)

Method Summary

Public Methods
public

Destroys this OBJLoaderPlugin.

public

load(params: *): Entity

Loads an OBJ model from a file into this OBJLoader's Viewer.

Inherited Summary

From class Plugin
public

ID for this Plugin, unique within its Viewer.

public

The Viewer that contains this Plugin.

public

Destroys this Plugin and removes it from its Viewer.

public

error(msg: String)

Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this Plugin.

public

Returns true if there are any subscribers to the given event on this Plugin.

public

log(msg: String)

Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin.

public

off(subId: String)

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

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this Plugin.

public

once(event: String, callback: Function, scope: Object)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd.

public

scheduleTask(task: *)

Schedule a task to perform on the next browser interval

public

warn(msg: String)

Logs a warning message to the JavaScript developer console, prefixed with the ID of this Plugin.

Public Constructors

public constructor(viewer: Viewer, cfg: Object) source

Creates this Plugin and installs it into the given Viewer.

Override:

Plugin#constructor

Params:

NameTypeAttributeDescription
viewer Viewer

The Viewer.

cfg Object

Plugin configuration.

cfg.id String
  • optional
  • default: "OBJLoader"

Optional ID for this plugin, so that we can find it within Viewer#plugins.

Public Methods

public destroy() source

Destroys this OBJLoaderPlugin.

Override:

Plugin#destroy

public load(params: *): Entity source

Loads an OBJ model from a file into this OBJLoader's Viewer.

Params:

NameTypeAttributeDescription
params *

Loading parameters.

params.id String

ID to assign to the model's root Entity, unique among all components in the Viewer's Scene.

params.src String

Path to an OBJ file.

params.metaModelSrc String
  • optional

Path to an optional metadata file.

params.position Number[]
  • optional
  • default: [0,0,0]

The model World-space 3D position.

params.scale Number[]
  • optional
  • default: [1,1,1]

The model's World-space scale.

params.rotation Number[]
  • optional
  • default: [0,0,0]

The model's World-space rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

params.matrix Number[]
  • optional
  • default: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]

The model's world transform matrix. Overrides the position, scale and rotation parameters.

params.edgeThreshold Number
  • optional
  • default: 20

When xraying, highlighting, selecting or edging, this is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn.

Return:

Entity

Entity representing the model, which will have Entity#isModel set true and will be registered by Entity#id in Scene#models