@awayjs/scene 0.13.323 → 0.13.324

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 (264) 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.js +285 -285
  10. package/dist/lib/Settings.d.ts +16 -16
  11. package/dist/lib/Settings.js +60 -60
  12. package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
  13. package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
  14. package/dist/lib/adapters/IFilter.d.ts +24 -24
  15. package/dist/lib/adapters/IFilter.js +1 -1
  16. package/dist/lib/adapters/IMovieClipAdapter.d.ts +15 -15
  17. package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
  18. package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
  19. package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
  20. package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
  21. package/dist/lib/base/IBitmapDrawable.js +1 -1
  22. package/dist/lib/base/IFrameLabel.d.ts +4 -4
  23. package/dist/lib/base/IFrameLabel.js +1 -1
  24. package/dist/lib/base/IFrameScript.d.ts +5 -5
  25. package/dist/lib/base/IFrameScript.js +1 -1
  26. package/dist/lib/base/MouseButtons.d.ts +26 -26
  27. package/dist/lib/base/MouseButtons.js +1 -1
  28. package/dist/lib/base/Timeline.d.ts +147 -147
  29. package/dist/lib/base/Timeline.js +525 -525
  30. package/dist/lib/base/TimelineActionType.d.ts +18 -18
  31. package/dist/lib/base/TimelineActionType.js +1 -1
  32. package/dist/lib/controllers/ControllerBase.d.ts +14 -14
  33. package/dist/lib/controllers/ControllerBase.js +60 -60
  34. package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
  35. package/dist/lib/controllers/FirstPersonController.js +228 -228
  36. package/dist/lib/controllers/FollowController.d.ts +12 -12
  37. package/dist/lib/controllers/FollowController.js +27 -27
  38. package/dist/lib/controllers/HoverController.d.ts +105 -105
  39. package/dist/lib/controllers/HoverController.js +302 -302
  40. package/dist/lib/controllers/LookAtController.d.ts +14 -14
  41. package/dist/lib/controllers/LookAtController.js +68 -68
  42. package/dist/lib/controllers/SpringController.d.ts +38 -38
  43. package/dist/lib/controllers/SpringController.js +59 -59
  44. package/dist/lib/display/Billboard.d.ts +132 -132
  45. package/dist/lib/display/Billboard.js +397 -397
  46. package/dist/lib/display/Camera.d.ts +31 -31
  47. package/dist/lib/display/Camera.js +72 -72
  48. package/dist/lib/display/DisplayObject.d.ts +921 -921
  49. package/dist/lib/display/DisplayObject.js +1595 -1595
  50. package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
  51. package/dist/lib/display/DisplayObjectContainer.js +486 -486
  52. package/dist/lib/display/LineSegment.d.ts +69 -69
  53. package/dist/lib/display/LineSegment.js +203 -203
  54. package/dist/lib/display/LoaderContainer.d.ts +504 -504
  55. package/dist/lib/display/LoaderContainer.js +603 -603
  56. package/dist/lib/display/MorphSprite.d.ts +20 -20
  57. package/dist/lib/display/MorphSprite.js +246 -246
  58. package/dist/lib/display/MovieClip.d.ts +149 -149
  59. package/dist/lib/display/MovieClip.js +733 -733
  60. package/dist/lib/display/SimpleButton.d.ts +158 -158
  61. package/dist/lib/display/SimpleButton.js +228 -228
  62. package/dist/lib/display/Skybox.d.ts +144 -144
  63. package/dist/lib/display/Skybox.js +288 -288
  64. package/dist/lib/display/Sprite.d.ts +65 -65
  65. package/dist/lib/display/Sprite.js +134 -134
  66. package/dist/lib/display/TextField.d.ts +1104 -1104
  67. package/dist/lib/display/TextField.js +3018 -3018
  68. package/dist/lib/display/TextSprite.d.ts +16 -16
  69. package/dist/lib/display/TextSprite.js +36 -36
  70. package/dist/lib/elements/SkyboxElements.d.ts +29 -29
  71. package/dist/lib/elements/SkyboxElements.js +127 -127
  72. package/dist/lib/errors/CastError.d.ts +4 -4
  73. package/dist/lib/errors/CastError.js +10 -10
  74. package/dist/lib/events/CameraEvent.d.ts +16 -16
  75. package/dist/lib/events/CameraEvent.js +30 -30
  76. package/dist/lib/events/FocusEvent.d.ts +42 -42
  77. package/dist/lib/events/FocusEvent.js +43 -43
  78. package/dist/lib/events/KeyboardEvent.d.ts +21 -21
  79. package/dist/lib/events/KeyboardEvent.js +43 -43
  80. package/dist/lib/events/MouseEvent.d.ts +91 -91
  81. package/dist/lib/events/MouseEvent.js +122 -122
  82. package/dist/lib/events/PointerEvent.d.ts +93 -93
  83. package/dist/lib/events/PointerEvent.js +73 -73
  84. package/dist/lib/events/ResizeEvent.d.ts +15 -15
  85. package/dist/lib/events/ResizeEvent.js +38 -38
  86. package/dist/lib/events/TextfieldEvent.d.ts +19 -19
  87. package/dist/lib/events/TextfieldEvent.js +28 -28
  88. package/dist/lib/events/TouchEvent.d.ts +54 -54
  89. package/dist/lib/events/TouchEvent.js +89 -89
  90. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +27 -27
  91. package/dist/lib/factories/DefaultSceneGraphFactory.js +55 -55
  92. package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
  93. package/dist/lib/factories/ISceneGraphFactory.js +1 -1
  94. package/dist/lib/image/SceneImage2D.d.ts +220 -219
  95. package/dist/lib/image/SceneImage2D.d.ts.map +1 -1
  96. package/dist/lib/image/SceneImage2D.js +610 -606
  97. package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
  98. package/dist/lib/managers/DefaultFontManager.js +101 -101
  99. package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
  100. package/dist/lib/managers/DeviceFontManager.js +44 -44
  101. package/dist/lib/managers/FrameScriptManager.d.ts +37 -37
  102. package/dist/lib/managers/FrameScriptManager.js +386 -386
  103. package/dist/lib/managers/IInputRecorder.d.ts +3 -3
  104. package/dist/lib/managers/IInputRecorder.js +1 -1
  105. package/dist/lib/managers/MouseManager.d.ts +74 -74
  106. package/dist/lib/managers/MouseManager.js +803 -803
  107. package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
  108. package/dist/lib/prefabs/PrefabBase.js +42 -42
  109. package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
  110. package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
  111. package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
  112. package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
  113. package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
  114. package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
  115. package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
  116. package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
  117. package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
  118. package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
  119. package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
  120. package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
  121. package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
  122. package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
  123. package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
  124. package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
  125. package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
  126. package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
  127. package/dist/lib/text/AntiAliasType.d.ts +24 -24
  128. package/dist/lib/text/AntiAliasType.js +28 -28
  129. package/dist/lib/text/BitmapFontChar.d.ts +39 -39
  130. package/dist/lib/text/BitmapFontChar.js +42 -42
  131. package/dist/lib/text/BitmapFontTable.d.ts +73 -73
  132. package/dist/lib/text/BitmapFontTable.js +183 -183
  133. package/dist/lib/text/FNTGenerator.d.ts +10 -10
  134. package/dist/lib/text/FNTGenerator.js +74 -74
  135. package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
  136. package/dist/lib/text/FNTGeneratorCanvas.d.ts.map +1 -1
  137. package/dist/lib/text/FNTGeneratorCanvas.js +211 -202
  138. package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
  139. package/dist/lib/text/FNTGeneratrorBase.js +7 -7
  140. package/dist/lib/text/Font.d.ts +38 -38
  141. package/dist/lib/text/Font.js +109 -109
  142. package/dist/lib/text/FontLookUpMode.d.ts +5 -5
  143. package/dist/lib/text/FontLookUpMode.js +7 -7
  144. package/dist/lib/text/FontStyleName.d.ts +6 -6
  145. package/dist/lib/text/FontStyleName.js +7 -7
  146. package/dist/lib/text/GridFitType.d.ts +31 -31
  147. package/dist/lib/text/GridFitType.js +35 -35
  148. package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
  149. package/dist/lib/text/HTMLTextProcessor.js +426 -426
  150. package/dist/lib/text/IFontTable.d.ts +16 -16
  151. package/dist/lib/text/IFontTable.js +1 -1
  152. package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
  153. package/dist/lib/text/TesselatedFontChar.js +66 -66
  154. package/dist/lib/text/TesselatedFontTable.d.ts +88 -88
  155. package/dist/lib/text/TesselatedFontTable.js +963 -963
  156. package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
  157. package/dist/lib/text/TextFieldAutoSize.js +32 -32
  158. package/dist/lib/text/TextFieldType.d.ts +20 -20
  159. package/dist/lib/text/TextFieldType.js +24 -24
  160. package/dist/lib/text/TextFormat.d.ts +273 -273
  161. package/dist/lib/text/TextFormat.js +449 -449
  162. package/dist/lib/text/TextFormatAlign.d.ts +26 -26
  163. package/dist/lib/text/TextFormatAlign.js +30 -30
  164. package/dist/lib/text/TextInteractionMode.d.ts +21 -21
  165. package/dist/lib/text/TextInteractionMode.js +25 -25
  166. package/dist/lib/text/TextLineMetrics.d.ts +61 -61
  167. package/dist/lib/text/TextLineMetrics.js +42 -42
  168. package/dist/lib/text/TextShape.d.ts +22 -22
  169. package/dist/lib/text/TextShape.js +75 -75
  170. package/dist/lib/tools/Merge.d.ts +81 -81
  171. package/dist/lib/tools/Merge.js +266 -266
  172. package/dist/lib/utils/Cast.d.ts +20 -20
  173. package/dist/lib/utils/Cast.js +271 -271
  174. package/index.ts +92 -92
  175. package/lib/Scene.ts +339 -339
  176. package/lib/Settings.ts +83 -83
  177. package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
  178. package/lib/adapters/IFilter.ts +25 -25
  179. package/lib/adapters/IMovieClipAdapter.ts +26 -26
  180. package/lib/adapters/ITextfieldAdapter.ts +6 -6
  181. package/lib/base/IBitmapDrawable.ts +13 -13
  182. package/lib/base/IFrameLabel.ts +3 -3
  183. package/lib/base/IFrameScript.ts +4 -4
  184. package/lib/base/MouseButtons.ts +31 -31
  185. package/lib/base/Timeline.ts +715 -715
  186. package/lib/base/TimelineActionType.ts +18 -18
  187. package/lib/controllers/ControllerBase.ts +66 -66
  188. package/lib/controllers/FirstPersonController.ts +241 -241
  189. package/lib/controllers/FollowController.ts +22 -22
  190. package/lib/controllers/HoverController.ts +304 -304
  191. package/lib/controllers/LookAtController.ts +75 -75
  192. package/lib/controllers/SpringController.ts +91 -91
  193. package/lib/display/Billboard.ts +468 -468
  194. package/lib/display/Camera.ts +75 -75
  195. package/lib/display/DisplayObject.ts +1829 -1829
  196. package/lib/display/DisplayObjectContainer.ts +546 -546
  197. package/lib/display/LineSegment.ts +229 -229
  198. package/lib/display/LoaderContainer.ts +651 -651
  199. package/lib/display/MorphSprite.ts +339 -339
  200. package/lib/display/MovieClip.ts +870 -870
  201. package/lib/display/SimpleButton.ts +224 -224
  202. package/lib/display/Skybox.ts +352 -352
  203. package/lib/display/Sprite.ts +154 -154
  204. package/lib/display/TextField.ts +3875 -3875
  205. package/lib/display/TextSprite.ts +34 -34
  206. package/lib/elements/SkyboxElements.ts +141 -141
  207. package/lib/errors/CastError.ts +6 -6
  208. package/lib/events/CameraEvent.ts +29 -29
  209. package/lib/events/FocusEvent.ts +69 -69
  210. package/lib/events/KeyboardEvent.ts +40 -40
  211. package/lib/events/MouseEvent.ts +144 -144
  212. package/lib/events/PointerEvent.ts +145 -145
  213. package/lib/events/ResizeEvent.ts +31 -31
  214. package/lib/events/TextfieldEvent.ts +28 -28
  215. package/lib/events/TouchEvent.ts +103 -103
  216. package/lib/factories/DefaultSceneGraphFactory.ts +58 -58
  217. package/lib/factories/ISceneGraphFactory.ts +28 -28
  218. package/lib/image/SceneImage2D.ts +912 -907
  219. package/lib/managers/DefaultFontManager.ts +124 -124
  220. package/lib/managers/DeviceFontManager.ts +55 -55
  221. package/lib/managers/FrameScriptManager.ts +440 -440
  222. package/lib/managers/IInputRecorder.ts +2 -2
  223. package/lib/managers/MouseManager.ts +942 -942
  224. package/lib/prefabs/PrefabBase.ts +47 -47
  225. package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
  226. package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
  227. package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
  228. package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
  229. package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
  230. package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
  231. package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
  232. package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
  233. package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
  234. package/lib/text/AntiAliasType.ts +24 -24
  235. package/lib/text/BitmapFontChar.ts +53 -53
  236. package/lib/text/BitmapFontTable.ts +213 -213
  237. package/lib/text/FNTGenerator.ts +100 -100
  238. package/lib/text/FNTGeneratorCanvas.ts +292 -283
  239. package/lib/text/FNTGeneratrorBase.ts +10 -10
  240. package/lib/text/Font.ts +114 -114
  241. package/lib/text/FontLookUpMode.ts +5 -5
  242. package/lib/text/FontStyleName.ts +6 -6
  243. package/lib/text/GridFitType.ts +32 -32
  244. package/lib/text/HTMLTextProcessor.ts +421 -421
  245. package/lib/text/IFontTable.ts +17 -17
  246. package/lib/text/TesselatedFontChar.ts +80 -80
  247. package/lib/text/TesselatedFontTable.ts +1181 -1181
  248. package/lib/text/TextFieldAutoSize.ts +30 -30
  249. package/lib/text/TextFieldType.ts +21 -21
  250. package/lib/text/TextFormat.ts +603 -603
  251. package/lib/text/TextFormatAlign.ts +28 -28
  252. package/lib/text/TextInteractionMode.ts +21 -21
  253. package/lib/text/TextLineMetrics.ts +74 -74
  254. package/lib/text/TextShape.ts +91 -91
  255. package/lib/tools/Merge.ts +311 -311
  256. package/lib/utils/Cast.ts +304 -304
  257. package/package.json +74 -74
  258. package/rollup.config.js +33 -33
  259. package/scripts/build.sh +2 -2
  260. package/scripts/gendocs.sh +14 -14
  261. package/scripts/genexamples.sh +14 -14
  262. package/scripts/genfull.sh +14 -14
  263. package/system.config.js +51 -51
  264. package/tsconfig.json +18 -18
@@ -1,606 +1,610 @@
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.clear = function () {
366
- var _this = this;
367
- // we call clear in parent class from dispose, call direct
368
- if (this._clearFromDispose) {
369
- _super.prototype.clear.call(this);
370
- return;
371
- }
372
- // clear should drop abstraction, but we can't doing this if unloaded
373
- var t = this.syncData(true);
374
- // not require unload, we already doings this
375
- this.unmarkToUnload();
376
- this.lastUsedTime = -1;
377
- if (typeof t === 'boolean') {
378
- this.wasUpload = false;
379
- _super.prototype.clear.call(this);
380
- return;
381
- }
382
- t.then(function () {
383
- _this.wasUpload = false;
384
- _super.prototype.clear.call(_this);
385
- });
386
- };
387
- /**
388
- * @inheritdoc
389
- */
390
- SceneImage2D.prototype.getPixel32 = function (x, y) {
391
- this.syncData();
392
- return _super.prototype.getPixel32.call(this, x, y);
393
- };
394
- /**
395
- * @inheritdoc
396
- */
397
- SceneImage2D.prototype.getPixel = function (x, y) {
398
- var result = this.getPixel32(x, y);
399
- return result & 0x00ffffff;
400
- };
401
- SceneImage2D.prototype.draw = function (source, matrix, colorTransform, blendMode, clipRect, smoothing) {
402
- /* eslint-enable */
403
- this.unmarkToUnload();
404
- if (source instanceof DisplayObject) {
405
- this._drawAsDisplay(source, matrix, colorTransform, blendMode, clipRect, smoothing);
406
- }
407
- else {
408
- this._drawAsBitmap(source, matrix, colorTransform, blendMode, clipRect, smoothing);
409
- }
410
- this._lastUsedFill = null;
411
- this._imageDataDirty = true;
412
- this.invalidateOwners();
413
- };
414
- SceneImage2D._mapSupportedBlendMode = function (blendMode) {
415
- if (blendMode === void 0) { blendMode = ''; }
416
- switch (blendMode) {
417
- case null:
418
- case '':
419
- case BlendMode.NORMAL:
420
- case BlendMode.LAYER:
421
- return BlendMode.LAYER;
422
- case BlendMode.MULTIPLY:
423
- case BlendMode.ADD:
424
- case BlendMode.ALPHA:
425
- return blendMode;
426
- }
427
- //console.debug("[ImageBitmap] Unsupport BlendMode", blendMode);
428
- return BlendMode.LAYER;
429
- };
430
- SceneImage2D.prototype._drawAsBitmap = function (source, matrix, colorTransform, blendMode, _clipRect, smoothing) {
431
- // default global blend mode
432
- blendMode = blendMode || BlendMode.LAYER;
433
- if (!SceneImage2D._billboardRenderer) {
434
- this.createBillboardRenderer();
435
- }
436
- if (this._initalFillColor !== null)
437
- this.fillRect(this._rect, this._initalFillColor);
438
- var stage = this._stage;
439
- var mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
440
- var supportNativeBlend = !blendMode || mappedBlend !== BlendMode.LAYER || blendMode == BlendMode.LAYER;
441
- var useTmp = (!supportNativeBlend || this === source);
442
- var target = useTmp ?
443
- stage.filterManager.popTemp(this.width, this.height, false)
444
- : this;
445
- var renderer = SceneImage2D._billboardRenderer;
446
- var root = SceneImage2D._billboardRoot;
447
- var billboard = SceneImage2D._billboard;
448
- billboard.style.sampler.smooth = smoothing;
449
- renderer.disableClear = !useTmp;
450
- renderer.view.target = target;
451
- renderer.view.projection.scale = 1000 / target.height;
452
- billboard.style.image = source;
453
- // not all blend modes can be used for rendering
454
- billboard.material.blendMode = !useTmp ? mappedBlend : BlendMode.LAYER;
455
- billboard.material.useColorTransform = !!colorTransform;
456
- if (useTmp) {
457
- // we clear TMP and render to it, prepare to composing
458
- renderer.view.backgroundColor = 0x0;
459
- renderer.view.backgroundAlpha = 0;
460
- }
461
- if (matrix) {
462
- var m = root.transform.matrix3D;
463
- m.identity();
464
- m._rawData[0] = matrix.a;
465
- m._rawData[1] = -matrix.b;
466
- m._rawData[4] = matrix.c;
467
- m._rawData[5] = -matrix.d;
468
- m._rawData[12] = matrix.tx;
469
- m._rawData[13] = target.height - matrix.ty;
470
- root.transform.invalidateComponents();
471
- }
472
- else {
473
- root.transform.rotateTo(0, 0, 0);
474
- root.transform.scaleTo(1, -1, 1);
475
- root.transform.moveTo(0, target.height, 0);
476
- }
477
- root.transform.colorTransform = colorTransform;
478
- //render
479
- renderer.render();
480
- //
481
- if (useTmp) {
482
- stage.filterManager.copyPixels(target, this, this.rect, TMP_POINT, true, blendMode);
483
- stage.filterManager.pushTemp(target);
484
- }
485
- //reset material blendMode
486
- billboard.material.blendMode = BlendMode.NORMAL;
487
- };
488
- SceneImage2D.prototype._drawAsDisplay = function (source, matrix, colorTransform, blendMode, _clipRect, _smoothing) {
489
- if (blendMode === void 0) { blendMode = ''; }
490
- // default global blend mode
491
- blendMode = blendMode || BlendMode.LAYER;
492
- if (!SceneImage2D._renderer) {
493
- this.createRenderer();
494
- }
495
- var root = SceneImage2D._root;
496
- var rootNode = SceneImage2D._rootNode;
497
- var renderer = SceneImage2D._renderer;
498
- // when we should use MSAA, we will create temporary image and draw to it
499
- var internal = this.canUseMSAAInternaly;
500
- var nativeMSAA = (!source.isAsset(Billboard) &&
501
- this._stage.context.glVersion === 2 && // can be used because a webgl2
502
- Settings.ALLOW_FORCE_MSAA > 1 && // because a quality is more that 1
503
- !internal); // and not internal
504
- // target image for rendering.
505
- var target = this;
506
- // we should run compositor when blendMode !== LAYER (default)
507
- // or when we use MSAA + fill is not flat.
508
- var useBlend = blendMode !== BlendMode.LAYER || (this._lastUsedFill === null && nativeMSAA);
509
- var useTemp = useBlend || nativeMSAA;
510
- // lazy filling
511
- // we require fill image with initial color, because we not doing this immediate
512
- // and when blend is required, because we should blend with vald color
513
- if ((!nativeMSAA || useBlend) && this._initalFillColor !== null)
514
- this.fillRect(this._rect, this._initalFillColor);
515
- else
516
- this._initalFillColor = null;
517
- if (useTemp) {
518
- target = SceneImage2D.getTemp(this.width, this.height, this._stage, nativeMSAA);
519
- // because target image is stupid filled - it not require merging
520
- // BUT when blend is required - we shpuld skip color clear and use empty TMP
521
- if (!useBlend && this._lastUsedFill !== null) {
522
- if (this._transparent) {
523
- //premulitply fill color!
524
- var _a = ColorUtils.float32ColorToARGB(this._lastUsedFill), a = _a[0], r = _a[1], g = _a[2], b = _a[3];
525
- a /= 0xFF;
526
- this._lastUsedFill = ColorUtils.ARGBtoFloat32(a * 0xFF, r * a | 0, g * a | 0, b * a | 0);
527
- }
528
- // bitmap was filled plain, go clear TMP to this color too
529
- renderer.disableClear = false;
530
- renderer.view.backgroundColor = this._lastUsedFill & 0xffffff;
531
- renderer.view.backgroundAlpha = this._transparent ? (this._lastUsedFill >>> 24 & 0xff) / 0xff : 1;
532
- }
533
- else {
534
- // we clear TMP and render to it, prepare to composing
535
- renderer.disableClear = false;
536
- renderer.view.backgroundColor = 0x0;
537
- renderer.view.backgroundAlpha = 0;
538
- // copy from source to tmp
539
- // TMP_POINT.setTo(0,0);
540
- // this._stage.copyPixels(this, target, this._rect, TMP_POINT, null, null, false);
541
- }
542
- }
543
- var transform = renderer.view.projection.transform;
544
- var mat3d = transform.matrix3D;
545
- mat3d.identity();
546
- if (matrix) {
547
- var raw = mat3d._rawData;
548
- raw[0] = matrix.a;
549
- raw[1] = matrix.b;
550
- raw[4] = matrix.c;
551
- raw[5] = matrix.d;
552
- raw[10] = 1;
553
- raw[12] = matrix.tx;
554
- raw[13] = matrix.ty;
555
- }
556
- // todo By this line we flip normals, and cull will be broken
557
- // NEED FIX THIS ASAP, or flip cull state
558
- mat3d.appendScale(1, -1, 1);
559
- mat3d.appendTranslation(0, this._rect.height, 1000);
560
- mat3d.invert();
561
- transform.matrix3D = mat3d;
562
- renderer.antiAlias = (internal ? this.antialiasQuality : target.antialiasQuality) || 0;
563
- renderer.view.target = target;
564
- renderer.view.projection.scale = 1000 / this._rect.height;
565
- // shift view, because target can be more
566
- renderer.view.projection.ratio = (this._rect.width / this._rect.height);
567
- renderer.view.x = -(target.width - this.width);
568
- renderer.view.y = -(target.height - this.height);
569
- renderer.view.width = this.width;
570
- renderer.view.height = this.height;
571
- var sourceNode = rootNode.addChildAt(source, 0);
572
- var transformDisabled = sourceNode.transformDisabled;
573
- sourceNode.transformDisabled = true;
574
- // masks should be enabled!
575
- sourceNode.maskDisabled = false;
576
- root.transform.colorTransform = colorTransform;
577
- // anyway we not support this =))
578
- root.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
579
- //save snapshot if unlocked
580
- //if (!this._locked)
581
- //SceneImage2D.scene.view.target=this;
582
- //SceneImage2D.scene.renderer.disableClear = !this._locked;
583
- renderer.render();
584
- // reset render to default value
585
- renderer.antiAlias = 0;
586
- renderer.disableClear = true;
587
- rootNode.removeChildAt(0);
588
- sourceNode.transformDisabled = transformDisabled;
589
- if (useTemp) {
590
- // because we copy MSAA into no msaa, it should passed as BLIT
591
- this._stage.filterManager.copyPixels(target, this, this._rect, TMP_POINT, useBlend, blendMode // apply blend mode if this needed.
592
- );
593
- SceneImage2D.tryStoreImage(target, this._stage);
594
- }
595
- };
596
- SceneImage2D.prototype.reset = function () { };
597
- SceneImage2D.prototype.clone = function () {
598
- var image = SceneImage2D.getImage(this.width, this.height, this.transparent, null, false, this._stage, false);
599
- this.copyTo(image);
600
- return image;
601
- };
602
- SceneImage2D.assetType = '[image SceneImage2D]';
603
- return SceneImage2D;
604
- }(BitmapImage2D));
605
- export { SceneImage2D };
606
- 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._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);