-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadable.js
More file actions
93 lines (72 loc) · 2.91 KB
/
Loadable.js
File metadata and controls
93 lines (72 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function ObjectIsNotInActiveSceneError(msg) {
this.name = "ObjectIsNotInActiveSceneError";
this.message = msg;
}
function ObjectIsNotInSceneError(msg) {}
const Loadable = function Loadable(type) {
const gm = new GlMath();
let _scene = null;
const loadableType = type;
Object.defineProperty(this, "loadableType", {
get: () => loadableType,
enumerable: false,
configurable: false,
});
this.addToScene = function(scene) {
if(_scene != null)
this.removeFromScene();
_scene = scene;
_scene.add(this);
}
this.removeFromScene = function() {
if(!_scene)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not remove this object from scene!");
let node = _scene.find(this);
if(!node)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not remove this object from scene!");
_scene.remove(node);
}
this.addChild = function(child) {
const objNode = _scene.find(this);
if(objNode == null)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not append child this object!");
_scene.add(child, objNode);
child._scene = _scene;
}
this.translate = function() {
const translation = new Translation(gm.translateMatrix(...arguments));
const objNode = _scene.find(this);
if(objNode == null)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not add transform(translate) to this object!");
_scene.addAsParent(translation, objNode);
if(type === "CAMERA")
this.isUpdated = true;
}
this.rotate = function() {
const rotation = new Rotation(gm.rotateMatrix(...arguments));
const objNode = _scene.find(this);
if(objNode == null)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not add transform(rotate) to this object!");
_scene.addAsParent(rotation, objNode);
if(type === "CAMERA")
this.isUpdated = true;
}
this.scale = function() {
const scaling = new Scaling(gm.scaleMatrix(...arguments));
const objNode = _scene.find(this);
if(objNode == null)
throw new ObjectIsNotInActiveSceneError("This object is not in binded scene! You can not add transform(rotate) to this object!");
_scene.addAsParent(scaling, objNode);
if(type === "CAMERA")
this.isUpdated = true;
}
this.addController = function(Controller, settings = {}) {
Controller(this, settings);
}
Object.defineProperty(this, "_scene", {
get: () => _scene,
set: (sc) => _scene = sc,
enumerable:false,
configurable:false,
});
}