cocos2d-cli 1.6.5 → 2.0.0

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 (61) hide show
  1. package/dist/bin/cocos2d-cli.js +64 -0
  2. package/dist/src/commands/add-component.js +3 -0
  3. package/dist/src/commands/add.js +3 -0
  4. package/dist/src/commands/build.js +6 -0
  5. package/dist/src/commands/create-scene.js +3 -0
  6. package/dist/src/commands/get.js +3 -0
  7. package/dist/src/commands/prefab-create.js +109 -0
  8. package/dist/src/commands/remove-component.js +3 -0
  9. package/dist/src/commands/remove.js +3 -0
  10. package/dist/src/commands/screenshot.js +41 -0
  11. package/dist/src/commands/set-component.js +3 -0
  12. package/dist/src/commands/set.js +3 -0
  13. package/dist/src/commands/tree.js +24 -0
  14. package/{src → dist/src}/lib/cc/CCButton.js +115 -122
  15. package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
  16. package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
  17. package/{src → dist/src}/lib/cc/CCColor.js +30 -32
  18. package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
  19. package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
  20. package/{src → dist/src}/lib/cc/CCNode.js +190 -256
  21. package/{src → dist/src}/lib/cc/CCObject.js +19 -23
  22. package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
  23. package/{src → dist/src}/lib/cc/CCRect.js +30 -32
  24. package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
  25. package/{src → dist/src}/lib/cc/CCScene.js +32 -42
  26. package/dist/src/lib/cc/CCSceneAsset.js +242 -0
  27. package/{src → dist/src}/lib/cc/CCSize.js +22 -26
  28. package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
  29. package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
  30. package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
  31. package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
  32. package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
  33. package/dist/src/lib/fire-utils.js +86 -0
  34. package/dist/src/lib/json-parser.js +114 -0
  35. package/dist/src/lib/node-utils.js +131 -0
  36. package/{src → dist/src}/lib/screenshot-core.js +221 -285
  37. package/dist/src/lib/templates.js +17 -0
  38. package/dist/src/lib/utils.js +81 -0
  39. package/package.json +13 -6
  40. package/bin/cocos2d-cli.js +0 -152
  41. package/src/commands/add-component.js +0 -112
  42. package/src/commands/add.js +0 -177
  43. package/src/commands/build.js +0 -78
  44. package/src/commands/create-scene.js +0 -181
  45. package/src/commands/get.js +0 -108
  46. package/src/commands/prefab-create.js +0 -111
  47. package/src/commands/remove-component.js +0 -111
  48. package/src/commands/remove.js +0 -99
  49. package/src/commands/screenshot.js +0 -108
  50. package/src/commands/set-component.js +0 -119
  51. package/src/commands/set.js +0 -107
  52. package/src/commands/tree.js +0 -29
  53. package/src/lib/cc/CCSceneAsset.js +0 -303
  54. package/src/lib/cc/index.js +0 -42
  55. package/src/lib/fire-utils.js +0 -374
  56. package/src/lib/json-parser.js +0 -185
  57. package/src/lib/node-utils.js +0 -395
  58. package/src/lib/screenshot/favicon.ico +0 -0
  59. package/src/lib/screenshot/index.html +0 -30
  60. package/src/lib/templates.js +0 -49
  61. package/src/lib/utils.js +0 -202
@@ -1,42 +1,32 @@
1
- const CCNode = require('./CCNode');
2
-
3
- /**
4
- * Cocos Creator 场景类
5
- * 继承自 CCNode
6
- */
7
- class CCScene extends CCNode {
8
- constructor(name = 'NewScene') {
9
- super(name);
10
- this.__type__ = 'cc.Scene';
11
-
12
- // 场景特有属性
13
- this._is3DNode = true;
14
- this._anchorPoint.set(0, 0);
15
- this.autoReleaseAssets = false;
16
- }
17
-
18
- toJSON() {
19
- // 显式控制属性顺序,Scene 特有顺序
20
- return {
21
- __type__: this.__type__,
22
- _objFlags: this._objFlags,
23
- _parent: this._parent,
24
- _children: this._children,
25
- _active: this._active,
26
- _components: this._components,
27
- _prefab: this._prefab,
28
- _opacity: this._opacity,
29
- _color: this._color.toJSON(),
30
- _contentSize: this._contentSize.toJSON(),
31
- _anchorPoint: this._anchorPoint.toJSON(),
32
- _trs: this._trs.toJSON(),
33
- _is3DNode: this._is3DNode,
34
- _groupIndex: this._groupIndex,
35
- groupIndex: this.groupIndex,
36
- autoReleaseAssets: this.autoReleaseAssets,
37
- _id: this._id
38
- };
39
- }
40
- }
41
-
42
- module.exports = CCScene;
1
+ import CCNode from './CCNode.js';
2
+ export default class CCScene extends CCNode {
3
+ autoReleaseAssets;
4
+ constructor(name = 'NewScene') {
5
+ super(name);
6
+ this.__type__ = 'cc.Scene';
7
+ this._is3DNode = true;
8
+ this._anchorPoint.set(0, 0);
9
+ this.autoReleaseAssets = false;
10
+ }
11
+ toJSON() {
12
+ return {
13
+ __type__: this.__type__,
14
+ _objFlags: this._objFlags,
15
+ _parent: this._parent,
16
+ _children: this._children,
17
+ _active: this._active,
18
+ _components: this._components,
19
+ _prefab: this._prefab,
20
+ _opacity: this._opacity,
21
+ _color: this._color.toJSON(),
22
+ _contentSize: this._contentSize.toJSON(),
23
+ _anchorPoint: this._anchorPoint.toJSON(),
24
+ _trs: this._trs.toJSON(),
25
+ _is3DNode: this._is3DNode,
26
+ _groupIndex: this._groupIndex,
27
+ groupIndex: this.groupIndex,
28
+ autoReleaseAssets: this.autoReleaseAssets,
29
+ _id: this._id
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,242 @@
1
+ import CCObject from './CCObject.js';
2
+ import CCScene from './CCScene.js';
3
+ import CCNode from './CCNode.js';
4
+ import CCCanvas from './CCCanvas.js';
5
+ import CCWidget from './CCWidget.js';
6
+ import CCSprite from './CCSprite.js';
7
+ import CCLabel from './CCLabel.js';
8
+ import CCButton from './CCButton.js';
9
+ import CCCamera from './CCCamera.js';
10
+ import { generateCompressedUUID } from '../utils.js';
11
+ export default class CCSceneAsset extends CCObject {
12
+ _native;
13
+ _scene;
14
+ constructor() {
15
+ super('');
16
+ this.__type__ = 'cc.SceneAsset';
17
+ this._native = '';
18
+ this._scene = null;
19
+ }
20
+ getScene() {
21
+ return this._scene;
22
+ }
23
+ addNode(node) {
24
+ if (!this._scene)
25
+ return null;
26
+ node._parent = { __id__: 1 };
27
+ if (!this._scene._children)
28
+ this._scene._children = [];
29
+ this._scene._children.push({ __id__: 0 });
30
+ node._id = generateCompressedUUID();
31
+ return node;
32
+ }
33
+ removeNode(node) {
34
+ if (!node._parent)
35
+ return false;
36
+ const idx = -1;
37
+ if (idx > -1) {
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ static fromJSON(json) {
43
+ const asset = new CCSceneAsset();
44
+ const objects = [];
45
+ json.forEach((item, index) => {
46
+ objects[index] = createObject(item);
47
+ });
48
+ json.forEach((item, index) => {
49
+ setupReferences(objects[index], item, objects);
50
+ });
51
+ asset._scene = objects[1];
52
+ return asset;
53
+ }
54
+ toJSON() {
55
+ const result = [];
56
+ const indexMap = new Map();
57
+ indexMap.set(this, 0);
58
+ result.push({
59
+ __type__: 'cc.SceneAsset',
60
+ _name: '',
61
+ _objFlags: 0,
62
+ _native: '',
63
+ scene: { __id__: 1 }
64
+ });
65
+ if (this._scene) {
66
+ indexMap.set(this._scene, 1);
67
+ }
68
+ result.push(null);
69
+ const processNode = (node) => {
70
+ if (!node)
71
+ return;
72
+ indexMap.set(node, result.length);
73
+ result.push(null);
74
+ if (node._children) {
75
+ node._children.forEach(child => processNode(child));
76
+ }
77
+ if (node._components) {
78
+ node._components.forEach(comp => {
79
+ indexMap.set(comp, result.length);
80
+ result.push(componentToJSON(comp, indexMap));
81
+ });
82
+ }
83
+ result[indexMap.get(node)] = {
84
+ __type__: 'cc.Node',
85
+ _name: node._name,
86
+ _objFlags: node._objFlags,
87
+ _parent: node._parent ? { __id__: indexMap.get(node._parent) } : null,
88
+ _children: node._children?.map(c => ({ __id__: indexMap.get(c) })) || [],
89
+ _active: node._active,
90
+ _components: node._components?.map(c => ({ __id__: indexMap.get(c) })) || [],
91
+ _prefab: null,
92
+ _opacity: node._opacity,
93
+ _color: node._color.toJSON(),
94
+ _contentSize: node._contentSize.toJSON(),
95
+ _anchorPoint: node._anchorPoint.toJSON(),
96
+ _trs: node._trs.toJSON(),
97
+ _eulerAngles: node._eulerAngles.toJSON(),
98
+ _skewX: node._skewX,
99
+ _skewY: node._skewY,
100
+ _is3DNode: node._is3DNode,
101
+ _groupIndex: node._groupIndex,
102
+ groupIndex: node.groupIndex,
103
+ _id: node._id || ''
104
+ };
105
+ };
106
+ if (this._scene?._children) {
107
+ this._scene._children.forEach(child => processNode(child));
108
+ }
109
+ if (this._scene) {
110
+ result[1] = {
111
+ __type__: 'cc.Scene',
112
+ _objFlags: this._scene._objFlags,
113
+ _parent: null,
114
+ _children: this._scene._children?.map(c => ({ __id__: indexMap.get(c) })) || [],
115
+ _active: this._scene._active,
116
+ _components: [],
117
+ _prefab: null,
118
+ _opacity: this._scene._opacity,
119
+ _color: this._scene._color.toJSON(),
120
+ _contentSize: this._scene._contentSize.toJSON(),
121
+ _anchorPoint: this._scene._anchorPoint.toJSON(),
122
+ _trs: this._scene._trs.toJSON(),
123
+ _is3DNode: this._scene._is3DNode,
124
+ _groupIndex: this._scene._groupIndex,
125
+ groupIndex: this._scene.groupIndex,
126
+ autoReleaseAssets: this._scene.autoReleaseAssets || false,
127
+ _id: this._scene._id || ''
128
+ };
129
+ }
130
+ return result;
131
+ }
132
+ }
133
+ function componentToJSON(comp, indexMap) {
134
+ const json = {
135
+ __type__: comp.__type__,
136
+ _name: comp._name || '',
137
+ _objFlags: comp._objFlags || 0,
138
+ node: { __id__: indexMap.get(comp.node) },
139
+ _enabled: comp._enabled !== false
140
+ };
141
+ for (const key of Object.keys(comp)) {
142
+ if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key))
143
+ continue;
144
+ const val = comp[key];
145
+ if (val === undefined)
146
+ continue;
147
+ json[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
148
+ }
149
+ json._id = comp._id || '';
150
+ return json;
151
+ }
152
+ function createObject(item) {
153
+ const type = item.__type__;
154
+ if (type === 'cc.SceneAsset')
155
+ return null;
156
+ if (type === 'cc.Scene') {
157
+ const scene = new CCScene();
158
+ scene._id = item._id || '';
159
+ if (item._active !== undefined)
160
+ scene._active = item._active;
161
+ if (item.autoReleaseAssets !== undefined)
162
+ scene.autoReleaseAssets = item.autoReleaseAssets;
163
+ return scene;
164
+ }
165
+ if (type === 'cc.Node') {
166
+ const node = new CCNode(item._name || 'Node');
167
+ node._id = item._id || '';
168
+ copyNodeProps(node, item);
169
+ return node;
170
+ }
171
+ const comp = createComponentInstance(type);
172
+ if (comp) {
173
+ copyComponentProps(comp, item);
174
+ return comp;
175
+ }
176
+ const obj = { __type__: type };
177
+ for (const key of Object.keys(item)) {
178
+ obj[key] = item[key];
179
+ }
180
+ return obj;
181
+ }
182
+ function createComponentInstance(type) {
183
+ switch (type) {
184
+ case 'cc.Canvas': return new CCCanvas();
185
+ case 'cc.Widget': return new CCWidget();
186
+ case 'cc.Sprite': return new CCSprite();
187
+ case 'cc.Label': return new CCLabel();
188
+ case 'cc.Button': return new CCButton();
189
+ case 'cc.Camera': return new CCCamera();
190
+ default: return null;
191
+ }
192
+ }
193
+ function copyComponentProps(comp, item) {
194
+ for (const key of Object.keys(item)) {
195
+ if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key))
196
+ continue;
197
+ comp[key] = item[key];
198
+ }
199
+ if (item._id)
200
+ comp._id = item._id;
201
+ }
202
+ function copyNodeProps(node, item) {
203
+ if (item._active !== undefined)
204
+ node._active = item._active;
205
+ if (item._opacity !== undefined)
206
+ node._opacity = item._opacity;
207
+ if (item._is3DNode !== undefined)
208
+ node._is3DNode = item._is3DNode;
209
+ if (item._groupIndex !== undefined)
210
+ node._groupIndex = item._groupIndex;
211
+ if (item.groupIndex !== undefined)
212
+ node.groupIndex = item.groupIndex;
213
+ if (item._skewX !== undefined)
214
+ node._skewX = item._skewX;
215
+ if (item._skewY !== undefined)
216
+ node._skewY = item._skewY;
217
+ if (item._color)
218
+ node._color.set(item._color.r, item._color.g, item._color.b, item._color.a);
219
+ if (item._contentSize)
220
+ node._contentSize.set(item._contentSize.width, item._contentSize.height);
221
+ if (item._anchorPoint)
222
+ node._anchorPoint.set(item._anchorPoint.x, item._anchorPoint.y);
223
+ if (item._trs?.array)
224
+ item._trs.array.forEach((v, i) => node._trs.array[i] = v);
225
+ if (item._eulerAngles)
226
+ node._eulerAngles.set(item._eulerAngles.x, item._eulerAngles.y, item._eulerAngles.z);
227
+ }
228
+ function setupReferences(obj, item, objects) {
229
+ if (!obj)
230
+ return;
231
+ if (obj.__type__ === 'cc.Scene' || obj.__type__ === 'cc.Node') {
232
+ if (item._parent)
233
+ obj._parent = objects[item._parent.__id__];
234
+ if (item._children)
235
+ obj._children = item._children.map((c) => objects[c.__id__]).filter(Boolean);
236
+ if (item._components) {
237
+ obj._components = item._components.map((c) => objects[c.__id__]).filter(Boolean);
238
+ obj._components.forEach((c) => { if (c)
239
+ c.node = obj; });
240
+ }
241
+ }
242
+ }
@@ -1,26 +1,22 @@
1
- /**
2
- * Cocos Creator 尺寸类
3
- */
4
- class CCSize {
5
- constructor(width = 0, height = 0) {
6
- this.__type__ = 'cc.Size';
7
- this.width = width;
8
- this.height = height;
9
- }
10
-
11
- set(width, height) {
12
- this.width = width;
13
- this.height = height;
14
- return this;
15
- }
16
-
17
- toJSON() {
18
- return {
19
- __type__: this.__type__,
20
- width: this.width,
21
- height: this.height
22
- };
23
- }
24
- }
25
-
26
- module.exports = CCSize;
1
+ export default class CCSize {
2
+ __type__;
3
+ width;
4
+ height;
5
+ constructor(width = 0, height = 0) {
6
+ this.__type__ = 'cc.Size';
7
+ this.width = width;
8
+ this.height = height;
9
+ }
10
+ set(width, height) {
11
+ this.width = width;
12
+ this.height = height;
13
+ return this;
14
+ }
15
+ toJSON() {
16
+ return {
17
+ __type__: this.__type__,
18
+ width: this.width,
19
+ height: this.height
20
+ };
21
+ }
22
+ }
@@ -1,94 +1,82 @@
1
- const CCComponent = require('./CCComponent');
2
- const CCVec2 = require('./CCVec2');
3
-
4
- const default_sprite_splash = 'a23235d1-15db-4b95-8439-a2e005bfff91';
5
-
6
- /**
7
- * Cocos Creator Sprite 组件
8
- */
9
- class CCSprite extends CCComponent {
10
- constructor() {
11
- super();
12
- this.__type__ = 'cc.Sprite';
13
-
14
- this._materials = [{ __uuid__: 'eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432' }];
15
- this._srcBlendFactor = 770;
16
- this._dstBlendFactor = 771;
17
- this._spriteFrame = null;
18
- this._type = 0;
19
- this._sizeMode = 0;
20
- this._fillType = 0;
21
- this._fillCenter = new CCVec2();
22
- this._fillStart = 0;
23
- this._fillRange = 0;
24
- this._isTrimmedMode = true;
25
- this._atlas = null;
26
-
27
- this.setSpriteFrame(default_sprite_splash);
28
- }
29
-
30
- /**
31
- * 设置精灵帧
32
- */
33
- setSpriteFrame(uuid) {
34
- this._spriteFrame = { __uuid__: uuid };
35
- return this;
36
- }
37
-
38
- /**
39
- * 设置尺寸模式
40
- * 0: CUSTOM, 1: TRIMMED, 2: RAW
41
- */
42
- setSizeMode(mode) {
43
- this._sizeMode = mode;
44
- return this;
45
- }
46
-
47
- /**
48
- * 获取属性
49
- */
50
- getProp() {
51
- const SIZE_MODE = ['CUSTOM', 'RAW', 'TRIMMED'];
52
- const SPRITE_TYPE = ['SIMPLE', 'SLICED', 'TILED', 'FILLED', 'MESH'];
53
- return {
54
- sizeMode: SIZE_MODE[this._sizeMode] || this._sizeMode,
55
- type: SPRITE_TYPE[this._type] || this._type,
56
- trim: this._isTrimmedMode
57
- };
58
- }
59
-
60
- /**
61
- * 设置属性
62
- */
63
- setProp(props) {
64
- if (props.sizeMode !== undefined) this.setSizeMode(props.sizeMode);
65
- if (props.spriteFrame !== undefined) this.setSpriteFrame(props.spriteFrame);
66
- if (props.type !== undefined) this._type = props.type;
67
- return this;
68
- }
69
-
70
- toJSON() {
71
- return {
72
- __type__: this.__type__,
73
- _name: this._name,
74
- _objFlags: this._objFlags,
75
- node: this.node,
76
- _enabled: this._enabled,
77
- _materials: this._materials,
78
- _srcBlendFactor: this._srcBlendFactor,
79
- _dstBlendFactor: this._dstBlendFactor,
80
- _spriteFrame: this._spriteFrame,
81
- _type: this._type,
82
- _sizeMode: this._sizeMode,
83
- _fillType: this._fillType,
84
- _fillCenter: this._fillCenter.toJSON(),
85
- _fillStart: this._fillStart,
86
- _fillRange: this._fillRange,
87
- _isTrimmedMode: this._isTrimmedMode,
88
- _atlas: this._atlas,
89
- _id: this._id
90
- };
91
- }
92
- }
93
-
94
- module.exports = CCSprite;
1
+ import CCComponent from './CCComponent.js';
2
+ import CCVec2 from './CCVec2.js';
3
+ const default_sprite_splash = 'a23235d1-15db-4b95-8439-a2e005bfff91';
4
+ export default class CCSprite extends CCComponent {
5
+ _materials;
6
+ _srcBlendFactor;
7
+ _dstBlendFactor;
8
+ _spriteFrame;
9
+ _type;
10
+ _sizeMode;
11
+ _fillType;
12
+ _fillCenter;
13
+ _fillStart;
14
+ _fillRange;
15
+ _isTrimmedMode;
16
+ _atlas;
17
+ constructor() {
18
+ super();
19
+ this.__type__ = 'cc.Sprite';
20
+ this._materials = [{ __uuid__: 'eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432' }];
21
+ this._srcBlendFactor = 770;
22
+ this._dstBlendFactor = 771;
23
+ this._spriteFrame = null;
24
+ this._type = 0;
25
+ this._sizeMode = 0;
26
+ this._fillType = 0;
27
+ this._fillCenter = new CCVec2();
28
+ this._fillStart = 0;
29
+ this._fillRange = 0;
30
+ this._isTrimmedMode = true;
31
+ this._atlas = null;
32
+ this.setSpriteFrame(default_sprite_splash);
33
+ }
34
+ setSpriteFrame(uuid) {
35
+ this._spriteFrame = { __uuid__: uuid };
36
+ return this;
37
+ }
38
+ setSizeMode(mode) {
39
+ this._sizeMode = mode;
40
+ return this;
41
+ }
42
+ getProp() {
43
+ const SIZE_MODE = ['CUSTOM', 'RAW', 'TRIMMED'];
44
+ const SPRITE_TYPE = ['SIMPLE', 'SLICED', 'TILED', 'FILLED', 'MESH'];
45
+ return {
46
+ sizeMode: SIZE_MODE[this._sizeMode] || this._sizeMode,
47
+ type: SPRITE_TYPE[this._type] || this._type,
48
+ trim: this._isTrimmedMode
49
+ };
50
+ }
51
+ setProp(props) {
52
+ if (props.sizeMode !== undefined)
53
+ this.setSizeMode(props.sizeMode);
54
+ if (props.spriteFrame !== undefined)
55
+ this.setSpriteFrame(props.spriteFrame);
56
+ if (props.type !== undefined)
57
+ this._type = props.type;
58
+ return this;
59
+ }
60
+ toJSON() {
61
+ return {
62
+ __type__: this.__type__,
63
+ _name: this._name,
64
+ _objFlags: this._objFlags,
65
+ node: this.node,
66
+ _enabled: this._enabled,
67
+ _materials: this._materials,
68
+ _srcBlendFactor: this._srcBlendFactor,
69
+ _dstBlendFactor: this._dstBlendFactor,
70
+ _spriteFrame: this._spriteFrame,
71
+ _type: this._type,
72
+ _sizeMode: this._sizeMode,
73
+ _fillType: this._fillType,
74
+ _fillCenter: this._fillCenter.toJSON(),
75
+ _fillStart: this._fillStart,
76
+ _fillRange: this._fillRange,
77
+ _isTrimmedMode: this._isTrimmedMode,
78
+ _atlas: this._atlas,
79
+ _id: this._id
80
+ };
81
+ }
82
+ }
@@ -1,74 +1,49 @@
1
- /**
2
- * Cocos Creator 变换数据类 (TRS = Translation, Rotation, Scale)
3
- * array: [posX, posY, posZ, rotX, rotY, rotZ, rotW, scaleX, scaleY, scaleZ]
4
- */
5
- class CCTrs {
6
- constructor() {
7
- this.__type__ = 'TypedArray';
8
- this.ctor = 'Float64Array';
9
- this.array = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
10
- }
11
-
12
- // Position
13
- get x() { return this.array[0]; }
14
- set x(v) { this.array[0] = v; }
15
-
16
- get y() { return this.array[1]; }
17
- set y(v) { this.array[1] = v; }
18
-
19
- get z() { return this.array[2]; }
20
- set z(v) { this.array[2] = v; }
21
-
22
- // Scale
23
- get scaleX() { return this.array[7]; }
24
- set scaleX(v) { this.array[7] = v; }
25
-
26
- get scaleY() { return this.array[8]; }
27
- set scaleY(v) { this.array[8] = v; }
28
-
29
- get scaleZ() { return this.array[9]; }
30
- set scaleZ(v) { this.array[9] = v; }
31
-
32
- // Rotation (四元数)
33
- get rotX() { return this.array[3]; }
34
- set rotX(v) { this.array[3] = v; }
35
-
36
- get rotY() { return this.array[4]; }
37
- set rotY(v) { this.array[4] = v; }
38
-
39
- get rotZ() { return this.array[5]; }
40
- set rotZ(v) { this.array[5] = v; }
41
-
42
- get rotW() { return this.array[6]; }
43
- set rotW(v) { this.array[6] = v; }
44
-
45
- /**
46
- * 设置位置
47
- */
48
- setPosition(x, y, z = 0) {
49
- this.array[0] = x;
50
- this.array[1] = y;
51
- this.array[2] = z;
52
- return this;
53
- }
54
-
55
- /**
56
- * 设置缩放
57
- */
58
- setScale(x, y = x, z = 1) {
59
- this.array[7] = x;
60
- this.array[8] = y;
61
- this.array[9] = z;
62
- return this;
63
- }
64
-
65
- toJSON() {
66
- return {
67
- __type__: this.__type__,
68
- ctor: this.ctor,
69
- array: [...this.array]
70
- };
71
- }
72
- }
73
-
74
- module.exports = CCTrs;
1
+ export default class CCTrs {
2
+ __type__;
3
+ ctor;
4
+ array;
5
+ constructor() {
6
+ this.__type__ = 'TypedArray';
7
+ this.ctor = 'Float64Array';
8
+ this.array = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
9
+ }
10
+ get x() { return this.array[0]; }
11
+ set x(v) { this.array[0] = v; }
12
+ get y() { return this.array[1]; }
13
+ set y(v) { this.array[1] = v; }
14
+ get z() { return this.array[2]; }
15
+ set z(v) { this.array[2] = v; }
16
+ get scaleX() { return this.array[7]; }
17
+ set scaleX(v) { this.array[7] = v; }
18
+ get scaleY() { return this.array[8]; }
19
+ set scaleY(v) { this.array[8] = v; }
20
+ get scaleZ() { return this.array[9]; }
21
+ set scaleZ(v) { this.array[9] = v; }
22
+ get rotX() { return this.array[3]; }
23
+ set rotX(v) { this.array[3] = v; }
24
+ get rotY() { return this.array[4]; }
25
+ set rotY(v) { this.array[4] = v; }
26
+ get rotZ() { return this.array[5]; }
27
+ set rotZ(v) { this.array[5] = v; }
28
+ get rotW() { return this.array[6]; }
29
+ set rotW(v) { this.array[6] = v; }
30
+ setPosition(x, y, z = 0) {
31
+ this.array[0] = x;
32
+ this.array[1] = y;
33
+ this.array[2] = z;
34
+ return this;
35
+ }
36
+ setScale(x, y = x, z = 1) {
37
+ this.array[7] = x;
38
+ this.array[8] = y;
39
+ this.array[9] = z;
40
+ return this;
41
+ }
42
+ toJSON() {
43
+ return {
44
+ __type__: this.__type__,
45
+ ctor: this.ctor,
46
+ array: [...this.array]
47
+ };
48
+ }
49
+ }