@anov/3d-ability 0.0.134 → 0.0.136

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.
@@ -0,0 +1,28 @@
1
+ import { Object3D } from '@anov/3d-core';
2
+ import type { IWater } from './types';
3
+ export interface IWaterOption {
4
+ size?: number;
5
+ height?: number;
6
+ waterColor?: number;
7
+ doubleSided?: boolean;
8
+ [key: string]: any;
9
+ }
10
+ declare class Water extends Object3D implements IWater {
11
+ private _option;
12
+ private _mesh;
13
+ private _disposeCallback;
14
+ constructor(option: IWaterOption);
15
+ init(): void;
16
+ setSize(size: number): void;
17
+ /**
18
+ * 设置当前高度
19
+ */
20
+ setHeight(height: number): void;
21
+ /**
22
+ * 获取当前高度
23
+ */
24
+ getHeight(): number;
25
+ update(): void;
26
+ destroy(): void;
27
+ }
28
+ export { Water };
@@ -0,0 +1,130 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ import { DoubleSide, Object3D, PlaneGeometry, RepeatWrapping, TextureLoader, Water as ThreeWater, Vector3, use } from '@anov/3d-core';
18
+ import { WaterImg } from "./types";
19
+ var DEFAULT_OPTION = {
20
+ size: 1000,
21
+ height: 0,
22
+ waterColor: 0x001E0F,
23
+ fog: false,
24
+ sunColor: 0xFFFFFF,
25
+ distortionScale: 1.5,
26
+ alpha: 1.0,
27
+ doubleSided: true // 是否双面渲染
28
+ };
29
+ var Water = /*#__PURE__*/function (_Object3D) {
30
+ _inherits(Water, _Object3D);
31
+ var _super = _createSuper(Water);
32
+ function Water(option) {
33
+ var _this;
34
+ _classCallCheck(this, Water);
35
+ _this = _super.call(this);
36
+ _defineProperty(_assertThisInitialized(_this), "_option", void 0);
37
+ _defineProperty(_assertThisInitialized(_this), "_mesh", void 0);
38
+ _defineProperty(_assertThisInitialized(_this), "_disposeCallback", void 0);
39
+ _this._option = _objectSpread(_objectSpread({}, DEFAULT_OPTION), option || {});
40
+ _this.init();
41
+ return _this;
42
+ }
43
+ _createClass(Water, [{
44
+ key: "init",
45
+ value: function init() {
46
+ var _this$_option = this._option,
47
+ size = _this$_option.size,
48
+ alpha = _this$_option.alpha,
49
+ height = _this$_option.height,
50
+ sunColor = _this$_option.sunColor,
51
+ waterColor = _this$_option.waterColor,
52
+ distortionScale = _this$_option.distortionScale;
53
+ var waterGeometry = new PlaneGeometry(size, size);
54
+ var water = new ThreeWater(waterGeometry, {
55
+ textureWidth: 512,
56
+ textureHeight: 512,
57
+ waterNormals: new TextureLoader().load(WaterImg, function (texture) {
58
+ texture.wrapS = texture.wrapT = RepeatWrapping;
59
+ }),
60
+ alpha: alpha,
61
+ sunDirection: new Vector3(),
62
+ sunColor: sunColor,
63
+ waterColor: waterColor,
64
+ distortionScale: distortionScale
65
+ });
66
+ water.rotation.x = -Math.PI / 2;
67
+ water.name = 'SYS_WATER';
68
+ water.material.side = DoubleSide;
69
+ water.position.y = height;
70
+ this.add(water);
71
+ this._mesh = water;
72
+ }
73
+ }, {
74
+ key: "setSize",
75
+ value: function setSize(size) {
76
+ if (!this._mesh) {
77
+ console.warn('Water not created');
78
+ return;
79
+ }
80
+ if (this._option.size === size) return;
81
+ this._option.size = size;
82
+ var geometry = new PlaneGeometry(size, size);
83
+ this._mesh.geometry.dispose();
84
+ this._mesh.geometry = geometry;
85
+ }
86
+
87
+ /**
88
+ * 设置当前高度
89
+ */
90
+ }, {
91
+ key: "setHeight",
92
+ value: function setHeight(height) {
93
+ if (!this._mesh) {
94
+ console.warn('Water not created');
95
+ return;
96
+ }
97
+ this._mesh.position.y = height;
98
+ this._option.height = height;
99
+ }
100
+
101
+ /**
102
+ * 获取当前高度
103
+ */
104
+ }, {
105
+ key: "getHeight",
106
+ value: function getHeight() {
107
+ var _this$_mesh$position$, _this$_mesh;
108
+ return (_this$_mesh$position$ = (_this$_mesh = this._mesh) === null || _this$_mesh === void 0 ? void 0 : _this$_mesh.position.y) !== null && _this$_mesh$position$ !== void 0 ? _this$_mesh$position$ : 0;
109
+ }
110
+ }, {
111
+ key: "update",
112
+ value: function update() {
113
+ var _this2 = this;
114
+ this._disposeCallback = use.useframeAfter(function () {
115
+ if (_this2._mesh) _this2._mesh.material.uniforms.time.value += 1.0 / 60.0;
116
+ });
117
+ }
118
+
119
+ // 销毁
120
+ }, {
121
+ key: "destroy",
122
+ value: function destroy() {
123
+ this._disposeCallback && this._disposeCallback();
124
+ this.remove(this._mesh);
125
+ }
126
+ }]);
127
+ return Water;
128
+ }(Object3D);
129
+ export { Water };
130
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DoubleSide","Object3D","PlaneGeometry","RepeatWrapping","TextureLoader","Water","ThreeWater","Vector3","use","WaterImg","DEFAULT_OPTION","size","height","waterColor","fog","sunColor","distortionScale","alpha","doubleSided","_Object3D","_inherits","_super","_createSuper","option","_this","_classCallCheck","call","_defineProperty","_assertThisInitialized","_option","_objectSpread","init","_createClass","key","value","_this$_option","waterGeometry","water","textureWidth","textureHeight","waterNormals","load","texture","wrapS","wrapT","sunDirection","rotation","x","Math","PI","name","material","side","position","y","add","_mesh","setSize","console","warn","geometry","dispose","setHeight","getHeight","_this$_mesh$position$","_this$_mesh","update","_this2","_disposeCallback","useframeAfter","uniforms","time","destroy","remove"],"sources":["../../../src/business/Water/index.ts"],"sourcesContent":["import { DoubleSide, Object3D, PlaneGeometry, RepeatWrapping, TextureLoader, Water as ThreeWater, Vector3, use } from '@anov/3d-core'\nimport { WaterImg } from './types'\nimport type { IWater } from './types'\n\nexport interface IWaterOption {\n size?: number\n height?: number\n waterColor?: number\n doubleSided?: boolean // 是否双面渲染\n [key: string]: any\n}\n\nconst DEFAULT_OPTION = {\n size: 1000,\n height: 0,\n waterColor: 0x001E0F,\n fog: false,\n sunColor: 0xFFFFFF,\n distortionScale: 1.5,\n alpha: 1.0,\n doubleSided: true, // 是否双面渲染\n}\n\nclass Water extends Object3D implements IWater {\n private _option: IWaterOption\n private _mesh: ThreeWater\n private _disposeCallback: Function | null\n constructor(option: IWaterOption) {\n super()\n this._option = { ...DEFAULT_OPTION, ...(option || {}) }\n this.init()\n }\n\n init() {\n const { size, alpha, height, sunColor, waterColor, distortionScale } = this._option\n const waterGeometry = new PlaneGeometry(size, size)\n const water = new ThreeWater(waterGeometry, {\n textureWidth: 512,\n textureHeight: 512,\n waterNormals: new TextureLoader().load(WaterImg, (texture) => {\n texture.wrapS = texture.wrapT = RepeatWrapping\n }),\n alpha,\n sunDirection: new Vector3(),\n sunColor,\n waterColor,\n distortionScale,\n })\n water.rotation.x = -Math.PI / 2\n water.name = 'SYS_WATER'\n water.material.side = DoubleSide\n water.position.y = height\n\n this.add(water)\n this._mesh = water\n }\n\n setSize(size: number) {\n if (!this._mesh) {\n console.warn('Water not created')\n return\n }\n if (this._option.size === size)\n return\n this._option.size = size\n const geometry = new PlaneGeometry(size, size)\n this._mesh.geometry.dispose()\n this._mesh.geometry = geometry\n }\n\n /**\n * 设置当前高度\n */\n setHeight(height: number): void {\n if (!this._mesh) {\n console.warn('Water not created')\n return\n }\n this._mesh.position.y = height\n this._option.height = height\n }\n\n /**\n * 获取当前高度\n */\n getHeight(): number {\n return this._mesh?.position.y ?? 0\n }\n\n update() {\n this._disposeCallback = use.useframeAfter(() => {\n if (this._mesh)\n this._mesh.material.uniforms.time.value += 1.0 / 60.0\n })\n }\n\n // 销毁\n destroy() {\n this._disposeCallback && this._disposeCallback()\n this.remove(this._mesh)\n }\n}\n\nexport { Water }"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,cAAc,EAAEC,aAAa,EAAEC,KAAK,IAAIC,UAAU,EAAEC,OAAO,EAAEC,GAAG,QAAQ,eAAe;AACrI,SAASC,QAAQ;AAWjB,IAAMC,cAAc,GAAG;EACrBC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,CAAC;EACTC,UAAU,EAAE,QAAQ;EACpBC,GAAG,EAAE,KAAK;EACVC,QAAQ,EAAE,QAAQ;EAClBC,eAAe,EAAE,GAAG;EACpBC,KAAK,EAAE,GAAG;EACVC,WAAW,EAAE,IAAI,CAAE;AACrB,CAAC;AAAA,IAEKb,KAAK,0BAAAc,SAAA;EAAAC,SAAA,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