@awayjs/scene 0.13.264 → 0.13.266

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 (268) hide show
  1. package/.eslintrc +100 -100
  2. package/README.md +61 -61
  3. package/bundle/awayjs-scene.umd.js +2 -2
  4. package/bundle/awayjs-scene.umd.js.map +1 -1
  5. package/copyVersionToIndex.js +23 -23
  6. package/dist/index.d.ts +76 -75
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +67 -66
  9. package/dist/lib/Scene.d.ts +84 -84
  10. package/dist/lib/Scene.js +288 -288
  11. package/dist/lib/Settings.d.ts +16 -16
  12. package/dist/lib/Settings.js +60 -60
  13. package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
  14. package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
  15. package/dist/lib/adapters/IFilter.d.ts +24 -24
  16. package/dist/lib/adapters/IFilter.js +1 -1
  17. package/dist/lib/adapters/IMovieClipAdapter.d.ts +14 -14
  18. package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
  19. package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
  20. package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
  21. package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
  22. package/dist/lib/base/IBitmapDrawable.js +1 -1
  23. package/dist/lib/base/IFrameLabel.d.ts +4 -4
  24. package/dist/lib/base/IFrameLabel.js +1 -1
  25. package/dist/lib/base/IFrameScript.d.ts +5 -5
  26. package/dist/lib/base/IFrameScript.js +1 -1
  27. package/dist/lib/base/MouseButtons.d.ts +26 -22
  28. package/dist/lib/base/MouseButtons.d.ts.map +1 -1
  29. package/dist/lib/base/MouseButtons.js +1 -1
  30. package/dist/lib/base/Timeline.d.ts +148 -148
  31. package/dist/lib/base/Timeline.js +535 -535
  32. package/dist/lib/base/TimelineActionType.d.ts +18 -18
  33. package/dist/lib/base/TimelineActionType.js +1 -1
  34. package/dist/lib/controllers/ControllerBase.d.ts +14 -14
  35. package/dist/lib/controllers/ControllerBase.js +60 -60
  36. package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
  37. package/dist/lib/controllers/FirstPersonController.js +228 -228
  38. package/dist/lib/controllers/FollowController.d.ts +12 -12
  39. package/dist/lib/controllers/FollowController.js +27 -27
  40. package/dist/lib/controllers/HoverController.d.ts +105 -105
  41. package/dist/lib/controllers/HoverController.js +302 -302
  42. package/dist/lib/controllers/LookAtController.d.ts +14 -14
  43. package/dist/lib/controllers/LookAtController.js +68 -68
  44. package/dist/lib/controllers/SpringController.d.ts +38 -38
  45. package/dist/lib/controllers/SpringController.js +59 -59
  46. package/dist/lib/display/Billboard.d.ts +147 -147
  47. package/dist/lib/display/Billboard.js +426 -426
  48. package/dist/lib/display/Camera.d.ts +40 -40
  49. package/dist/lib/display/Camera.js +90 -90
  50. package/dist/lib/display/DisplayObject.d.ts +938 -938
  51. package/dist/lib/display/DisplayObject.js +1641 -1641
  52. package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
  53. package/dist/lib/display/DisplayObjectContainer.js +480 -480
  54. package/dist/lib/display/LineSegment.d.ts +84 -84
  55. package/dist/lib/display/LineSegment.js +215 -215
  56. package/dist/lib/display/LoaderContainer.d.ts +504 -504
  57. package/dist/lib/display/LoaderContainer.js +603 -603
  58. package/dist/lib/display/MorphSprite.d.ts +20 -20
  59. package/dist/lib/display/MorphSprite.js +254 -254
  60. package/dist/lib/display/MovieClip.d.ts +152 -152
  61. package/dist/lib/display/MovieClip.js +735 -735
  62. package/dist/lib/display/SimpleButton.d.ts +158 -158
  63. package/dist/lib/display/SimpleButton.js +228 -228
  64. package/dist/lib/display/Skybox.d.ts +156 -156
  65. package/dist/lib/display/Skybox.js +309 -309
  66. package/dist/lib/display/Sprite.d.ts +70 -70
  67. package/dist/lib/display/Sprite.js +144 -144
  68. package/dist/lib/display/TextField.d.ts +1109 -1109
  69. package/dist/lib/display/TextField.js +3109 -3109
  70. package/dist/lib/display/TextSprite.d.ts +10 -10
  71. package/dist/lib/display/TextSprite.js +25 -25
  72. package/dist/lib/elements/SkyboxElements.d.ts +29 -29
  73. package/dist/lib/elements/SkyboxElements.js +127 -127
  74. package/dist/lib/errors/CastError.d.ts +4 -4
  75. package/dist/lib/errors/CastError.js +10 -10
  76. package/dist/lib/events/CameraEvent.d.ts +16 -16
  77. package/dist/lib/events/CameraEvent.js +30 -30
  78. package/dist/lib/events/FocusEvent.d.ts +42 -42
  79. package/dist/lib/events/FocusEvent.js +43 -43
  80. package/dist/lib/events/KeyboardEvent.d.ts +21 -21
  81. package/dist/lib/events/KeyboardEvent.js +43 -43
  82. package/dist/lib/events/MouseEvent.d.ts +91 -184
  83. package/dist/lib/events/MouseEvent.d.ts.map +1 -1
  84. package/dist/lib/events/MouseEvent.js +122 -191
  85. package/dist/lib/events/PointerEvent.d.ts +94 -0
  86. package/dist/lib/events/PointerEvent.d.ts.map +1 -0
  87. package/dist/lib/events/PointerEvent.js +73 -0
  88. package/dist/lib/events/ResizeEvent.d.ts +15 -15
  89. package/dist/lib/events/ResizeEvent.js +38 -38
  90. package/dist/lib/events/TextfieldEvent.d.ts +19 -19
  91. package/dist/lib/events/TextfieldEvent.js +28 -28
  92. package/dist/lib/events/TouchEvent.d.ts +51 -0
  93. package/dist/lib/events/TouchEvent.d.ts.map +1 -0
  94. package/dist/lib/events/TouchEvent.js +83 -0
  95. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +26 -26
  96. package/dist/lib/factories/DefaultSceneGraphFactory.js +54 -54
  97. package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
  98. package/dist/lib/factories/ISceneGraphFactory.js +1 -1
  99. package/dist/lib/image/SceneImage2D.d.ts +236 -236
  100. package/dist/lib/image/SceneImage2D.js +687 -687
  101. package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
  102. package/dist/lib/managers/DefaultFontManager.js +101 -101
  103. package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
  104. package/dist/lib/managers/DeviceFontManager.js +44 -44
  105. package/dist/lib/managers/FrameScriptManager.d.ts +36 -36
  106. package/dist/lib/managers/FrameScriptManager.js +377 -377
  107. package/dist/lib/managers/IInputRecorder.d.ts +3 -3
  108. package/dist/lib/managers/IInputRecorder.js +1 -1
  109. package/dist/lib/managers/MouseManager.d.ts +76 -89
  110. package/dist/lib/managers/MouseManager.d.ts.map +1 -1
  111. package/dist/lib/managers/MouseManager.js +809 -759
  112. package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
  113. package/dist/lib/prefabs/PrefabBase.js +42 -42
  114. package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
  115. package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
  116. package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
  117. package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
  118. package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
  119. package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
  120. package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
  121. package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
  122. package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
  123. package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
  124. package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
  125. package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
  126. package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
  127. package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
  128. package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
  129. package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
  130. package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
  131. package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
  132. package/dist/lib/text/AntiAliasType.d.ts +24 -24
  133. package/dist/lib/text/AntiAliasType.js +28 -28
  134. package/dist/lib/text/BitmapFontChar.d.ts +39 -39
  135. package/dist/lib/text/BitmapFontChar.js +42 -42
  136. package/dist/lib/text/BitmapFontTable.d.ts +80 -80
  137. package/dist/lib/text/BitmapFontTable.js +203 -203
  138. package/dist/lib/text/FNTGenerator.d.ts +10 -10
  139. package/dist/lib/text/FNTGenerator.js +74 -74
  140. package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
  141. package/dist/lib/text/FNTGeneratorCanvas.js +205 -205
  142. package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
  143. package/dist/lib/text/FNTGeneratrorBase.js +7 -7
  144. package/dist/lib/text/Font.d.ts +38 -38
  145. package/dist/lib/text/Font.js +109 -109
  146. package/dist/lib/text/FontLookUpMode.d.ts +5 -5
  147. package/dist/lib/text/FontLookUpMode.js +7 -7
  148. package/dist/lib/text/FontStyleName.d.ts +6 -6
  149. package/dist/lib/text/FontStyleName.js +7 -7
  150. package/dist/lib/text/GridFitType.d.ts +31 -31
  151. package/dist/lib/text/GridFitType.js +35 -35
  152. package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
  153. package/dist/lib/text/HTMLTextProcessor.js +423 -423
  154. package/dist/lib/text/IFontTable.d.ts +16 -16
  155. package/dist/lib/text/IFontTable.js +1 -1
  156. package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
  157. package/dist/lib/text/TesselatedFontChar.js +66 -66
  158. package/dist/lib/text/TesselatedFontTable.d.ts +95 -95
  159. package/dist/lib/text/TesselatedFontTable.js +992 -992
  160. package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
  161. package/dist/lib/text/TextFieldAutoSize.js +32 -32
  162. package/dist/lib/text/TextFieldType.d.ts +20 -20
  163. package/dist/lib/text/TextFieldType.js +24 -24
  164. package/dist/lib/text/TextFormat.d.ts +273 -273
  165. package/dist/lib/text/TextFormat.js +440 -440
  166. package/dist/lib/text/TextFormatAlign.d.ts +26 -26
  167. package/dist/lib/text/TextFormatAlign.js +30 -30
  168. package/dist/lib/text/TextInteractionMode.d.ts +21 -21
  169. package/dist/lib/text/TextInteractionMode.js +25 -25
  170. package/dist/lib/text/TextLineMetrics.d.ts +61 -61
  171. package/dist/lib/text/TextLineMetrics.js +42 -42
  172. package/dist/lib/text/TextShape.d.ts +20 -20
  173. package/dist/lib/text/TextShape.js +75 -75
  174. package/dist/lib/tools/Merge.d.ts +81 -81
  175. package/dist/lib/tools/Merge.js +266 -266
  176. package/dist/lib/utils/Cast.d.ts +20 -20
  177. package/dist/lib/utils/Cast.js +271 -271
  178. package/index.ts +92 -91
  179. package/lib/Scene.ts +343 -343
  180. package/lib/Settings.ts +83 -83
  181. package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
  182. package/lib/adapters/IFilter.ts +25 -25
  183. package/lib/adapters/IMovieClipAdapter.ts +24 -24
  184. package/lib/adapters/ITextfieldAdapter.ts +6 -6
  185. package/lib/base/IBitmapDrawable.ts +13 -13
  186. package/lib/base/IFrameLabel.ts +3 -3
  187. package/lib/base/IFrameScript.ts +4 -4
  188. package/lib/base/MouseButtons.ts +31 -26
  189. package/lib/base/Timeline.ts +727 -727
  190. package/lib/base/TimelineActionType.ts +18 -18
  191. package/lib/controllers/ControllerBase.ts +66 -66
  192. package/lib/controllers/FirstPersonController.ts +241 -241
  193. package/lib/controllers/FollowController.ts +22 -22
  194. package/lib/controllers/HoverController.ts +304 -304
  195. package/lib/controllers/LookAtController.ts +75 -75
  196. package/lib/controllers/SpringController.ts +91 -91
  197. package/lib/display/Billboard.ts +504 -504
  198. package/lib/display/Camera.ts +89 -89
  199. package/lib/display/DisplayObject.ts +1893 -1893
  200. package/lib/display/DisplayObjectContainer.ts +538 -538
  201. package/lib/display/LineSegment.ts +248 -248
  202. package/lib/display/LoaderContainer.ts +651 -651
  203. package/lib/display/MorphSprite.ts +347 -347
  204. package/lib/display/MovieClip.ts +879 -879
  205. package/lib/display/SimpleButton.ts +224 -224
  206. package/lib/display/Skybox.ts +379 -379
  207. package/lib/display/Sprite.ts +165 -165
  208. package/lib/display/TextField.ts +3958 -3958
  209. package/lib/display/TextSprite.ts +22 -22
  210. package/lib/elements/SkyboxElements.ts +141 -141
  211. package/lib/errors/CastError.ts +6 -6
  212. package/lib/events/CameraEvent.ts +29 -29
  213. package/lib/events/FocusEvent.ts +69 -69
  214. package/lib/events/KeyboardEvent.ts +40 -40
  215. package/lib/events/MouseEvent.ts +147 -287
  216. package/lib/events/PointerEvent.ts +146 -0
  217. package/lib/events/ResizeEvent.ts +31 -31
  218. package/lib/events/TextfieldEvent.ts +28 -28
  219. package/lib/events/TouchEvent.ts +101 -0
  220. package/lib/factories/DefaultSceneGraphFactory.ts +56 -56
  221. package/lib/factories/ISceneGraphFactory.ts +28 -28
  222. package/lib/image/SceneImage2D.ts +1020 -1020
  223. package/lib/managers/DefaultFontManager.ts +124 -124
  224. package/lib/managers/DeviceFontManager.ts +55 -55
  225. package/lib/managers/FrameScriptManager.ts +431 -431
  226. package/lib/managers/IInputRecorder.ts +2 -2
  227. package/lib/managers/MouseManager.ts +944 -882
  228. package/lib/prefabs/PrefabBase.ts +47 -47
  229. package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
  230. package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
  231. package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
  232. package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
  233. package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
  234. package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
  235. package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
  236. package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
  237. package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
  238. package/lib/text/AntiAliasType.ts +24 -24
  239. package/lib/text/BitmapFontChar.ts +53 -53
  240. package/lib/text/BitmapFontTable.ts +232 -232
  241. package/lib/text/FNTGenerator.ts +100 -100
  242. package/lib/text/FNTGeneratorCanvas.ts +287 -287
  243. package/lib/text/FNTGeneratrorBase.ts +10 -10
  244. package/lib/text/Font.ts +114 -114
  245. package/lib/text/FontLookUpMode.ts +5 -5
  246. package/lib/text/FontStyleName.ts +6 -6
  247. package/lib/text/GridFitType.ts +32 -32
  248. package/lib/text/HTMLTextProcessor.ts +418 -418
  249. package/lib/text/IFontTable.ts +17 -17
  250. package/lib/text/TesselatedFontChar.ts +80 -80
  251. package/lib/text/TesselatedFontTable.ts +1221 -1221
  252. package/lib/text/TextFieldAutoSize.ts +30 -30
  253. package/lib/text/TextFieldType.ts +21 -21
  254. package/lib/text/TextFormat.ts +601 -601
  255. package/lib/text/TextFormatAlign.ts +28 -28
  256. package/lib/text/TextInteractionMode.ts +21 -21
  257. package/lib/text/TextLineMetrics.ts +74 -74
  258. package/lib/text/TextShape.ts +90 -90
  259. package/lib/tools/Merge.ts +311 -311
  260. package/lib/utils/Cast.ts +304 -304
  261. package/package.json +74 -74
  262. package/rollup.config.js +33 -33
  263. package/scripts/build.sh +2 -2
  264. package/scripts/gendocs.sh +14 -14
  265. package/scripts/genexamples.sh +14 -14
  266. package/scripts/genfull.sh +14 -14
  267. package/system.config.js +51 -51
  268. package/tsconfig.json +18 -18
@@ -1,687 +1,687 @@
1
- import { __extends } from "tslib";
2
- import { View } from '@awayjs/view';
3
- import { MethodMaterial } from '@awayjs/materials';
4
- import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
5
- import { DisplayObject } from '../display/DisplayObject';
6
- import { Billboard } from '../display/Billboard';
7
- import { Settings } from '../Settings';
8
- import { Rectangle, Point, PerspectiveProjection, CoordinateSystem, Vector3D, Transform, ColorUtils } from '@awayjs/core';
9
- import { Stage, BitmapImage2D, _Stage_BitmapImage2D, BlendMode } from '@awayjs/stage';
10
- import { DefaultRenderer, RenderGroup, Style } from '@awayjs/renderer';
11
- // empty matrix for transform reset
12
- var TMP_POINT = new Point(0, 0);
13
- /**
14
- *
15
- */
16
- var SceneImage2D = /** @class */ (function (_super) {
17
- __extends(SceneImage2D, _super);
18
- /**
19
- * Creates a BitmapImage2D object with a specified width and height. If you
20
- * specify a value for the <code>fillColor</code> parameter, every pixel in
21
- * the bitmap is set to that color.
22
- *
23
- * <p>By default, the bitmap is created as transparent, unless you pass
24
- * the value <code>false</code> for the transparent parameter. After you
25
- * create an opaque bitmap, you cannot change it to a transparent bitmap.
26
- * Every pixel in an opaque bitmap uses only 24 bits of color channel
27
- * information. If you define the bitmap as transparent, every pixel uses 32
28
- * bits of color channel information, including an alpha transparency
29
- * channel.</p>
30
- *
31
- * @param width The width of the bitmap image in pixels.
32
- * @param height The height of the bitmap image in pixels.
33
- * @param transparent Specifies whether the bitmap image supports per-pixel
34
- * transparency. The default value is <code>true</code>
35
- * (transparent). To create a fully transparent bitmap,
36
- * set the value of the <code>transparent</code>
37
- * parameter to <code>true</code> and the value of the
38
- * <code>fillColor</code> parameter to 0x00000000(or to
39
- * 0). Setting the <code>transparent</code> property to
40
- * <code>false</code> can result in minor improvements
41
- * in rendering performance.
42
- * @param fillColor A 32-bit ARGB color value that you use to fill the
43
- * bitmap image area. The default value is
44
- * 0xFFFFFFFF(solid white).
45
- */
46
- function SceneImage2D(width, height, transparent, fillColor, powerOfTwo, stage) {
47
- if (transparent === void 0) { transparent = true; }
48
- if (fillColor === void 0) { fillColor = 0xffffffff; }
49
- if (powerOfTwo === void 0) { powerOfTwo = true; }
50
- if (stage === void 0) { stage = null; }
51
- var _this = _super.call(this, width, height, transparent, null, powerOfTwo, stage) || this;
52
- _this._initalFillColor = null;
53
- _this._lastUsedFill = null;
54
- _this._internalSync = false;
55
- _this._msaaNeedDrop = false;
56
- _this._enforceMSAASupport = false;
57
- /*private*/ _this._antialiasQuality = Settings.ALLOW_FORCE_MSAA;
58
- _this._clearFromDispose = false;
59
- _this._initalFillColor = fillColor;
60
- _this._lastUsedFill = fillColor;
61
- return _this;
62
- }
63
- SceneImage2D.getImage = function (width, height, transparent, fillColor, powerOfTwo, stage, msaa) {
64
- if (transparent === void 0) { transparent = true; }
65
- if (fillColor === void 0) { fillColor = 0xffffffff; }
66
- if (powerOfTwo === void 0) { powerOfTwo = true; }
67
- if (stage === void 0) { stage = null; }
68
- if (msaa === void 0) { msaa = false; }
69
- var result = new SceneImage2D(width, height, transparent, fillColor, powerOfTwo, stage);
70
- if (!msaa) {
71
- result._msaaNeedDrop = true;
72
- result._antialiasQuality = 0;
73
- }
74
- else {
75
- result._enforceMSAASupport = true;
76
- }
77
- return result;
78
- };
79
- SceneImage2D.tryStoreImage = function (image, stage) {
80
- stage.filterManager.pushTemp(image);
81
- };
82
- SceneImage2D.getTemp = function (width, height, stage, msaa) {
83
- if (msaa === void 0) { msaa = false; }
84
- var image = stage.filterManager.popTemp(width, height, msaa && Settings.ALLOW_FORCE_MSAA > 1);
85
- image.antialiasQuality = msaa ? Settings.ALLOW_FORCE_MSAA : 0;
86
- return image;
87
- };
88
- SceneImage2D.prototype._dropMSAA = function () {
89
- if (this._msaaNeedDrop || !this.canUseMSAAInternaly) {
90
- return;
91
- }
92
- this._enforceMSAASupport = false;
93
- this._msaaNeedDrop = true;
94
- // force dispose texture and buffers
95
- // MSAA not stored in pool
96
- if (this.wasUpload) {
97
- // super unload not call sync, we call it
98
- _super.prototype.unload.call(this);
99
- }
100
- console.debug('[SceneImage2D Experemental] Drop MSAA support because a setPixel* operation called after upload.', this.id);
101
- };
102
- Object.defineProperty(SceneImage2D.prototype, "canUseMSAAInternaly", {
103
- get: function () {
104
- if (this._enforceMSAASupport) {
105
- return true;
106
- }
107
- var minW = Settings.MSAA_MINIMAL_IMAGE_SIZE;
108
- var minH = Settings.MSAA_MINIMAL_IMAGE_SIZE;
109
- if (this._stage) {
110
- minH = Math.min(this._stage.height, minH);
111
- minW = Math.min(this._stage.width, minW);
112
- }
113
- return (this.width >= minW &&
114
- this.height >= minH &&
115
- !this._msaaNeedDrop);
116
- },
117
- enumerable: false,
118
- configurable: true
119
- });
120
- Object.defineProperty(SceneImage2D.prototype, "antialiasQuality", {
121
- get: function () {
122
- return this.canUseMSAAInternaly ? this._antialiasQuality : 0;
123
- },
124
- enumerable: false,
125
- configurable: true
126
- });
127
- SceneImage2D.prototype.syncData = function (async) {
128
- var _this = this;
129
- if (async === void 0) { async = false; }
130
- if (async && this._asyncRead) {
131
- return this._asyncRead;
132
- }
133
- if (!async && this._asyncRead) {
134
- throw '[SceneImage2D] Synced read not allowed while async read is requested!';
135
- }
136
- this.applySymbol();
137
- // update data from pixels from GPU
138
- if (!this._imageDataDirty) {
139
- return async ? Promise.resolve(false) : false;
140
- }
141
- var context = this._stage.context;
142
- this._stage.setRenderTarget(this, false);
143
- // when we call syncData, we already loose other data
144
- // not require apply symbol etc, because it already should be applied
145
- if (!this._data) {
146
- this._data = new Uint8ClampedArray(this.width * this.height * 4);
147
- }
148
- // mark that this internal call, avoid reqursion loop
149
- this._internalSync = true;
150
- this._asyncRead = context.drawToBitmapImage2D(this, false, async);
151
- this._internalSync = false;
152
- this._stage.setRenderTarget(null);
153
- if (!async) {
154
- this._imageDataDirty = false;
155
- // we store pixel buffer already as PMA.
156
- // we should prevent unpack what already is PMA
157
- this._unpackPMA = false;
158
- return true;
159
- }
160
- return this._asyncRead.then(function (_status) {
161
- _this._imageDataDirty = false;
162
- _this._unpackPMA = false;
163
- _this._asyncRead = null;
164
- return true;
165
- });
166
- };
167
- /* overide internal */ SceneImage2D.prototype.getDataInternal = function (constructEmpty, skipSync) {
168
- if (constructEmpty === void 0) { constructEmpty = true; }
169
- if (skipSync === void 0) { skipSync = false; }
170
- // if sync called, check that this is requried
171
- if (!skipSync && this._imageDataDirty && !this._internalSync) {
172
- // sync data already should fill _data
173
- this.syncData(false);
174
- return this._data;
175
- }
176
- if (this._initalFillColor === null) {
177
- return _super.prototype.getDataInternal.call(this, constructEmpty, true);
178
- }
179
- // disable empty buffer filling
180
- // and check that buffer is empyt (has now symbol or alpha)
181
- var data = _super.prototype.getDataInternal.call(this, false, true);
182
- // if it empty, fill with initlal value
183
- if (!data) {
184
- // fill rect constuct buffer inside
185
- _super.prototype.fillRect.call(this, this.rect, this._initalFillColor);
186
- this._initalFillColor = null;
187
- return this._data;
188
- }
189
- return data;
190
- };
191
- Object.defineProperty(SceneImage2D.prototype, "assetType", {
192
- /**
193
- *
194
- * @returns {string}
195
- */
196
- get: function () {
197
- return SceneImage2D.assetType;
198
- },
199
- enumerable: false,
200
- configurable: true
201
- });
202
- SceneImage2D.prototype.createRenderer = function () {
203
- //create the projection
204
- var projection = new PerspectiveProjection();
205
- projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
206
- projection.originX = -1;
207
- projection.originY = 1;
208
- projection.transform = new Transform();
209
- projection.transform.scaleTo(1, -1, 1);
210
- projection.transform.moveTo(0, 0, -1000);
211
- //create the view
212
- SceneImage2D._view = new View(projection, this._stage);
213
- SceneImage2D._root = new DisplayObjectContainer();
214
- SceneImage2D._rootNode = SceneImage2D._view.getNode(SceneImage2D._root);
215
- SceneImage2D._renderer = RenderGroup
216
- .getInstance(DefaultRenderer)
217
- .getRenderer(SceneImage2D._rootNode.partition);
218
- //set the view properties
219
- SceneImage2D._view.backgroundAlpha = 0;
220
- SceneImage2D._view.backgroundColor = 0x0;
221
- //set the renderer properties
222
- SceneImage2D._renderer.disableClear = true;
223
- SceneImage2D._renderer.renderableSorter = null; //new RenderableSort2D();
224
- //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
225
- };
226
- SceneImage2D.prototype.createBillboardRenderer = function () {
227
- //create the projection
228
- var projection = new PerspectiveProjection();
229
- projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
230
- projection.originX = -1;
231
- projection.originY = 1;
232
- projection.transform = new Transform();
233
- projection.transform.moveTo(0, 0, -1000);
234
- projection.transform.lookAt(new Vector3D());
235
- //create the view
236
- SceneImage2D._billboardView = new View(projection, this._stage);
237
- SceneImage2D._billboardRoot = new DisplayObjectContainer();
238
- SceneImage2D._billboardRenderer = RenderGroup
239
- .getInstance(DefaultRenderer)
240
- .getRenderer(SceneImage2D._billboardView.getNode(SceneImage2D._billboardRoot).partition);
241
- //SceneImage2D._billboardRoot.partition = SceneImage2D._billboardRenderer.partition;
242
- //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
243
- //set the view properties
244
- SceneImage2D._billboardView.backgroundAlpha = 0;
245
- SceneImage2D._billboardView.backgroundColor = 0x0;
246
- //set the renderer properties
247
- SceneImage2D._billboardRenderer.disableClear = true;
248
- SceneImage2D._billboardRenderer.renderableSorter = null; //new RenderableSort2D();
249
- var mat = new MethodMaterial(new BitmapImage2D(128, 128, true, 0x0));
250
- mat.bothSides = true;
251
- mat.alphaBlending = true;
252
- SceneImage2D._billboard = new Billboard(mat);
253
- SceneImage2D._billboard.style = new Style();
254
- SceneImage2D._billboardRoot.addChild(SceneImage2D._billboard);
255
- };
256
- /**
257
- * Frees memory that is used to store the BitmapImage2D object.
258
- *
259
- * <p>When the <code>dispose()</code> method is called on an image, the width
260
- * and height of the image are set to 0. All subsequent calls to methods or
261
- * properties of this BitmapImage2D instance fail, and an exception is thrown.
262
- * </p>
263
- *
264
- * <p><code>BitmapImage2D.dispose()</code> releases the memory occupied by the
265
- * actual bitmap data, immediately(a bitmap can consume up to 64 MB of
266
- * memory). After using <code>BitmapImage2D.dispose()</code>, the BitmapImage2D
267
- * object is no longer usable and an exception may be thrown if
268
- * you call functions on the BitmapImage2D object. However,
269
- * <code>BitmapImage2D.dispose()</code> does not garbage collect the BitmapImage2D
270
- * object(approximately 128 bytes); the memory occupied by the actual
271
- * BitmapImage2D object is released at the time the BitmapImage2D object is
272
- * collected by the garbage collector.</p>
273
- *
274
- */
275
- SceneImage2D.prototype.dispose = function () {
276
- this._clearFromDispose = true;
277
- this.dropAllReferences();
278
- this.unmarkToUnload();
279
- this.unuseWeakRef();
280
- // drop buffer, because is big
281
- this._data = null;
282
- this._locked = false;
283
- _super.prototype.dispose.call(this);
284
- this._clearFromDispose = false;
285
- };
286
- SceneImage2D.prototype.unload = function () {
287
- var _this = this;
288
- // query async unload
289
- var t = this.syncData(true);
290
- // strict quard
291
- if (typeof t !== 'boolean') {
292
- t.then(function () { return _super.prototype.unload.call(_this); });
293
- return;
294
- }
295
- _super.prototype.unload.call(this);
296
- };
297
- SceneImage2D.prototype.deepClone = function (from) {
298
- this.copyPixels(from, this._rect, new Point(0, 0));
299
- };
300
- /**
301
- * Fills a rectangular area of pixels with a specified ARGB color.
302
- *
303
- * @param rect The rectangular area to fill.
304
- * @param color The ARGB color value that fills the area. ARGB colors are
305
- * often specified in hexadecimal format; for example,
306
- * 0xFF336699.
307
- * @throws TypeError The rect is null.
308
- */
309
- SceneImage2D.prototype.fillRect = function (rect, color) {
310
- this.dropAllReferences();
311
- var argb = ColorUtils.float32ColorToARGB(color);
312
- var alpha = this._transparent ? argb[0] / 255 : 1;
313
- var isCrop = rect !== this._rect && !this._rect.equals(rect);
314
- this._stage.setRenderTarget(this, true, 0, 0, true);
315
- this._stage.setScissor(rect);
316
- // we shure that color is fully filled when there are not any crops
317
- this._lastUsedFill = isCrop ? null : color;
318
- this._stage.clear((argb[1] / 0xff) * alpha, (argb[2] / 0xff) * alpha, (argb[3] / 0xff) * alpha, alpha);
319
- this._stage.setScissor(null);
320
- this._imageDataDirty = true;
321
- };
322
- /**
323
- * Provides a fast routine to perform pixel manipulation between images with
324
- * no stretching, rotation, or color effects. This method copies a
325
- * rectangular area of a source image to a rectangular area of the same size
326
- * at the destination point of the destination BitmapImage2D object.
327
- *
328
- * <p>If you include the <code>alphaBitmap</code> and <code>alphaPoint</code>
329
- * parameters, you can use a secondary image as an alpha source for the
330
- * source image. If the source image has alpha data, both sets of alpha data
331
- * are used to composite pixels from the source image to the destination
332
- * image. The <code>alphaPoint</code> parameter is the point in the alpha
333
- * image that corresponds to the upper-left corner of the source rectangle.
334
- * Any pixels outside the intersection of the source image and alpha image
335
- * are not copied to the destination image.</p>
336
- *
337
- * <p>The <code>mergeAlpha</code> property controls whether or not the alpha
338
- * channel is used when a transparent image is copied onto another
339
- * transparent image. To copy pixels with the alpha channel data, set the
340
- * <code>mergeAlpha</code> property to <code>true</code>. By default, the
341
- * <code>mergeAlpha</code> property is <code>false</code>.</p>
342
- *
343
- * @param source The input bitmap image from which to copy pixels.
344
- * The source image can be a different BitmapImage2D
345
- * instance, or it can refer to the current
346
- * BitmapImage2D instance.
347
- * @param sourceRect A rectangle that defines the area of the source
348
- * image to use as input.
349
- * @param destPoint The destination point that represents the
350
- * upper-left corner of the rectangular area where
351
- * the new pixels are placed.
352
- * @param alphaBitmapData A secondary, alpha BitmapImage2D object source.
353
- * @param alphaPoint The point in the alpha BitmapImage2D object source
354
- * that corresponds to the upper-left corner of the
355
- * <code>sourceRect</code> parameter.
356
- * @param mergeAlpha To use the alpha channel, set the value to
357
- * <code>true</code>. To copy pixels with no alpha
358
- * channel, set the value to <code>false</code>.
359
- * @throws TypeError The sourceBitmapImage2D, sourceRect, destPoint are null.
360
- */
361
- SceneImage2D.prototype.copyPixels = function (source, sourceRect, destPoint, alphaBitmapData, alphaPoint, mergeAlpha) {
362
- this._lastUsedFill = null;
363
- this.dropAllReferences();
364
- this.unmarkToUnload();
365
- // need drop alpha from source when target is not has alpha
366
- mergeAlpha = this.transparent !== source.transparent || mergeAlpha;
367
- // CPU based copy, not require run GPU based copy
368
- // block is equal, one of image not uploaded yet
369
- // and source image no require SYNC
370
- if (!source._imageDataDirty &&
371
- sourceRect.equals(this._rect) &&
372
- this._rect.equals(source.rect) &&
373
- !mergeAlpha && (!this.wasUpload || !source.wasUpload)) {
374
- var data = source.getDataInternal(true);
375
- // inline, instead of setPixels, because it use a lot of checks
376
- if (this._data) {
377
- this._data.set(data);
378
- }
379
- else {
380
- this._data = data.slice();
381
- }
382
- // we should sync this, because we can apply PMA twice, that not needed for us
383
- this._unpackPMA = source._unpackPMA;
384
- // we should reset initial color, because not require fill it after copyPixel
385
- this._initalFillColor = null;
386
- this._imageDataDirty = false;
387
- this.invalidateGPU();
388
- return;
389
- }
390
- if (source.width * source.height <= Settings.CPU_COPY_PIXELS_COUNT && !mergeAlpha) {
391
- // todo Not implemented yet, need to implement and check performance change
392
- // i think that increase some small operation performance,
393
- // because copy by GPU required upload array to VRAM,
394
- // and games that use set/get pixels and copyPixels only for math process not required use GPU copy
395
- }
396
- if (this._initalFillColor !== null) {
397
- this.fillRect(this._rect, this._initalFillColor);
398
- this._initalFillColor = null;
399
- }
400
- var compositeSource = source;
401
- // merge alpha with source
402
- if (alphaBitmapData) {
403
- compositeSource = this._stage.filterManager.popTemp(source.width, source.height);
404
- //this._stage.filterManager.copyPixels(source, compositeSource, source.rect, source.rect.topLeft);
405
- this._stage.filterManager.copyPixels(alphaBitmapData, compositeSource, new Rectangle(alphaPoint.x, alphaPoint.y, sourceRect.width, sourceRect.height), new Point(0, 0));
406
- this._stage.filterManager.copyPixels(source, compositeSource, source.rect, new Point(0, 0), true, 'alpha_back');
407
- }
408
- this._stage.filterManager.copyPixels(compositeSource, this, sourceRect, destPoint, mergeAlpha);
409
- if (alphaBitmapData) {
410
- this._stage.filterManager.pushTemp(compositeSource);
411
- }
412
- this._imageDataDirty = true;
413
- };
414
- SceneImage2D.prototype.threshold = function (source, sourceRect, destPoint, operation, threshold, color, mask, copySource) {
415
- this._lastUsedFill = null;
416
- this.dropAllReferences();
417
- this.unmarkToUnload();
418
- this._stage.threshold(source, this, sourceRect, destPoint, operation, threshold, color, mask, copySource);
419
- this._imageDataDirty = true;
420
- };
421
- SceneImage2D.prototype.applyFilter = function (source, sourceRect, destPoint, filter) {
422
- if (!Settings.USE_UNSAFE_FILTERS || !filter || !filter.filterName) {
423
- return false;
424
- }
425
- this.dropAllReferences(false);
426
- var result = this._stage.filterManager.applyFilter(source, this, sourceRect, destPoint, filter.filterName, filter);
427
- this._imageDataDirty = result;
428
- return result;
429
- };
430
- SceneImage2D.prototype.colorTransform = function (rect, colorTransform) {
431
- this.dropAllReferences();
432
- this.unmarkToUnload();
433
- this._lastUsedFill = null;
434
- this._stage.colorTransform(this, this, rect, colorTransform);
435
- this._imageDataDirty = true;
436
- };
437
- SceneImage2D.prototype.setPixel = function (x, y, color) {
438
- // we can't upload buffer in MSAA texture after creating - only render it and get
439
- if (this.canUseMSAAInternaly) {
440
- this._dropMSAA();
441
- }
442
- _super.prototype.setPixel.call(this, x, y, color);
443
- };
444
- SceneImage2D.prototype.setPixel32 = function (x, y, color) {
445
- // we can't upload buffer in MSAA texture after creating - only render it and get
446
- if (this.canUseMSAAInternaly) {
447
- this._dropMSAA();
448
- }
449
- _super.prototype.setPixel32.call(this, x, y, color);
450
- };
451
- SceneImage2D.prototype.setPixels = function (rect, buffer) {
452
- // we can't upload buffer in MSAA texture after creating - only render it and get
453
- if (this.wasUpload && this.canUseMSAAInternaly) {
454
- this._dropMSAA();
455
- }
456
- _super.prototype.setPixels.call(this, rect, buffer);
457
- };
458
- SceneImage2D.prototype.clear = function () {
459
- var _this = this;
460
- // we call clear in parent class from dispose, call direct
461
- if (this._clearFromDispose) {
462
- _super.prototype.clear.call(this);
463
- return;
464
- }
465
- // clear should drop abstraction, but we can't doing this if unloaded
466
- var t = this.syncData(true);
467
- // not require unload, we already doings this
468
- this.unmarkToUnload();
469
- this.lastUsedTime = -1;
470
- if (typeof t === 'boolean') {
471
- this.wasUpload = false;
472
- _super.prototype.clear.call(this);
473
- return;
474
- }
475
- t.then(function () {
476
- _this.wasUpload = false;
477
- _super.prototype.clear.call(_this);
478
- });
479
- };
480
- /**
481
- * @inheritdoc
482
- */
483
- SceneImage2D.prototype.getPixel32 = function (x, y) {
484
- this.syncData();
485
- return _super.prototype.getPixel32.call(this, x, y);
486
- };
487
- /**
488
- * @inheritdoc
489
- */
490
- SceneImage2D.prototype.getPixel = function (x, y) {
491
- var result = this.getPixel32(x, y);
492
- return result & 0x00ffffff;
493
- };
494
- SceneImage2D.prototype.draw = function (source, matrix, colorTransform, blendMode, clipRect, smoothing) {
495
- /* eslint-enable */
496
- this.dropAllReferences();
497
- this.unmarkToUnload();
498
- if (source instanceof DisplayObject) {
499
- this._drawAsDisplay(source, matrix, colorTransform, blendMode, clipRect, smoothing);
500
- }
501
- else {
502
- this._drawAsBitmap(source, matrix, colorTransform, blendMode, clipRect, smoothing);
503
- }
504
- this._lastUsedFill = null;
505
- this._imageDataDirty = true;
506
- this.invalidate();
507
- };
508
- SceneImage2D._mapSupportedBlendMode = function (blendMode) {
509
- if (blendMode === void 0) { blendMode = ''; }
510
- switch (blendMode) {
511
- case null:
512
- case '':
513
- case BlendMode.NORMAL:
514
- case BlendMode.LAYER:
515
- return BlendMode.LAYER;
516
- case BlendMode.MULTIPLY:
517
- case BlendMode.ADD:
518
- case BlendMode.ALPHA:
519
- return blendMode;
520
- }
521
- //console.debug("[ImageBitmap] Unsupport BlendMode", blendMode);
522
- return BlendMode.LAYER;
523
- };
524
- SceneImage2D.prototype._drawAsBitmap = function (source, matrix, colorTransform, blendMode, _clipRect, smoothing) {
525
- if (!SceneImage2D._billboardRenderer) {
526
- this.createBillboardRenderer();
527
- }
528
- if (this._initalFillColor !== null) {
529
- this.fillRect(this._rect, this._initalFillColor);
530
- this._initalFillColor = null;
531
- }
532
- var stage = this._stage;
533
- var mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
534
- var supportNativeBlend = !blendMode || mappedBlend !== BlendMode.LAYER || blendMode == BlendMode.LAYER;
535
- var useTmp = (!supportNativeBlend || this === source);
536
- var target = useTmp ?
537
- stage.filterManager.popTemp(this.width, this.height, false)
538
- : this;
539
- var renderer = SceneImage2D._billboardRenderer;
540
- var root = SceneImage2D._billboardRoot;
541
- var billboard = SceneImage2D._billboard;
542
- billboard.sampler.smooth = smoothing;
543
- renderer.disableClear = !useTmp;
544
- renderer.view.target = target;
545
- renderer.view.projection.scale = 1000 / target.height;
546
- billboard.material.style.image = source;
547
- // not all blend modes can be used for rendering
548
- billboard.material.blendMode = !useTmp ? SceneImage2D._mapSupportedBlendMode(blendMode) : BlendMode.LAYER;
549
- billboard.material.useColorTransform = !!colorTransform;
550
- if (matrix) {
551
- var m = root.transform.matrix3D;
552
- m.identity();
553
- m._rawData[0] = matrix.a;
554
- m._rawData[1] = -matrix.b;
555
- m._rawData[4] = matrix.c;
556
- m._rawData[5] = -matrix.d;
557
- m._rawData[12] = matrix.tx;
558
- m._rawData[13] = target.height - matrix.ty;
559
- root.transform.invalidateComponents();
560
- }
561
- else {
562
- root.transform.rotateTo(0, 0, 0);
563
- root.transform.scaleTo(1, -1, 1);
564
- root.transform.moveTo(0, target.height, 0);
565
- }
566
- root.transform.colorTransform = colorTransform;
567
- //render
568
- renderer.render();
569
- //
570
- if (useTmp) {
571
- stage.filterManager.copyPixels(target, this, this.rect, TMP_POINT, true, blendMode);
572
- stage.filterManager.pushTemp(target);
573
- }
574
- };
575
- SceneImage2D.prototype._drawAsDisplay = function (source, matrix, colorTransform, blendMode, _clipRect, _smoothing) {
576
- if (blendMode === void 0) { blendMode = ''; }
577
- // default global blend mode
578
- blendMode = blendMode || BlendMode.LAYER;
579
- if (!SceneImage2D._renderer) {
580
- this.createRenderer();
581
- }
582
- var root = SceneImage2D._root;
583
- var rootNode = SceneImage2D._rootNode;
584
- var renderer = SceneImage2D._renderer;
585
- // when we should use MSAA, we will create temporary image and draw to it
586
- var internal = this.canUseMSAAInternaly;
587
- var nativeMSAA = (!source.isAsset(Billboard) &&
588
- this._stage.context.glVersion === 2 && // can be used because a webgl2
589
- Settings.ALLOW_FORCE_MSAA > 1 && // because a quality is more that 1
590
- !internal); // and not internal
591
- // target image for rendering.
592
- var target = this;
593
- // we should run compositor when blendMode !== LAYER (default)
594
- // or when we use MSAA + fill is not flat.
595
- var useBlend = blendMode !== BlendMode.LAYER || this._lastUsedFill === null;
596
- var useTemp = useBlend || nativeMSAA;
597
- // lazy filling
598
- // we require fill image with initial color, because we not doing this immediate
599
- // and when blend is required, because we should blend with vald color
600
- if ((!nativeMSAA || useBlend) && this._initalFillColor !== null) {
601
- this.fillRect(this._rect, this._initalFillColor);
602
- this._initalFillColor = null;
603
- }
604
- if (useTemp) {
605
- target = SceneImage2D.getTemp(this.width, this.height, this._stage, nativeMSAA);
606
- // because target image is stupid filled - it not require merging
607
- // BUT when blend is required - we shpuld skip color clear and use empty TMP
608
- if (!useBlend && this._lastUsedFill !== null) {
609
- // bitmap was filled plain, go clear TMP to this color too
610
- renderer.disableClear = false;
611
- renderer.view.backgroundColor = this._lastUsedFill & 0xffffff;
612
- renderer.view.backgroundAlpha = this._transparent ? (this._lastUsedFill >>> 24 & 0xff) / 0xff : 1;
613
- }
614
- else {
615
- // we clear TMP and render to it, prepare to composing
616
- renderer.disableClear = false;
617
- renderer.view.backgroundColor = 0x0;
618
- renderer.view.backgroundAlpha = 0;
619
- // copy from source to tmp
620
- // TMP_POINT.setTo(0,0);
621
- // this._stage.copyPixels(this, target, this._rect, TMP_POINT, null, null, false);
622
- }
623
- }
624
- var transform = renderer.view.projection.transform;
625
- var mat3d = transform.matrix3D;
626
- mat3d.identity();
627
- if (matrix) {
628
- var raw = mat3d._rawData;
629
- raw[0] = matrix.a;
630
- raw[1] = matrix.b;
631
- raw[4] = matrix.c;
632
- raw[5] = matrix.d;
633
- raw[10] = 1;
634
- raw[12] = matrix.tx;
635
- raw[13] = matrix.ty;
636
- }
637
- // todo By this line we flip normals, and cull will be broken
638
- // NEED FIX THIS ASAP, or flip cull state
639
- mat3d.appendScale(1, -1, 1);
640
- mat3d.appendTranslation(0, this._rect.height, 1000);
641
- mat3d.invert();
642
- transform.matrix3D = mat3d;
643
- renderer.antiAlias = (internal ? this.antialiasQuality : target.antialiasQuality) || 0;
644
- renderer.view.target = target;
645
- renderer.view.projection.scale = 1000 / this._rect.height;
646
- // shift view, because target can be more
647
- renderer.view.projection.ratio = (this._rect.width / this._rect.height);
648
- renderer.view.x = -(target.width - this.width);
649
- renderer.view.y = -(target.height - this.height);
650
- renderer.view.width = this.width;
651
- renderer.view.height = this.height;
652
- var sourceNode = rootNode.addChildAt(source, 0);
653
- var transformDisabled = sourceNode.transformDisabled;
654
- sourceNode.transformDisabled = true;
655
- // color transform should be enabled!
656
- sourceNode.colorTransformDisabled = false;
657
- root.transform.colorTransform = colorTransform;
658
- // anyway we not support this =))
659
- root.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
660
- //save snapshot if unlocked
661
- //if (!this._locked)
662
- //SceneImage2D.scene.view.target=this;
663
- //SceneImage2D.scene.renderer.disableClear = !this._locked;
664
- renderer.render();
665
- // reset render to default value
666
- renderer.antiAlias = 0;
667
- renderer.disableClear = true;
668
- rootNode.removeChildAt(0);
669
- sourceNode.transformDisabled = transformDisabled;
670
- if (useTemp) {
671
- // because we copy MSAA into no msaa, it should passed as BLIT
672
- this._stage.filterManager.copyPixels(target, this, this._rect, TMP_POINT, useBlend, blendMode // apply blend mode if this needed.
673
- );
674
- SceneImage2D.tryStoreImage(target, this._stage);
675
- }
676
- };
677
- SceneImage2D.prototype.reset = function () { };
678
- SceneImage2D.prototype.clone = function () {
679
- var image = SceneImage2D.getImage(this.width, this.height, this.transparent, null, false, this._stage, false);
680
- image.deepClone(this);
681
- return image;
682
- };
683
- SceneImage2D.assetType = '[image SceneImage2D]';
684
- return SceneImage2D;
685
- }(BitmapImage2D));
686
- export { SceneImage2D };
687
- Stage.registerAbstraction(_Stage_BitmapImage2D, SceneImage2D);
1
+ import { __extends } from "tslib";
2
+ import { View } from '@awayjs/view';
3
+ import { MethodMaterial } from '@awayjs/materials';
4
+ import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
5
+ import { DisplayObject } from '../display/DisplayObject';
6
+ import { Billboard } from '../display/Billboard';
7
+ import { Settings } from '../Settings';
8
+ import { Rectangle, Point, PerspectiveProjection, CoordinateSystem, Vector3D, Transform, ColorUtils } from '@awayjs/core';
9
+ import { Stage, BitmapImage2D, _Stage_BitmapImage2D, BlendMode } from '@awayjs/stage';
10
+ import { DefaultRenderer, RenderGroup, Style } from '@awayjs/renderer';
11
+ // empty matrix for transform reset
12
+ var TMP_POINT = new Point(0, 0);
13
+ /**
14
+ *
15
+ */
16
+ var SceneImage2D = /** @class */ (function (_super) {
17
+ __extends(SceneImage2D, _super);
18
+ /**
19
+ * Creates a BitmapImage2D object with a specified width and height. If you
20
+ * specify a value for the <code>fillColor</code> parameter, every pixel in
21
+ * the bitmap is set to that color.
22
+ *
23
+ * <p>By default, the bitmap is created as transparent, unless you pass
24
+ * the value <code>false</code> for the transparent parameter. After you
25
+ * create an opaque bitmap, you cannot change it to a transparent bitmap.
26
+ * Every pixel in an opaque bitmap uses only 24 bits of color channel
27
+ * information. If you define the bitmap as transparent, every pixel uses 32
28
+ * bits of color channel information, including an alpha transparency
29
+ * channel.</p>
30
+ *
31
+ * @param width The width of the bitmap image in pixels.
32
+ * @param height The height of the bitmap image in pixels.
33
+ * @param transparent Specifies whether the bitmap image supports per-pixel
34
+ * transparency. The default value is <code>true</code>
35
+ * (transparent). To create a fully transparent bitmap,
36
+ * set the value of the <code>transparent</code>
37
+ * parameter to <code>true</code> and the value of the
38
+ * <code>fillColor</code> parameter to 0x00000000(or to
39
+ * 0). Setting the <code>transparent</code> property to
40
+ * <code>false</code> can result in minor improvements
41
+ * in rendering performance.
42
+ * @param fillColor A 32-bit ARGB color value that you use to fill the
43
+ * bitmap image area. The default value is
44
+ * 0xFFFFFFFF(solid white).
45
+ */
46
+ function SceneImage2D(width, height, transparent, fillColor, powerOfTwo, stage) {
47
+ if (transparent === void 0) { transparent = true; }
48
+ if (fillColor === void 0) { fillColor = 0xffffffff; }
49
+ if (powerOfTwo === void 0) { powerOfTwo = true; }
50
+ if (stage === void 0) { stage = null; }
51
+ var _this = _super.call(this, width, height, transparent, null, powerOfTwo, stage) || this;
52
+ _this._initalFillColor = null;
53
+ _this._lastUsedFill = null;
54
+ _this._internalSync = false;
55
+ _this._msaaNeedDrop = false;
56
+ _this._enforceMSAASupport = false;
57
+ /*private*/ _this._antialiasQuality = Settings.ALLOW_FORCE_MSAA;
58
+ _this._clearFromDispose = false;
59
+ _this._initalFillColor = fillColor;
60
+ _this._lastUsedFill = fillColor;
61
+ return _this;
62
+ }
63
+ SceneImage2D.getImage = function (width, height, transparent, fillColor, powerOfTwo, stage, msaa) {
64
+ if (transparent === void 0) { transparent = true; }
65
+ if (fillColor === void 0) { fillColor = 0xffffffff; }
66
+ if (powerOfTwo === void 0) { powerOfTwo = true; }
67
+ if (stage === void 0) { stage = null; }
68
+ if (msaa === void 0) { msaa = false; }
69
+ var result = new SceneImage2D(width, height, transparent, fillColor, powerOfTwo, stage);
70
+ if (!msaa) {
71
+ result._msaaNeedDrop = true;
72
+ result._antialiasQuality = 0;
73
+ }
74
+ else {
75
+ result._enforceMSAASupport = true;
76
+ }
77
+ return result;
78
+ };
79
+ SceneImage2D.tryStoreImage = function (image, stage) {
80
+ stage.filterManager.pushTemp(image);
81
+ };
82
+ SceneImage2D.getTemp = function (width, height, stage, msaa) {
83
+ if (msaa === void 0) { msaa = false; }
84
+ var image = stage.filterManager.popTemp(width, height, msaa && Settings.ALLOW_FORCE_MSAA > 1);
85
+ image.antialiasQuality = msaa ? Settings.ALLOW_FORCE_MSAA : 0;
86
+ return image;
87
+ };
88
+ SceneImage2D.prototype._dropMSAA = function () {
89
+ if (this._msaaNeedDrop || !this.canUseMSAAInternaly) {
90
+ return;
91
+ }
92
+ this._enforceMSAASupport = false;
93
+ this._msaaNeedDrop = true;
94
+ // force dispose texture and buffers
95
+ // MSAA not stored in pool
96
+ if (this.wasUpload) {
97
+ // super unload not call sync, we call it
98
+ _super.prototype.unload.call(this);
99
+ }
100
+ console.debug('[SceneImage2D Experemental] Drop MSAA support because a setPixel* operation called after upload.', this.id);
101
+ };
102
+ Object.defineProperty(SceneImage2D.prototype, "canUseMSAAInternaly", {
103
+ get: function () {
104
+ if (this._enforceMSAASupport) {
105
+ return true;
106
+ }
107
+ var minW = Settings.MSAA_MINIMAL_IMAGE_SIZE;
108
+ var minH = Settings.MSAA_MINIMAL_IMAGE_SIZE;
109
+ if (this._stage) {
110
+ minH = Math.min(this._stage.height, minH);
111
+ minW = Math.min(this._stage.width, minW);
112
+ }
113
+ return (this.width >= minW &&
114
+ this.height >= minH &&
115
+ !this._msaaNeedDrop);
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ Object.defineProperty(SceneImage2D.prototype, "antialiasQuality", {
121
+ get: function () {
122
+ return this.canUseMSAAInternaly ? this._antialiasQuality : 0;
123
+ },
124
+ enumerable: false,
125
+ configurable: true
126
+ });
127
+ SceneImage2D.prototype.syncData = function (async) {
128
+ var _this = this;
129
+ if (async === void 0) { async = false; }
130
+ if (async && this._asyncRead) {
131
+ return this._asyncRead;
132
+ }
133
+ if (!async && this._asyncRead) {
134
+ throw '[SceneImage2D] Synced read not allowed while async read is requested!';
135
+ }
136
+ this.applySymbol();
137
+ // update data from pixels from GPU
138
+ if (!this._imageDataDirty) {
139
+ return async ? Promise.resolve(false) : false;
140
+ }
141
+ var context = this._stage.context;
142
+ this._stage.setRenderTarget(this, false);
143
+ // when we call syncData, we already loose other data
144
+ // not require apply symbol etc, because it already should be applied
145
+ if (!this._data) {
146
+ this._data = new Uint8ClampedArray(this.width * this.height * 4);
147
+ }
148
+ // mark that this internal call, avoid reqursion loop
149
+ this._internalSync = true;
150
+ this._asyncRead = context.drawToBitmapImage2D(this, false, async);
151
+ this._internalSync = false;
152
+ this._stage.setRenderTarget(null);
153
+ if (!async) {
154
+ this._imageDataDirty = false;
155
+ // we store pixel buffer already as PMA.
156
+ // we should prevent unpack what already is PMA
157
+ this._unpackPMA = false;
158
+ return true;
159
+ }
160
+ return this._asyncRead.then(function (_status) {
161
+ _this._imageDataDirty = false;
162
+ _this._unpackPMA = false;
163
+ _this._asyncRead = null;
164
+ return true;
165
+ });
166
+ };
167
+ /* overide internal */ SceneImage2D.prototype.getDataInternal = function (constructEmpty, skipSync) {
168
+ if (constructEmpty === void 0) { constructEmpty = true; }
169
+ if (skipSync === void 0) { skipSync = false; }
170
+ // if sync called, check that this is requried
171
+ if (!skipSync && this._imageDataDirty && !this._internalSync) {
172
+ // sync data already should fill _data
173
+ this.syncData(false);
174
+ return this._data;
175
+ }
176
+ if (this._initalFillColor === null) {
177
+ return _super.prototype.getDataInternal.call(this, constructEmpty, true);
178
+ }
179
+ // disable empty buffer filling
180
+ // and check that buffer is empyt (has now symbol or alpha)
181
+ var data = _super.prototype.getDataInternal.call(this, false, true);
182
+ // if it empty, fill with initlal value
183
+ if (!data) {
184
+ // fill rect constuct buffer inside
185
+ _super.prototype.fillRect.call(this, this.rect, this._initalFillColor);
186
+ this._initalFillColor = null;
187
+ return this._data;
188
+ }
189
+ return data;
190
+ };
191
+ Object.defineProperty(SceneImage2D.prototype, "assetType", {
192
+ /**
193
+ *
194
+ * @returns {string}
195
+ */
196
+ get: function () {
197
+ return SceneImage2D.assetType;
198
+ },
199
+ enumerable: false,
200
+ configurable: true
201
+ });
202
+ SceneImage2D.prototype.createRenderer = function () {
203
+ //create the projection
204
+ var projection = new PerspectiveProjection();
205
+ projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
206
+ projection.originX = -1;
207
+ projection.originY = 1;
208
+ projection.transform = new Transform();
209
+ projection.transform.scaleTo(1, -1, 1);
210
+ projection.transform.moveTo(0, 0, -1000);
211
+ //create the view
212
+ SceneImage2D._view = new View(projection, this._stage);
213
+ SceneImage2D._root = new DisplayObjectContainer();
214
+ SceneImage2D._rootNode = SceneImage2D._view.getNode(SceneImage2D._root);
215
+ SceneImage2D._renderer = RenderGroup
216
+ .getInstance(DefaultRenderer)
217
+ .getRenderer(SceneImage2D._rootNode.partition);
218
+ //set the view properties
219
+ SceneImage2D._view.backgroundAlpha = 0;
220
+ SceneImage2D._view.backgroundColor = 0x0;
221
+ //set the renderer properties
222
+ SceneImage2D._renderer.disableClear = true;
223
+ SceneImage2D._renderer.renderableSorter = null; //new RenderableSort2D();
224
+ //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
225
+ };
226
+ SceneImage2D.prototype.createBillboardRenderer = function () {
227
+ //create the projection
228
+ var projection = new PerspectiveProjection();
229
+ projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
230
+ projection.originX = -1;
231
+ projection.originY = 1;
232
+ projection.transform = new Transform();
233
+ projection.transform.moveTo(0, 0, -1000);
234
+ projection.transform.lookAt(new Vector3D());
235
+ //create the view
236
+ SceneImage2D._billboardView = new View(projection, this._stage);
237
+ SceneImage2D._billboardRoot = new DisplayObjectContainer();
238
+ SceneImage2D._billboardRenderer = RenderGroup
239
+ .getInstance(DefaultRenderer)
240
+ .getRenderer(SceneImage2D._billboardView.getNode(SceneImage2D._billboardRoot).partition);
241
+ //SceneImage2D._billboardRoot.partition = SceneImage2D._billboardRenderer.partition;
242
+ //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
243
+ //set the view properties
244
+ SceneImage2D._billboardView.backgroundAlpha = 0;
245
+ SceneImage2D._billboardView.backgroundColor = 0x0;
246
+ //set the renderer properties
247
+ SceneImage2D._billboardRenderer.disableClear = true;
248
+ SceneImage2D._billboardRenderer.renderableSorter = null; //new RenderableSort2D();
249
+ var mat = new MethodMaterial(new BitmapImage2D(128, 128, true, 0x0));
250
+ mat.bothSides = true;
251
+ mat.alphaBlending = true;
252
+ SceneImage2D._billboard = new Billboard(mat);
253
+ SceneImage2D._billboard.style = new Style();
254
+ SceneImage2D._billboardRoot.addChild(SceneImage2D._billboard);
255
+ };
256
+ /**
257
+ * Frees memory that is used to store the BitmapImage2D object.
258
+ *
259
+ * <p>When the <code>dispose()</code> method is called on an image, the width
260
+ * and height of the image are set to 0. All subsequent calls to methods or
261
+ * properties of this BitmapImage2D instance fail, and an exception is thrown.
262
+ * </p>
263
+ *
264
+ * <p><code>BitmapImage2D.dispose()</code> releases the memory occupied by the
265
+ * actual bitmap data, immediately(a bitmap can consume up to 64 MB of
266
+ * memory). After using <code>BitmapImage2D.dispose()</code>, the BitmapImage2D
267
+ * object is no longer usable and an exception may be thrown if
268
+ * you call functions on the BitmapImage2D object. However,
269
+ * <code>BitmapImage2D.dispose()</code> does not garbage collect the BitmapImage2D
270
+ * object(approximately 128 bytes); the memory occupied by the actual
271
+ * BitmapImage2D object is released at the time the BitmapImage2D object is
272
+ * collected by the garbage collector.</p>
273
+ *
274
+ */
275
+ SceneImage2D.prototype.dispose = function () {
276
+ this._clearFromDispose = true;
277
+ this.dropAllReferences();
278
+ this.unmarkToUnload();
279
+ this.unuseWeakRef();
280
+ // drop buffer, because is big
281
+ this._data = null;
282
+ this._locked = false;
283
+ _super.prototype.dispose.call(this);
284
+ this._clearFromDispose = false;
285
+ };
286
+ SceneImage2D.prototype.unload = function () {
287
+ var _this = this;
288
+ // query async unload
289
+ var t = this.syncData(true);
290
+ // strict quard
291
+ if (typeof t !== 'boolean') {
292
+ t.then(function () { return _super.prototype.unload.call(_this); });
293
+ return;
294
+ }
295
+ _super.prototype.unload.call(this);
296
+ };
297
+ SceneImage2D.prototype.deepClone = function (from) {
298
+ this.copyPixels(from, this._rect, new Point(0, 0));
299
+ };
300
+ /**
301
+ * Fills a rectangular area of pixels with a specified ARGB color.
302
+ *
303
+ * @param rect The rectangular area to fill.
304
+ * @param color The ARGB color value that fills the area. ARGB colors are
305
+ * often specified in hexadecimal format; for example,
306
+ * 0xFF336699.
307
+ * @throws TypeError The rect is null.
308
+ */
309
+ SceneImage2D.prototype.fillRect = function (rect, color) {
310
+ this.dropAllReferences();
311
+ var argb = ColorUtils.float32ColorToARGB(color);
312
+ var alpha = this._transparent ? argb[0] / 255 : 1;
313
+ var isCrop = rect !== this._rect && !this._rect.equals(rect);
314
+ this._stage.setRenderTarget(this, true, 0, 0, true);
315
+ this._stage.setScissor(rect);
316
+ // we shure that color is fully filled when there are not any crops
317
+ this._lastUsedFill = isCrop ? null : color;
318
+ this._stage.clear((argb[1] / 0xff) * alpha, (argb[2] / 0xff) * alpha, (argb[3] / 0xff) * alpha, alpha);
319
+ this._stage.setScissor(null);
320
+ this._imageDataDirty = true;
321
+ };
322
+ /**
323
+ * Provides a fast routine to perform pixel manipulation between images with
324
+ * no stretching, rotation, or color effects. This method copies a
325
+ * rectangular area of a source image to a rectangular area of the same size
326
+ * at the destination point of the destination BitmapImage2D object.
327
+ *
328
+ * <p>If you include the <code>alphaBitmap</code> and <code>alphaPoint</code>
329
+ * parameters, you can use a secondary image as an alpha source for the
330
+ * source image. If the source image has alpha data, both sets of alpha data
331
+ * are used to composite pixels from the source image to the destination
332
+ * image. The <code>alphaPoint</code> parameter is the point in the alpha
333
+ * image that corresponds to the upper-left corner of the source rectangle.
334
+ * Any pixels outside the intersection of the source image and alpha image
335
+ * are not copied to the destination image.</p>
336
+ *
337
+ * <p>The <code>mergeAlpha</code> property controls whether or not the alpha
338
+ * channel is used when a transparent image is copied onto another
339
+ * transparent image. To copy pixels with the alpha channel data, set the
340
+ * <code>mergeAlpha</code> property to <code>true</code>. By default, the
341
+ * <code>mergeAlpha</code> property is <code>false</code>.</p>
342
+ *
343
+ * @param source The input bitmap image from which to copy pixels.
344
+ * The source image can be a different BitmapImage2D
345
+ * instance, or it can refer to the current
346
+ * BitmapImage2D instance.
347
+ * @param sourceRect A rectangle that defines the area of the source
348
+ * image to use as input.
349
+ * @param destPoint The destination point that represents the
350
+ * upper-left corner of the rectangular area where
351
+ * the new pixels are placed.
352
+ * @param alphaBitmapData A secondary, alpha BitmapImage2D object source.
353
+ * @param alphaPoint The point in the alpha BitmapImage2D object source
354
+ * that corresponds to the upper-left corner of the
355
+ * <code>sourceRect</code> parameter.
356
+ * @param mergeAlpha To use the alpha channel, set the value to
357
+ * <code>true</code>. To copy pixels with no alpha
358
+ * channel, set the value to <code>false</code>.
359
+ * @throws TypeError The sourceBitmapImage2D, sourceRect, destPoint are null.
360
+ */
361
+ SceneImage2D.prototype.copyPixels = function (source, sourceRect, destPoint, alphaBitmapData, alphaPoint, mergeAlpha) {
362
+ this._lastUsedFill = null;
363
+ this.dropAllReferences();
364
+ this.unmarkToUnload();
365
+ // need drop alpha from source when target is not has alpha
366
+ mergeAlpha = this.transparent !== source.transparent || mergeAlpha;
367
+ // CPU based copy, not require run GPU based copy
368
+ // block is equal, one of image not uploaded yet
369
+ // and source image no require SYNC
370
+ if (!source._imageDataDirty &&
371
+ sourceRect.equals(this._rect) &&
372
+ this._rect.equals(source.rect) &&
373
+ !mergeAlpha && (!this.wasUpload || !source.wasUpload)) {
374
+ var data = source.getDataInternal(true);
375
+ // inline, instead of setPixels, because it use a lot of checks
376
+ if (this._data) {
377
+ this._data.set(data);
378
+ }
379
+ else {
380
+ this._data = data.slice();
381
+ }
382
+ // we should sync this, because we can apply PMA twice, that not needed for us
383
+ this._unpackPMA = source._unpackPMA;
384
+ // we should reset initial color, because not require fill it after copyPixel
385
+ this._initalFillColor = null;
386
+ this._imageDataDirty = false;
387
+ this.invalidateGPU();
388
+ return;
389
+ }
390
+ if (source.width * source.height <= Settings.CPU_COPY_PIXELS_COUNT && !mergeAlpha) {
391
+ // todo Not implemented yet, need to implement and check performance change
392
+ // i think that increase some small operation performance,
393
+ // because copy by GPU required upload array to VRAM,
394
+ // and games that use set/get pixels and copyPixels only for math process not required use GPU copy
395
+ }
396
+ if (this._initalFillColor !== null) {
397
+ this.fillRect(this._rect, this._initalFillColor);
398
+ this._initalFillColor = null;
399
+ }
400
+ var compositeSource = source;
401
+ // merge alpha with source
402
+ if (alphaBitmapData) {
403
+ compositeSource = this._stage.filterManager.popTemp(source.width, source.height);
404
+ //this._stage.filterManager.copyPixels(source, compositeSource, source.rect, source.rect.topLeft);
405
+ this._stage.filterManager.copyPixels(alphaBitmapData, compositeSource, new Rectangle(alphaPoint.x, alphaPoint.y, sourceRect.width, sourceRect.height), new Point(0, 0));
406
+ this._stage.filterManager.copyPixels(source, compositeSource, source.rect, new Point(0, 0), true, 'alpha_back');
407
+ }
408
+ this._stage.filterManager.copyPixels(compositeSource, this, sourceRect, destPoint, mergeAlpha);
409
+ if (alphaBitmapData) {
410
+ this._stage.filterManager.pushTemp(compositeSource);
411
+ }
412
+ this._imageDataDirty = true;
413
+ };
414
+ SceneImage2D.prototype.threshold = function (source, sourceRect, destPoint, operation, threshold, color, mask, copySource) {
415
+ this._lastUsedFill = null;
416
+ this.dropAllReferences();
417
+ this.unmarkToUnload();
418
+ this._stage.threshold(source, this, sourceRect, destPoint, operation, threshold, color, mask, copySource);
419
+ this._imageDataDirty = true;
420
+ };
421
+ SceneImage2D.prototype.applyFilter = function (source, sourceRect, destPoint, filter) {
422
+ if (!Settings.USE_UNSAFE_FILTERS || !filter || !filter.filterName) {
423
+ return false;
424
+ }
425
+ this.dropAllReferences(false);
426
+ var result = this._stage.filterManager.applyFilter(source, this, sourceRect, destPoint, filter.filterName, filter);
427
+ this._imageDataDirty = result;
428
+ return result;
429
+ };
430
+ SceneImage2D.prototype.colorTransform = function (rect, colorTransform) {
431
+ this.dropAllReferences();
432
+ this.unmarkToUnload();
433
+ this._lastUsedFill = null;
434
+ this._stage.colorTransform(this, this, rect, colorTransform);
435
+ this._imageDataDirty = true;
436
+ };
437
+ SceneImage2D.prototype.setPixel = function (x, y, color) {
438
+ // we can't upload buffer in MSAA texture after creating - only render it and get
439
+ if (this.canUseMSAAInternaly) {
440
+ this._dropMSAA();
441
+ }
442
+ _super.prototype.setPixel.call(this, x, y, color);
443
+ };
444
+ SceneImage2D.prototype.setPixel32 = function (x, y, color) {
445
+ // we can't upload buffer in MSAA texture after creating - only render it and get
446
+ if (this.canUseMSAAInternaly) {
447
+ this._dropMSAA();
448
+ }
449
+ _super.prototype.setPixel32.call(this, x, y, color);
450
+ };
451
+ SceneImage2D.prototype.setPixels = function (rect, buffer) {
452
+ // we can't upload buffer in MSAA texture after creating - only render it and get
453
+ if (this.wasUpload && this.canUseMSAAInternaly) {
454
+ this._dropMSAA();
455
+ }
456
+ _super.prototype.setPixels.call(this, rect, buffer);
457
+ };
458
+ SceneImage2D.prototype.clear = function () {
459
+ var _this = this;
460
+ // we call clear in parent class from dispose, call direct
461
+ if (this._clearFromDispose) {
462
+ _super.prototype.clear.call(this);
463
+ return;
464
+ }
465
+ // clear should drop abstraction, but we can't doing this if unloaded
466
+ var t = this.syncData(true);
467
+ // not require unload, we already doings this
468
+ this.unmarkToUnload();
469
+ this.lastUsedTime = -1;
470
+ if (typeof t === 'boolean') {
471
+ this.wasUpload = false;
472
+ _super.prototype.clear.call(this);
473
+ return;
474
+ }
475
+ t.then(function () {
476
+ _this.wasUpload = false;
477
+ _super.prototype.clear.call(_this);
478
+ });
479
+ };
480
+ /**
481
+ * @inheritdoc
482
+ */
483
+ SceneImage2D.prototype.getPixel32 = function (x, y) {
484
+ this.syncData();
485
+ return _super.prototype.getPixel32.call(this, x, y);
486
+ };
487
+ /**
488
+ * @inheritdoc
489
+ */
490
+ SceneImage2D.prototype.getPixel = function (x, y) {
491
+ var result = this.getPixel32(x, y);
492
+ return result & 0x00ffffff;
493
+ };
494
+ SceneImage2D.prototype.draw = function (source, matrix, colorTransform, blendMode, clipRect, smoothing) {
495
+ /* eslint-enable */
496
+ this.dropAllReferences();
497
+ this.unmarkToUnload();
498
+ if (source instanceof DisplayObject) {
499
+ this._drawAsDisplay(source, matrix, colorTransform, blendMode, clipRect, smoothing);
500
+ }
501
+ else {
502
+ this._drawAsBitmap(source, matrix, colorTransform, blendMode, clipRect, smoothing);
503
+ }
504
+ this._lastUsedFill = null;
505
+ this._imageDataDirty = true;
506
+ this.invalidate();
507
+ };
508
+ SceneImage2D._mapSupportedBlendMode = function (blendMode) {
509
+ if (blendMode === void 0) { blendMode = ''; }
510
+ switch (blendMode) {
511
+ case null:
512
+ case '':
513
+ case BlendMode.NORMAL:
514
+ case BlendMode.LAYER:
515
+ return BlendMode.LAYER;
516
+ case BlendMode.MULTIPLY:
517
+ case BlendMode.ADD:
518
+ case BlendMode.ALPHA:
519
+ return blendMode;
520
+ }
521
+ //console.debug("[ImageBitmap] Unsupport BlendMode", blendMode);
522
+ return BlendMode.LAYER;
523
+ };
524
+ SceneImage2D.prototype._drawAsBitmap = function (source, matrix, colorTransform, blendMode, _clipRect, smoothing) {
525
+ if (!SceneImage2D._billboardRenderer) {
526
+ this.createBillboardRenderer();
527
+ }
528
+ if (this._initalFillColor !== null) {
529
+ this.fillRect(this._rect, this._initalFillColor);
530
+ this._initalFillColor = null;
531
+ }
532
+ var stage = this._stage;
533
+ var mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
534
+ var supportNativeBlend = !blendMode || mappedBlend !== BlendMode.LAYER || blendMode == BlendMode.LAYER;
535
+ var useTmp = (!supportNativeBlend || this === source);
536
+ var target = useTmp ?
537
+ stage.filterManager.popTemp(this.width, this.height, false)
538
+ : this;
539
+ var renderer = SceneImage2D._billboardRenderer;
540
+ var root = SceneImage2D._billboardRoot;
541
+ var billboard = SceneImage2D._billboard;
542
+ billboard.sampler.smooth = smoothing;
543
+ renderer.disableClear = !useTmp;
544
+ renderer.view.target = target;
545
+ renderer.view.projection.scale = 1000 / target.height;
546
+ billboard.material.style.image = source;
547
+ // not all blend modes can be used for rendering
548
+ billboard.material.blendMode = !useTmp ? SceneImage2D._mapSupportedBlendMode(blendMode) : BlendMode.LAYER;
549
+ billboard.material.useColorTransform = !!colorTransform;
550
+ if (matrix) {
551
+ var m = root.transform.matrix3D;
552
+ m.identity();
553
+ m._rawData[0] = matrix.a;
554
+ m._rawData[1] = -matrix.b;
555
+ m._rawData[4] = matrix.c;
556
+ m._rawData[5] = -matrix.d;
557
+ m._rawData[12] = matrix.tx;
558
+ m._rawData[13] = target.height - matrix.ty;
559
+ root.transform.invalidateComponents();
560
+ }
561
+ else {
562
+ root.transform.rotateTo(0, 0, 0);
563
+ root.transform.scaleTo(1, -1, 1);
564
+ root.transform.moveTo(0, target.height, 0);
565
+ }
566
+ root.transform.colorTransform = colorTransform;
567
+ //render
568
+ renderer.render();
569
+ //
570
+ if (useTmp) {
571
+ stage.filterManager.copyPixels(target, this, this.rect, TMP_POINT, true, blendMode);
572
+ stage.filterManager.pushTemp(target);
573
+ }
574
+ };
575
+ SceneImage2D.prototype._drawAsDisplay = function (source, matrix, colorTransform, blendMode, _clipRect, _smoothing) {
576
+ if (blendMode === void 0) { blendMode = ''; }
577
+ // default global blend mode
578
+ blendMode = blendMode || BlendMode.LAYER;
579
+ if (!SceneImage2D._renderer) {
580
+ this.createRenderer();
581
+ }
582
+ var root = SceneImage2D._root;
583
+ var rootNode = SceneImage2D._rootNode;
584
+ var renderer = SceneImage2D._renderer;
585
+ // when we should use MSAA, we will create temporary image and draw to it
586
+ var internal = this.canUseMSAAInternaly;
587
+ var nativeMSAA = (!source.isAsset(Billboard) &&
588
+ this._stage.context.glVersion === 2 && // can be used because a webgl2
589
+ Settings.ALLOW_FORCE_MSAA > 1 && // because a quality is more that 1
590
+ !internal); // and not internal
591
+ // target image for rendering.
592
+ var target = this;
593
+ // we should run compositor when blendMode !== LAYER (default)
594
+ // or when we use MSAA + fill is not flat.
595
+ var useBlend = blendMode !== BlendMode.LAYER || this._lastUsedFill === null;
596
+ var useTemp = useBlend || nativeMSAA;
597
+ // lazy filling
598
+ // we require fill image with initial color, because we not doing this immediate
599
+ // and when blend is required, because we should blend with vald color
600
+ if ((!nativeMSAA || useBlend) && this._initalFillColor !== null) {
601
+ this.fillRect(this._rect, this._initalFillColor);
602
+ this._initalFillColor = null;
603
+ }
604
+ if (useTemp) {
605
+ target = SceneImage2D.getTemp(this.width, this.height, this._stage, nativeMSAA);
606
+ // because target image is stupid filled - it not require merging
607
+ // BUT when blend is required - we shpuld skip color clear and use empty TMP
608
+ if (!useBlend && this._lastUsedFill !== null) {
609
+ // bitmap was filled plain, go clear TMP to this color too
610
+ renderer.disableClear = false;
611
+ renderer.view.backgroundColor = this._lastUsedFill & 0xffffff;
612
+ renderer.view.backgroundAlpha = this._transparent ? (this._lastUsedFill >>> 24 & 0xff) / 0xff : 1;
613
+ }
614
+ else {
615
+ // we clear TMP and render to it, prepare to composing
616
+ renderer.disableClear = false;
617
+ renderer.view.backgroundColor = 0x0;
618
+ renderer.view.backgroundAlpha = 0;
619
+ // copy from source to tmp
620
+ // TMP_POINT.setTo(0,0);
621
+ // this._stage.copyPixels(this, target, this._rect, TMP_POINT, null, null, false);
622
+ }
623
+ }
624
+ var transform = renderer.view.projection.transform;
625
+ var mat3d = transform.matrix3D;
626
+ mat3d.identity();
627
+ if (matrix) {
628
+ var raw = mat3d._rawData;
629
+ raw[0] = matrix.a;
630
+ raw[1] = matrix.b;
631
+ raw[4] = matrix.c;
632
+ raw[5] = matrix.d;
633
+ raw[10] = 1;
634
+ raw[12] = matrix.tx;
635
+ raw[13] = matrix.ty;
636
+ }
637
+ // todo By this line we flip normals, and cull will be broken
638
+ // NEED FIX THIS ASAP, or flip cull state
639
+ mat3d.appendScale(1, -1, 1);
640
+ mat3d.appendTranslation(0, this._rect.height, 1000);
641
+ mat3d.invert();
642
+ transform.matrix3D = mat3d;
643
+ renderer.antiAlias = (internal ? this.antialiasQuality : target.antialiasQuality) || 0;
644
+ renderer.view.target = target;
645
+ renderer.view.projection.scale = 1000 / this._rect.height;
646
+ // shift view, because target can be more
647
+ renderer.view.projection.ratio = (this._rect.width / this._rect.height);
648
+ renderer.view.x = -(target.width - this.width);
649
+ renderer.view.y = -(target.height - this.height);
650
+ renderer.view.width = this.width;
651
+ renderer.view.height = this.height;
652
+ var sourceNode = rootNode.addChildAt(source, 0);
653
+ var transformDisabled = sourceNode.transformDisabled;
654
+ sourceNode.transformDisabled = true;
655
+ // color transform should be enabled!
656
+ sourceNode.colorTransformDisabled = false;
657
+ root.transform.colorTransform = colorTransform;
658
+ // anyway we not support this =))
659
+ root.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
660
+ //save snapshot if unlocked
661
+ //if (!this._locked)
662
+ //SceneImage2D.scene.view.target=this;
663
+ //SceneImage2D.scene.renderer.disableClear = !this._locked;
664
+ renderer.render();
665
+ // reset render to default value
666
+ renderer.antiAlias = 0;
667
+ renderer.disableClear = true;
668
+ rootNode.removeChildAt(0);
669
+ sourceNode.transformDisabled = transformDisabled;
670
+ if (useTemp) {
671
+ // because we copy MSAA into no msaa, it should passed as BLIT
672
+ this._stage.filterManager.copyPixels(target, this, this._rect, TMP_POINT, useBlend, blendMode // apply blend mode if this needed.
673
+ );
674
+ SceneImage2D.tryStoreImage(target, this._stage);
675
+ }
676
+ };
677
+ SceneImage2D.prototype.reset = function () { };
678
+ SceneImage2D.prototype.clone = function () {
679
+ var image = SceneImage2D.getImage(this.width, this.height, this.transparent, null, false, this._stage, false);
680
+ image.deepClone(this);
681
+ return image;
682
+ };
683
+ SceneImage2D.assetType = '[image SceneImage2D]';
684
+ return SceneImage2D;
685
+ }(BitmapImage2D));
686
+ export { SceneImage2D };
687
+ Stage.registerAbstraction(_Stage_BitmapImage2D, SceneImage2D);