babylon.shape2d.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11. };
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var Shape2D = (function (_super) {
  15. __extends(Shape2D, _super);
  16. function Shape2D() {
  17. _super.apply(this, arguments);
  18. }
  19. Object.defineProperty(Shape2D.prototype, "border", {
  20. get: function () {
  21. return this._border;
  22. },
  23. set: function (value) {
  24. this._border = value;
  25. this._updateTransparencyStatus();
  26. },
  27. enumerable: true,
  28. configurable: true
  29. });
  30. Object.defineProperty(Shape2D.prototype, "fill", {
  31. get: function () {
  32. return this._fill;
  33. },
  34. set: function (value) {
  35. this._fill = value;
  36. this._updateTransparencyStatus();
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. Object.defineProperty(Shape2D.prototype, "borderThickness", {
  42. get: function () {
  43. return this._borderThickness;
  44. },
  45. set: function (value) {
  46. this._borderThickness = value;
  47. },
  48. enumerable: true,
  49. configurable: true
  50. });
  51. Shape2D.prototype.setupShape2D = function (owner, parent, id, position, isVisible, fill, border, borderThickness) {
  52. if (borderThickness === void 0) { borderThickness = 1.0; }
  53. this.setupRenderablePrim2D(owner, parent, id, position, isVisible);
  54. this.border = border;
  55. this.fill = fill;
  56. this.borderThickness = borderThickness;
  57. };
  58. Shape2D.prototype.getUsedShaderCategories = function (dataPart) {
  59. var cat = _super.prototype.getUsedShaderCategories.call(this, dataPart);
  60. // Fill Part
  61. if (dataPart.id === Shape2D.SHAPE2D_FILLPARTID) {
  62. var fill = this.fill;
  63. if (fill instanceof BABYLON.SolidColorBrush2D) {
  64. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLSOLID);
  65. }
  66. if (fill instanceof BABYLON.GradientColorBrush2D) {
  67. cat.push(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT);
  68. }
  69. }
  70. // Border Part
  71. if (dataPart.id === Shape2D.SHAPE2D_BORDERPARTID) {
  72. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDER);
  73. var border = this.border;
  74. if (border instanceof BABYLON.SolidColorBrush2D) {
  75. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID);
  76. }
  77. if (border instanceof BABYLON.GradientColorBrush2D) {
  78. cat.push(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT);
  79. }
  80. }
  81. return cat;
  82. };
  83. Shape2D.prototype.refreshInstanceDataPart = function (part) {
  84. if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
  85. return false;
  86. }
  87. // Fill Part
  88. if (part.id === Shape2D.SHAPE2D_FILLPARTID) {
  89. var d = part;
  90. if (this.fill) {
  91. var fill = this.fill;
  92. if (fill instanceof BABYLON.SolidColorBrush2D) {
  93. d.fillSolidColor = fill.color;
  94. }
  95. else if (fill instanceof BABYLON.GradientColorBrush2D) {
  96. d.fillGradientColor1 = fill.color1;
  97. d.fillGradientColor2 = fill.color2;
  98. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(fill.scale, fill.scale, fill.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), fill.rotation), new BABYLON.Vector3(fill.translation.x, fill.translation.y, 0));
  99. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  100. d.fillGradientTY = ty;
  101. }
  102. }
  103. }
  104. else if (part.id === Shape2D.SHAPE2D_BORDERPARTID) {
  105. var d = part;
  106. if (this.border) {
  107. d.borderThickness = this.borderThickness;
  108. var border = this.border;
  109. if (border instanceof BABYLON.SolidColorBrush2D) {
  110. d.borderSolidColor = border.color;
  111. }
  112. else if (border instanceof BABYLON.GradientColorBrush2D) {
  113. d.borderGradientColor1 = border.color1;
  114. d.borderGradientColor2 = border.color2;
  115. var t = BABYLON.Matrix.Compose(new BABYLON.Vector3(border.scale, border.scale, border.scale), BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), border.rotation), new BABYLON.Vector3(border.translation.x, border.translation.y, 0));
  116. var ty = new BABYLON.Vector4(t.m[1], t.m[5], t.m[9], t.m[13]);
  117. d.borderGradientTY = ty;
  118. }
  119. }
  120. }
  121. return true;
  122. };
  123. Shape2D.prototype._updateTransparencyStatus = function () {
  124. this.isTransparent = (this._border && this._border.isTransparent()) || (this._fill && this._fill.isTransparent());
  125. };
  126. Shape2D.SHAPE2D_BORDERPARTID = 1;
  127. Shape2D.SHAPE2D_FILLPARTID = 2;
  128. Shape2D.SHAPE2D_CATEGORY_BORDER = "Border";
  129. Shape2D.SHAPE2D_CATEGORY_BORDERSOLID = "BorderSolid";
  130. Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT = "BorderGradient";
  131. Shape2D.SHAPE2D_CATEGORY_FILLSOLID = "FillSolid";
  132. Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT = "FillGradient";
  133. Shape2D.SHAPE2D_PROPCOUNT = BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5;
  134. __decorate([
  135. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, function (pi) { return Shape2D.borderProperty = pi; }, true)
  136. ], Shape2D.prototype, "border", null);
  137. __decorate([
  138. BABYLON.modelLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, function (pi) { return Shape2D.fillProperty = pi; }, true)
  139. ], Shape2D.prototype, "fill", null);
  140. __decorate([
  141. BABYLON.instanceLevelProperty(BABYLON.RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 3, function (pi) { return Shape2D.borderThicknessProperty = pi; })
  142. ], Shape2D.prototype, "borderThickness", null);
  143. Shape2D = __decorate([
  144. BABYLON.className("Shape2D")
  145. ], Shape2D);
  146. return Shape2D;
  147. })(BABYLON.RenderablePrim2D);
  148. BABYLON.Shape2D = Shape2D;
  149. var Shape2DInstanceData = (function (_super) {
  150. __extends(Shape2DInstanceData, _super);
  151. function Shape2DInstanceData() {
  152. _super.apply(this, arguments);
  153. }
  154. Object.defineProperty(Shape2DInstanceData.prototype, "fillSolidColor", {
  155. // FILL ATTRIBUTES
  156. get: function () {
  157. return null;
  158. },
  159. enumerable: true,
  160. configurable: true
  161. });
  162. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor1", {
  163. get: function () {
  164. return null;
  165. },
  166. enumerable: true,
  167. configurable: true
  168. });
  169. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientColor2", {
  170. get: function () {
  171. return null;
  172. },
  173. enumerable: true,
  174. configurable: true
  175. });
  176. Object.defineProperty(Shape2DInstanceData.prototype, "fillGradientTY", {
  177. get: function () {
  178. return null;
  179. },
  180. enumerable: true,
  181. configurable: true
  182. });
  183. Object.defineProperty(Shape2DInstanceData.prototype, "borderThickness", {
  184. // BORDER ATTRIBUTES
  185. get: function () {
  186. return null;
  187. },
  188. enumerable: true,
  189. configurable: true
  190. });
  191. Object.defineProperty(Shape2DInstanceData.prototype, "borderSolidColor", {
  192. get: function () {
  193. return null;
  194. },
  195. enumerable: true,
  196. configurable: true
  197. });
  198. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor1", {
  199. get: function () {
  200. return null;
  201. },
  202. enumerable: true,
  203. configurable: true
  204. });
  205. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientColor2", {
  206. get: function () {
  207. return null;
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. Object.defineProperty(Shape2DInstanceData.prototype, "borderGradientTY", {
  213. get: function () {
  214. return null;
  215. },
  216. enumerable: true,
  217. configurable: true
  218. });
  219. __decorate([
  220. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLSOLID)
  221. ], Shape2DInstanceData.prototype, "fillSolidColor", null);
  222. __decorate([
  223. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  224. ], Shape2DInstanceData.prototype, "fillGradientColor1", null);
  225. __decorate([
  226. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  227. ], Shape2DInstanceData.prototype, "fillGradientColor2", null);
  228. __decorate([
  229. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_FILLGRADIENT)
  230. ], Shape2DInstanceData.prototype, "fillGradientTY", null);
  231. __decorate([
  232. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDER)
  233. ], Shape2DInstanceData.prototype, "borderThickness", null);
  234. __decorate([
  235. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERSOLID)
  236. ], Shape2DInstanceData.prototype, "borderSolidColor", null);
  237. __decorate([
  238. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  239. ], Shape2DInstanceData.prototype, "borderGradientColor1", null);
  240. __decorate([
  241. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  242. ], Shape2DInstanceData.prototype, "borderGradientColor2", null);
  243. __decorate([
  244. BABYLON.instanceData(Shape2D.SHAPE2D_CATEGORY_BORDERGRADIENT)
  245. ], Shape2DInstanceData.prototype, "borderGradientTY", null);
  246. return Shape2DInstanceData;
  247. })(BABYLON.InstanceDataBase);
  248. BABYLON.Shape2DInstanceData = Shape2DInstanceData;
  249. })(BABYLON || (BABYLON = {}));