Class: LevelComponent

THING.LevelComponent()

LevelComponent The object level component.

Constructor

new LevelComponent()

The level actions of object, it could process object's action(s) when enter its level.
Source:

Extends

Members

active :Boolean

Active or deactive component.
Type:
  • Boolean
Overrides:
Source:

app :THING.App

Get application.
Type:
Overrides:
Source:

config :LevelConfig

Get or set the level configuration
Type:
Source:
Example
// Get the current level configuration
let levelComponent  = THING.App.current.root.level;
levelComponent.config = { ignoreVisible: true, ignoreStyle: false };
// @expect { levelComponent.config.ignoreVisible === true }
// @expect { levelComponent.config.ignoreStyle === false }

localViewpoint :Viewpoint

Gets or sets the local camera position and target position (read from the scene file).
Type:
Source:
Example
let levelComponent = THING.App.current.root.level;
// Get the local viewpoint
let localViewpoint = levelComponent.localViewpoint;
let ret1 = typeof localViewpoint === 'object';
let ret2 = localViewpoint === null;
// @expect { ret1 == true || ret2 == true }

// Set the local viewpoint
levelComponent.localViewpoint = {
  position: [0, 0, 0],
  target: [1, 1, 1]
};
// @expect {levelComponent.localViewpoint.position[0] === 0 && levelComponent.localViewpoint.target[2] === 1}

object :THING.BaseObject

Get object.
Type:
Overrides:
Source:

onActiveChange :OnActiveChangeComponentCallback

When active change callback function.
Type:
Overrides:
Source:

onAfterAdd :OnAfterAddComponentCallback

After add.
Type:
Overrides:
Source:

onAfterAddChild :OnAddChildComponentCallback

When after add child callback function.
Type:
Overrides:
Source:

onAfterRemove :OnAfterRemoveComponentCallback

After remove.
Type:
Overrides:
Source:

onAfterRemoveChild :OnRemoveChildComponentCallback

When after remove child callback function.
Type:
Overrides:
Source:

onBeforeAdd :OnBeforeAddComponentCallback

Before add.
Type:
Overrides:
Source:

onBeforeAddChild :OnAddChildComponentCallback

When before add child callback function.
Type:
Overrides:
Source:

onBeforeRemove :OnBeforeRemoveComponentCallback

Before remove.
Type:
Overrides:
Source:

onBeforeRemoveChild :OnRemoveChildComponentCallback

When before remove child callback function.
Type:
Overrides:
Source:

onCopy :OnCopyComponentCallback

When copy callback function.
Type:
Overrides:
Source:

onInit :OnInitComponentCallback

When initialize callback function.
Type:
Overrides:
Source:

onLoadResource :OnLoadResourceComponentCallback

When load resource callback function.
Type:
Overrides:
Source:

onParentChange :OnParentChangeComponentCallback

When change parent callback function.
Type:
Overrides:
Source:

onRefresh :OnRefreshComponentCallback

When refresh callback function.
Type:
Overrides:
Source:

onResize :OnResizeComponentCallback

When resize callback function.
Type:
Overrides:
Source:

onUnloadResource :OnUnloadResourceComponentCallback

When unload resource callback function.
Type:
Overrides:
Source:

onUpdate :OnUpdateComponentCallback

When update callback function.
Type:
Overrides:
Source:

onVisibleChange :OnVisibleChangeComponentCallback

When visible change callback function.
Type:
Overrides:
Source:

viewpoint :Viewpoint

Gets or sets the world camera viewpoint position and camera target position (read from the scene file).
Type:
Source:
Example
let levelComponent = THING.App.current.root.level;
// Get the world viewpoint
let viewpoint = levelComponent.viewpoint;
let ret1 = typeof viewpoint === 'object';
let ret2 = viewpoint === null;
// @expect { ret1 == true || ret2 == true }

// Set the world viewpoint
levelComponent.viewpoint = {
  position: [0, 0, 0],
  target: [1, 1, 1]
};
// @expect {levelComponent.viewpoint.position[0] === 0 && levelComponent.viewpoint.target[2] === 1}

Methods

onAdd(object)

When add component.
Parameters:
Name Type Description
object THING.BaseObject The object.
Overrides:
Source:

onExport() → {Object|null}

Export data to an external source.
Overrides:
Source:
Returns:
- The exported data.
Type
Object | null
Example
let levelComponent = THING.App.current.root.level;
levelComponent.onImport({ viewpoint: { position: [1, 2, 3], target: [4, 5, 6] }, config: { ignoreStyle:true, ignoreVisible:false } });
// Export data to an external source
let exportedData = levelComponent.onExport();
// @expect { exportedData.viewpoint.position[1] === 2 }
// @expect { exportedData.viewpoint.target[0] === 4 }
// @expect { exportedData.config.ignoreStyle === true }
let ret = exportedData.config.ignoreVisible == undefined;
// @expect { ret === true }

onImport(external)

Imports data from an external source.
Parameters:
Name Type Description
external Object The external data to import.
Overrides:
Source:
Example
let levelComponent = THING.App.current.root.level;
// Import data from an external source
// Example 1: Importing data
levelComponent.onImport({ viewpoint: { position: [1, 2, 3], target: [4, 5, 6] }, config: { ignoreStyle:true, ignoreVisible:false } });
// @expect { levelComponent.localViewpoint.position[0] === 1 }
// @expect { levelComponent.localViewpoint.target[2] === 6 }
// @expect { levelComponent.config.ignoreStyle === true }
// @expect { levelComponent.config.ignoreVisible === false }

onRemove()

When remove component.
Overrides:
Source: