@awayjs/scene 0.13.326 → 0.13.328

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