13aaf3af6ea86b1e14397111cbcf22b8168c4712.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Camera, Component, Node, RenderTexture, Sprite, SpriteFrame, UITransform, _decorator, gfx, _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _crd, ccclass, property, RtToSprite;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. return {
  8. setters: [function (_cc) {
  9. _cclegacy = _cc.cclegacy;
  10. __checkObsolete__ = _cc.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  12. Camera = _cc.Camera;
  13. Component = _cc.Component;
  14. Node = _cc.Node;
  15. RenderTexture = _cc.RenderTexture;
  16. Sprite = _cc.Sprite;
  17. SpriteFrame = _cc.SpriteFrame;
  18. UITransform = _cc.UITransform;
  19. _decorator = _cc._decorator;
  20. gfx = _cc.gfx;
  21. }],
  22. execute: function () {
  23. _crd = true;
  24. _cclegacy._RF.push({}, "f608cdDWBNEKLILVNBcQYvf", "RtToSprite", undefined);
  25. __checkObsolete__(['Camera', 'Component', 'EventTouch', 'Node', 'RenderTexture', 'Sprite', 'SpriteFrame', 'UITransform', 'Vec3', '_decorator', 'gfx']);
  26. ({
  27. ccclass,
  28. property
  29. } = _decorator);
  30. /** 三维模型显示到二维精灵上 */
  31. _export("RtToSprite", RtToSprite = (_dec = ccclass('RtToSprite'), _dec2 = property({
  32. type: Camera,
  33. tooltip: "渲染模型的三维摄像机"
  34. }), _dec3 = property({
  35. type: Sprite,
  36. tooltip: "显示模型的二维精灵组件"
  37. }), _dec4 = property({
  38. tooltip: "是否触摸控制旋转"
  39. }), _dec5 = property({
  40. type: Node,
  41. tooltip: "三维模型",
  42. visible: function visible() {
  43. //@ts-ignore
  44. return this.rotation === true;
  45. }
  46. }), _dec(_class = (_class2 = class RtToSprite extends Component {
  47. constructor() {
  48. super(...arguments);
  49. _initializerDefineProperty(this, "camera", _descriptor, this);
  50. _initializerDefineProperty(this, "sprite", _descriptor2, this);
  51. _initializerDefineProperty(this, "rotation", _descriptor3, this);
  52. _initializerDefineProperty(this, "model", _descriptor4, this);
  53. this.rt = new RenderTexture();
  54. this.touched = false;
  55. }
  56. // 是否触摸节点
  57. start() {
  58. var size = this.sprite.getComponent(UITransform);
  59. this.refreshRenderTexture(size.width, size.height);
  60. if (this.rotation) {
  61. this.sprite.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
  62. this.sprite.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  63. this.sprite.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  64. this.sprite.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
  65. }
  66. }
  67. onTouchStart(event) {
  68. this.touched = true;
  69. }
  70. onTouchMove(event) {
  71. if (this.touched) {
  72. var eulerAngles = this.model.eulerAngles;
  73. var deltaX = event.touch.getDelta().x;
  74. eulerAngles.y += -deltaX;
  75. this.model.eulerAngles = eulerAngles;
  76. }
  77. }
  78. onTouchEnd(event) {
  79. this.touched = false;
  80. }
  81. /** 刷新纹理内容 */
  82. refreshRenderTexture(w, h) {
  83. var colorAttachment = new gfx.ColorAttachment();
  84. var depthStencilAttachment = new gfx.DepthStencilAttachment();
  85. var pi = new gfx.RenderPassInfo([colorAttachment], depthStencilAttachment);
  86. this.rt.reset({
  87. width: w,
  88. height: h,
  89. passInfo: pi
  90. });
  91. var spriteframe = this.sprite.spriteFrame;
  92. var sp = new SpriteFrame();
  93. sp.reset({
  94. originalSize: spriteframe.originalSize,
  95. rect: spriteframe.rect,
  96. offset: spriteframe.offset,
  97. isRotate: spriteframe.rotated,
  98. borderTop: spriteframe.insetTop,
  99. borderLeft: spriteframe.insetLeft,
  100. borderBottom: spriteframe.insetBottom,
  101. borderRight: spriteframe.insetRight
  102. });
  103. this.camera.targetTexture = this.rt;
  104. sp.texture = this.rt;
  105. this.sprite.spriteFrame = sp;
  106. }
  107. onDestroy() {
  108. if (this.rotation) {
  109. this.sprite.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
  110. this.sprite.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  111. this.sprite.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  112. this.sprite.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
  113. }
  114. this.rt.destroy();
  115. }
  116. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "camera", [_dec2], {
  117. configurable: true,
  118. enumerable: true,
  119. writable: true,
  120. initializer: function initializer() {
  121. return null;
  122. }
  123. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "sprite", [_dec3], {
  124. configurable: true,
  125. enumerable: true,
  126. writable: true,
  127. initializer: function initializer() {
  128. return null;
  129. }
  130. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "rotation", [_dec4], {
  131. configurable: true,
  132. enumerable: true,
  133. writable: true,
  134. initializer: function initializer() {
  135. return false;
  136. }
  137. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "model", [_dec5], {
  138. configurable: true,
  139. enumerable: true,
  140. writable: true,
  141. initializer: function initializer() {
  142. return null;
  143. }
  144. })), _class2)) || _class));
  145. _cclegacy._RF.pop();
  146. _crd = false;
  147. }
  148. };
  149. });
  150. //# sourceMappingURL=13aaf3af6ea86b1e14397111cbcf22b8168c4712.js.map