@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,908 +1,913 @@
1
-
2
- import { ContainerNode, View } from '@awayjs/view';
3
- import { MaterialBase } from '@awayjs/materials';
4
- import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
5
- import { DisplayObject } from '../display/DisplayObject';
6
- import { Billboard } from '../display/Billboard';
7
- import { Settings } from '../Settings';
8
-
9
- import {
10
- ColorTransform,
11
- Matrix,
12
- Rectangle,
13
- Point,
14
- PerspectiveProjection,
15
- CoordinateSystem,
16
- Vector3D,
17
- Transform,
18
- ColorUtils,
19
- } from '@awayjs/core';
20
-
21
- import { Stage,
22
- BitmapImage2D,
23
- _Stage_BitmapImage2D,
24
- BlendMode,
25
- Image2D
26
- } from '@awayjs/stage';
27
-
28
- import { DefaultRenderer, RenderGroup } from '@awayjs/renderer';
29
- import { MaterialManager } from '@awayjs/graphics';
30
-
31
- // empty matrix for transform reset
32
- const TMP_POINT = new Point(0,0);
33
-
34
- /**
35
- *
36
- */
37
- export class SceneImage2D extends BitmapImage2D {
38
- public static assetType: string = '[image SceneImage2D]';
39
-
40
- public static getImage(
41
- width: number, height: number, transparent: boolean = true,
42
- fillColor: number = 0xffffffff,
43
- powerOfTwo: boolean = true, stage: Stage = null, msaa = false
44
- ) {
45
- const result = new SceneImage2D(
46
- width,
47
- height,
48
- transparent,
49
- fillColor,
50
- powerOfTwo,
51
- stage
52
- );
53
-
54
- if (!msaa) {
55
- result._msaaNeedDrop = true;
56
- result._antialiasQuality = 0;
57
- } else {
58
- result._enforceMSAASupport = true;
59
- }
60
-
61
- return result;
62
- }
63
-
64
- public static tryStoreImage(image: Image2D, stage: Stage): void {
65
- stage.filterManager.pushTemp(image);
66
- }
67
-
68
- private static getTemp(width: number, height: number, stage: Stage, msaa = false) {
69
- const image = stage.filterManager.popTemp(width, height, msaa && Settings.ALLOW_FORCE_MSAA > 1);
70
-
71
- image.antialiasQuality = msaa ? Settings.ALLOW_FORCE_MSAA : 0;
72
- return image;
73
- }
74
-
75
- private static _renderer: DefaultRenderer;
76
- private static _billboardRenderer: DefaultRenderer;
77
- private static _view: View;
78
- private static _billboardView: View;
79
- private static _root: DisplayObjectContainer;
80
- private static _rootNode: ContainerNode;
81
- private static _billboardRoot: DisplayObjectContainer;
82
- private static _billboard: Billboard;
83
-
84
- protected _msaaNeedDrop: boolean = false;
85
-
86
- protected _enforceMSAASupport: boolean = false;
87
-
88
- protected _dropMSAA() {
89
- if (this._msaaNeedDrop || !this.canUseMSAAInternaly) {
90
- return;
91
- }
92
-
93
- this._enforceMSAASupport = false;
94
- this._msaaNeedDrop = true;
95
-
96
- // force dispose texture and buffers
97
- // MSAA not stored in pool
98
- if (this.wasUpload) {
99
- // super unload not call sync, we call it
100
- super.unload();
101
- }
102
-
103
- console.debug(
104
- '[SceneImage2D Experemental] Drop MSAA support because a setPixel* operation called after upload.',
105
- this.id
106
- );
107
- }
108
-
109
- public get canUseMSAAInternaly () {
110
- if (this._enforceMSAASupport) {
111
- return true;
112
- }
113
-
114
- let minW = Settings.MSAA_MINIMAL_IMAGE_SIZE;
115
- let minH = Settings.MSAA_MINIMAL_IMAGE_SIZE;
116
-
117
- if (this._stage) {
118
- minH = Math.min(this._stage.height, minH);
119
- minW = Math.min(this._stage.width, minW);
120
- }
121
-
122
- return (
123
- this.width >= minW &&
124
- this.height >= minH &&
125
- !this._msaaNeedDrop
126
- );
127
- }
128
-
129
- /*private*/ _antialiasQuality: number = Settings.ALLOW_FORCE_MSAA;
130
- public get antialiasQuality() {
131
- return this.canUseMSAAInternaly ? this._antialiasQuality : 0;
132
- }
133
-
134
- /**
135
- *
136
- * @returns {string}
137
- */
138
- public get assetType(): string {
139
- return SceneImage2D.assetType;
140
- }
141
-
142
- /**
143
- * Creates a BitmapImage2D object with a specified width and height. If you
144
- * specify a value for the <code>fillColor</code> parameter, every pixel in
145
- * the bitmap is set to that color.
146
- *
147
- * <p>By default, the bitmap is created as transparent, unless you pass
148
- * the value <code>false</code> for the transparent parameter. After you
149
- * create an opaque bitmap, you cannot change it to a transparent bitmap.
150
- * Every pixel in an opaque bitmap uses only 24 bits of color channel
151
- * information. If you define the bitmap as transparent, every pixel uses 32
152
- * bits of color channel information, including an alpha transparency
153
- * channel.</p>
154
- *
155
- * @param width The width of the bitmap image in pixels.
156
- * @param height The height of the bitmap image in pixels.
157
- * @param transparent Specifies whether the bitmap image supports per-pixel
158
- * transparency. The default value is <code>true</code>
159
- * (transparent). To create a fully transparent bitmap,
160
- * set the value of the <code>transparent</code>
161
- * parameter to <code>true</code> and the value of the
162
- * <code>fillColor</code> parameter to 0x00000000(or to
163
- * 0). Setting the <code>transparent</code> property to
164
- * <code>false</code> can result in minor improvements
165
- * in rendering performance.
166
- * @param fillColor A 32-bit ARGB color value that you use to fill the
167
- * bitmap image area. The default value is
168
- * 0xFFFFFFFF(solid white).
169
- */
170
- constructor(
171
- width: number, height: number, transparent: boolean = true,
172
- fillColor: number = 0xffffffff, powerOfTwo: boolean = true, stage: Stage = null) {
173
-
174
- super(width, height, transparent, fillColor, powerOfTwo, stage);
175
-
176
- }
177
-
178
- private createRenderer() {
179
- //create the projection
180
- const projection = new PerspectiveProjection();
181
- projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
182
- projection.originX = -1;
183
- projection.originY = 1;
184
- projection.transform = new Transform();
185
- projection.transform.scaleTo(1, -1, 1);
186
- projection.transform.moveTo(0, 0, -1000);
187
-
188
- //create the view
189
- SceneImage2D._view = new View(projection, this._stage);
190
- SceneImage2D._root = new DisplayObjectContainer();
191
- SceneImage2D._rootNode = SceneImage2D._view.getNode(SceneImage2D._root);
192
- SceneImage2D._renderer = <DefaultRenderer> RenderGroup
193
- .getInstance(DefaultRenderer)
194
- .getRenderer(SceneImage2D._rootNode);
195
-
196
- //set the view properties
197
- SceneImage2D._view.backgroundAlpha = 0;
198
- SceneImage2D._view.backgroundColor = 0x0;
199
-
200
- //set the renderer properties
201
- SceneImage2D._renderer.disableClear = true;
202
- SceneImage2D._renderer.renderableSorter = null;//new RenderableSort2D();
203
- //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
204
- }
205
-
206
- private createBillboardRenderer(): void {
207
- //create the projection
208
- const projection = new PerspectiveProjection();
209
- projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
210
- projection.originX = -1;
211
- projection.originY = 1;
212
- projection.transform = new Transform();
213
- projection.transform.moveTo(0, 0, -1000);
214
- projection.transform.lookAt(new Vector3D());
215
-
216
- //create the view
217
- SceneImage2D._billboardView = new View(projection, this._stage);
218
- SceneImage2D._billboardRoot = new DisplayObjectContainer();
219
- SceneImage2D._billboardRenderer = <DefaultRenderer> RenderGroup
220
- .getInstance(DefaultRenderer)
221
- .getRenderer(SceneImage2D._billboardView.getNode(SceneImage2D._billboardRoot));
222
-
223
- //SceneImage2D._billboardRoot.partition = SceneImage2D._billboardRenderer.partition;
224
-
225
- //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
226
- //set the view properties
227
- SceneImage2D._billboardView.backgroundAlpha = 0;
228
- SceneImage2D._billboardView.backgroundColor = 0x0;
229
-
230
- //set the renderer properties
231
- SceneImage2D._billboardRenderer.disableClear = true;
232
- SceneImage2D._billboardRenderer.renderableSorter = null;//new RenderableSort2D();
233
-
234
- SceneImage2D._billboard = new Billboard(MaterialManager.getMaterialForBitmap());
235
-
236
- SceneImage2D._billboardRoot.addChild(SceneImage2D._billboard);
237
- }
238
-
239
- /**
240
- * Frees memory that is used to store the BitmapImage2D object.
241
- *
242
- * <p>When the <code>dispose()</code> method is called on an image, the width
243
- * and height of the image are set to 0. All subsequent calls to methods or
244
- * properties of this BitmapImage2D instance fail, and an exception is thrown.
245
- * </p>
246
- *
247
- * <p><code>BitmapImage2D.dispose()</code> releases the memory occupied by the
248
- * actual bitmap data, immediately(a bitmap can consume up to 64 MB of
249
- * memory). After using <code>BitmapImage2D.dispose()</code>, the BitmapImage2D
250
- * object is no longer usable and an exception may be thrown if
251
- * you call functions on the BitmapImage2D object. However,
252
- * <code>BitmapImage2D.dispose()</code> does not garbage collect the BitmapImage2D
253
- * object(approximately 128 bytes); the memory occupied by the actual
254
- * BitmapImage2D object is released at the time the BitmapImage2D object is
255
- * collected by the garbage collector.</p>
256
- *
257
- */
258
- public dispose(): void {
259
- this._clearFromDispose = true;
260
-
261
- this.unmarkToUnload();
262
- this.unuseWeakRef();
263
-
264
- // drop buffer, because is big
265
- this._data = null;
266
- this._locked = false;
267
- super.dispose();
268
-
269
- this._clearFromDispose = false;
270
- }
271
-
272
- public unload() {
273
- // query async unload
274
- if (this._imageDataDirty) {
275
- const t = this.syncData(true);
276
-
277
- // strict quard
278
- if (typeof t !== 'boolean') {
279
- t.then(() => super.unload());
280
- return;
281
- }
282
- }
283
-
284
- super.unload();
285
- }
286
-
287
- public copyTo(target: SceneImage2D): void {
288
- target.copyPixels(this, target.rect, new Point(0,0));
289
- }
290
-
291
- /**
292
- * Provides a fast routine to perform pixel manipulation between images with
293
- * no stretching, rotation, or color effects. This method copies a
294
- * rectangular area of a source image to a rectangular area of the same size
295
- * at the destination point of the destination BitmapImage2D object.
296
- *
297
- * <p>If you include the <code>alphaBitmap</code> and <code>alphaPoint</code>
298
- * parameters, you can use a secondary image as an alpha source for the
299
- * source image. If the source image has alpha data, both sets of alpha data
300
- * are used to composite pixels from the source image to the destination
301
- * image. The <code>alphaPoint</code> parameter is the point in the alpha
302
- * image that corresponds to the upper-left corner of the source rectangle.
303
- * Any pixels outside the intersection of the source image and alpha image
304
- * are not copied to the destination image.</p>
305
- *
306
- * <p>The <code>mergeAlpha</code> property controls whether or not the alpha
307
- * channel is used when a transparent image is copied onto another
308
- * transparent image. To copy pixels with the alpha channel data, set the
309
- * <code>mergeAlpha</code> property to <code>true</code>. By default, the
310
- * <code>mergeAlpha</code> property is <code>false</code>.</p>
311
- *
312
- * @param source The input bitmap image from which to copy pixels.
313
- * The source image can be a different BitmapImage2D
314
- * instance, or it can refer to the current
315
- * BitmapImage2D instance.
316
- * @param sourceRect A rectangle that defines the area of the source
317
- * image to use as input.
318
- * @param destPoint The destination point that represents the
319
- * upper-left corner of the rectangular area where
320
- * the new pixels are placed.
321
- * @param alphaBitmapData A secondary, alpha BitmapImage2D object source.
322
- * @param alphaPoint The point in the alpha BitmapImage2D object source
323
- * that corresponds to the upper-left corner of the
324
- * <code>sourceRect</code> parameter.
325
- * @param mergeAlpha To use the alpha channel, set the value to
326
- * <code>true</code>. To copy pixels with no alpha
327
- * channel, set the value to <code>false</code>.
328
- * @throws TypeError The sourceBitmapImage2D, sourceRect, destPoint are null.
329
- */
330
- public copyPixels(
331
- source: BitmapImage2D, sourceRect: Rectangle, destPoint: Point,
332
- alphaBitmapData?: BitmapImage2D, alphaPoint?: Point, mergeAlpha?: boolean): void {
333
-
334
- this._lastUsedFill = null;
335
- this.unmarkToUnload();
336
-
337
- // need drop alpha from source when target is not has alpha
338
- mergeAlpha = this.transparent !== source.transparent || mergeAlpha;
339
-
340
- // CPU based copy, not require run GPU based copy
341
- // block is equal, one of image not uploaded yet
342
- // and source image no require SYNC
343
- if (!(<SceneImage2D>source)._imageDataDirty &&
344
- sourceRect.equals(this._rect) &&
345
- this._rect.equals(source.rect) &&
346
- !mergeAlpha && (!this.wasUpload || !source.wasUpload)
347
- ) {
348
- const data = source.getDataInternal(true);
349
-
350
- // inline, instead of setPixels, because it use a lot of checks
351
- if (this._data) {
352
- this._data.set(data);
353
- } else {
354
- this._data = data.slice();
355
- }
356
-
357
- // we should sync this, because we can apply PMA twice, that not needed for us
358
- this._unpackPMA = (<any> source)._unpackPMA;
359
- // we should reset initial color, because not require fill it after copyPixel
360
- this._initalFillColor = null;
361
- this._imageDataDirty = false;
362
- this.invalidateGPU();
363
- return;
364
- }
365
-
366
- if (source.width * source.height <= Settings.CPU_COPY_PIXELS_COUNT && !mergeAlpha) {
367
- // todo Not implemented yet, need to implement and check performance change
368
- // i think that increase some small operation performance,
369
- // because copy by GPU required upload array to VRAM,
370
- // and games that use set/get pixels and copyPixels only for math process not required use GPU copy
371
- }
372
-
373
- if (this._initalFillColor !== null)
374
- this.fillRect(this._rect, this._initalFillColor);
375
-
376
- let compositeSource: Image2D = source;
377
-
378
- // merge alpha with source
379
- if (alphaBitmapData) {
380
- compositeSource = this._stage.filterManager.popTemp(source.width, source.height);
381
-
382
- //this._stage.filterManager.copyPixels(source, compositeSource, source.rect, source.rect.topLeft);
383
- this._stage.filterManager.copyPixels(
384
- alphaBitmapData,
385
- compositeSource,
386
- new Rectangle(
387
- alphaPoint.x,
388
- alphaPoint.y,
389
- sourceRect.width,
390
- sourceRect.height
391
- ),
392
- new Point(0,0)
393
- );
394
-
395
- this._stage.filterManager.copyPixels(
396
- source,
397
- compositeSource,
398
- source.rect,
399
- new Point(0,0),
400
- true,
401
- 'alpha_back'
402
- );
403
- }
404
-
405
- this._stage.filterManager.copyPixels(
406
- compositeSource,
407
- this,
408
- sourceRect,
409
- destPoint,
410
- mergeAlpha
411
- );
412
-
413
- if (alphaBitmapData) {
414
- this._stage.filterManager.pushTemp(compositeSource);
415
- }
416
-
417
- this._imageDataDirty = true;
418
- this.invalidateOwners();
419
- }
420
-
421
- public threshold(
422
- source: BitmapImage2D,
423
- sourceRect: Rectangle,
424
- destPoint: Point,
425
- operation: string,
426
- threshold: number,
427
- color: number,
428
- mask: number,
429
- copySource: boolean
430
- ): void {
431
-
432
- this._lastUsedFill = null;
433
- this.unmarkToUnload();
434
-
435
- if (this._initalFillColor !== null)
436
- this.fillRect(this._rect, this._initalFillColor);
437
-
438
- this._stage.threshold(source, this, sourceRect, destPoint, operation, threshold, color, mask, copySource);
439
- this._imageDataDirty = true;
440
- this.invalidateOwners();
441
- }
442
-
443
- public applyFilter (source: BitmapImage2D, sourceRect: Rectangle, destPoint: Point, filter: any): boolean {
444
- if (!Settings.USE_UNSAFE_FILTERS || !filter || !filter.filterName) {
445
- return false;
446
- }
447
-
448
- const result = this._stage.filterManager.applyFilter (
449
- source,
450
- this,
451
- sourceRect,
452
- destPoint,
453
- filter.filterName, filter);
454
-
455
- this._imageDataDirty = result;
456
-
457
- if (result)
458
- this.invalidateOwners();
459
-
460
- return result;
461
- }
462
-
463
- public colorTransform(rect: Rectangle, colorTransform: ColorTransform): void {
464
- this.unmarkToUnload();
465
-
466
- this._lastUsedFill = null;
467
-
468
- this._stage.colorTransform(this, this, rect, colorTransform);
469
-
470
- this._imageDataDirty = true;
471
- this.invalidateOwners();
472
- }
473
-
474
- public setPixel(x: number, y: number, color: number) {
475
- // we can't upload buffer in MSAA texture after creating - only render it and get
476
- if (this.canUseMSAAInternaly) {
477
- this._dropMSAA();
478
- }
479
-
480
- super.setPixel(x, y, color);
481
- }
482
-
483
- public setPixel32(x: number, y: number, color: number) {
484
- // we can't upload buffer in MSAA texture after creating - only render it and get
485
- if (this.canUseMSAAInternaly) {
486
- this._dropMSAA();
487
- }
488
-
489
- super.setPixel32(x, y, color);
490
- }
491
-
492
- public setPixels(rect: Rectangle, buffer: Uint8ClampedArray) {
493
- // we can't upload buffer in MSAA texture after creating - only render it and get
494
- if (this.wasUpload && this.canUseMSAAInternaly) {
495
- this._dropMSAA();
496
- }
497
-
498
- super.setPixels(rect, buffer);
499
- }
500
-
501
- private _clearFromDispose = false;
502
- public clear() {
503
- // we call clear in parent class from dispose, call direct
504
- if (this._clearFromDispose) {
505
- super.clear();
506
- return;
507
- }
508
-
509
- // clear should drop abstraction, but we can't doing this if unloaded
510
- const t = this.syncData(true);
511
-
512
- // not require unload, we already doings this
513
- this.unmarkToUnload();
514
- this.lastUsedTime = -1;
515
-
516
- if (typeof t === 'boolean') {
517
- this.wasUpload = false;
518
- super.clear();
519
- return;
520
- }
521
-
522
- t.then(() => {
523
- this.wasUpload = false;
524
- super.clear();
525
- });
526
- }
527
-
528
- /**
529
- * @inheritdoc
530
- */
531
- public getPixel32(x: number, y: number): number {
532
- this.syncData();
533
-
534
- return super.getPixel32(x, y);
535
- }
536
-
537
- /**
538
- * @inheritdoc
539
- */
540
- public getPixel(x: number, y: number): number {
541
- const result = this.getPixel32(x, y);
542
-
543
- return result & 0x00ffffff;
544
- }
545
-
546
- /**
547
- * Draws the <code>source</code> display object onto the bitmap image, using
548
- * the NME software renderer. You can specify <code>matrix</code>,
549
- * <code>colorTransform</code>, <code>blendMode</code>, and a destination
550
- * <code>clipRect</code> parameter to control how the rendering performs.
551
- * Optionally, you can specify whether the bitmap should be smoothed when
552
- * scaled(this works only if the source object is a BitmapImage2D object).
553
- *
554
- * <p>The source display object does not use any of its applied
555
- * transformations for this call. It is treated as it exists in the library
556
- * or file, with no matrix transform, no color transform, and no blend mode.
557
- * To draw a display object(such as a movie clip) by using its own transform
558
- * properties, you can copy its <code>transform</code> property object to the
559
- * <code>transform</code> property of the Bitmap object that uses the
560
- * BitmapImage2D object.</p>
561
- *
562
- * @param source The display object or BitmapImage2D object to draw to
563
- * the BitmapImage2D object.(The DisplayObject and
564
- * BitmapImage2D classes implement the IBitmapDrawable
565
- * interface.)
566
- * @param matrix A Matrix object used to scale, rotate, or translate
567
- * the coordinates of the bitmap. If you do not want to
568
- * apply a matrix transformation to the image, set this
569
- * parameter to an identity matrix, created with the
570
- * default <code>new Matrix()</code> constructor, or
571
- * pass a <code>null</code> value.
572
- * @param colorTransform A ColorTransform object that you use to adjust the
573
- * color values of the bitmap. If no object is
574
- * supplied, the bitmap image's colors are not
575
- * transformed. If you must pass this parameter but you
576
- * do not want to transform the image, set this
577
- * parameter to a ColorTransform object created with
578
- * the default <code>new ColorTransform()</code>
579
- * constructor.
580
- * @param blendMode A string value, from the flash.display.BlendMode
581
- * class, specifying the blend mode to be applied to
582
- * the resulting bitmap.
583
- * @param clipRect A Rectangle object that defines the area of the
584
- * source object to draw. If you do not supply this
585
- * value, no clipping occurs and the entire source
586
- * object is drawn.
587
- * @param smoothing A Boolean value that determines whether a BitmapImage2D
588
- * object is smoothed when scaled or rotated, due to a
589
- * scaling or rotation in the <code>matrix</code>
590
- * parameter. The <code>smoothing</code> parameter only
591
- * applies if the <code>source</code> parameter is a
592
- * BitmapImage2D object. With <code>smoothing</code> set
593
- * to <code>false</code>, the rotated or scaled
594
- * BitmapImage2D image can appear pixelated or jagged. For
595
- * example, the following two images use the same
596
- * BitmapImage2D object for the <code>source</code>
597
- * parameter, but the <code>smoothing</code> parameter
598
- * is set to <code>true</code> on the left and
599
- * <code>false</code> on the right:
600
- *
601
- * <p>Drawing a bitmap with <code>smoothing</code> set
602
- * to <code>true</code> takes longer than doing so with
603
- * <code>smoothing</code> set to
604
- * <code>false</code>.</p>
605
- * @throws ArgumentError The <code>source</code> parameter is not a
606
- * BitmapImage2D or DisplayObject object.
607
- * @throws ArgumentError The source is null or not a valid IBitmapDrawable
608
- * object.
609
- * @throws SecurityError The <code>source</code> object and(in the case of a
610
- * Sprite or MovieClip object) all of its child objects
611
- * do not come from the same domain as the caller, or
612
- * are not in a content that is accessible to the
613
- * caller by having called the
614
- * <code>Security.allowDomain()</code> method. This
615
- * restriction does not apply to AIR content in the
616
- * application security sandbox.
617
- */
618
-
619
- /* eslint-disable */
620
- public draw(source: DisplayObject, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean);
621
- public draw(source: BitmapImage2D, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean);
622
- public draw(source: any, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean): void
623
- {
624
- /* eslint-enable */
625
-
626
- this.unmarkToUnload();
627
-
628
- if (source instanceof DisplayObject) {
629
- this._drawAsDisplay(source, matrix, colorTransform, blendMode, clipRect, smoothing);
630
- } else {
631
- this._drawAsBitmap(source, matrix, colorTransform, blendMode, clipRect, smoothing);
632
- }
633
-
634
- this._lastUsedFill = null;
635
- this._imageDataDirty = true;
636
- this.invalidateOwners();
637
- }
638
-
639
- private static _mapSupportedBlendMode(blendMode: string = ''): string {
640
- switch (blendMode) {
641
- case null:
642
- case '':
643
- case BlendMode.NORMAL:
644
- case BlendMode.LAYER:
645
- return BlendMode.LAYER;
646
- case BlendMode.MULTIPLY:
647
- case BlendMode.ADD:
648
- case BlendMode.ALPHA:
649
- return blendMode;
650
- }
651
-
652
- //console.debug("[ImageBitmap] Unsupport BlendMode", blendMode);
653
- return BlendMode.LAYER;
654
- }
655
-
656
- private _drawAsBitmap(
657
- source: BitmapImage2D, matrix?: Matrix, colorTransform?: ColorTransform,
658
- blendMode?: string, _clipRect?: Rectangle, smoothing?: boolean
659
- ) {
660
- // default global blend mode
661
- blendMode = blendMode || BlendMode.LAYER;
662
-
663
- if (!SceneImage2D._billboardRenderer) {
664
- this.createBillboardRenderer();
665
- }
666
-
667
- if (this._initalFillColor !== null)
668
- this.fillRect(this._rect, this._initalFillColor);
669
-
670
- const stage = this._stage;
671
- const mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
672
- const supportNativeBlend = !blendMode || mappedBlend !== BlendMode.LAYER || blendMode == BlendMode.LAYER;
673
- const useTmp = (!supportNativeBlend || this === source);
674
- const target = useTmp ?
675
- stage.filterManager.popTemp(this.width, this.height, false)
676
- : this;
677
-
678
- const renderer = SceneImage2D._billboardRenderer;
679
- const root = SceneImage2D._billboardRoot;
680
- const billboard = SceneImage2D._billboard;
681
-
682
- billboard.style.sampler.smooth = smoothing;
683
-
684
- renderer.disableClear = !useTmp;
685
- renderer.view.target = target;
686
- renderer.view.projection.scale = 1000 / target.height;
687
-
688
- billboard.style.image = source;
689
-
690
- // not all blend modes can be used for rendering
691
- billboard.material.blendMode = !useTmp ? mappedBlend : BlendMode.LAYER;
692
-
693
- (<MaterialBase> billboard.material).useColorTransform = !!colorTransform;
694
-
695
- if (useTmp) {
696
- // we clear TMP and render to it, prepare to composing
697
- renderer.view.backgroundColor = 0x0;
698
- renderer.view.backgroundAlpha = 0;
699
- }
700
-
701
- if (matrix) {
702
- const m = root.transform.matrix3D;
703
-
704
- m.identity();
705
-
706
- m._rawData[0] = matrix.a;
707
- m._rawData[1] = -matrix.b;
708
- m._rawData[4] = matrix.c;
709
- m._rawData[5] = -matrix.d;
710
- m._rawData[12] = matrix.tx;
711
- m._rawData[13] = target.height - matrix.ty;
712
-
713
- root.transform.invalidateComponents();
714
- } else {
715
-
716
- root.transform.rotateTo(0,0,0);
717
- root.transform.scaleTo(1, -1, 1);
718
- root.transform.moveTo(0, target.height,0);
719
- }
720
-
721
- root.transform.colorTransform = colorTransform;
722
-
723
- //render
724
- renderer.render();
725
-
726
- //
727
- if (useTmp) {
728
- stage.filterManager.copyPixels(
729
- target,
730
- this,
731
- this.rect,
732
- TMP_POINT,
733
- true,
734
- blendMode
735
- );
736
-
737
- stage.filterManager.pushTemp(target);
738
- }
739
-
740
- //reset material blendMode
741
- billboard.material.blendMode = BlendMode.NORMAL;
742
- }
743
-
744
- private _drawAsDisplay(
745
- source: DisplayObject, matrix?: Matrix, colorTransform?: ColorTransform,
746
- blendMode: string = '', _clipRect?: Rectangle, _smoothing?: boolean
747
- ) {
748
- // default global blend mode
749
- blendMode = blendMode || BlendMode.LAYER;
750
-
751
- if (!SceneImage2D._renderer) {
752
- this.createRenderer();
753
- }
754
-
755
- const root = SceneImage2D._root;
756
- const rootNode = SceneImage2D._rootNode;
757
- const renderer = SceneImage2D._renderer;
758
-
759
- // when we should use MSAA, we will create temporary image and draw to it
760
- const internal = this.canUseMSAAInternaly;
761
- const nativeMSAA = (
762
- !source.isAsset(Billboard) &&
763
- this._stage.context.glVersion === 2 && // can be used because a webgl2
764
- Settings.ALLOW_FORCE_MSAA > 1 && // because a quality is more that 1
765
- !internal); // and not internal
766
-
767
- // target image for rendering.
768
- let target: Image2D = this;
769
-
770
- // we should run compositor when blendMode !== LAYER (default)
771
- // or when we use MSAA + fill is not flat.
772
- const useBlend = blendMode !== BlendMode.LAYER || (this._lastUsedFill === null && nativeMSAA);
773
-
774
- const useTemp = useBlend || nativeMSAA;
775
-
776
- // lazy filling
777
- // we require fill image with initial color, because we not doing this immediate
778
- // and when blend is required, because we should blend with vald color
779
- if ((!nativeMSAA || useBlend) && this._initalFillColor !== null)
780
- this.fillRect(this._rect, this._initalFillColor);
781
- else
782
- this._initalFillColor = null;
783
-
784
- if (useTemp) {
785
- target = SceneImage2D.getTemp(this.width, this.height, this._stage, nativeMSAA);
786
-
787
- // because target image is stupid filled - it not require merging
788
- // BUT when blend is required - we shpuld skip color clear and use empty TMP
789
- if (!useBlend && this._lastUsedFill !== null) {
790
-
791
- if (this._transparent) {
792
- //premulitply fill color!
793
- let [a, r, g, b] = ColorUtils.float32ColorToARGB(this._lastUsedFill);
794
- a /= 0xFF;
795
- this._lastUsedFill = ColorUtils.ARGBtoFloat32(a * 0xFF, r * a | 0, g * a | 0, b * a | 0);
796
- }
797
- // bitmap was filled plain, go clear TMP to this color too
798
- renderer.disableClear = false;
799
- renderer.view.backgroundColor = this._lastUsedFill & 0xffffff;
800
- renderer.view.backgroundAlpha = this._transparent ? (this._lastUsedFill >>> 24 & 0xff) / 0xff : 1;
801
- } else {
802
- // we clear TMP and render to it, prepare to composing
803
- renderer.disableClear = false;
804
- renderer.view.backgroundColor = 0x0;
805
- renderer.view.backgroundAlpha = 0;
806
-
807
- // copy from source to tmp
808
- // TMP_POINT.setTo(0,0);
809
- // this._stage.copyPixels(this, target, this._rect, TMP_POINT, null, null, false);
810
- }
811
- }
812
-
813
- const transform = renderer.view.projection.transform;
814
- const mat3d = transform.matrix3D;
815
- mat3d.identity();
816
-
817
- if (matrix) {
818
- const raw = mat3d._rawData;
819
- raw[0] = matrix.a;
820
- raw[1] = matrix.b;
821
- raw[4] = matrix.c;
822
- raw[5] = matrix.d;
823
- raw[10] = 1;
824
- raw[12] = matrix.tx;
825
- raw[13] = matrix.ty;
826
- }
827
-
828
- // todo By this line we flip normals, and cull will be broken
829
- // NEED FIX THIS ASAP, or flip cull state
830
- mat3d.appendScale(1, -1, 1);
831
- mat3d.appendTranslation(0, this._rect.height, 1000);
832
-
833
- mat3d.invert();
834
- transform.matrix3D = mat3d;
835
-
836
- renderer.antiAlias = (internal ? this.antialiasQuality : (<any>target).antialiasQuality) || 0;
837
-
838
- renderer.view.target = target;
839
- renderer.view.projection.scale = 1000 / this._rect.height;
840
-
841
- // shift view, because target can be more
842
- renderer.view.projection.ratio = (this._rect.width / this._rect.height);
843
- renderer.view.x = -(target.width - this.width);
844
- renderer.view.y = -(target.height - this.height);
845
- renderer.view.width = this.width;
846
- renderer.view.height = this.height;
847
-
848
- const sourceNode: ContainerNode = rootNode.addChildAt(source, 0);
849
- const transformDisabled = sourceNode.transformDisabled;
850
-
851
- sourceNode.transformDisabled = true;
852
- // masks should be enabled!
853
- sourceNode.maskDisabled = false;
854
-
855
- root.transform.colorTransform = colorTransform;
856
- // anyway we not support this =))
857
- root.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
858
-
859
- //save snapshot if unlocked
860
- //if (!this._locked)
861
- //SceneImage2D.scene.view.target=this;
862
- //SceneImage2D.scene.renderer.disableClear = !this._locked;
863
-
864
- renderer.render();
865
-
866
- // reset render to default value
867
- renderer.antiAlias = 0;
868
- renderer.disableClear = true;
869
-
870
- rootNode.removeChildAt(0);
871
-
872
- sourceNode.transformDisabled = transformDisabled;
873
-
874
- if (useTemp) {
875
- // because we copy MSAA into no msaa, it should passed as BLIT
876
- this._stage.filterManager.copyPixels(
877
- target,
878
- this,
879
- this._rect,
880
- TMP_POINT,
881
- useBlend,
882
- blendMode // apply blend mode if this needed.
883
- );
884
-
885
- SceneImage2D.tryStoreImage(target, this._stage);
886
- }
887
- }
888
-
889
- public reset() {}
890
-
891
- public clone(): SceneImage2D {
892
- const image = SceneImage2D.getImage(
893
- this.width,
894
- this.height,
895
- this.transparent,
896
- null,
897
- false,
898
- this._stage,
899
- false
900
- );
901
-
902
- this.copyTo(image);
903
-
904
- return image;
905
- }
906
- }
907
-
1
+
2
+ import { ContainerNode, View } from '@awayjs/view';
3
+ import { MaterialBase } from '@awayjs/materials';
4
+ import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
5
+ import { DisplayObject } from '../display/DisplayObject';
6
+ import { Billboard } from '../display/Billboard';
7
+ import { Settings } from '../Settings';
8
+
9
+ import {
10
+ ColorTransform,
11
+ Matrix,
12
+ Rectangle,
13
+ Point,
14
+ PerspectiveProjection,
15
+ CoordinateSystem,
16
+ Vector3D,
17
+ Transform,
18
+ ColorUtils,
19
+ } from '@awayjs/core';
20
+
21
+ import { Stage,
22
+ BitmapImage2D,
23
+ _Stage_BitmapImage2D,
24
+ BlendMode,
25
+ Image2D
26
+ } from '@awayjs/stage';
27
+
28
+ import { DefaultRenderer, RenderGroup } from '@awayjs/renderer';
29
+ import { MaterialManager } from '@awayjs/graphics';
30
+
31
+ // empty matrix for transform reset
32
+ const TMP_POINT = new Point(0,0);
33
+
34
+ /**
35
+ *
36
+ */
37
+ export class SceneImage2D extends BitmapImage2D {
38
+ public static assetType: string = '[image SceneImage2D]';
39
+
40
+ public static getImage(
41
+ width: number, height: number, transparent: boolean = true,
42
+ fillColor: number = 0xffffffff,
43
+ powerOfTwo: boolean = true, stage: Stage = null, msaa = false
44
+ ) {
45
+ const result = new SceneImage2D(
46
+ width,
47
+ height,
48
+ transparent,
49
+ fillColor,
50
+ powerOfTwo,
51
+ stage
52
+ );
53
+
54
+ if (!msaa) {
55
+ result._msaaNeedDrop = true;
56
+ result._antialiasQuality = 0;
57
+ } else {
58
+ result._enforceMSAASupport = true;
59
+ }
60
+
61
+ return result;
62
+ }
63
+
64
+ public static tryStoreImage(image: Image2D, stage: Stage): void {
65
+ stage.filterManager.pushTemp(image);
66
+ }
67
+
68
+ private static getTemp(width: number, height: number, stage: Stage, msaa = false) {
69
+ const image = stage.filterManager.popTemp(width, height, msaa && Settings.ALLOW_FORCE_MSAA > 1);
70
+
71
+ image.antialiasQuality = msaa ? Settings.ALLOW_FORCE_MSAA : 0;
72
+ return image;
73
+ }
74
+
75
+ private static _renderer: DefaultRenderer;
76
+ private static _billboardRenderer: DefaultRenderer;
77
+ private static _view: View;
78
+ private static _billboardView: View;
79
+ private static _root: DisplayObjectContainer;
80
+ private static _rootNode: ContainerNode;
81
+ private static _billboardRoot: DisplayObjectContainer;
82
+ private static _billboard: Billboard;
83
+
84
+ protected _msaaNeedDrop: boolean = false;
85
+
86
+ protected _enforceMSAASupport: boolean = false;
87
+
88
+ protected _dropMSAA() {
89
+ if (this._msaaNeedDrop || !this.canUseMSAAInternaly) {
90
+ return;
91
+ }
92
+
93
+ this._enforceMSAASupport = false;
94
+ this._msaaNeedDrop = true;
95
+
96
+ // force dispose texture and buffers
97
+ // MSAA not stored in pool
98
+ if (this.wasUpload) {
99
+ // super unload not call sync, we call it
100
+ super.unload();
101
+ }
102
+
103
+ console.debug(
104
+ '[SceneImage2D Experemental] Drop MSAA support because a setPixel* operation called after upload.',
105
+ this.id
106
+ );
107
+ }
108
+
109
+ public get canUseMSAAInternaly () {
110
+ if (this._enforceMSAASupport) {
111
+ return true;
112
+ }
113
+
114
+ let minW = Settings.MSAA_MINIMAL_IMAGE_SIZE;
115
+ let minH = Settings.MSAA_MINIMAL_IMAGE_SIZE;
116
+
117
+ if (this._stage) {
118
+ minH = Math.min(this._stage.height, minH);
119
+ minW = Math.min(this._stage.width, minW);
120
+ }
121
+
122
+ return (
123
+ this.width >= minW &&
124
+ this.height >= minH &&
125
+ !this._msaaNeedDrop
126
+ );
127
+ }
128
+
129
+ /*private*/ _antialiasQuality: number = Settings.ALLOW_FORCE_MSAA;
130
+ public get antialiasQuality() {
131
+ return this.canUseMSAAInternaly ? this._antialiasQuality : 0;
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @returns {string}
137
+ */
138
+ public get assetType(): string {
139
+ return SceneImage2D.assetType;
140
+ }
141
+
142
+ /**
143
+ * Creates a BitmapImage2D object with a specified width and height. If you
144
+ * specify a value for the <code>fillColor</code> parameter, every pixel in
145
+ * the bitmap is set to that color.
146
+ *
147
+ * <p>By default, the bitmap is created as transparent, unless you pass
148
+ * the value <code>false</code> for the transparent parameter. After you
149
+ * create an opaque bitmap, you cannot change it to a transparent bitmap.
150
+ * Every pixel in an opaque bitmap uses only 24 bits of color channel
151
+ * information. If you define the bitmap as transparent, every pixel uses 32
152
+ * bits of color channel information, including an alpha transparency
153
+ * channel.</p>
154
+ *
155
+ * @param width The width of the bitmap image in pixels.
156
+ * @param height The height of the bitmap image in pixels.
157
+ * @param transparent Specifies whether the bitmap image supports per-pixel
158
+ * transparency. The default value is <code>true</code>
159
+ * (transparent). To create a fully transparent bitmap,
160
+ * set the value of the <code>transparent</code>
161
+ * parameter to <code>true</code> and the value of the
162
+ * <code>fillColor</code> parameter to 0x00000000(or to
163
+ * 0). Setting the <code>transparent</code> property to
164
+ * <code>false</code> can result in minor improvements
165
+ * in rendering performance.
166
+ * @param fillColor A 32-bit ARGB color value that you use to fill the
167
+ * bitmap image area. The default value is
168
+ * 0xFFFFFFFF(solid white).
169
+ */
170
+ constructor(
171
+ width: number, height: number, transparent: boolean = true,
172
+ fillColor: number = 0xffffffff, powerOfTwo: boolean = true, stage: Stage = null) {
173
+
174
+ super(width, height, transparent, fillColor, powerOfTwo, stage);
175
+
176
+ }
177
+
178
+ private createRenderer() {
179
+ //create the projection
180
+ const projection = new PerspectiveProjection();
181
+ projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
182
+ projection.originX = -1;
183
+ projection.originY = 1;
184
+ projection.transform = new Transform();
185
+ projection.transform.scaleTo(1, -1, 1);
186
+ projection.transform.moveTo(0, 0, -1000);
187
+
188
+ //create the view
189
+ SceneImage2D._view = new View(projection, this._stage);
190
+ SceneImage2D._root = new DisplayObjectContainer();
191
+ SceneImage2D._rootNode = SceneImage2D._view.getNode(SceneImage2D._root);
192
+ SceneImage2D._renderer = <DefaultRenderer> RenderGroup
193
+ .getInstance(DefaultRenderer)
194
+ .getRenderer(SceneImage2D._rootNode);
195
+
196
+ //set the view properties
197
+ SceneImage2D._view.backgroundAlpha = 0;
198
+ SceneImage2D._view.backgroundColor = 0x0;
199
+
200
+ //set the renderer properties
201
+ SceneImage2D._renderer.disableClear = true;
202
+ SceneImage2D._renderer.renderableSorter = null;//new RenderableSort2D();
203
+ //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
204
+ }
205
+
206
+ private createBillboardRenderer(): void {
207
+ //create the projection
208
+ const projection = new PerspectiveProjection();
209
+ projection.coordinateSystem = CoordinateSystem.RIGHT_HANDED;
210
+ projection.originX = -1;
211
+ projection.originY = 1;
212
+ projection.transform = new Transform();
213
+ projection.transform.moveTo(0, 0, -1000);
214
+ projection.transform.lookAt(new Vector3D());
215
+
216
+ //create the view
217
+ SceneImage2D._billboardView = new View(projection, this._stage);
218
+ SceneImage2D._billboardRoot = new DisplayObjectContainer();
219
+ SceneImage2D._billboardRenderer = <DefaultRenderer> RenderGroup
220
+ .getInstance(DefaultRenderer)
221
+ .getRenderer(SceneImage2D._billboardView.getNode(SceneImage2D._billboardRoot));
222
+
223
+ //SceneImage2D._billboardRoot.partition = SceneImage2D._billboardRenderer.partition;
224
+
225
+ //SceneImage2D._renderer.antiAlias = Settings.ALLOW_FORCE_MSAA;
226
+ //set the view properties
227
+ SceneImage2D._billboardView.backgroundAlpha = 0;
228
+ SceneImage2D._billboardView.backgroundColor = 0x0;
229
+
230
+ //set the renderer properties
231
+ SceneImage2D._billboardRenderer.disableClear = true;
232
+ SceneImage2D._billboardRenderer.renderableSorter = null;//new RenderableSort2D();
233
+
234
+ SceneImage2D._billboard = new Billboard(MaterialManager.getMaterialForBitmap());
235
+
236
+ SceneImage2D._billboardRoot.addChild(SceneImage2D._billboard);
237
+ }
238
+
239
+ /**
240
+ * Frees memory that is used to store the BitmapImage2D object.
241
+ *
242
+ * <p>When the <code>dispose()</code> method is called on an image, the width
243
+ * and height of the image are set to 0. All subsequent calls to methods or
244
+ * properties of this BitmapImage2D instance fail, and an exception is thrown.
245
+ * </p>
246
+ *
247
+ * <p><code>BitmapImage2D.dispose()</code> releases the memory occupied by the
248
+ * actual bitmap data, immediately(a bitmap can consume up to 64 MB of
249
+ * memory). After using <code>BitmapImage2D.dispose()</code>, the BitmapImage2D
250
+ * object is no longer usable and an exception may be thrown if
251
+ * you call functions on the BitmapImage2D object. However,
252
+ * <code>BitmapImage2D.dispose()</code> does not garbage collect the BitmapImage2D
253
+ * object(approximately 128 bytes); the memory occupied by the actual
254
+ * BitmapImage2D object is released at the time the BitmapImage2D object is
255
+ * collected by the garbage collector.</p>
256
+ *
257
+ */
258
+ public dispose(): void {
259
+ this._clearFromDispose = true;
260
+
261
+ this.unmarkToUnload();
262
+ this.unuseWeakRef();
263
+
264
+ // drop buffer, because is big
265
+ this._data = null;
266
+ this._locked = false;
267
+ super.dispose();
268
+
269
+ this._clearFromDispose = false;
270
+ }
271
+
272
+ public unload() {
273
+ // query async unload
274
+ if (this._imageDataDirty) {
275
+ const t = this.syncData(true);
276
+
277
+ // strict quard
278
+ if (typeof t !== 'boolean') {
279
+ t.then(() => super.unload());
280
+ return;
281
+ }
282
+ }
283
+
284
+ super.unload();
285
+ }
286
+
287
+ public copyTo(target: SceneImage2D): void {
288
+ target.copyPixels(this, target.rect, new Point(0,0));
289
+ }
290
+
291
+ /**
292
+ * Provides a fast routine to perform pixel manipulation between images with
293
+ * no stretching, rotation, or color effects. This method copies a
294
+ * rectangular area of a source image to a rectangular area of the same size
295
+ * at the destination point of the destination BitmapImage2D object.
296
+ *
297
+ * <p>If you include the <code>alphaBitmap</code> and <code>alphaPoint</code>
298
+ * parameters, you can use a secondary image as an alpha source for the
299
+ * source image. If the source image has alpha data, both sets of alpha data
300
+ * are used to composite pixels from the source image to the destination
301
+ * image. The <code>alphaPoint</code> parameter is the point in the alpha
302
+ * image that corresponds to the upper-left corner of the source rectangle.
303
+ * Any pixels outside the intersection of the source image and alpha image
304
+ * are not copied to the destination image.</p>
305
+ *
306
+ * <p>The <code>mergeAlpha</code> property controls whether or not the alpha
307
+ * channel is used when a transparent image is copied onto another
308
+ * transparent image. To copy pixels with the alpha channel data, set the
309
+ * <code>mergeAlpha</code> property to <code>true</code>. By default, the
310
+ * <code>mergeAlpha</code> property is <code>false</code>.</p>
311
+ *
312
+ * @param source The input bitmap image from which to copy pixels.
313
+ * The source image can be a different BitmapImage2D
314
+ * instance, or it can refer to the current
315
+ * BitmapImage2D instance.
316
+ * @param sourceRect A rectangle that defines the area of the source
317
+ * image to use as input.
318
+ * @param destPoint The destination point that represents the
319
+ * upper-left corner of the rectangular area where
320
+ * the new pixels are placed.
321
+ * @param alphaBitmapData A secondary, alpha BitmapImage2D object source.
322
+ * @param alphaPoint The point in the alpha BitmapImage2D object source
323
+ * that corresponds to the upper-left corner of the
324
+ * <code>sourceRect</code> parameter.
325
+ * @param mergeAlpha To use the alpha channel, set the value to
326
+ * <code>true</code>. To copy pixels with no alpha
327
+ * channel, set the value to <code>false</code>.
328
+ * @throws TypeError The sourceBitmapImage2D, sourceRect, destPoint are null.
329
+ */
330
+ public copyPixels(
331
+ source: BitmapImage2D, sourceRect: Rectangle, destPoint: Point,
332
+ alphaBitmapData?: BitmapImage2D, alphaPoint?: Point, mergeAlpha?: boolean): void {
333
+
334
+ this._lastUsedFill = null;
335
+ this.unmarkToUnload();
336
+
337
+ // need drop alpha from source when target is not has alpha
338
+ mergeAlpha = this.transparent !== source.transparent || mergeAlpha;
339
+
340
+ // CPU based copy, not require run GPU based copy
341
+ // block is equal, one of image not uploaded yet
342
+ // and source image no require SYNC
343
+ if (!(<SceneImage2D>source)._imageDataDirty &&
344
+ sourceRect.equals(this._rect) &&
345
+ this._rect.equals(source.rect) &&
346
+ !mergeAlpha && (!this.wasUpload || !source.wasUpload)
347
+ ) {
348
+ const data = source.getDataInternal(true);
349
+
350
+ // inline, instead of setPixels, because it use a lot of checks
351
+ if (this._data) {
352
+ this._data.set(data);
353
+ } else {
354
+ this._data = data.slice();
355
+ }
356
+
357
+ // we should sync this, because we can apply PMA twice, that not needed for us
358
+ this._unpackPMA = (<any> source)._unpackPMA;
359
+ // we should reset initial color, because not require fill it after copyPixel
360
+ this._initalFillColor = null;
361
+ this._imageDataDirty = false;
362
+ this.invalidateGPU();
363
+ return;
364
+ }
365
+
366
+ if (source.width * source.height <= Settings.CPU_COPY_PIXELS_COUNT && !mergeAlpha) {
367
+ // todo Not implemented yet, need to implement and check performance change
368
+ // i think that increase some small operation performance,
369
+ // because copy by GPU required upload array to VRAM,
370
+ // and games that use set/get pixels and copyPixels only for math process not required use GPU copy
371
+ }
372
+
373
+ if (this._initalFillColor !== null)
374
+ this.fillRect(this._rect, this._initalFillColor);
375
+
376
+ let compositeSource: Image2D = source;
377
+
378
+ // merge alpha with source
379
+ if (alphaBitmapData) {
380
+ compositeSource = this._stage.filterManager.popTemp(source.width, source.height);
381
+
382
+ //this._stage.filterManager.copyPixels(source, compositeSource, source.rect, source.rect.topLeft);
383
+ this._stage.filterManager.copyPixels(
384
+ alphaBitmapData,
385
+ compositeSource,
386
+ new Rectangle(
387
+ alphaPoint.x,
388
+ alphaPoint.y,
389
+ sourceRect.width,
390
+ sourceRect.height
391
+ ),
392
+ new Point(0,0)
393
+ );
394
+
395
+ this._stage.filterManager.copyPixels(
396
+ source,
397
+ compositeSource,
398
+ source.rect,
399
+ new Point(0,0),
400
+ true,
401
+ 'alpha_back'
402
+ );
403
+ }
404
+
405
+ this._stage.filterManager.copyPixels(
406
+ compositeSource,
407
+ this,
408
+ sourceRect,
409
+ destPoint,
410
+ mergeAlpha
411
+ );
412
+
413
+ if (alphaBitmapData) {
414
+ this._stage.filterManager.pushTemp(compositeSource);
415
+ }
416
+
417
+ this._imageDataDirty = true;
418
+ this.invalidateOwners();
419
+ }
420
+
421
+ public threshold(
422
+ source: BitmapImage2D,
423
+ sourceRect: Rectangle,
424
+ destPoint: Point,
425
+ operation: string,
426
+ threshold: number,
427
+ color: number,
428
+ mask: number,
429
+ copySource: boolean
430
+ ): void {
431
+
432
+ this._lastUsedFill = null;
433
+ this.unmarkToUnload();
434
+
435
+ if (this._initalFillColor !== null)
436
+ this.fillRect(this._rect, this._initalFillColor);
437
+
438
+ this._stage.threshold(source, this, sourceRect, destPoint, operation, threshold, color, mask, copySource);
439
+ this._imageDataDirty = true;
440
+ this.invalidateOwners();
441
+ }
442
+
443
+ public applyFilter (source: BitmapImage2D, sourceRect: Rectangle, destPoint: Point, filter: any): boolean {
444
+ if (!Settings.USE_UNSAFE_FILTERS || !filter || !filter.filterName) {
445
+ return false;
446
+ }
447
+
448
+ const result = this._stage.filterManager.applyFilter (
449
+ source,
450
+ this,
451
+ sourceRect,
452
+ destPoint,
453
+ filter.filterName, filter);
454
+
455
+ this._imageDataDirty = result;
456
+
457
+ if (result)
458
+ this.invalidateOwners();
459
+
460
+ return result;
461
+ }
462
+
463
+ public colorTransform(rect: Rectangle, colorTransform: ColorTransform): void {
464
+ this.unmarkToUnload();
465
+
466
+ this._lastUsedFill = null;
467
+
468
+ this._stage.colorTransform(this, this, rect, colorTransform);
469
+
470
+ this._imageDataDirty = true;
471
+ this.invalidateOwners();
472
+ }
473
+
474
+ public setPixel(x: number, y: number, color: number) {
475
+ // we can't upload buffer in MSAA texture after creating - only render it and get
476
+ if (this.canUseMSAAInternaly) {
477
+ this._dropMSAA();
478
+ }
479
+
480
+ super.setPixel(x, y, color);
481
+ }
482
+
483
+ public setPixel32(x: number, y: number, color: number) {
484
+ // we can't upload buffer in MSAA texture after creating - only render it and get
485
+ if (this.canUseMSAAInternaly) {
486
+ this._dropMSAA();
487
+ }
488
+
489
+ super.setPixel32(x, y, color);
490
+ }
491
+
492
+ public setPixels(rect: Rectangle, buffer: Uint8ClampedArray) {
493
+ // we can't upload buffer in MSAA texture after creating - only render it and get
494
+ if (this.wasUpload && this.canUseMSAAInternaly) {
495
+ this._dropMSAA();
496
+ }
497
+
498
+ super.setPixels(rect, buffer);
499
+ }
500
+
501
+ public getPixels(rect: Rectangle): Uint8ClampedArray {
502
+ this.syncData();
503
+ return super.getPixels(rect);
504
+ }
505
+
506
+ private _clearFromDispose = false;
507
+ public clear() {
508
+ // we call clear in parent class from dispose, call direct
509
+ if (this._clearFromDispose) {
510
+ super.clear();
511
+ return;
512
+ }
513
+
514
+ // clear should drop abstraction, but we can't doing this if unloaded
515
+ const t = this.syncData(true);
516
+
517
+ // not require unload, we already doings this
518
+ this.unmarkToUnload();
519
+ this.lastUsedTime = -1;
520
+
521
+ if (typeof t === 'boolean') {
522
+ this.wasUpload = false;
523
+ super.clear();
524
+ return;
525
+ }
526
+
527
+ t.then(() => {
528
+ this.wasUpload = false;
529
+ super.clear();
530
+ });
531
+ }
532
+
533
+ /**
534
+ * @inheritdoc
535
+ */
536
+ public getPixel32(x: number, y: number): number {
537
+ this.syncData();
538
+
539
+ return super.getPixel32(x, y);
540
+ }
541
+
542
+ /**
543
+ * @inheritdoc
544
+ */
545
+ public getPixel(x: number, y: number): number {
546
+ const result = this.getPixel32(x, y);
547
+
548
+ return result & 0x00ffffff;
549
+ }
550
+
551
+ /**
552
+ * Draws the <code>source</code> display object onto the bitmap image, using
553
+ * the NME software renderer. You can specify <code>matrix</code>,
554
+ * <code>colorTransform</code>, <code>blendMode</code>, and a destination
555
+ * <code>clipRect</code> parameter to control how the rendering performs.
556
+ * Optionally, you can specify whether the bitmap should be smoothed when
557
+ * scaled(this works only if the source object is a BitmapImage2D object).
558
+ *
559
+ * <p>The source display object does not use any of its applied
560
+ * transformations for this call. It is treated as it exists in the library
561
+ * or file, with no matrix transform, no color transform, and no blend mode.
562
+ * To draw a display object(such as a movie clip) by using its own transform
563
+ * properties, you can copy its <code>transform</code> property object to the
564
+ * <code>transform</code> property of the Bitmap object that uses the
565
+ * BitmapImage2D object.</p>
566
+ *
567
+ * @param source The display object or BitmapImage2D object to draw to
568
+ * the BitmapImage2D object.(The DisplayObject and
569
+ * BitmapImage2D classes implement the IBitmapDrawable
570
+ * interface.)
571
+ * @param matrix A Matrix object used to scale, rotate, or translate
572
+ * the coordinates of the bitmap. If you do not want to
573
+ * apply a matrix transformation to the image, set this
574
+ * parameter to an identity matrix, created with the
575
+ * default <code>new Matrix()</code> constructor, or
576
+ * pass a <code>null</code> value.
577
+ * @param colorTransform A ColorTransform object that you use to adjust the
578
+ * color values of the bitmap. If no object is
579
+ * supplied, the bitmap image's colors are not
580
+ * transformed. If you must pass this parameter but you
581
+ * do not want to transform the image, set this
582
+ * parameter to a ColorTransform object created with
583
+ * the default <code>new ColorTransform()</code>
584
+ * constructor.
585
+ * @param blendMode A string value, from the flash.display.BlendMode
586
+ * class, specifying the blend mode to be applied to
587
+ * the resulting bitmap.
588
+ * @param clipRect A Rectangle object that defines the area of the
589
+ * source object to draw. If you do not supply this
590
+ * value, no clipping occurs and the entire source
591
+ * object is drawn.
592
+ * @param smoothing A Boolean value that determines whether a BitmapImage2D
593
+ * object is smoothed when scaled or rotated, due to a
594
+ * scaling or rotation in the <code>matrix</code>
595
+ * parameter. The <code>smoothing</code> parameter only
596
+ * applies if the <code>source</code> parameter is a
597
+ * BitmapImage2D object. With <code>smoothing</code> set
598
+ * to <code>false</code>, the rotated or scaled
599
+ * BitmapImage2D image can appear pixelated or jagged. For
600
+ * example, the following two images use the same
601
+ * BitmapImage2D object for the <code>source</code>
602
+ * parameter, but the <code>smoothing</code> parameter
603
+ * is set to <code>true</code> on the left and
604
+ * <code>false</code> on the right:
605
+ *
606
+ * <p>Drawing a bitmap with <code>smoothing</code> set
607
+ * to <code>true</code> takes longer than doing so with
608
+ * <code>smoothing</code> set to
609
+ * <code>false</code>.</p>
610
+ * @throws ArgumentError The <code>source</code> parameter is not a
611
+ * BitmapImage2D or DisplayObject object.
612
+ * @throws ArgumentError The source is null or not a valid IBitmapDrawable
613
+ * object.
614
+ * @throws SecurityError The <code>source</code> object and(in the case of a
615
+ * Sprite or MovieClip object) all of its child objects
616
+ * do not come from the same domain as the caller, or
617
+ * are not in a content that is accessible to the
618
+ * caller by having called the
619
+ * <code>Security.allowDomain()</code> method. This
620
+ * restriction does not apply to AIR content in the
621
+ * application security sandbox.
622
+ */
623
+
624
+ /* eslint-disable */
625
+ public draw(source: DisplayObject, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean);
626
+ public draw(source: BitmapImage2D, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean);
627
+ public draw(source: any, matrix?: Matrix, colorTransform?: ColorTransform, blendMode?: string, clipRect?: Rectangle, smoothing?: boolean): void
628
+ {
629
+ /* eslint-enable */
630
+
631
+ this.unmarkToUnload();
632
+
633
+ if (source instanceof DisplayObject) {
634
+ this._drawAsDisplay(source, matrix, colorTransform, blendMode, clipRect, smoothing);
635
+ } else {
636
+ this._drawAsBitmap(source, matrix, colorTransform, blendMode, clipRect, smoothing);
637
+ }
638
+
639
+ this._lastUsedFill = null;
640
+ this._imageDataDirty = true;
641
+ this.invalidateOwners();
642
+ }
643
+
644
+ private static _mapSupportedBlendMode(blendMode: string = ''): string {
645
+ switch (blendMode) {
646
+ case null:
647
+ case '':
648
+ case BlendMode.NORMAL:
649
+ case BlendMode.LAYER:
650
+ return BlendMode.LAYER;
651
+ case BlendMode.MULTIPLY:
652
+ case BlendMode.ADD:
653
+ case BlendMode.ALPHA:
654
+ return blendMode;
655
+ }
656
+
657
+ //console.debug("[ImageBitmap] Unsupport BlendMode", blendMode);
658
+ return BlendMode.LAYER;
659
+ }
660
+
661
+ private _drawAsBitmap(
662
+ source: BitmapImage2D, matrix?: Matrix, colorTransform?: ColorTransform,
663
+ blendMode?: string, _clipRect?: Rectangle, smoothing?: boolean
664
+ ) {
665
+ // default global blend mode
666
+ blendMode = blendMode || BlendMode.LAYER;
667
+
668
+ if (!SceneImage2D._billboardRenderer) {
669
+ this.createBillboardRenderer();
670
+ }
671
+
672
+ if (this._initalFillColor !== null)
673
+ this.fillRect(this._rect, this._initalFillColor);
674
+
675
+ const stage = this._stage;
676
+ const mappedBlend = SceneImage2D._mapSupportedBlendMode(blendMode);
677
+ const supportNativeBlend = !blendMode || mappedBlend !== BlendMode.LAYER || blendMode == BlendMode.LAYER;
678
+ const useTmp = (!supportNativeBlend || this === source);
679
+ const target = useTmp ?
680
+ stage.filterManager.popTemp(this.width, this.height, false)
681
+ : this;
682
+
683
+ const renderer = SceneImage2D._billboardRenderer;
684
+ const root = SceneImage2D._billboardRoot;
685
+ const billboard = SceneImage2D._billboard;
686
+
687
+ billboard.style.sampler.smooth = smoothing;
688
+
689
+ renderer.disableClear = !useTmp;
690
+ renderer.view.target = target;
691
+ renderer.view.projection.scale = 1000 / target.height;
692
+
693
+ billboard.style.image = source;
694
+
695
+ // not all blend modes can be used for rendering
696
+ billboard.material.blendMode = !useTmp ? mappedBlend : BlendMode.LAYER;
697
+
698
+ (<MaterialBase> billboard.material).useColorTransform = !!colorTransform;
699
+
700
+ if (useTmp) {
701
+ // we clear TMP and render to it, prepare to composing
702
+ renderer.view.backgroundColor = 0x0;
703
+ renderer.view.backgroundAlpha = 0;
704
+ }
705
+
706
+ if (matrix) {
707
+ const m = root.transform.matrix3D;
708
+
709
+ m.identity();
710
+
711
+ m._rawData[0] = matrix.a;
712
+ m._rawData[1] = -matrix.b;
713
+ m._rawData[4] = matrix.c;
714
+ m._rawData[5] = -matrix.d;
715
+ m._rawData[12] = matrix.tx;
716
+ m._rawData[13] = target.height - matrix.ty;
717
+
718
+ root.transform.invalidateComponents();
719
+ } else {
720
+
721
+ root.transform.rotateTo(0,0,0);
722
+ root.transform.scaleTo(1, -1, 1);
723
+ root.transform.moveTo(0, target.height,0);
724
+ }
725
+
726
+ root.transform.colorTransform = colorTransform;
727
+
728
+ //render
729
+ renderer.render();
730
+
731
+ //
732
+ if (useTmp) {
733
+ stage.filterManager.copyPixels(
734
+ target,
735
+ this,
736
+ this.rect,
737
+ TMP_POINT,
738
+ true,
739
+ blendMode
740
+ );
741
+
742
+ stage.filterManager.pushTemp(target);
743
+ }
744
+
745
+ //reset material blendMode
746
+ billboard.material.blendMode = BlendMode.NORMAL;
747
+ }
748
+
749
+ private _drawAsDisplay(
750
+ source: DisplayObject, matrix?: Matrix, colorTransform?: ColorTransform,
751
+ blendMode: string = '', _clipRect?: Rectangle, _smoothing?: boolean
752
+ ) {
753
+ // default global blend mode
754
+ blendMode = blendMode || BlendMode.LAYER;
755
+
756
+ if (!SceneImage2D._renderer) {
757
+ this.createRenderer();
758
+ }
759
+
760
+ const root = SceneImage2D._root;
761
+ const rootNode = SceneImage2D._rootNode;
762
+ const renderer = SceneImage2D._renderer;
763
+
764
+ // when we should use MSAA, we will create temporary image and draw to it
765
+ const internal = this.canUseMSAAInternaly;
766
+ const nativeMSAA = (
767
+ !source.isAsset(Billboard) &&
768
+ this._stage.context.glVersion === 2 && // can be used because a webgl2
769
+ Settings.ALLOW_FORCE_MSAA > 1 && // because a quality is more that 1
770
+ !internal); // and not internal
771
+
772
+ // target image for rendering.
773
+ let target: Image2D = this;
774
+
775
+ // we should run compositor when blendMode !== LAYER (default)
776
+ // or when we use MSAA + fill is not flat.
777
+ const useBlend = blendMode !== BlendMode.LAYER || (this._lastUsedFill === null && nativeMSAA);
778
+
779
+ const useTemp = useBlend || nativeMSAA;
780
+
781
+ // lazy filling
782
+ // we require fill image with initial color, because we not doing this immediate
783
+ // and when blend is required, because we should blend with vald color
784
+ if ((!nativeMSAA || useBlend) && this._initalFillColor !== null)
785
+ this.fillRect(this._rect, this._initalFillColor);
786
+ else
787
+ this._initalFillColor = null;
788
+
789
+ if (useTemp) {
790
+ target = SceneImage2D.getTemp(this.width, this.height, this._stage, nativeMSAA);
791
+
792
+ // because target image is stupid filled - it not require merging
793
+ // BUT when blend is required - we shpuld skip color clear and use empty TMP
794
+ if (!useBlend && this._lastUsedFill !== null) {
795
+
796
+ if (this._transparent) {
797
+ //premulitply fill color!
798
+ let [a, r, g, b] = ColorUtils.float32ColorToARGB(this._lastUsedFill);
799
+ a /= 0xFF;
800
+ this._lastUsedFill = ColorUtils.ARGBtoFloat32(a * 0xFF, r * a | 0, g * a | 0, b * a | 0);
801
+ }
802
+ // bitmap was filled plain, go clear TMP to this color too
803
+ renderer.disableClear = false;
804
+ renderer.view.backgroundColor = this._lastUsedFill & 0xffffff;
805
+ renderer.view.backgroundAlpha = this._transparent ? (this._lastUsedFill >>> 24 & 0xff) / 0xff : 1;
806
+ } else {
807
+ // we clear TMP and render to it, prepare to composing
808
+ renderer.disableClear = false;
809
+ renderer.view.backgroundColor = 0x0;
810
+ renderer.view.backgroundAlpha = 0;
811
+
812
+ // copy from source to tmp
813
+ // TMP_POINT.setTo(0,0);
814
+ // this._stage.copyPixels(this, target, this._rect, TMP_POINT, null, null, false);
815
+ }
816
+ }
817
+
818
+ const transform = renderer.view.projection.transform;
819
+ const mat3d = transform.matrix3D;
820
+ mat3d.identity();
821
+
822
+ if (matrix) {
823
+ const raw = mat3d._rawData;
824
+ raw[0] = matrix.a;
825
+ raw[1] = matrix.b;
826
+ raw[4] = matrix.c;
827
+ raw[5] = matrix.d;
828
+ raw[10] = 1;
829
+ raw[12] = matrix.tx;
830
+ raw[13] = matrix.ty;
831
+ }
832
+
833
+ // todo By this line we flip normals, and cull will be broken
834
+ // NEED FIX THIS ASAP, or flip cull state
835
+ mat3d.appendScale(1, -1, 1);
836
+ mat3d.appendTranslation(0, this._rect.height, 1000);
837
+
838
+ mat3d.invert();
839
+ transform.matrix3D = mat3d;
840
+
841
+ renderer.antiAlias = (internal ? this.antialiasQuality : (<any>target).antialiasQuality) || 0;
842
+
843
+ renderer.view.target = target;
844
+ renderer.view.projection.scale = 1000 / this._rect.height;
845
+
846
+ // shift view, because target can be more
847
+ renderer.view.projection.ratio = (this._rect.width / this._rect.height);
848
+ renderer.view.x = -(target.width - this.width);
849
+ renderer.view.y = -(target.height - this.height);
850
+ renderer.view.width = this.width;
851
+ renderer.view.height = this.height;
852
+
853
+ const sourceNode: ContainerNode = rootNode.addChildAt(source, 0);
854
+ const transformDisabled = sourceNode.transformDisabled;
855
+
856
+ sourceNode.transformDisabled = true;
857
+ // masks should be enabled!
858
+ sourceNode.maskDisabled = false;
859
+
860
+ root.transform.colorTransform = colorTransform;
861
+ // anyway we not support this =))
862
+ root.blendMode = SceneImage2D._mapSupportedBlendMode(blendMode);
863
+
864
+ //save snapshot if unlocked
865
+ //if (!this._locked)
866
+ //SceneImage2D.scene.view.target=this;
867
+ //SceneImage2D.scene.renderer.disableClear = !this._locked;
868
+
869
+ renderer.render();
870
+
871
+ // reset render to default value
872
+ renderer.antiAlias = 0;
873
+ renderer.disableClear = true;
874
+
875
+ rootNode.removeChildAt(0);
876
+
877
+ sourceNode.transformDisabled = transformDisabled;
878
+
879
+ if (useTemp) {
880
+ // because we copy MSAA into no msaa, it should passed as BLIT
881
+ this._stage.filterManager.copyPixels(
882
+ target,
883
+ this,
884
+ this._rect,
885
+ TMP_POINT,
886
+ useBlend,
887
+ blendMode // apply blend mode if this needed.
888
+ );
889
+
890
+ SceneImage2D.tryStoreImage(target, this._stage);
891
+ }
892
+ }
893
+
894
+ public reset() {}
895
+
896
+ public clone(): SceneImage2D {
897
+ const image = SceneImage2D.getImage(
898
+ this.width,
899
+ this.height,
900
+ this.transparent,
901
+ null,
902
+ false,
903
+ this._stage,
904
+ false
905
+ );
906
+
907
+ this.copyTo(image);
908
+
909
+ return image;
910
+ }
911
+ }
912
+
908
913
  Stage.registerAbstraction(_Stage_BitmapImage2D, SceneImage2D);