import {OBJLoaderPlugin} from '@xeokit/xeokit-sdk/src/plugins/OBJLoaderPlugin/OBJLoaderPlugin.js'
OBJLoaderPlugin
Extends:
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
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 |
destroy() Destroys this OBJLoaderPlugin. |
|
public |
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 |
destroy() Destroys this Plugin and removes it from its Viewer. |
|
public |
Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Fires an event on this Plugin. |
|
public |
Returns true if there are any subscribers to the given event on this Plugin. |
|
public |
Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Cancels an event subscription that was previously made with Plugin#on or Plugin#once. |
|
public |
Subscribes to an event on this Plugin. |
|
public |
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 |
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#constructorPublic Methods
public load(params: *): Entity source
Loads an OBJ model from a file into this OBJLoader's Viewer.
Params:
Name | Type | Attribute | Description |
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 |
|
Path to an optional metadata file. |
params.position | Number[] |
|
The model World-space 3D position. |
params.scale | Number[] |
|
The model's World-space scale. |
params.rotation | Number[] |
|
The model's World-space rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. |
params.matrix | Number[] |
|
The model's world transform matrix. Overrides the position, scale and rotation parameters. |
params.edgeThreshold | Number |
|
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 |