@awayjs/scene 0.13.312 → 0.13.314

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.
@@ -73,8 +73,6 @@ export class Billboard extends DisplayObjectContainer implements IPickable {
73
73
  private _billboardHeight: number;
74
74
  private _billboardRect: Rectangle;
75
75
 
76
- private _sampler: ImageSampler;
77
-
78
76
  private _onInvalidateTextureDelegate: (event: MaterialEvent) => void;
79
77
 
80
78
  public static getNewBillboard(
@@ -144,10 +142,6 @@ export class Billboard extends DisplayObjectContainer implements IPickable {
144
142
  this._invalidateMaterial();
145
143
  }
146
144
 
147
- public get sampler(): ImageSampler {
148
- return this._sampler;
149
- }
150
-
151
145
  /**
152
146
  *
153
147
  */
@@ -185,11 +179,12 @@ export class Billboard extends DisplayObjectContainer implements IPickable {
185
179
 
186
180
  this._onInvalidateTextureDelegate = (event: MaterialEvent) => this._onInvalidateTexture(event);
187
181
 
182
+ this.style = new Style();
183
+ this.style.sampler = new ImageSampler(false, smoothing, false);
184
+
188
185
  this.material = material;
189
186
 
190
187
  this._updateDimensions();
191
- if (this._sampler)
192
- this._sampler.smooth = smoothing;
193
188
  }
194
189
 
195
190
  public invalidateElements(): void {
@@ -272,24 +267,18 @@ export class Billboard extends DisplayObjectContainer implements IPickable {
272
267
  const image = this.image;
273
268
 
274
269
  if (image && !image.isDisposed) {
275
- const texture = this.material.getTextureAt(0);
276
-
277
- this._sampler = <ImageSampler> (
278
- this._style?.getSamplerAt(texture)
279
- || this.material.style?.getSamplerAt(texture)
280
- || texture.getSamplerAt(0)
281
- || ImageUtils.getDefaultImageSampler());
270
+ const sampler = this.style.sampler;
282
271
 
283
- if (this._sampler.imageRect) {
284
- this._billboardWidth = this._sampler.imageRect.width * image.width;
285
- this._billboardHeight = this._sampler.imageRect.height * image.height;
272
+ if (sampler.imageRect) {
273
+ this._billboardWidth = sampler.imageRect.width * image.width;
274
+ this._billboardHeight = sampler.imageRect.height * image.height;
286
275
  } else {
287
276
  this._billboardWidth = image.rect.width;
288
277
  this._billboardHeight = image.rect.height;
289
278
  }
290
279
 
291
280
  this._billboardRect =
292
- this._sampler.frameRect || new Rectangle(0, 0, this._billboardWidth, this._billboardHeight);
281
+ sampler.frameRect || new Rectangle(0, 0, this._billboardWidth, this._billboardHeight);
293
282
  } else {
294
283
  this._billboardWidth = 1;
295
284
  this._billboardHeight = 1;
@@ -144,7 +144,7 @@ export class MorphSprite extends Sprite {
144
144
  newTrans.ty = startTrans.ty * ratioStart + endTrans.ty * ratioEnd;
145
145
 
146
146
  resultFillStyle = new BitmapFillStyle(
147
- startStyle.material,
147
+ startStyle.image,
148
148
  newTrans,
149
149
  startStyle.repeat,
150
150
  startStyle.smooth);
@@ -6,9 +6,7 @@ import { IEntity } from '@awayjs/view';
6
6
 
7
7
  import { Style, TriangleElements } from '@awayjs/renderer';
8
8
 
9
- import { MaterialBase } from '@awayjs/materials';
10
-
11
- import { Graphics, Shape, GraphicsFactoryHelper, MaterialManager } from '@awayjs/graphics';
9
+ import { Graphics, Shape, GraphicsFactoryHelper, MaterialManager, SolidFillStyle, TextureAtlas } from '@awayjs/graphics';
12
10
 
13
11
  import { TesselatedFontTable } from '../text/TesselatedFontTable';
14
12
  import { AntiAliasType } from '../text/AntiAliasType';
@@ -617,17 +615,18 @@ export class TextField extends DisplayObjectContainer {
617
615
  }
618
616
 
619
617
  if (this.cursorShape.style.color !== color) {
620
- const alpha = ColorUtils.float32ColorToARGB(color)[0];
621
-
622
- const obj = MaterialManager.getMaterialForColor(color, (alpha / 255) || 1);
623
-
624
- if (obj.colorPos) {
625
- this.cursorShape.style = new Style();
626
- const sampler: ImageSampler = new ImageSampler();
627
- obj.material.animateUVs = true;
628
- this.cursorShape.style.color = color;
629
- this.cursorShape.style.addSamplerAt(sampler, obj.material.getTextureAt(0));
630
- this.cursorShape.style.uvMatrix = new Matrix(0, 0, 0, 0, obj.colorPos.x, obj.colorPos.y);
618
+ const solid = new SolidFillStyle(
619
+ color,
620
+ ColorUtils.float32ColorToARGB(color)[0] / 255 || 1
621
+ );
622
+ const material = MaterialManager.getMaterialForColor(solid);
623
+ const shape = this.cursorShape;
624
+
625
+ shape.material = material;
626
+ if (material.getNumTextures()) {
627
+ shape.style = new Style();
628
+ shape.style.image = TextureAtlas.getTextureForColor(solid);
629
+ shape.style.uvMatrix = solid.getUVMatrix();
631
630
  }
632
631
  }
633
632
  this.scrollToCursor(x,y);
@@ -2747,34 +2746,31 @@ export class TextField extends DisplayObjectContainer {
2747
2746
  textShape.elements.setPositions(attr);
2748
2747
  textShape.elements.invalidate();
2749
2748
 
2750
- textShape.shape = <Shape> this.targetGraphics.addShape(Shape.getShape(textShape.elements));
2749
+ const shape = textShape.shape = <Shape> this.targetGraphics.addShape(Shape.getShape(textShape.elements));
2751
2750
 
2752
2751
  // has BUG for QWOP, temporarily enable it (default)
2753
- textShape.shape.deepHitCheck = true;
2754
- textShape.shape.usages++;
2755
-
2756
- const sampler: ImageSampler = new ImageSampler();
2757
- textShape.shape.style = new Style();
2758
- if (textShape.format.material && this._textColor == 0) {
2759
- textShape.shape.material = this._textFormats[0].material;
2760
- textShape.shape.style.addSamplerAt(sampler, textShape.shape.material.getTextureAt(0));
2761
- (<MaterialBase> textShape.shape.material).animateUVs = true;
2762
- textShape.shape.style.uvMatrix =
2752
+ shape.deepHitCheck = true;
2753
+ shape.usages++;
2754
+ shape.style = new Style();
2755
+
2756
+ if (textShape.format.bitmap && this._textColor == 0) {
2757
+ shape.material = MaterialManager.getMaterialForBitmap(true);
2758
+ shape.style.image = this._textFormats[0].bitmap;
2759
+ shape.style.uvMatrix =
2763
2760
  new Matrix(0, 0, 0, 0, textShape.format.uv_values[0], textShape.format.uv_values[1]);
2764
2761
  } else {
2765
2762
 
2766
2763
  const color = this.getTextColorForTextFormat(textShape.format);
2767
- let alpha = ColorUtils.float32ColorToARGB(color)[0];
2768
- if (alpha == 0) {
2769
- alpha = 255;
2770
- }
2771
- const obj = MaterialManager.getMaterialForColor(color, alpha / 255);
2772
-
2773
- textShape.shape.material = obj.material;
2774
- if (obj.colorPos) {
2775
- textShape.shape.style.addSamplerAt(sampler, textShape.shape.material.getTextureAt(0));
2776
- (<MaterialBase> textShape.shape.material).animateUVs = true;
2777
- textShape.shape.style.uvMatrix = new Matrix(0, 0, 0, 0, obj.colorPos.x, obj.colorPos.y);
2764
+ const solid = new SolidFillStyle(
2765
+ color,
2766
+ ColorUtils.float32ColorToARGB(color)[0] / 255 || 1
2767
+ );
2768
+
2769
+ const material = MaterialManager.getMaterialForColor(solid);
2770
+ shape.material = material;
2771
+ if (material.getNumTextures()) {
2772
+ shape.style.image = TextureAtlas.getTextureForColor(solid);
2773
+ shape.style.uvMatrix = solid.getUVMatrix();
2778
2774
  }
2779
2775
  }
2780
2776
  }
@@ -2862,9 +2858,6 @@ export class TextField extends DisplayObjectContainer {
2862
2858
  continue;
2863
2859
  }
2864
2860
 
2865
- const color = this.getTextColorForTextFormat(textShape.format);
2866
- const alpha = ColorUtils.float32ColorToARGB(color)[0] || 255;
2867
-
2868
2861
  textShape.elements = new TriangleElements();
2869
2862
 
2870
2863
  textShape.elements.setPositions(attr);
@@ -2875,37 +2868,41 @@ export class TextField extends DisplayObjectContainer {
2875
2868
 
2876
2869
  textShape.elements.invalidate();
2877
2870
 
2878
- textShape.shape = Shape.getShape(textShape.elements);
2871
+ const shape = textShape.shape = Shape.getShape(textShape.elements);
2879
2872
  // has BUG for QWOP, temporarily enable it (default)
2880
- textShape.shape.deepHitCheck = true;
2881
- textShape.shape.usages++;
2873
+ shape.deepHitCheck = true;
2874
+ shape.usages++;
2882
2875
 
2883
- const sampler: ImageSampler = new ImageSampler(false, true, true);
2884
- textShape.shape.style = new Style();
2876
+ shape.style = new Style();
2877
+ shape.style.sampler = new ImageSampler(false, true, true);
2885
2878
 
2886
- if (textShape.fntMaterial) {
2879
+ if (textShape.fntBitmap) {
2887
2880
  // used by FNT fonts
2888
- textShape.shape.material = textShape.fntMaterial;
2889
- textShape.shape.style.addSamplerAt(sampler, textShape.shape.material.getTextureAt(0));
2881
+ shape.material = MaterialManager.getMaterialForBitmap();
2882
+ shape.style.image = textShape.fntBitmap;
2890
2883
  //(<MaterialBase> textShape.shape.material).colorTransform=new ColorTransform();
2891
2884
  //(<MaterialBase> textShape.shape.material).colorTransform.color=color;
2892
- } else if (textShape.format.material && this._textColor == 0) {
2885
+ } else if (textShape.format.bitmap && this._textColor == 0) {
2893
2886
  // used for textfields loaded from awd.
2894
2887
  // the material on the format uses textureAtlas from awd
2895
- textShape.shape.material = this._textFormats[0].material;
2896
- textShape.shape.style.addSamplerAt(sampler, textShape.shape.material.getTextureAt(0));
2897
- (<MaterialBase> textShape.shape.material).animateUVs = true;
2898
- textShape.shape.style.uvMatrix =
2888
+ shape.material = MaterialManager.getMaterialForBitmap(true);
2889
+ shape.style.image = this._textFormats[0].bitmap;
2890
+ shape.style.uvMatrix =
2899
2891
  new Matrix(0, 0, 0, 0, textShape.format.uv_values[0], textShape.format.uv_values[1]);
2900
2892
  } else {
2901
2893
  // used by runtime textureatlas.
2902
2894
  // (standart for dynamic created text and text loaded from swf)
2903
- const obj = MaterialManager.getMaterialForColor(color, alpha / 255);
2904
- textShape.shape.material = obj.material;
2905
- if (obj.colorPos) {
2906
- textShape.shape.style.addSamplerAt(sampler, textShape.shape.material.getTextureAt(0));
2907
- (<MaterialBase> textShape.shape.material).animateUVs = true;
2908
- textShape.shape.style.uvMatrix = new Matrix(0, 0, 0, 0, obj.colorPos.x, obj.colorPos.y);
2895
+ const color = this.getTextColorForTextFormat(textShape.format);
2896
+ const solid = new SolidFillStyle(
2897
+ color,
2898
+ ColorUtils.float32ColorToARGB(color)[0] / 255 || 1
2899
+ );
2900
+
2901
+ const material = MaterialManager.getMaterialForColor(solid);
2902
+ shape.material = material;
2903
+ if (material.getNumTextures()) {
2904
+ shape.style.image = TextureAtlas.getTextureForColor(solid);
2905
+ shape.style.uvMatrix = solid.getUVMatrix();
2909
2906
  }
2910
2907
  }
2911
2908
  }
@@ -15,7 +15,7 @@ export class TextSprite extends Sprite {
15
15
  const tf: TextField = this.parentTextField;
16
16
  //tf.reConstruct(true);
17
17
 
18
- if (tf._textFormats[0] && !tf._textFormats[0].font_table.isAsset(TesselatedFontTable) && !tf._textFormats[0].material) {
18
+ if (tf._textFormats[0] && !tf._textFormats[0].font_table.isAsset(TesselatedFontTable) && !tf._textFormats[0].bitmap) {
19
19
  this.transform.colorTransform.color = (tf.textColor != null) ? tf.textColor : tf._textFormats[0].color;
20
20
  this._invalidateHierarchicalProperty(HierarchicalProperty.COLOR_TRANSFORM);
21
21
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { ContainerNode, View } from '@awayjs/view';
3
- import { MaterialBase, MethodMaterial } from '@awayjs/materials';
3
+ import { MaterialBase } from '@awayjs/materials';
4
4
  import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
5
5
  import { DisplayObject } from '../display/DisplayObject';
6
6
  import { Billboard } from '../display/Billboard';
@@ -25,7 +25,8 @@ import { Stage,
25
25
  Image2D
26
26
  } from '@awayjs/stage';
27
27
 
28
- import { DefaultRenderer, RenderGroup, Style } from '@awayjs/renderer';
28
+ import { DefaultRenderer, RenderGroup } from '@awayjs/renderer';
29
+ import { MaterialManager } from '@awayjs/graphics';
29
30
 
30
31
  // empty matrix for transform reset
31
32
  const TMP_POINT = new Point(0,0);
@@ -230,12 +231,7 @@ export class SceneImage2D extends BitmapImage2D {
230
231
  SceneImage2D._billboardRenderer.disableClear = true;
231
232
  SceneImage2D._billboardRenderer.renderableSorter = null;//new RenderableSort2D();
232
233
 
233
- const mat: MethodMaterial = new MethodMaterial(new BitmapImage2D(128, 128, true, 0x0));
234
- mat.bothSides = true;
235
- mat.alphaBlending = true;
236
-
237
- SceneImage2D._billboard = new Billboard(mat);
238
- SceneImage2D._billboard.style = new Style();
234
+ SceneImage2D._billboard = new Billboard(MaterialManager.getMaterialForBitmap());
239
235
 
240
236
  SceneImage2D._billboardRoot.addChild(SceneImage2D._billboard);
241
237
  }
@@ -262,7 +258,6 @@ export class SceneImage2D extends BitmapImage2D {
262
258
  public dispose(): void {
263
259
  this._clearFromDispose = true;
264
260
 
265
- this.dropAllReferences();
266
261
  this.unmarkToUnload();
267
262
  this.unuseWeakRef();
268
263
 
@@ -289,8 +284,8 @@ export class SceneImage2D extends BitmapImage2D {
289
284
  super.unload();
290
285
  }
291
286
 
292
- protected deepClone(from: BitmapImage2D) {
293
- this.copyPixels(from, this._rect, new Point(0,0));
287
+ public copyTo(target: SceneImage2D): void {
288
+ target.copyPixels(this, target.rect, new Point(0,0));
294
289
  }
295
290
 
296
291
  /**
@@ -337,7 +332,6 @@ export class SceneImage2D extends BitmapImage2D {
337
332
  alphaBitmapData?: BitmapImage2D, alphaPoint?: Point, mergeAlpha?: boolean): void {
338
333
 
339
334
  this._lastUsedFill = null;
340
- this.dropAllReferences();
341
335
  this.unmarkToUnload();
342
336
 
343
337
  // need drop alpha from source when target is not has alpha
@@ -435,7 +429,6 @@ export class SceneImage2D extends BitmapImage2D {
435
429
  ): void {
436
430
 
437
431
  this._lastUsedFill = null;
438
- this.dropAllReferences();
439
432
  this.unmarkToUnload();
440
433
 
441
434
  if (this._initalFillColor !== null)
@@ -450,8 +443,6 @@ export class SceneImage2D extends BitmapImage2D {
450
443
  return false;
451
444
  }
452
445
 
453
- this.dropAllReferences(false);
454
-
455
446
  const result = this._stage.filterManager.applyFilter (
456
447
  source,
457
448
  this,
@@ -464,7 +455,6 @@ export class SceneImage2D extends BitmapImage2D {
464
455
  }
465
456
 
466
457
  public colorTransform(rect: Rectangle, colorTransform: ColorTransform): void {
467
- this.dropAllReferences();
468
458
  this.unmarkToUnload();
469
459
 
470
460
  this._lastUsedFill = null;
@@ -626,7 +616,6 @@ export class SceneImage2D extends BitmapImage2D {
626
616
  {
627
617
  /* eslint-enable */
628
618
 
629
- this.dropAllReferences();
630
619
  this.unmarkToUnload();
631
620
 
632
621
  if (source instanceof DisplayObject) {
@@ -683,13 +672,13 @@ export class SceneImage2D extends BitmapImage2D {
683
672
  const root = SceneImage2D._billboardRoot;
684
673
  const billboard = SceneImage2D._billboard;
685
674
 
686
- billboard.sampler.smooth = smoothing;
675
+ billboard.style.sampler.smooth = smoothing;
687
676
 
688
677
  renderer.disableClear = !useTmp;
689
678
  renderer.view.target = target;
690
679
  renderer.view.projection.scale = 1000 / target.height;
691
680
 
692
- billboard.material.style.image = source;
681
+ billboard.style.image = source;
693
682
 
694
683
  // not all blend modes can be used for rendering
695
684
  billboard.material.blendMode = !useTmp ? mappedBlend : BlendMode.LAYER;
@@ -741,6 +730,8 @@ export class SceneImage2D extends BitmapImage2D {
741
730
  stage.filterManager.pushTemp(target);
742
731
  }
743
732
 
733
+ //reset material blendMode
734
+ billboard.material.blendMode = BlendMode.NORMAL;
744
735
  }
745
736
 
746
737
  private _drawAsDisplay(
@@ -908,7 +899,8 @@ export class SceneImage2D extends BitmapImage2D {
908
899
  false
909
900
  );
910
901
 
911
- image.deepClone(this);
902
+ this.copyTo(image);
903
+
912
904
  return image;
913
905
  }
914
906
  }
@@ -1,12 +1,10 @@
1
- import { Matrix, AssetBase, Point, Rectangle, ColorTransform, ColorUtils } from '@awayjs/core';
1
+ import { AssetBase, Point, Rectangle, ColorTransform, ColorUtils } from '@awayjs/core';
2
2
 
3
- import { ImageSampler, AttributesBuffer, Float2Attributes, AttributesView, BitmapImage2D, Stage } from '@awayjs/stage';
3
+ import { AttributesBuffer, Float2Attributes, AttributesView, BitmapImage2D, Stage } from '@awayjs/stage';
4
4
 
5
5
  import { Style, TriangleElements } from '@awayjs/renderer';
6
6
 
7
- import { GraphicsPath, Shape, GraphicsFactoryFills, GraphicsFactoryHelper, MaterialManager, GraphicsPathCommand } from '@awayjs/graphics';
8
-
9
- import { MaterialBase, MethodMaterial } from '@awayjs/materials';
7
+ import { GraphicsPath, Shape, GraphicsFactoryFills, GraphicsFactoryHelper, MaterialManager, GraphicsPathCommand, SolidFillStyle, TextureAtlas } from '@awayjs/graphics';
10
8
 
11
9
  import { TesselatedFontChar } from './TesselatedFontChar';
12
10
  import { IFontTable } from './IFontTable';
@@ -357,20 +355,17 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
357
355
  attributesView.dispose();
358
356
  const elements = new TriangleElements(vertexBuffer);
359
357
  elements.setPositions(new Float2Attributes(vertexBuffer));
360
- const shape = Shape.getShape(elements);
361
358
 
362
- const sampler: ImageSampler = new ImageSampler();
363
- shape.style = new Style();
359
+ const shape = Shape.getShape(elements);
360
+ const solid = new SolidFillStyle(0xFFFFFF, 1);
361
+ const material = MaterialManager.getMaterialForColor(solid);
364
362
 
365
- const color = 0xFFFFFF;
366
- const alpha = 1;
367
- const obj = MaterialManager.getMaterialForColor(color, alpha);
363
+ shape.material = material;
368
364
 
369
- shape.material = obj.material;
370
- if (obj.colorPos) {
371
- shape.style.addSamplerAt(sampler, shape.material.getTextureAt(0));
372
- (<MaterialBase> shape.material).animateUVs = true;
373
- shape.style.uvMatrix = new Matrix(0, 0, 0, 0, obj.colorPos.x, obj.colorPos.y);
365
+ if (material.getNumTextures()) {
366
+ shape.style = new Style();
367
+ shape.style.image = TextureAtlas.getTextureForColor(solid);
368
+ shape.style.uvMatrix = solid.getUVMatrix();
374
369
  }
375
370
  shapes[i] = shape;
376
371
  }
@@ -748,17 +743,11 @@ export class TesselatedFontTable extends AssetBase implements IFontTable {
748
743
  private _queryShape (tf: TextField, format: TextFormat, channel = -1): TextShape {
749
744
  const textShape = tf.getTextShapeForIdentifierAndFormat(this._cacheKey(format.color, channel), format);
750
745
 
751
- if (channel >= 0 && !textShape.fntMaterial) {
746
+ if (channel >= 0 && !textShape.fntBitmap) {
752
747
  const argb = ColorUtils.float32ColorToARGB(format.color);
753
- const mat = new MethodMaterial(this._fnt_channels[channel]);
754
-
755
- mat.colorTransform = new ColorTransform(argb[1] / 255, argb[2] / 255, argb[3] / 255);
756
- mat.bothSides = true;
757
- mat.alphaBlending = true;
758
- mat.useColorTransform = true;
759
- mat.style.sampler = new ImageSampler(false, true, true);
760
748
 
761
- textShape.fntMaterial = mat;
749
+ textShape.fntBitmap = this._fnt_channels[channel];
750
+ textShape.fntColorTransform = new ColorTransform(argb[1] / 255, argb[2] / 255, argb[3] / 255);
762
751
  }
763
752
 
764
753
  return textShape;
@@ -1,5 +1,5 @@
1
1
  import { AssetBase } from '@awayjs/core';
2
- import { IMaterial } from '@awayjs/renderer';
2
+ import { Image2D } from '@awayjs/stage';
3
3
  import { IFontTable } from './IFontTable';
4
4
  import { FontStyleName } from './FontStyleName';
5
5
  import { TextFormatAlign } from './TextFormatAlign';
@@ -366,7 +366,7 @@ export class TextFormat extends AssetBase {
366
366
  * The material to use for texturing geometry generated for this text-format.
367
367
  * this material will be used by the TextField
368
368
  */
369
- public material: IMaterial;
369
+ public bitmap: Image2D;
370
370
 
371
371
  /**
372
372
  * The uv-values of the colors in textureatlas.
@@ -2,16 +2,17 @@ import { TriangleElements } from '@awayjs/renderer';
2
2
 
3
3
  import { Shape } from '@awayjs/graphics';
4
4
 
5
- import { MaterialBase } from '@awayjs/materials';
6
-
7
5
  import { TextFormat } from './TextFormat';
6
+ import { BitmapImage2D } from '@awayjs/stage';
7
+ import { ColorTransform } from '@awayjs/core';
8
8
 
9
9
  export class TextShape {
10
10
 
11
11
  public verts: Array<Float32Array> = [];
12
12
  public uvs: Array<Float32Array> = [];
13
13
  public shape: Shape;
14
- public fntMaterial: MaterialBase;
14
+ public fntBitmap: BitmapImage2D;
15
+ public fntColorTransform: ColorTransform;
15
16
  public elements: TriangleElements;
16
17
 
17
18
  private _length: number = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.312",
3
+ "version": "0.13.314",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",