@awayjs/scene 0.13.314 → 0.13.316

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.
@@ -194,7 +194,6 @@ export class DisplayObject extends AssetBase implements IBitmapDrawable, IContai
194
194
 
195
195
  private _scrollRect: Rectangle;
196
196
  private _scrollRectPrimitive: Sprite;
197
- private _scrollRectPrimitiveDirty: boolean;
198
197
 
199
198
  protected _parent: DisplayObjectContainer;
200
199
  public _sessionID: number = -1;
@@ -1152,24 +1151,44 @@ export class DisplayObject extends AssetBase implements IBitmapDrawable, IContai
1152
1151
  * up and down.</p>
1153
1152
  */
1154
1153
  public get scrollRect(): Rectangle {
1155
- return this._scrollRect;
1154
+ return this._scrollRect?.clone();
1156
1155
  }
1157
1156
 
1158
1157
  public set scrollRect(value: Rectangle) {
1159
- // @todo: check if rectangle has same values as previous
1160
- //if (this._scrollRect == value)
1161
- // return;
1162
1158
 
1163
- this._scrollRect = value;
1159
+ let invalidatePos = true;
1164
1160
 
1165
- if (!value && this._scrollRectPrimitive) {
1166
- const idx = this.masks.indexOf(this._scrollRectPrimitive);
1167
- this.masks.splice(idx, 1);
1168
- this._scrollRectPrimitive = null;
1161
+ if (!!this._scrollRect != !!value) {
1162
+ //invalidate masks only if scrollRect is being enabled or disabled
1163
+ this._invalidateHierarchicalProperty(HierarchicalProperty.MASKS);
1164
+ this._scrollRect = value?.clone();
1165
+ } else if (this._scrollRect && !this._scrollRect.equals(value)) {
1166
+ this._scrollRect.copyFrom(value);
1167
+ } else {
1168
+ //invalidate position only if scrollRect changes
1169
+ invalidatePos = false;
1169
1170
  }
1170
1171
 
1171
- this._transform.invalidatePosition();
1172
- this._scrollRectPrimitiveDirty = true;
1172
+ if (invalidatePos) {
1173
+ this._transform.invalidatePosition();
1174
+
1175
+ if (value) {
1176
+ if (!this._scrollRectPrimitive) {
1177
+ //create ScrollRectPrimitive
1178
+ this._scrollRectPrimitive = new Sprite();
1179
+ this._scrollRectPrimitive.maskMode = true;
1180
+ }
1181
+
1182
+ //update ScrollRectPrimitive
1183
+ this._scrollRectPrimitive.graphics.clear();
1184
+ this._scrollRectPrimitive.graphics.beginFill(0x0000ff, 1);
1185
+ this._scrollRectPrimitive.graphics.drawRect(value.x,value.y,value.width,value.height);
1186
+ this._scrollRectPrimitive.graphics.endFill();
1187
+ } else if (this._scrollRectPrimitive) {
1188
+ //remove ScrollRectPrimitive
1189
+ this._scrollRectPrimitive = null;
1190
+ }
1191
+ }
1173
1192
  }
1174
1193
 
1175
1194
  /**
@@ -1234,23 +1253,6 @@ export class DisplayObject extends AssetBase implements IBitmapDrawable, IContai
1234
1253
  }
1235
1254
 
1236
1255
  public getScrollRectPrimitive(): IContainer {
1237
- if (this._scrollRectPrimitiveDirty) {
1238
- this._scrollRectPrimitiveDirty = false;
1239
-
1240
- if (!this._scrollRectPrimitive) {
1241
- this._scrollRectPrimitive = new Sprite();
1242
- this._scrollRectPrimitive.maskMode = true;
1243
- if (!this.masks)
1244
- this.masks = [];
1245
- this.masks.push(this._scrollRectPrimitive);
1246
- }
1247
-
1248
- this._scrollRectPrimitive.graphics.clear();
1249
- this._scrollRectPrimitive.graphics.beginFill(0x0000ff, 1);
1250
- this._scrollRectPrimitive.graphics.drawRect(0,0,this._scrollRect.width,this._scrollRect.height);
1251
- this._scrollRectPrimitive.graphics.endFill();
1252
- }
1253
-
1254
1256
  return this._scrollRectPrimitive;
1255
1257
  }
1256
1258
 
@@ -171,7 +171,7 @@ export class DisplayObjectContainer extends DisplayObject implements IRenderCont
171
171
 
172
172
  child._setParent(this);
173
173
 
174
- for (const key in this._abstractionPool)
174
+ for (const key in this._containerNodes)
175
175
  this._containerNodes[key].addChildAt(child, index);
176
176
 
177
177
  return child;
@@ -532,7 +532,7 @@ export class DisplayObjectContainer extends DisplayObject implements IRenderCont
532
532
 
533
533
  child._setParent(null);
534
534
 
535
- for (const key in this._abstractionPool)
535
+ for (const key in this._containerNodes)
536
536
  this._containerNodes[key].removeChildAt(index);
537
537
 
538
538
  return child;
@@ -1,7 +1,8 @@
1
1
  import { Vector3D, Matrix3D, Box, Sphere } from '@awayjs/core';
2
2
 
3
3
  import { PickingCollision, _Pick_PickableBase,
4
- PickEntity, IEntityTraverser, IEntity } from '@awayjs/view';
4
+ PickEntity, IEntityTraverser, IEntity,
5
+ IPickable } from '@awayjs/view';
5
6
 
6
7
  import { IMaterial } from '@awayjs/renderer';
7
8
 
@@ -10,13 +11,15 @@ import { DisplayObject } from './DisplayObject';
10
11
  /**
11
12
  * A Line Segment primitive.
12
13
  */
13
- export class LineSegment extends DisplayObject {
14
+ export class LineSegment extends DisplayObject implements IPickable {
14
15
  public static assetType: string = '[asset LineSegment]';
15
16
 
16
17
  public _startPosition: Vector3D;
17
18
  public _endPosition: Vector3D;
18
19
  public _halfThickness: number;
19
20
 
21
+ public _pickObjects: Record<number, _Pick_PickableBase> = {};
22
+
20
23
  /**
21
24
  *
22
25
  */
@@ -89,6 +92,13 @@ export class LineSegment extends DisplayObject {
89
92
  this._halfThickness = thickness * 0.5;
90
93
  }
91
94
 
95
+ public invalidateElements(): void {
96
+ for (const key in this._pickObjects)
97
+ this._pickObjects[key]._onInvalidateElements();
98
+
99
+ super.invalidateElements();
100
+ }
101
+
92
102
  public getEntity(): IEntity {
93
103
  return this;
94
104
  }
@@ -116,11 +126,12 @@ export class _Render_LineSegment extends _Render_RenderableBase {
116
126
  * @protected
117
127
  */
118
128
  protected _getStageElements(): _Stage_ElementsBase {
119
- const elements: LineElements = _Render_LineSegment._lineGraphics[(<LineSegment> this._asset).id]
120
- || (_Render_LineSegment._lineGraphics[(<LineSegment> this._asset).id] = new LineElements());
129
+ const lineSegment: LineSegment = <LineSegment> this.renderable;
130
+ const elements: LineElements = _Render_LineSegment._lineGraphics[lineSegment.id]
131
+ || (_Render_LineSegment._lineGraphics[lineSegment.id] = new LineElements());
121
132
 
122
- const start: Vector3D = (<LineSegment> this._asset).startPosition;
123
- const end: Vector3D = (<LineSegment> this._asset).endPosition;
133
+ const start: Vector3D = lineSegment.startPosition;
134
+ const end: Vector3D = lineSegment.endPosition;
124
135
 
125
136
  const positions: Float32Array = new Float32Array(6);
126
137
  const thickness: Float32Array = new Float32Array(1);
@@ -131,22 +142,25 @@ export class _Render_LineSegment extends _Render_RenderableBase {
131
142
  positions[3] = end.x;
132
143
  positions[4] = end.y;
133
144
  positions[5] = end.z;
134
- thickness[0] = (<LineSegment> this._asset).thickness;
145
+ thickness[0] = lineSegment.thickness;
135
146
 
136
147
  elements.setPositions(positions);
137
148
  elements.setThickness(thickness);
138
149
 
139
- return elements.getAbstraction<_Stage_ElementsBase>(this._stage);
150
+ return this._stage.abstractions.getAbstraction<_Stage_ElementsBase>(elements);
140
151
  }
141
152
 
142
153
  protected _getRenderMaterial(): _Render_MaterialBase {
143
- const material: IMaterial = (<LineSegment> this._asset).material || MaterialUtils.getDefaultColorMaterial();
144
- return material.getAbstraction<_Render_MaterialBase>(
145
- this.entity.renderer.getRenderElements(this.stageElements.elements));
154
+ return this.entity.renderer
155
+ .getRenderElements(this.stageElements.elements).abstractions
156
+ .getAbstraction<_Render_MaterialBase>(
157
+ (<LineSegment> this.renderable).material
158
+ || MaterialUtils.getDefaultColorMaterial()
159
+ );
146
160
  }
147
161
 
148
162
  protected _getStyle(): Style {
149
- return (<LineSegment> this._asset).style;
163
+ return this.renderable.style;
150
164
  }
151
165
  }
152
166
 
@@ -164,8 +178,9 @@ export class _Pick_LineSegment extends _Pick_PickableBase {
164
178
  if (this._orientedBoxBoundsDirty) {
165
179
  this._orientedBoxBoundsDirty = false;
166
180
 
167
- const startPosition: Vector3D = (<LineSegment> this._asset).startPosition;
168
- const endPosition: Vector3D = (<LineSegment> this._asset).endPosition;
181
+ const lineSegment: LineSegment = <LineSegment> this.pickable;
182
+ const startPosition: Vector3D = lineSegment.startPosition;
183
+ const endPosition: Vector3D = lineSegment.endPosition;
169
184
 
170
185
  this._orientedBoxBounds = new Box(Math.min(startPosition.x, endPosition.x),
171
186
  Math.min(startPosition.y, endPosition.y),
@@ -185,8 +200,9 @@ export class _Pick_LineSegment extends _Pick_PickableBase {
185
200
  if (this._orientedSphereBoundsDirty) {
186
201
  this._orientedSphereBoundsDirty = false;
187
202
 
188
- const startPosition: Vector3D = (<LineSegment> this._asset).startPosition;
189
- const endPosition: Vector3D = (<LineSegment> this._asset).endPosition;
203
+ const lineSegment: LineSegment = <LineSegment> this.pickable;
204
+ const startPosition: Vector3D = lineSegment.startPosition;
205
+ const endPosition: Vector3D = lineSegment.endPosition;
190
206
 
191
207
  const halfWidth: number = (endPosition.x - startPosition.x) / 2;
192
208
  const halfHeight: number = (endPosition.y - startPosition.y) / 2;
@@ -205,17 +205,14 @@ import { SkyboxElements, _Stage_SkyboxElements } from '../elements/SkyboxElement
205
205
  * using material methods to define their appearance.
206
206
  */
207
207
  export class _Render_SkyboxMaterial extends _Render_MaterialPassBase {
208
- public _skybox: Skybox;
209
208
  public _texture: _Shader_TextureBase;
210
209
 
211
210
  public init(skybox: Skybox, renderElements: _Render_ElementsBase): void {
212
211
  super.init(skybox, renderElements);
213
212
 
214
- this._skybox = skybox;
215
-
216
213
  this._shader = new ShaderBase(renderElements, this, this, this._stage);
217
214
 
218
- this._texture = this._skybox.texture.getAbstraction<_Shader_TextureBase>(this._shader);
215
+ this._texture = this._shader.abstractions.getAbstraction<_Shader_TextureBase>((<Skybox> this.material).texture);
219
216
 
220
217
  this._pAddPass(this);
221
218
  }
@@ -225,8 +222,6 @@ export class _Render_SkyboxMaterial extends _Render_MaterialPassBase {
225
222
 
226
223
  this._texture.onClear();
227
224
  this._texture = null;
228
-
229
- this._skybox = null;
230
225
  }
231
226
 
232
227
  /**
@@ -235,10 +230,12 @@ export class _Render_SkyboxMaterial extends _Render_MaterialPassBase {
235
230
  public _pUpdateRender(): void {
236
231
  super._pUpdateRender();
237
232
 
238
- this.requiresBlending = ((<IMaterial> this._asset).blendMode != BlendMode.NORMAL);
233
+ const material: IMaterial = this.material;
234
+
235
+ this.requiresBlending = (material.blendMode != BlendMode.NORMAL);
239
236
 
240
- this.shader.setBlendMode(((<IMaterial> this._asset).blendMode == BlendMode.NORMAL && this.requiresBlending) ?
241
- BlendMode.LAYER : (<IMaterial> this._asset).blendMode);
237
+ this.shader.setBlendMode((material.blendMode == BlendMode.NORMAL && this.requiresBlending) ?
238
+ BlendMode.LAYER : material.blendMode);
242
239
  }
243
240
 
244
241
  public _includeDependencies(shader: ShaderBase): void {
@@ -303,16 +300,17 @@ export class _Render_Skybox extends _Render_RenderableBase {
303
300
  -1,-1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1));
304
301
  }
305
302
 
306
- return elements.getAbstraction<_Stage_SkyboxElements>(this._stage);
303
+ return this._stage.abstractions.getAbstraction<_Stage_SkyboxElements>(elements);
307
304
  }
308
305
 
309
306
  protected _getRenderMaterial(): _Render_SkyboxMaterial {
310
- return this._asset.getAbstraction<_Render_SkyboxMaterial>(
311
- this.entity.renderer.getRenderElements(this.stageElements.elements));
307
+ return this.entity.renderer
308
+ .getRenderElements(this.stageElements.elements).abstractions
309
+ .getAbstraction<_Render_SkyboxMaterial>(this.renderable);
312
310
  }
313
311
 
314
312
  protected _getStyle(): Style {
315
- return (<Skybox> this._asset).style;
313
+ return this.renderable.style;
316
314
  }
317
315
  }
318
316
 
@@ -126,14 +126,14 @@ export class _Stage_SkyboxElements extends _Stage_TriangleElements {
126
126
 
127
127
  shader.viewMatrix.copyFrom(this._skyboxProjection, true);
128
128
 
129
- const context: IContextGL = this._stage.context;
129
+ const context: IContextGL = (<Stage> this._pool).context;
130
130
  context.setProgramConstantsFromArray(ContextGLProgramType.VERTEX, shader.vertexConstantData);
131
131
  context.setProgramConstantsFromArray(ContextGLProgramType.FRAGMENT, shader.fragmentConstantData);
132
132
 
133
133
  if (this._indices)
134
134
  this.getIndexBufferGL().draw(ContextGLDrawMode.TRIANGLES, 0, this.numIndices);
135
135
  else
136
- this._stage.context.drawVertices(ContextGLDrawMode.TRIANGLES, offset, count || this.numVertices);
136
+ (<Stage> this._pool).context.drawVertices(ContextGLDrawMode.TRIANGLES, offset, count || this.numVertices);
137
137
  }
138
138
  }
139
139
 
@@ -838,14 +838,7 @@ export class SceneImage2D extends BitmapImage2D {
838
838
  renderer.view.width = this.width;
839
839
  renderer.view.height = this.height;
840
840
 
841
- let sourceNode: ContainerNode = rootNode.getChildAt(0);
842
-
843
- if (sourceNode?.container != source) {
844
- if (sourceNode)
845
- rootNode.removeChildAt(0);
846
- sourceNode = rootNode.addChildAt(source, 0);
847
- }
848
-
841
+ const sourceNode: ContainerNode = rootNode.addChildAt(source, 0);
849
842
  const transformDisabled = sourceNode.transformDisabled;
850
843
 
851
844
  sourceNode.transformDisabled = true;
@@ -869,6 +862,8 @@ export class SceneImage2D extends BitmapImage2D {
869
862
  renderer.antiAlias = 0;
870
863
  renderer.disableClear = true;
871
864
 
865
+ rootNode.removeChildAt(0);
866
+
872
867
  sourceNode.transformDisabled = transformDisabled;
873
868
 
874
869
  if (useTemp) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.314",
3
+ "version": "0.13.316",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",