@awayjs/scene 0.13.277 → 0.13.279

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.
@@ -176,102 +176,94 @@ export class MorphSprite extends Sprite {
176
176
  const ratioStart = 1 - ratio;
177
177
  const ratioEnd = ratio;
178
178
 
179
- const len_contours = startPath._commands.length;
179
+ const len_contours = startPath.commands.length;
180
180
 
181
- if (endPath._commands.length !== len_contours) {
181
+ if (endPath.commands.length !== len_contours) {
182
182
  //len_contours = Math.min(endPath._commands.length, len_contours);
183
183
  throw ('Error in morph data - different number of contour');
184
184
  }
185
+ let startDataCnt = 0;
186
+ let endDataCnt = 0;
187
+ let startLastX = 0;
188
+ let startLastY = 0;
189
+ let endLastX = 0;
190
+ let endLastY = 0;
185
191
 
186
- for (let c = 0; c < len_contours; c++) {
187
-
188
- const startCmds = startPath._commands[c];
189
- const startData = startPath._data[c];
190
- const endCmds = endPath._commands[c];
191
- const endData = endPath._data[c];
192
-
193
- let startDataCnt = 0;
194
- let endDataCnt = 0;
195
- let startLastX = 0;
196
- let startLastY = 0;
197
- let endLastX = 0;
198
- let endLastY = 0;
192
+ const startData = startPath.data;
193
+ const endData = endPath.data;
199
194
 
200
- let len_cmds = startCmds.length;
195
+ for (let c = 0; c < len_contours; c++) {
201
196
 
202
- if (endCmds.length != len_cmds) {
203
- len_cmds = Math.min(endCmds.length, len_cmds);
204
- once(this, 'different number of commands in contour');
205
- return;
206
- }
207
- for (let c2 = 0; c2 < len_cmds; c2++) {
208
- switch (startCmds[c2]) {
209
- case GraphicsPathCommand.MOVE_TO:
210
- if (endCmds[c2] != GraphicsPathCommand.MOVE_TO) {
211
- throw ('Error in morph data - both shapes must start with Move too command');
212
- }
197
+ const startCmd = startPath.commands[c];
198
+
199
+ const endCmd = endPath.commands[c];
200
+
201
+ switch (startCmd) {
202
+ case GraphicsPathCommand.MOVE_TO:
203
+ if (endCmd != GraphicsPathCommand.MOVE_TO) {
204
+ throw ('Error in morph data - both shapes must start with Move too command');
205
+ }
206
+ startLastX = startData[startDataCnt++];
207
+ startLastY = startData[startDataCnt++];
208
+ endLastX = endData[endDataCnt++];
209
+ endLastY = endData[endDataCnt++];
210
+ newPath.moveTo(
211
+ ratioStart * startLastX + ratioEnd * endLastX,
212
+ ratioStart * startLastY + ratioEnd * endLastY);
213
+ break;
214
+ case GraphicsPathCommand.LINE_TO:
215
+ if (endCmd == GraphicsPathCommand.LINE_TO) {
213
216
  startLastX = startData[startDataCnt++];
214
217
  startLastY = startData[startDataCnt++];
215
218
  endLastX = endData[endDataCnt++];
216
219
  endLastY = endData[endDataCnt++];
217
- newPath.moveTo(
220
+ newPath.lineTo(
218
221
  ratioStart * startLastX + ratioEnd * endLastX,
219
222
  ratioStart * startLastY + ratioEnd * endLastY);
220
- break;
221
- case GraphicsPathCommand.LINE_TO:
222
- if (endCmds[c2] == GraphicsPathCommand.LINE_TO) {
223
- startLastX = startData[startDataCnt++];
224
- startLastY = startData[startDataCnt++];
225
- endLastX = endData[endDataCnt++];
226
- endLastY = endData[endDataCnt++];
227
- newPath.lineTo(
228
- ratioStart * startLastX + ratioEnd * endLastX,
229
- ratioStart * startLastY + ratioEnd * endLastY);
230
- } else if (endCmds[c2] == GraphicsPathCommand.CURVE_TO) {
231
- const ctrX = startLastX + (startData[startDataCnt++] - startLastX) / 2;
232
- const ctrY = startLastY + (startData[startDataCnt++] - startLastY) / 2;
233
-
234
- newPath.curveTo(
235
- ratioStart * ctrX + ratioEnd * endData[endDataCnt++],
236
- ratioStart * ctrY + ratioEnd * endData[endDataCnt++],
237
- ratioStart * startData[startDataCnt - 2] + ratioEnd * endData[endDataCnt++],
238
- ratioStart * startData[startDataCnt - 1] + ratioEnd * endData[endDataCnt++]);
239
-
240
- startLastX = startData[startDataCnt - 2];
241
- startLastY = startData[startDataCnt - 1];
242
- endLastX = endData[endDataCnt - 2];
243
- endLastY = endData[endDataCnt - 1];
244
- }
245
- break;
246
- case GraphicsPathCommand.CURVE_TO:
247
- if (endCmds[c2] == GraphicsPathCommand.LINE_TO) {
248
- const ctrX = endLastX + (endData[endDataCnt++] - endLastX) / 2;
249
- const ctrY = endLastY + (endData[endDataCnt++] - endLastY) / 2;
250
-
251
- newPath.curveTo(
252
- ratioStart * startData[startDataCnt++] + ratioEnd * ctrX,
253
- ratioStart * startData[startDataCnt++] + ratioEnd * ctrY,
254
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt - 2],
255
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt - 1]);
256
-
257
- startLastX = startData[startDataCnt - 2];
258
- startLastY = startData[startDataCnt - 1];
259
- endLastX = endData[endDataCnt - 2];
260
- endLastY = endData[endDataCnt - 1];
261
- } else if (endCmds[c2] == GraphicsPathCommand.CURVE_TO) {
262
- newPath.curveTo(
263
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
264
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
265
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
266
- ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++]);
267
-
268
- startLastX = startData[startDataCnt - 2];
269
- startLastY = startData[startDataCnt - 1];
270
- endLastX = endData[endDataCnt - 2];
271
- endLastY = endData[endDataCnt - 1];
272
- }
273
- break;
274
- }
223
+ } else if (endCmd == GraphicsPathCommand.CURVE_TO) {
224
+ const ctrX = startLastX + (startData[startDataCnt++] - startLastX) / 2;
225
+ const ctrY = startLastY + (startData[startDataCnt++] - startLastY) / 2;
226
+
227
+ newPath.curveTo(
228
+ ratioStart * ctrX + ratioEnd * endData[endDataCnt++],
229
+ ratioStart * ctrY + ratioEnd * endData[endDataCnt++],
230
+ ratioStart * startData[startDataCnt - 2] + ratioEnd * endData[endDataCnt++],
231
+ ratioStart * startData[startDataCnt - 1] + ratioEnd * endData[endDataCnt++]);
232
+
233
+ startLastX = startData[startDataCnt - 2];
234
+ startLastY = startData[startDataCnt - 1];
235
+ endLastX = endData[endDataCnt - 2];
236
+ endLastY = endData[endDataCnt - 1];
237
+ }
238
+ break;
239
+ case GraphicsPathCommand.CURVE_TO:
240
+ if (endCmd == GraphicsPathCommand.LINE_TO) {
241
+ const ctrX = endLastX + (endData[endDataCnt++] - endLastX) / 2;
242
+ const ctrY = endLastY + (endData[endDataCnt++] - endLastY) / 2;
243
+
244
+ newPath.curveTo(
245
+ ratioStart * startData[startDataCnt++] + ratioEnd * ctrX,
246
+ ratioStart * startData[startDataCnt++] + ratioEnd * ctrY,
247
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt - 2],
248
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt - 1]);
249
+
250
+ startLastX = startData[startDataCnt - 2];
251
+ startLastY = startData[startDataCnt - 1];
252
+ endLastX = endData[endDataCnt - 2];
253
+ endLastY = endData[endDataCnt - 1];
254
+ } else if (endCmd == GraphicsPathCommand.CURVE_TO) {
255
+ newPath.curveTo(
256
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
257
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
258
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++],
259
+ ratioStart * startData[startDataCnt++] + ratioEnd * endData[endDataCnt++]);
260
+
261
+ startLastX = startData[startDataCnt - 2];
262
+ startLastY = startData[startDataCnt - 1];
263
+ endLastX = endData[endDataCnt - 2];
264
+ endLastY = endData[endDataCnt - 1];
265
+ }
266
+ break;
275
267
  }
276
268
  }
277
269
  }
@@ -26,13 +26,10 @@ export class BitmapFontTable extends AssetBase implements IFontTable {
26
26
  public _font_chars_dic: Object;
27
27
  private _font_em_size: number;
28
28
  private _whitespace_width: number;
29
- private _offset_x: number;
30
- private _offset_y: number;
31
29
  private _ascent: number;
32
30
  private _descent: number;
33
31
  private _texture_width: number;
34
32
  private _texture_height: number;
35
- private _charDictDirty: Boolean;
36
33
  public font: any;
37
34
  public _adjust_size: number;
38
35
 
@@ -175,22 +172,6 @@ export class BitmapFontTable extends AssetBase implements IFontTable {
175
172
  this._descent = value;
176
173
  }
177
174
 
178
- get offset_x(): number {
179
- return this._offset_x;
180
- }
181
-
182
- set offset_x(value: number) {
183
- this._offset_x = value;
184
- }
185
-
186
- get offset_y(): number {
187
- return this._offset_y;
188
- }
189
-
190
- set offset_y(value: number) {
191
- this._offset_y = value;
192
- }
193
-
194
175
  public get_font_chars(): Array<BitmapFontChar> {
195
176
  return this._font_chars;
196
177
  }
@@ -67,56 +67,52 @@ export class FNTGeneratorCanvas extends FNTGeneratorBase {
67
67
  const fillData = char.fill_data_path;
68
68
 
69
69
  // empty command
70
- if (fillData.commands[0].length === 0 && fillData.commands.length === 1) {
70
+ if (fillData.commands.length === 0) {
71
71
  return null;
72
72
  }
73
73
 
74
74
  const path = new Path2D();
75
75
  const box = new Bounds();
76
+ const data = fillData.data;
77
+ const commands = fillData.commands;
78
+
79
+ let pointer = 0;
80
+ for (const command of commands) {
81
+ switch (command) {
82
+ case GraphicsPathCommand.MOVE_TO: {
83
+ // flash path in twips, transform it
84
+ const px = data[pointer++] / 20;
85
+ const py = data[pointer++] / 20;
86
+
87
+ box.grown(px, py);
88
+ path.moveTo(px, py);
89
+ break;
90
+ }
91
+
92
+ case GraphicsPathCommand.LINE_TO: {
93
+ const px = data[pointer++] / 20;
94
+ const py = data[pointer++] / 20;
95
+
96
+ box.grown(px, py);
97
+ path.lineTo(px, py);
98
+ break;
99
+ }
100
+
101
+ case GraphicsPathCommand.CURVE_TO: {
102
+ const cx = data[pointer++] / 20;
103
+ const cy = data[pointer++] / 20;
104
+ const dx = data[pointer++] / 20;
105
+ const dy = data[pointer++] / 20;
106
+
107
+ box.grown(cx, cy);
108
+ box.grown(dx, dy);
76
109
 
77
- for (let i = 0; i < fillData.commands.length; i++) {
78
- const data = fillData.data[i];
79
- const commands = fillData.commands[i];
80
-
81
- let pointer = 0;
82
- for (const command of commands) {
83
- switch (command) {
84
- case GraphicsPathCommand.MOVE_TO: {
85
- // flash path in twips, transform it
86
- const px = data[pointer++] / 20;
87
- const py = data[pointer++] / 20;
88
-
89
- box.grown(px, py);
90
- path.moveTo(px, py);
91
- break;
92
- }
93
-
94
- case GraphicsPathCommand.LINE_TO: {
95
- const px = data[pointer++] / 20;
96
- const py = data[pointer++] / 20;
97
-
98
- box.grown(px, py);
99
- path.lineTo(px, py);
100
- break;
101
- }
102
-
103
- case GraphicsPathCommand.CURVE_TO: {
104
- const cx = data[pointer++] / 20;
105
- const cy = data[pointer++] / 20;
106
- const dx = data[pointer++] / 20;
107
- const dy = data[pointer++] / 20;
108
-
109
- box.grown(cx, cy);
110
- box.grown(dx, dy);
111
-
112
- path.quadraticCurveTo(
113
- cx, cy,
114
- dx, dy
115
- );
116
- }
110
+ path.quadraticCurveTo(
111
+ cx, cy,
112
+ dx, dy
113
+ );
117
114
  }
118
115
  }
119
- //path.closePath();
120
116
  }
121
117
 
122
118
  return {
@@ -4,7 +4,7 @@ import { ImageSampler, AttributesBuffer, Float2Attributes, AttributesView, Bitma
4
4
 
5
5
  import { Style, TriangleElements } from '@awayjs/renderer';
6
6
 
7
- import { GraphicsPath, Shape, GraphicsFactoryFills, GraphicsFactoryHelper, MaterialManager } from '@awayjs/graphics';
7
+ import { GraphicsPath, Shape, GraphicsFactoryFills, GraphicsFactoryHelper, MaterialManager, GraphicsPathCommand } from '@awayjs/graphics';
8
8
 
9
9
  import { MaterialBase, MethodMaterial } from '@awayjs/materials';
10
10
 
@@ -48,26 +48,25 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
48
48
 
49
49
  public font: any;
50
50
 
51
- /*internal*/ _font_chars_dic: StringMap<TesselatedFontChar>;
52
- /*internal*/ _current_size: number;
53
- /*internal*/ _size_multiply: number;
51
+ /*internal*/ _font_chars_dic: StringMap<TesselatedFontChar> = {};
52
+ /*internal*/ _current_size: number = 0;
53
+ /*internal*/ _size_multiply: number = 0;
54
54
 
55
- private _font_chars: Array<TesselatedFontChar>;
56
- private _font_em_size: number;
55
+ private _font_chars: TesselatedFontChar[] = [];
56
+
57
+ // default size
58
+ private _font_em_size: number = 32;
57
59
 
58
60
  private _whitespace_width: number;
59
61
 
60
- private _offset_x: number;
61
- private _offset_y: number;
62
- private _ascent: number;
63
- private _descent: number;
64
- private _charDictDirty: Boolean;
65
- private _usesCurves: boolean;
62
+ private _ascent: number = 0;
63
+ private _descent: number = 0;
64
+ private _usesCurves: boolean = false;
66
65
  private _opentype_font: any;
67
- private _glyphIdxToChar: any;
66
+ private _glyphIdxToChar: Record<number, TesselatedFontChar> = {};
68
67
 
69
- private _fntSizeLimit: number=-1;
70
- private _fnt_channels: BitmapImage2D[];
68
+ private _fntSizeLimit: number = -1;
69
+ private _fnt_channels: BitmapImage2D[] = [];
71
70
 
72
71
  /**
73
72
  * Creates a new TesselatedFont object
@@ -76,18 +75,6 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
76
75
  */
77
76
  constructor(opentype_font: any = null) {
78
77
  super();
79
- this._font_chars = [];
80
- this._font_chars_dic = Object.create(null);
81
- this._current_size = 0;
82
- this._size_multiply = 0;
83
- this._ascent = 0;
84
- this._descent = 0;
85
- this._usesCurves = false;
86
- this._glyphIdxToChar = {};
87
- this._fnt_channels = [];
88
-
89
- // default size
90
- this._font_em_size = 32;
91
78
 
92
79
  if (opentype_font) {
93
80
  this._opentype_font = opentype_font;
@@ -524,22 +511,6 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
524
511
  this._descent = value;
525
512
  }
526
513
 
527
- get offset_x(): number {
528
- return this._offset_x;
529
- }
530
-
531
- set offset_x(value: number) {
532
- this._offset_x = value;
533
- }
534
-
535
- get offset_y(): number {
536
- return this._offset_y;
537
- }
538
-
539
- set offset_y(value: number) {
540
- this._offset_y = value;
541
- }
542
-
543
514
  public get_font_chars(): Array<TesselatedFontChar> {
544
515
  return this._font_chars;
545
516
  }
@@ -589,14 +560,14 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
589
560
 
590
561
  if (charGlyph.fill_data === null) {
591
562
 
592
- if (charGlyph.fill_data_path.commands[0][0] == 1
593
- && charGlyph.fill_data_path.data[0][0] == 0
594
- && charGlyph.fill_data_path.data[0][1] == 0) {
563
+ if (charGlyph.fill_data_path.commands[0] == GraphicsPathCommand.MOVE_TO
564
+ && charGlyph.fill_data_path.data[0] == 0
565
+ && charGlyph.fill_data_path.data[1] == 0) {
595
566
 
596
- charGlyph.fill_data_path.data[0].shift();
597
- charGlyph.fill_data_path.data[0].shift();
598
- charGlyph.fill_data_path.commands[0].shift();
599
- charGlyph.fill_data_path.commands[0][0] = 2;
567
+ charGlyph.fill_data_path.data.shift();
568
+ charGlyph.fill_data_path.data.shift();
569
+ charGlyph.fill_data_path.commands.shift();
570
+ charGlyph.fill_data_path.commands[0] = GraphicsPathCommand.LINE_TO;
600
571
  }
601
572
 
602
573
  charGlyph.fill_data = GraphicsFactoryFills.pathToAttributesBuffer(charGlyph.fill_data_path, true);
@@ -1118,11 +1089,11 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
1118
1089
 
1119
1090
  // hack for messed up "X": remove the first command if it is moveTo that points to 0,0
1120
1091
  // change the new first command to moveTo
1121
- if (path.commands[0][0] == 1 && path.data[0][0] == 0 && path.data[0][1] == 0) {
1122
- path.data[0].shift();
1123
- path.data[0].shift();
1124
- path.commands[0].shift();
1125
- path.commands[0][0] = 2;
1092
+ if (path.commands[0] == GraphicsPathCommand.MOVE_TO && path.data[0] == 0 && path.data[1] == 0) {
1093
+ path.data.shift();
1094
+ path.data.shift();
1095
+ path.commands.shift();
1096
+ path.commands[0] = GraphicsPathCommand.LINE_TO;
1126
1097
  }
1127
1098
 
1128
1099
  if (fontChar.fill_data) {
@@ -523,7 +523,7 @@ export class TextFormat extends AssetBase {
523
523
  * space between lines.
524
524
  */
525
525
  constructor(
526
- font: Font | string = null, size: number = null, color: number = null, bold: boolean = null,
526
+ font: Font | string = '_sans', size: number = null, color: number = null, bold: boolean = null,
527
527
  italic: boolean = null, underline: boolean = null, url: string = null,
528
528
  link_target: string = null, align: string = null,
529
529
  leftMargin: number = null, rightMargin: number = null, indent: number = null, leading: number = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.277",
3
+ "version": "0.13.279",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",