Class: BaseContainer3D

THING.BaseContainer3D()

Object3D The base object 3D.

Constructor

new BaseContainer3D()

The base container in scene.
Source:

Extends

Members

app :THING.App

Get application.
Type:
Overrides:
Source:
Example
let object = new THING.BaseObject();
let app = object.app;
let ret = app == THING.App.current;
// @expect(ret == true)

brothers :THING.Selector

Get the brothers.
Type:
Overrides:
Source:
Example
let box1 = new THING.Box();
	let box2 = new THING.Box({parent: box1});
	let box3 = new THING.Box({parent: box1});
	let brothers = box3.brothers;
 // @expect(brothers.length == 1);

children :THING.Selector

Get children.
Type:
Overrides:
Source:
Example
let object = new THING.BaseObject();
let child= new THING.BaseObject({parent: object});
let children = object.children;
let ret = children.length == 1;
// @expect(ret == true)

(readonly) components :Map.<String, THING.BaseComponent>

Get all components.
Type:
Overrides:
Source:
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'component1');
obj.addComponent(new THING.BaseComponent(), 'component2');
// @expect(obj.components.size == 2)

id :String

Get/Set id.
Type:
  • String
Overrides:
Source:
Example
let object = new THING.BaseObject();
object.id = 'DEVICE_007';
// @expect(object.id == 'DEVICE_007')

isBaseContainer3D :Boolean

Check whether it's BaseContainer3D type or inherit from it.
Type:
  • Boolean
Source:
Example
let point = new THING.BaseContainer3D();
let ret = point.isBaseContainer3D;
// @expect(ret == true);

name :String

Get/Set name.
Type:
  • String
Overrides:
Source:
Example
let object = new THING.BaseObject();
// @expect(object.name == '');
object.name = 'car';
// @expect(object.name == 'car');

parent :THING.BaseObject

Get/Set parent.
Type:
Overrides:
Source:
Example
let parent = new THING.BaseObject();
 let child = new THING.BaseObject({parent: parent});
	let ret = child.parent == parent;
	// @expect(ret == true);

parents :THING.Selector

Get the parents.
Type:
Overrides:
Source:
Example
let box1 = new THING.Box();
	let box2 = new THING.Box({parent: box1});
	let parents = box2.parents;
 // @expect(parents.length == 2);

queryable :Boolean

Enable/Disable queryable.
Type:
  • Boolean
Overrides:
Source:
Example
let object = new THING.BaseObject();
object.name = 'Hidden';
let ret = app.query('Hidden');
// @expect(ret[0].name = 'Hidden')
object.queryable = false;
ret = app.query('Hidden');
// @expect(ret.length = 0)

relationships :Array.<THING.Relationship>

Get/Set relationships.
Type:
Overrides:
Source:
Example
let object = new THING.Object3D();
let source = new THING.Object3D();
let target = new THING.Object3D();
let relationship = new THING.Relationship({
     type: 'control',
     source: source,
     target: target
});
object.addRelationship(relationship);
let ret = object.relationships[0].type == 'control';
// @expect(ret == true)

type :String

Get type.
Type:
  • String
Overrides:
Source:
Example
let object = new THING.BaseObject();
let type = object.type;
// @expect(type == 'BaseObject')

userData :Object

Get/Set user data.
Type:
  • Object
Overrides:
Source:
Example
let object = new THING.BaseObject();
object.userData['Notebook'] = {
	name: 'FlyingCar',
	price: 100
};
let name = object.userData['Notebook'].name;
// @expect(name == 'FlyingCar')
let price = object.userData['Notebook'].price
// @expect(price == 100)

uuid :String

Get/Set uuid.
Type:
  • String
Overrides:
Source:
Example
let object = new THING.BaseObject({uuid: 10000});
// @expect(object.uuid == 10000)
object.uuid = THING.Math.generateUUID();
// @expect(object.id != 10000)

Methods

add(object, options) → {Boolean}

Add object as child.
Parameters:
Name Type Description
object THING.BaseObject The object what you want to add.
options Object The options.
Overrides:
Source:
Returns:
Type
Boolean
Example
let parent = new THING.BaseObject();
let child = new THING.BaseObject();
parent.add(child);
let ret = child.isChildOf(parent);
 // @expect(ret == true);

addComponent(component, name, args?) → {Boolean}

Add component.
Parameters:
Name Type Description
component THING.BaseComponent | Object The component class or component object.
name String The name.
args? Object The initial arguments to create component.
Overrides:
Source:
Returns:
Type
Boolean
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'myComponent');
// @expect(obj.myComponent != null)

destroy() → {Boolean}

Destroy.
Overrides:
Source:
Returns:
Type
Boolean
Example
let object = new THING.BaseObject();
// @expect(object.destroyed == false);
object.destroy();
// @expect(object.destroyed == true)

getAllComponents() → {Array.<THING.BaseComponent>}

Get all components(it would create all registered components).
Overrides:
Source:
Returns:
Type
Array.<THING.BaseComponent>
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'component1');
obj.addComponent(new THING.BaseComponent(), 'component2');
let components = obj.getAllComponents();
// @expect(components.length == 2)

getAttribute(name) → {*}

Get attribute value.
Parameters:
Name Type Description
name String The attribute name, it can use like 'a/b/c' to access attribute.
Overrides:
Source:
Returns:
Type
*
Example
let object = new THING.BaseObject();
object.userData['power'] = 100;
let power = object.getAttribute('userData/power');
// @expect(power == 100)

getComponentByName(name) → {THING.BaseComponent}

Get component by name.
Parameters:
Name Type Description
name String The name.
Overrides:
Source:
Returns:
Type
THING.BaseComponent
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'myComponent');
let component = obj.getComponentByName('myComponent');
// @expect(component != null)

getComponentByType(type) → {THING.BaseComponent}

Get component by type.
Parameters:
Name Type Description
type * The component type.
Overrides:
Source:
Returns:
Type
THING.BaseComponent
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'myComponent');
let component = obj.getComponentByType(THING.BaseComponent);
// @expect(component != null)

getComponentsByType(type) → {Array.<THING.BaseComponent>}

Get components by type.
Parameters:
Name Type Description
type * The component type.
Overrides:
Source:
Returns:
Type
Array.<THING.BaseComponent>
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'component1');
obj.addComponent(new THING.BaseComponent(), 'component2');
let components = obj.getComponentsByType(THING.BaseComponent);
// @expect(components.length == 2)

hasAttribute(name) → {Boolean}

Check whether has attribute.
Parameters:
Name Type Description
name String The attribute name, it can use like 'a/b/c' to access attribute.
Overrides:
Source:
Returns:
Type
Boolean
Example
let object = new THING.BaseObject();
object.userData['power'] = 100;
let ret = object.hasAttribute('userData/power');
// @expect(ret == true)

hasChildren() → {Boolean}

Check whether has any children.
Overrides:
Source:
Returns:
Type
Boolean
Example
let parent = new THING.BaseObject();
 let child = new THING.BaseObject({parent: parent});
	let ret = parent.hasChildren();
	// @expect(ret == true);

hasComponent(name) → {Boolean}

Check whether has component.
Parameters:
Name Type Description
name String The name.
Overrides:
Source:
Returns:
Type
Boolean
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'myComponent');
let ret = obj.hasComponent('myComponent')
// @expect(ret == true)

isBrotherOf(object) → {Boolean}

Check whether it's brother.
Parameters:
Name Type Description
object THING.BaseObject The object to check.
Overrides:
Source:
Returns:
Type
Boolean
Example
let parent = new THING.BaseObject();
let child1 = new THING.BaseObject({parent: parent});
let child2 = new THING.BaseObject({parent: parent});
let ret = child1.isBrotherOf(child2);
 // @expect(ret == true);

isChildOf(object) → {Boolean}

Check whether it's child.
Parameters:
Name Type Description
object THING.BaseObject The object to check.
Overrides:
Source:
Returns:
Type
Boolean
Example
let parent = new THING.BaseObject();
let child = new THING.BaseObject({parent: parent});
let ret = child.isChildOf(parent);
 // @expect(ret == true);

off(type, condition?, tag)

Unregister event.
Parameters:
Name Type Description
type String The event type.
condition? String The condition to select objects.
tag String The event tag.
Overrides:
Source:
Example
let object = new THING.BaseObject();
let markOff = 0;
object.on('testOff', function(ev) {
		markOff = 1;
});
object.trigger('testOff');
// @expect(markOff == 1);
markOff = 0;
object.off('testOff');
object.trigger('testOff');
// @expect(markOff == 0);

on(type, condition, callback, tag, priority, options)

Register event.
Parameters:
Name Type Description
type String The event type.
condition String The condition to select objects.
callback function The callback function.
tag String The event tag.
priority Number The priority value(default is 0, higher value will be processed first).
options ObjectEventOptions The options.
Overrides:
Source:
Example
let object = new THING.BaseObject();
let mark = 0;
object.on('click', function(ev){
	mark = 1;
}, 'MyClick');
object.trigger('click');
// @expect(mark == 1)
let mark2 = 0;
object.on('click', '.Box', function(ev){
	mark2 = 1;
}, 'MyClick');
// @expect(mark2 == 0)

once(type, condition?, callback?, tag?, priority?, options?)

Register event what just trigger once time.
Parameters:
Name Type Description
type String The event type.
condition? String The condition to select objects.
callback? function The callback function.
tag? String The event tag.
priority? Number The priority value(default is 0, higher value will be processed first).
options? ObjectEventOptions The options.
Overrides:
Source:
Example
let object = new THING.BaseObject();
let markOnce = 0;
object.once('testOnce', function(ev) {
		markOnce = 1;
});
object.trigger('testOnce');
// @expect(markOnce == 1);
markOnce = 0;
object.trigger('testOnce');
// @expect(markOnce == 0);

pauseEvent(type, condition, tag)

Pause event.
Parameters:
Name Type Description
type String The event type.
condition String The condition to select objects.
tag String The event tag.
Overrides:
Source:
Example
let object = new THING.BaseObject();
let markPause = 0;
object.on('testPause', function(ev) {
		markPause = 1;
});
object.trigger('testPause');
// @expect(markPause == 1);
markPause = 0;
object.pauseEvent('testPause');
object.trigger('testPause');
// @expect(markPause == 0);

query(condition, options?) → {THING.Selector}

Query children by condition.
Parameters:
Name Type Description
condition String The condition to select objects.
options? ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child= new THING.BaseObject({parent: object});
child.userData = {power: 1000};
let children = object.children.query('[userData/power>100]');
let ret = children.length == 1;
// @expect(ret == true)

queryById(condition, options) → {THING.Selector}

Query children by id.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.BaseObject({parent: object});
child1.id = '10000';
let child2= new THING.BaseObject({parent: object});
let result = object.queryById('10000');
let ret = result[0].id == '10000';
 //@expect(ret == true)

queryByName(condition, options) → {THING.Selector}

Query children by name.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child= new THING.BaseObject({parent: object, name: 'liming'});
let result = object.queryByName('liming');
let ret = result[0].name == 'liming';
// @expect(ret == true)

queryByRegExp(condition, options) → {THING.Selector}

Query children by reg exp.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.BaseObject({parent: object, name: 'car1'});
let child2= new THING.BaseObject({parent: object, name: 'car2'});
let result = object.queryByRegExp(/car/);
let ret = result.length == 2;
 //@expect(ret == true)

queryByTags(condition, options) → {THING.Selector}

Query children by tag.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.Object3D({parent: object, name: 'car1'});
child1.tags.add('testCar');
let child2= new THING.BaseObject({parent: object, name: 'car2'});
let result = object.queryByTags('testCar');
let ret = result.length == 1;
 //@expect(ret == true)

queryByType(condition, options) → {THING.Selector}

Query children by type.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.Box({parent: object, id: '10000'});
let child2= new THING.BaseObject({parent: object});
let result = object.queryByType('Box');
let ret = result[0].id == '10000';
 //@expect(ret == true)

queryByUUID(condition, options) → {THING.Selector}

Query children by uuid.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.BaseObject({parent: object, uuid: '1000'});
let child2= new THING.BaseObject({parent: object});
let result = object.queryByUUID('1000');
let ret = result[0].uuid == '1000';
 //@expect(ret == true)

queryByUserData(condition, options) → {THING.Selector}

Query children by userData.
Parameters:
Name Type Description
condition String The condition to select objects.
options ObjectQueryOptions The options.
Overrides:
Source:
Returns:
Type
THING.Selector
Example
let object = new THING.BaseObject();
let child1= new THING.Box({parent: object});
child1.userData['power'] = 100;
let child2= new THING.BaseObject({parent: object});
let result = object.queryByUserData('power=100');
let ret = result[0].userData.power == 100;
 //@expect(ret == true)

remove(object) → {Boolean}

Remove child object.
Parameters:
Name Type Description
object THING.BaseObject The object what you want to remove.
Overrides:
Source:
Returns:
Type
Boolean
Example
let parent = new THING.BaseObject();
let child = new THING.BaseObject();
parent.add(child);
let ret = child.isChildOf(parent);
 // @expect(ret == true);
	parent.remove(child);
ret = child.isChildOf(parent);
	// @expect(ret == false);

removeAllComponents()

Remove all components.
Overrides:
Source:
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'component1');
obj.addComponent(new THING.BaseComponent(), 'component2');
obj.removeAllComponents();
// @expect(obj.components.size == 0)

removeComponent(name)

Remove component.
Parameters:
Name Type Description
name String The name.
Overrides:
Source:
Example
let obj = new THING.BaseObject();;
obj.addComponent(new THING.BaseComponent(), 'myComponent');
obj.removeComponent('myComponent');
// @expect(obj.components.size == 0)

resumeEvent(type, condition, tag)

Resume event.
Parameters:
Name Type Description
type String The event type.
condition String The condition to select objects.
tag String The event tag.
Overrides:
Source:
Example
let object = new THING.BaseObject();
let markResume = 0;
object.on('testResume', function(ev) {
		markResume = 1;
});
object.trigger('testResume');
// @expect(markResume == 1);
markResume = 0;
object.pauseEvent('testResume');
object.trigger('testResume');
// @expect(markResume == 0);
object.resumeEvent('testResume');
object.trigger('testResume');
// @expect(markResume == 1);

setAttribute(name, value)

Set attribute value.
Parameters:
Name Type Description
name String The attribute name, it can use like 'a/b/c' to access attribute.
value * The attribute value.
Overrides:
Source:
Example
let object = new THING.BaseObject();
object.setAttribute('userData/power', 200);
let power = object.getAttribute('userData/power');
// @expect(power == 200)

setAttributes(attributes, overwriteopt)

Set attribute values.
Parameters:
Name Type Attributes Default Description
attributes Object The attribute values.
overwrite Boolean <optional>
true True indicates overwrite attribute.
Overrides:
Source:
Example
let object = new THING.BaseObject();
object.setAttributes({
  "userData/name": 'Mr.Door',
  "userData/age": 18
})
let name = object.getAttribute('userData/name');
// @expect(name == 'Mr.Door')
let age = object.getAttribute('userData/age');
// @expect(age == 18)

traverse(callback)

Traverse self and all children.
Parameters:
Name Type Description
callback function The callback function.
Overrides:
Source:
Example
let parent = new THING.BaseObject();
let child1 = new THING.BaseObject({parent: parent});
let child2 = new THING.BaseObject({parent: parent});
let mark = 0;
parent.traverse((child) => {
		mark++;
});
// @expect(mark == 3)

traverseBranch(callback)

Traverse self and all children. (Support for exit at traverse runtime)
Parameters:
Name Type Description
callback function The callback function. (Return false to exit)
Overrides:
Source:
Example
let parent = new THING.BaseObject();
let child1 = new THING.BaseObject({parent: parent});
let child2 = new THING.BaseObject({parent: parent});
let mark = 0;
parent.traverseBranch((child)=>{
	   mark++;
});
// @expect(mark == 3)
mark = 0;
parent.traverseBranch((child)=>{
	   mark++;
    if(child.children.length > 0){
		   return false;
	   }
	   return true;
});
// @expect(mark == 1)

traverseComponentByType(type, callback)

Traverse component by type.
Parameters:
Name Type Description
type * The component type.
callback TraverseComponentByTypeCallback The callback function.
Overrides:
Source:
Example
object.addComponent(new MyComponent(), 'myComponent');
	object.traverseComponentByType(MyComponent, (component, name) => {
		console.log(component, name);
	});

trigger(type, ev, options?) → {*}

Trigger event.
Parameters:
Name Type Description
type String The event type.
ev Object The event info.
options? Object The options.
Properties
Name Type Description
tag String The tag name.
Overrides:
Source:
Returns:
Type
*
Example
let object = new THING.BaseObject();
 let markTrigger = {};
	object.on('myEvent', function(ev) {
		markTrigger = ev;
	});
	object.trigger('myEvent', { result: true });
 let ret = markTrigger.result;
 // @expect(ret == true);