Reference Source
public class | source

XML3DLoaderPlugin

Extends:

Plugin → XML3DLoaderPlugin

Viewer plugin that loads models from 3DXML 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.

Note that the name of this plugin is intentionally munged to "XML3D" because a JavaScript class name cannot begin with a numeral.

An 3DXML model is a zip archive that bundles multiple XML files and assets. Internally, the XML3DLoaderPlugin uses the zip.js library to unzip them before loading. The zip.js library uses Web workers for fast unzipping, so XML3DLoaderPlugin requires that we configure it with a workerScriptsPath property specifying the directory where zip.js keeps its Web worker script. See the example for how to do that.

Usage

In the example below, we'll use an XML3DLoaderPlugin to load a 3DXML model. When the model has loaded, we'll use the CameraFlightAnimation to fly the Camera to look at boundary of the model. We'll then get the model's Entity from the Scene and highlight the whole model.

// Create a xeokit Viewer
const viewer = new Viewer({
     canvasId: "myCanvas"
});

// Add an XML3DLoaderPlugin to the Viewer
var plugin = new XML3DLoaderPlugin(viewer, {
     id: "XML3DLoader",  // Default value
     workerScriptsPath : "../../src/plugins/XML3DLoader/zipjs/" // Path to zip.js workers dir
});

// We can also get the plugin by its ID on the Viewer
plugin = viewer.plugins.XML3DLoader;

// Load the 3DXML model
var model = plugin.load({ // Model is an Entity
    id: "myModel",
    src: "./models/xml3d/3dpreview.3dxml",
    scale: [0.1, 0.1, 0.1],
    rotate: [90, 0, 0],
    translate: [100,0,0],
    edges: true
});

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

// Update properties of the model via the entity
model.highlighted = true;

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

// Destroy the model
model.destroy();

Constructor Summary

Public Constructor
public

constructor(viewer: Viewer, cfg: Object)

Member Summary

Public Members
public

Supported 3DXML schema versions

Method Summary

Public Methods
public

load(params: *): Entity

Loads a 3DXML model from a file into this XML3DLoaderPlugin's Viewer.

Creates a tree of Entitys within the Viewer's Scene that represents the model.

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)

Fires an event at this Plugin.

public

log(msg: String)

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

public

on(event: String, callback: Function)

Subscribes to an event fired at this Plugin.

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: "XML3DLoader"

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

cfg.workerScriptsPath String

Path to the directory that contains the bundled zip.js archive, which is a dependency of this plugin. This directory contains the script that is used by zip.js to instantiate Web workers, which assist with unzipping the 3DXML, which is a ZIP archive.

Public Members

public supportedSchemas: string[] source

Supported 3DXML schema versions

Properties:

NameTypeAttributeDescription
supportedSchemas *

Public Methods

public load(params: *): Entity source

Loads a 3DXML model from a file into this XML3DLoaderPlugin's Viewer.

Creates a tree of Entitys within the Viewer's Scene that represents the model.

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
  • optional

Path to a 3DXML file.

params.edges Boolean
  • optional
  • default: false

Whether or not xeokit renders the Entity with edges emphasized.

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

The model's 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.backfaces Boolean
  • optional
  • default: false

When true, allows visible backfaces, wherever specified in the 3DXML. When false, ignores backfaces.

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