@awayjs/scene 0.13.326 → 0.13.327

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