@xort/cga 0.0.83 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/build/@xort_cga.js +639 -314
  2. package/deploy.sh +13 -1
  3. package/dist/IKanimation/Bone.d.ts +1 -3
  4. package/dist/IKanimation/Bone.js +4 -22
  5. package/dist/alg/extrude.js +4 -4
  6. package/dist/extends/geometryaid.js +7 -15
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +1 -2
  9. package/dist/math/Color.d.ts +1 -2
  10. package/dist/math/Color.js +14 -31
  11. package/dist/math/Euler.d.ts +4 -5
  12. package/dist/math/Euler.js +16 -34
  13. package/dist/math/HVec3.d.ts +1 -2
  14. package/dist/math/HVec3.js +13 -30
  15. package/dist/math/Quat.d.ts +1 -2
  16. package/dist/math/Quat.js +23 -43
  17. package/dist/math/Vec2.d.ts +4 -4
  18. package/dist/math/Vec2.js +7 -24
  19. package/dist/math/Vec3.d.ts +5 -9
  20. package/dist/math/Vec3.js +35 -52
  21. package/dist/math/Vec4.d.ts +4 -4
  22. package/dist/math/Vec4.js +11 -28
  23. package/dist/math/vecs.d.ts +19 -6
  24. package/dist/math/vecs.js +31 -1
  25. package/dist/render/{buffer-attribute.d.ts → bufferAttribute.d.ts} +8 -4
  26. package/dist/render/{buffer-attribute.js → bufferAttribute.js} +4 -0
  27. package/dist/render/geometry.d.ts +7 -9
  28. package/dist/render/geometry.js +22 -25
  29. package/dist/render/mesh.d.ts +23 -18
  30. package/dist/render/mesh.js +62 -57
  31. package/dist/render/types.d.ts +1 -0
  32. package/dist/struct/3d/Box.d.ts +1 -1
  33. package/dist/struct/3d/Plane.js +1 -1
  34. package/package.json +73 -73
  35. package/rollup.config.js +1 -1
  36. package/src/IKanimation/Bone.ts +1 -5
  37. package/src/alg/extrude.ts +6 -6
  38. package/src/app.ts +2 -10
  39. package/src/extends/geometryaid.ts +10 -13
  40. package/src/index.ts +2 -4
  41. package/src/math/Color.ts +6 -8
  42. package/src/math/Euler.ts +11 -12
  43. package/src/math/HVec3.ts +3 -5
  44. package/src/math/Quat.ts +18 -23
  45. package/src/math/Vec2.ts +7 -7
  46. package/src/math/Vec3.ts +37 -36
  47. package/src/math/Vec4.ts +9 -9
  48. package/src/math/vecs.ts +50 -8
  49. package/src/render/{buffer-attribute.ts → bufferAttribute.ts} +11 -4
  50. package/src/render/geometry.ts +18 -15
  51. package/src/render/mesh.ts +56 -54
  52. package/src/render/types.ts +2 -0
  53. package/src/struct/3d/Box.ts +1 -1
  54. package/src/struct/3d/Plane.ts +2 -4
  55. package/dist/math/Vec.d.ts +0 -7
  56. package/dist/math/Vec.js +0 -41
  57. package/dist/math/vector.d.ts +0 -114
  58. package/dist/math/vector.js +0 -371
  59. package/dist/render/eventhandler.d.ts +0 -78
  60. package/dist/render/eventhandler.js +0 -191
  61. package/dist/render/thing.d.ts +0 -34
  62. package/dist/render/thing.js +0 -194
  63. package/src/math/Vec.ts +0 -26
  64. package/src/render/eventhandler.ts +0 -196
  65. package/src/render/thing.ts +0 -204
@@ -1,196 +0,0 @@
1
- export class EventHandler {
2
- private _callbacks: any = {};
3
- private _callbackActive: any = {};
4
- constructor() {
5
- }
6
-
7
-
8
- _addCallback(name: string, callback: any, scope: any, once: boolean) {
9
- if (!name || typeof name !== 'string' || !callback)
10
- return;
11
-
12
- if (!this._callbacks[name])
13
- this._callbacks[name] = [];
14
-
15
- if (this._callbackActive[name] && this._callbackActive[name] === this._callbacks[name])
16
- this._callbackActive[name] = this._callbackActive[name].slice();
17
-
18
- this._callbacks[name].push({
19
- callback: callback,
20
- scope: scope || this,
21
- once: once || false
22
- });
23
- }
24
-
25
- /**
26
- * @function
27
- * @name EventHandler#on
28
- * @description Attach an event handler to an event.
29
- * @param {string} name - Name of the event to bind the callback to.
30
- * @param {callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments.
31
- * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this.
32
- * @returns {EventHandler} Self for chaining.
33
- * @example
34
- * obj.on('test', function (a, b) {
35
- * console.log(a + b);
36
- * });
37
- * obj.fire('test', 1, 2); // prints 3 to the console
38
- */
39
- on(name: string | string[], callback: any, scope?: any) {
40
- if (Array.isArray(name))
41
- name.forEach(v => this._addCallback(v, callback, scope, false));
42
- else
43
- this._addCallback(name, callback, scope, false);
44
-
45
- return this;
46
- }
47
-
48
- /**
49
- * @function
50
- * @name EventHandler#off
51
- * @description Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event,
52
- * if scope is not provided then all events with the callback will be unbound.
53
- * @param {string} [name] - Name of the event to unbind.
54
- * @param {callbacks.HandleEvent} [callback] - Function to be unbound.
55
- * @param {object} [scope] - Scope that was used as the this when the event is fired.
56
- * @returns {EventHandler} Self for chaining.
57
- * @example
58
- * var handler = function () {
59
- * };
60
- * obj.on('test', handler);
61
- *
62
- * obj.off(); // Removes all events
63
- * obj.off('test'); // Removes all events called 'test'
64
- * obj.off('test', handler); // Removes all handler functions, called 'test'
65
- * obj.off('test', handler, this); // Removes all hander functions, called 'test' with scope this
66
- */
67
- off(name: string | number, callback: any, scope: any) {
68
- if (name) {
69
- if (this._callbackActive[name] && this._callbackActive[name] === this._callbacks[name])
70
- this._callbackActive[name] = this._callbackActive[name].slice();
71
- } else {
72
- for (var key in this._callbackActive) {
73
- if (!this._callbacks[key])
74
- continue;
75
-
76
- if (this._callbacks[key] !== this._callbackActive[key])
77
- continue;
78
-
79
- this._callbackActive[key] = this._callbackActive[key].slice();
80
- }
81
- }
82
-
83
- if (!name) {
84
- this._callbacks = {};
85
- } else if (!callback) {
86
- if (this._callbacks[name])
87
- this._callbacks[name] = [];
88
- } else {
89
- var events = this._callbacks[name];
90
- if (!events)
91
- return this;
92
-
93
- var count = events.length;
94
-
95
- for (var i = 0; i < count; i++) {
96
- if (events[i].callback !== callback)
97
- continue;
98
-
99
- if (scope && events[i].scope !== scope)
100
- continue;
101
-
102
- events[i--] = events[--count];
103
- }
104
- events.length = count;
105
- }
106
-
107
- return this;
108
- }
109
-
110
- // ESLint rule disabled here as documenting arg1, arg2...argN as [...] rest
111
- // arguments is preferable to documenting each one individually.
112
- /* eslint-disable valid-jsdoc */
113
- /**
114
- * @function
115
- * @name EventHandler#fire
116
- * @description Fire an event, all additional arguments are passed on to the event listener.
117
- * @param {object} name - Name of event to fire.
118
- * @param {*} [args] - arguments that is passed to the event handler.
119
- * obj.fire('test', 'This is the message');
120
- */
121
- /* eslint-enable valid-jsdoc */
122
- fire(name: string | number, ...args: any[]) {
123
- if (!name || !this._callbacks[name])
124
- return this;
125
-
126
- var callbacks;
127
-
128
- if (!this._callbackActive[name]) {
129
- this._callbackActive[name] = this._callbacks[name];
130
- } else {
131
- if (this._callbackActive[name] === this._callbacks[name])
132
- this._callbackActive[name] = this._callbackActive[name].slice();
133
-
134
- callbacks = this._callbacks[name].slice();
135
- }
136
-
137
- // TODO: What does callbacks do here?
138
- // In particular this condition check looks wrong: (i < (callbacks || this._callbackActive[name]).length)
139
- // Because callbacks is not an integer
140
- // eslint-disable-next-line no-unmodified-loop-condition
141
- for (var i = 0; (callbacks || this._callbackActive[name]) && (i < (callbacks || this._callbackActive[name]).length); i++) {
142
- var evt = (callbacks || this._callbackActive[name])[i];
143
- evt.callback.call(evt.scope, ...args);
144
-
145
- if (evt.once) {
146
- var ind = this._callbacks[name].indexOf(evt);
147
- if (ind !== -1) {
148
- if (this._callbackActive[name] === this._callbacks[name])
149
- this._callbackActive[name] = this._callbackActive[name].slice();
150
-
151
- this._callbacks[name].splice(ind, 1);
152
- }
153
- }
154
- }
155
-
156
- if (!callbacks)
157
- this._callbackActive[name] = null;
158
-
159
- return this;
160
- }
161
-
162
- /**
163
- * @function
164
- * @name EventHandler#once
165
- * @description Attach an event handler to an event. This handler will be removed after being fired once.
166
- * @param {string} name - Name of the event to bind the callback to.
167
- * @param {callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments.
168
- * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this.
169
- * @returns {EventHandler} Self for chaining.
170
- * @example
171
- * obj.once('test', function (a, b) {
172
- * console.log(a + b);
173
- * });
174
- * obj.fire('test', 1, 2); // prints 3 to the console
175
- * obj.fire('test', 1, 2); // not going to get handled
176
- */
177
- once(name: string, callback: any, scope: any) {
178
- this._addCallback(name, callback, scope, true);
179
- return this;
180
- }
181
-
182
- /**
183
- * @function
184
- * @name EventHandler#hasEvent
185
- * @description Test if there are any handlers bound to an event name.
186
- * @param {string} name - The name of the event to test.
187
- * @returns {boolean} True if the object has handlers bound to the specified event name.
188
- * @example
189
- * obj.on('test', function () { }); // bind an event to 'test'
190
- * obj.hasEvent('test'); // returns true
191
- * obj.hasEvent('hello'); // returns false
192
- */
193
- hasEvent(name: string | number) {
194
- return (this._callbacks[name] && this._callbacks[name].length !== 0) || false;
195
- }
196
- }
@@ -1,204 +0,0 @@
1
- import { EventHandler } from './eventhandler';
2
- import { v4 as uuidv4 } from 'uuid';
3
-
4
- export class Thing extends EventHandler {
5
- protected cache: any = {};
6
- uuid: any;
7
- id: any;
8
- name: any;
9
- alias: any;
10
- isThing: boolean;
11
- parent: any;
12
- children: any[];
13
- meta: any;
14
- needsUpdate: boolean;
15
- _renderObject: any;
16
- _useData: any = {};
17
- tag: string;
18
- constructor(opts?: any) {
19
- super();
20
- opts = opts || {};
21
- this.uuid = uuidv4();
22
- this.id = this.uuid;
23
- this.name = opts.name || "未命名";
24
- this.alias = opts.alias;
25
- this.isThing = true
26
- this.parent = null;
27
- this.children = [];
28
- this.meta = undefined;
29
- this.needsUpdate = false;
30
- this._renderObject = null;
31
- this._useData = {};
32
- this.tag = "untagged";
33
-
34
- this.on("set", (name: string, oldValue: any, newValue: any) => {
35
- this.fire("set_" + name, name, oldValue, newValue);
36
- });
37
-
38
- for (const key in opts) {
39
- if (opts.hasOwnProperty(key)) {
40
- if (!(this as any)[key]) {
41
- (this as any)[key] = opts[key]
42
- }
43
- }
44
- }
45
- }
46
-
47
- add(thing: any, force: boolean = false) {
48
- if (arguments.length > 1) {
49
- for (var i = 0; i < arguments.length; i++) {
50
- this.add(arguments[i]);
51
- }
52
- return this;
53
- }
54
- if (thing === this) {
55
- console.error("Thing.add: 自己不能作为自己的子节点", thing);
56
- return this;
57
- }
58
- if (thing && this.isThing) {
59
-
60
- if (thing.parent) {
61
- thing.parent.remove(thing);
62
- }
63
-
64
- thing.parent = this;
65
- this.children.push(thing);
66
-
67
- } else if (thing && force) {
68
-
69
- if (thing.parent) {
70
- thing.parent.remove(thing);
71
- }
72
- thing.parent = this;
73
- this.children.push(thing);
74
-
75
- } else {
76
- console.error("Thing.add:不是Thing类型", thing);
77
- }
78
- return this;
79
- }
80
-
81
- remove(thing: any) {
82
- if (arguments.length > 1) {
83
- for (var i = 0; i < arguments.length; i++) {
84
- this.remove(arguments[i]);
85
- }
86
- return this;
87
- }
88
-
89
- var index = this.children.indexOf(thing);
90
-
91
- if (index !== -1) {
92
- thing.parent = null;
93
- // thing.dispatchEvent( { type: 'removed' } );
94
- this.children.splice(index, 1);
95
- }
96
-
97
- return this;
98
- }
99
-
100
-
101
- foreach(cb: (arg0: this) => void) {
102
- cb(this);
103
- var children = this.children;
104
- for (let i = 0; i < children.length; i++) {
105
- children[i].foreach(cb);
106
- }
107
- }
108
-
109
- getObjectByProperty(name: string, value: any) {
110
-
111
- if ((this as any)[name] === value) return this;
112
-
113
- for (var i = 0, l = this.children.length; i < l; i++) {
114
-
115
- var child = this.children[i];
116
- if (!child.getObjectByProperty)
117
- continue
118
- var object = child.getObjectByProperty(name, value);
119
-
120
- if (object !== undefined) {
121
- return object;
122
- }
123
- }
124
-
125
- return undefined;
126
-
127
- }
128
-
129
- getObjectById(id: any) {
130
- return this.getObjectByProperty('id', id);
131
- }
132
-
133
- getObjectByName(name: any) {
134
- return this.getObjectByProperty('name', name);
135
- }
136
-
137
- /**
138
- * 生成属性的set/get方法
139
- * @param {string} name
140
- * @param {function} setFunc
141
- * @param {boolean} skipEqualsCheck
142
- */
143
- defineProperty(name: string | number | symbol, setFunc: any, skipEqualsCheck = true) {
144
- Object.defineProperty(this, name, {
145
- get: () => {
146
- return this._useData[name];
147
- },
148
- set: (value) => {
149
- var data = this._useData;
150
- var oldValue = data[name];
151
- if (!skipEqualsCheck && oldValue === value) return;
152
- data[name] = value;
153
- if (setFunc) setFunc.call(this, value, oldValue);
154
- },
155
- configurable: true
156
- })
157
- }
158
-
159
- buildAccessor(name: any, bindObject: any = this) {
160
- if (!bindObject)
161
- return
162
- Object.defineProperty(bindObject, name, {
163
- get: function () {
164
- return bindObject[`_${name}`];
165
- },
166
- set: function (value) {
167
- var oldValue = bindObject[`_${name}`];
168
- bindObject[`_${name}`] = value;
169
- bindObject.fire('set', name, oldValue, value);
170
- },
171
- configurable: true
172
- });
173
- }
174
-
175
- buildAccessors(schema: any[], bindObject?: this) {
176
- schema.forEach((descriptor: any) => {
177
- this.buildAccessor(descriptor, bindObject)
178
- });
179
- }
180
-
181
- }
182
-
183
-
184
- export function buildAccessor(name: any, bindObject: any) {
185
- if (!bindObject)
186
- return
187
- Object.defineProperty(bindObject, name, {
188
- get: function () {
189
- return bindObject[`_${name}`];
190
- },
191
- set: function (value) {
192
- var oldValue = bindObject[`_${name}`];
193
- bindObject[`_${name}`] = value;
194
- bindObject.fire('set', name, oldValue, value);
195
- },
196
- configurable: true
197
- });
198
- }
199
-
200
- export function buildAccessors(schema: any[], bindObject: any) {
201
- schema.forEach((descriptor: any) => {
202
- buildAccessor(descriptor, bindObject)
203
- });
204
- }