@anov/3d-ability 0.0.13 → 0.0.14
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.
- package/dist/camera/index.js +31 -31
- package/dist/camera/index.js.map +1 -1
- package/dist/environment/sky/index.d.ts +15 -5
- package/dist/environment/sky/index.js +26 -20
- package/dist/environment/sky/index.js.map +1 -1
- package/dist/environment/skyv2/config.d.ts +32 -0
- package/dist/environment/skyv2/config.js +50 -0
- package/dist/environment/skyv2/config.js.map +1 -0
- package/dist/environment/skyv2/index.d.ts +14 -0
- package/dist/environment/skyv2/index.js +140 -0
- package/dist/environment/skyv2/index.js.map +1 -0
- package/dist/environment/skyv2/shader/cloud/frag.d.ts +2 -0
- package/dist/environment/skyv2/shader/cloud/frag.js +3 -0
- package/dist/environment/skyv2/shader/cloud/frag.js.map +1 -0
- package/dist/environment/skyv2/shader/cloud/vert.d.ts +2 -0
- package/dist/environment/skyv2/shader/cloud/vert.js +3 -0
- package/dist/environment/skyv2/shader/cloud/vert.js.map +1 -0
- package/dist/environment/skyv2/shader/sky/frag.d.ts +2 -0
- package/dist/environment/skyv2/shader/sky/frag.js +3 -0
- package/dist/environment/skyv2/shader/sky/frag.js.map +1 -0
- package/dist/environment/skyv2/type.d.ts +14 -0
- package/dist/environment/skyv2/type.js +26 -0
- package/dist/environment/skyv2/type.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/postEffects/outlinePass.js.map +1 -1
- package/dist/weather/index.d.ts +36 -0
- package/dist/weather/index.js +273 -5
- package/dist/weather/index.js.map +1 -1
- package/dist/weather/objects/CloudMesh.d.ts +22 -0
- package/dist/weather/objects/CloudMesh.js +122 -0
- package/dist/weather/objects/CloudMesh.js.map +1 -0
- package/dist/weather/{fog2DMesh.d.ts → objects/Fog2DMesh.d.ts} +6 -7
- package/dist/weather/objects/Fog2DMesh.js +94 -0
- package/dist/weather/objects/Fog2DMesh.js.map +1 -0
- package/dist/weather/objects/SkyMesh.d.ts +7 -0
- package/dist/weather/{fog2DMesh.js → objects/SkyMesh.js} +19 -55
- package/dist/weather/objects/SkyMesh.js.map +1 -0
- package/dist/weather/objects/SnowMesh.d.ts +17 -0
- package/dist/weather/objects/SnowMesh.js +163 -0
- package/dist/weather/objects/SnowMesh.js.map +1 -0
- package/dist/weather/shaders/cloud.d.ts +37 -0
- package/dist/weather/shaders/cloud.js +38 -0
- package/dist/weather/shaders/cloud.js.map +1 -0
- package/dist/weather/shaders/fog.d.ts +16 -0
- package/dist/weather/shaders/fog.js +17 -0
- package/dist/weather/shaders/fog.js.map +1 -0
- package/dist/weather/shaders/sky.d.ts +6 -0
- package/dist/weather/shaders/sky.js +7 -0
- package/dist/weather/shaders/sky.js.map +1 -0
- package/dist/weather/shaders/snow.d.ts +28 -0
- package/dist/weather/shaders/snow.js +33 -0
- package/dist/weather/shaders/snow.js.map +1 -0
- package/dist/weather/utils/constant.d.ts +38 -0
- package/dist/weather/utils/constant.js +25 -0
- package/dist/weather/utils/constant.js.map +1 -0
- package/dist/weather/utils/type.d.ts +11 -0
- package/dist/weather/utils/type.js +23 -0
- package/dist/weather/utils/type.js.map +1 -0
- package/package.json +3 -3
- package/dist/weather/fog2DMesh.js.map +0 -1
- package/dist/weather/glsl/fog.d.ts +0 -2
- package/dist/weather/glsl/fog.js +0 -3
- package/dist/weather/glsl/fog.js.map +0 -1
package/dist/weather/index.js
CHANGED
|
@@ -1,12 +1,280 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
6
|
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); } }
|
|
3
7
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
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; }
|
|
4
9
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5
10
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import { ModelLoader, use } from '@anov/3d-core';
|
|
12
|
+
import { EWeatherType } from "./utils/type";
|
|
13
|
+
import { Rain_Icon, Snow_Icon } from "./utils/constant";
|
|
14
|
+
import Fog2DMesh from "./objects/Fog2DMesh";
|
|
15
|
+
import CloudMesh from "./objects/CloudMesh";
|
|
16
|
+
import SkyMesh from "./objects/SkyMesh";
|
|
17
|
+
import SnowMesh from "./objects/SnowMesh";
|
|
18
|
+
var load = new ModelLoader();
|
|
19
|
+
var Weather = /*#__PURE__*/function () {
|
|
20
|
+
function Weather() {
|
|
21
|
+
_classCallCheck(this, Weather);
|
|
22
|
+
_defineProperty(this, "fog", void 0);
|
|
23
|
+
_defineProperty(this, "sky", void 0);
|
|
24
|
+
_defineProperty(this, "cloud", void 0);
|
|
25
|
+
_defineProperty(this, "snow", void 0);
|
|
26
|
+
_defineProperty(this, "loaded", void 0);
|
|
27
|
+
_defineProperty(this, "eventListener", new Set());
|
|
28
|
+
this.loaded = this.init();
|
|
29
|
+
}
|
|
30
|
+
_createClass(Weather, [{
|
|
31
|
+
key: "init",
|
|
32
|
+
value: function () {
|
|
33
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
34
|
+
var _this = this;
|
|
35
|
+
var gltf, mesh, _use$useScene, scene;
|
|
36
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
_context.next = 2;
|
|
40
|
+
return load.loadGLTF('./skySphereMesh.glb', false, true, './draco/');
|
|
41
|
+
case 2:
|
|
42
|
+
gltf = _context.sent;
|
|
43
|
+
mesh = gltf.scene;
|
|
44
|
+
this.sky = new SkyMesh(mesh.clone());
|
|
45
|
+
this.cloud = new CloudMesh(mesh.clone());
|
|
46
|
+
_use$useScene = use.useScene(), scene = _use$useScene.scene;
|
|
47
|
+
scene === null || scene === void 0 ? void 0 : scene.add(this.sky.mesh);
|
|
48
|
+
scene === null || scene === void 0 ? void 0 : scene.add(this.cloud.mesh);
|
|
49
|
+
use.useframe(function () {
|
|
50
|
+
var _this$cloud;
|
|
51
|
+
(_this$cloud = _this.cloud) === null || _this$cloud === void 0 ? void 0 : _this$cloud.update();
|
|
52
|
+
});
|
|
53
|
+
return _context.abrupt("return", true);
|
|
54
|
+
case 11:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context.stop();
|
|
57
|
+
}
|
|
58
|
+
}, _callee, this);
|
|
59
|
+
}));
|
|
60
|
+
function init() {
|
|
61
|
+
return _init.apply(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
return init;
|
|
64
|
+
}()
|
|
65
|
+
/**
|
|
66
|
+
* 天气设置
|
|
67
|
+
* @param weatherType 天气枚举值
|
|
68
|
+
* @param option 配置参数
|
|
69
|
+
*/
|
|
70
|
+
}, {
|
|
71
|
+
key: "setWeather",
|
|
72
|
+
value: function () {
|
|
73
|
+
var _setWeather = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(weatherType) {
|
|
74
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
75
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
76
|
+
case 0:
|
|
77
|
+
_context2.next = 2;
|
|
78
|
+
return this.loaded;
|
|
79
|
+
case 2:
|
|
80
|
+
this._reset();
|
|
81
|
+
_context2.t0 = weatherType;
|
|
82
|
+
_context2.next = _context2.t0 === EWeatherType.Foggy ? 6 : _context2.t0 === EWeatherType.Sand_Dust_Calm ? 6 : _context2.t0 === EWeatherType.Clear_Skies ? 7 : _context2.t0 === EWeatherType.Cloudy ? 7 : _context2.t0 === EWeatherType.Overcast ? 7 : _context2.t0 === EWeatherType.Rain ? 9 : _context2.t0 === EWeatherType.Rain_Thunderstorm ? 9 : _context2.t0 === EWeatherType.Snow ? 9 : _context2.t0 === EWeatherType.Snow_Blizzard ? 9 : 11;
|
|
83
|
+
break;
|
|
84
|
+
case 6:
|
|
85
|
+
// 沙尘暴
|
|
86
|
+
this._createFogMesh(weatherType);
|
|
87
|
+
case 7:
|
|
88
|
+
// 阴天
|
|
89
|
+
this._createCloudMesh(weatherType);
|
|
90
|
+
return _context2.abrupt("break", 11);
|
|
91
|
+
case 9:
|
|
92
|
+
// 暴雪
|
|
93
|
+
this._createSnowMesh(weatherType);
|
|
94
|
+
return _context2.abrupt("break", 11);
|
|
95
|
+
case 11:
|
|
96
|
+
case "end":
|
|
97
|
+
return _context2.stop();
|
|
98
|
+
}
|
|
99
|
+
}, _callee2, this);
|
|
100
|
+
}));
|
|
101
|
+
function setWeather(_x) {
|
|
102
|
+
return _setWeather.apply(this, arguments);
|
|
103
|
+
}
|
|
104
|
+
return setWeather;
|
|
105
|
+
}()
|
|
106
|
+
/**
|
|
107
|
+
* 设置不同天气的预设值:晴天、多云、阴天
|
|
108
|
+
* @param type
|
|
109
|
+
*/
|
|
110
|
+
}, {
|
|
111
|
+
key: "_createCloudMesh",
|
|
112
|
+
value: function _createCloudMesh(type) {
|
|
113
|
+
switch (type) {
|
|
114
|
+
case EWeatherType.Clear_Skies:
|
|
115
|
+
this.cloud.setEffect(type, {
|
|
116
|
+
cloudalpha: 3.0,
|
|
117
|
+
cloudscale: 8.0,
|
|
118
|
+
speed: 0.2,
|
|
119
|
+
flash: 0.0
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case EWeatherType.Cloudy:
|
|
123
|
+
this.cloud.setEffect(type, {
|
|
124
|
+
cloudalpha: 0.8,
|
|
125
|
+
cloudscale: 8.0,
|
|
126
|
+
speed: 0.3,
|
|
127
|
+
flash: 0.0
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
case EWeatherType.Overcast:
|
|
131
|
+
this.cloud.setEffect(type, {
|
|
132
|
+
cloudalpha: 1.8,
|
|
133
|
+
cloudscale: 1.0,
|
|
134
|
+
speed: 0.4,
|
|
135
|
+
flash: 1.0
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case EWeatherType.Sand_Dust_Calm:
|
|
139
|
+
this.cloud.setEffect(type, {
|
|
140
|
+
cloudalpha: 1.6,
|
|
141
|
+
cloudscale: 3.0,
|
|
142
|
+
speed: 0.5,
|
|
143
|
+
flash: 0
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case EWeatherType.Foggy:
|
|
147
|
+
this.cloud.setEffect(type, {
|
|
148
|
+
cloudalpha: 2.0,
|
|
149
|
+
cloudscale: 8.0,
|
|
150
|
+
speed: 0.2,
|
|
151
|
+
flash: 0.0
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 雾、沙尘暴
|
|
159
|
+
* @param type
|
|
160
|
+
*/
|
|
161
|
+
}, {
|
|
162
|
+
key: "_createFogMesh",
|
|
163
|
+
value: function _createFogMesh(type) {
|
|
164
|
+
var _this2 = this;
|
|
165
|
+
var _use$useScene2 = use.useScene(),
|
|
166
|
+
scene = _use$useScene2.scene;
|
|
167
|
+
if (!this.fog) this.fog = new Fog2DMesh();
|
|
168
|
+
var color, alpha;
|
|
169
|
+
switch (type) {
|
|
170
|
+
case EWeatherType.Foggy:
|
|
171
|
+
// 雾
|
|
172
|
+
color = [0.9, 0.9, 0.9];
|
|
173
|
+
alpha = 0.4;
|
|
174
|
+
break;
|
|
175
|
+
case EWeatherType.Sand_Dust_Calm:
|
|
176
|
+
// 沙尘暴
|
|
177
|
+
color = [1.0, 0.69, 0.48];
|
|
178
|
+
alpha = 0.6;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
this.fog.setColor(color);
|
|
182
|
+
this.fog.setAlpha(alpha);
|
|
183
|
+
scene === null || scene === void 0 ? void 0 : scene.add(this.fog);
|
|
184
|
+
var unFogFrame = use.useframe(function () {
|
|
185
|
+
_this2.fog.update();
|
|
186
|
+
});
|
|
187
|
+
this.eventListener.add(unFogFrame);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 雨、雪
|
|
192
|
+
* @param type
|
|
193
|
+
*/
|
|
194
|
+
}, {
|
|
195
|
+
key: "_createSnowMesh",
|
|
196
|
+
value: function _createSnowMesh(type) {
|
|
197
|
+
var _this3 = this;
|
|
198
|
+
var _use$useScene3 = use.useScene(),
|
|
199
|
+
scene = _use$useScene3.scene;
|
|
200
|
+
if (!this.snow) this.snow = new SnowMesh();
|
|
201
|
+
switch (type) {
|
|
202
|
+
case EWeatherType.Rain:
|
|
203
|
+
// 雨
|
|
204
|
+
this.snow.setEffect({
|
|
205
|
+
speed: [0, 5, 0],
|
|
206
|
+
size: 2,
|
|
207
|
+
icon: Rain_Icon,
|
|
208
|
+
count: 3000
|
|
209
|
+
});
|
|
210
|
+
break;
|
|
211
|
+
case EWeatherType.Rain_Thunderstorm:
|
|
212
|
+
// 强雷阵雨
|
|
213
|
+
this.snow.setEffect({
|
|
214
|
+
speed: [0, 10, 0],
|
|
215
|
+
size: 2,
|
|
216
|
+
icon: Rain_Icon,
|
|
217
|
+
count: 6000
|
|
218
|
+
});
|
|
219
|
+
break;
|
|
220
|
+
case EWeatherType.Snow:
|
|
221
|
+
// 雪
|
|
222
|
+
this.snow.setEffect({
|
|
223
|
+
speed: [0, 2, 0],
|
|
224
|
+
size: 10,
|
|
225
|
+
icon: Snow_Icon,
|
|
226
|
+
count: 1000
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
case EWeatherType.Snow_Blizzard:
|
|
230
|
+
// 暴雪
|
|
231
|
+
this.snow.setEffect({
|
|
232
|
+
speed: [0, 4, 0],
|
|
233
|
+
size: 10,
|
|
234
|
+
icon: Snow_Icon,
|
|
235
|
+
count: 2000
|
|
236
|
+
});
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
scene === null || scene === void 0 ? void 0 : scene.add(this.snow);
|
|
240
|
+
var unSnowFrame = use.useframe(function () {
|
|
241
|
+
_this3.snow.update();
|
|
242
|
+
});
|
|
243
|
+
this.eventListener.add(unSnowFrame);
|
|
244
|
+
}
|
|
245
|
+
}, {
|
|
246
|
+
key: "_reset",
|
|
247
|
+
value: function _reset() {
|
|
248
|
+
if (this.fog) this.fog.removeFromParent();
|
|
249
|
+
if (this.snow) this.snow.removeFromParent();
|
|
250
|
+
this.eventListener && this.eventListener.forEach(function (unEvent) {
|
|
251
|
+
return unEvent();
|
|
252
|
+
});
|
|
253
|
+
this.eventListener.clear();
|
|
254
|
+
}
|
|
255
|
+
}, {
|
|
256
|
+
key: "_destroy",
|
|
257
|
+
value: function _destroy() {
|
|
258
|
+
this._reset();
|
|
259
|
+
this.sky.removeFromParent();
|
|
260
|
+
this.sky.remove();
|
|
261
|
+
this.cloud.removeFromParent();
|
|
262
|
+
this.cloud.remove();
|
|
263
|
+
}
|
|
264
|
+
}, {
|
|
265
|
+
key: "remove",
|
|
266
|
+
value: function remove() {
|
|
267
|
+
this._destroy();
|
|
268
|
+
this.remove();
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
key: "removeFromParent",
|
|
272
|
+
value: function removeFromParent() {
|
|
273
|
+
this._destroy();
|
|
274
|
+
this.removeFromParent();
|
|
275
|
+
}
|
|
276
|
+
}]);
|
|
277
|
+
return Weather;
|
|
278
|
+
}();
|
|
11
279
|
export default Weather;
|
|
12
280
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Weather","console","log"],"sources":["../../src/weather/index.ts"],"sourcesContent":["class Weather {\n constructor() {\n console.log('Weather')\n }\n}\n\nexport default Weather"],"mappings":";;;;;;IAAMA,OAAO,6BACX,mBAAc;EAAA;EACZC,OAAO,CAACC,GAAG,CAAC,SAAS,CAAC;AACxB,CAAC;AAGH,eAAeF,OAAO"}
|
|
1
|
+
{"version":3,"names":["ModelLoader","use","EWeatherType","Rain_Icon","Snow_Icon","Fog2DMesh","CloudMesh","SkyMesh","SnowMesh","load","Weather","Set","loaded","init","loadGLTF","gltf","mesh","scene","sky","clone","cloud","useScene","add","useframe","update","weatherType","_reset","Foggy","Sand_Dust_Calm","Clear_Skies","Cloudy","Overcast","Rain","Rain_Thunderstorm","Snow","Snow_Blizzard","_createFogMesh","_createCloudMesh","_createSnowMesh","type","setEffect","cloudalpha","cloudscale","speed","flash","fog","color","alpha","setColor","setAlpha","unFogFrame","eventListener","snow","size","icon","count","unSnowFrame","removeFromParent","forEach","unEvent","clear","remove","_destroy"],"sources":["../../src/weather/index.ts"],"sourcesContent":["import type { Group } from '@anov/3d-core'\nimport { ModelLoader, use } from '@anov/3d-core'\nimport { EWeatherType } from './utils/type'\nimport { Rain_Icon, Snow_Icon } from './utils/constant'\nimport Fog2DMesh from './objects/Fog2DMesh'\nimport CloudMesh from './objects/CloudMesh'\nimport SkyMesh from './objects/SkyMesh'\nimport SnowMesh from './objects/SnowMesh'\n\nconst load = new ModelLoader()\nclass Weather {\n fog!: Fog2DMesh\n sky!: SkyMesh\n cloud!: CloudMesh\n snow!: SnowMesh\n loaded!: Promise<boolean>\n eventListener: Set<Function> = new Set()\n\n constructor() {\n this.loaded = this.init()\n }\n\n async init() {\n const gltf = await load.loadGLTF('./skySphereMesh.glb', false, true, './draco/')\n const mesh = gltf.scene as Group\n\n this.sky = new SkyMesh(mesh.clone())\n this.cloud = new CloudMesh(mesh.clone())\n\n const { scene } = use.useScene()\n scene?.add(this.sky.mesh)\n scene?.add(this.cloud.mesh)\n\n use.useframe(() => {\n this.cloud?.update()\n })\n return true\n }\n\n /**\n * 天气设置\n * @param weatherType 天气枚举值\n * @param option 配置参数\n */\n async setWeather(weatherType: string) {\n await this.loaded\n\n this._reset()\n switch (weatherType) {\n case EWeatherType.Foggy: // 有雾\n case EWeatherType.Sand_Dust_Calm: // 沙尘暴\n this._createFogMesh(weatherType)\n // eslint-disable-next-line no-fallthrough\n case EWeatherType.Clear_Skies: // 晴天\n case EWeatherType.Cloudy: // 多云\n case EWeatherType.Overcast: // 阴天\n this._createCloudMesh(weatherType)\n break\n case EWeatherType.Rain: // 雨\n case EWeatherType.Rain_Thunderstorm: // 强雷阵雨\n case EWeatherType.Snow: // 雪\n case EWeatherType.Snow_Blizzard: // 暴雪\n this._createSnowMesh(weatherType)\n break\n }\n }\n\n /**\n * 设置不同天气的预设值:晴天、多云、阴天\n * @param type\n */\n private _createCloudMesh(type: string) {\n switch (type) {\n case EWeatherType.Clear_Skies:\n this.cloud.setEffect(type, {\n cloudalpha: 3.0,\n cloudscale: 8.0,\n speed: 0.2,\n flash: 0.0,\n })\n break\n case EWeatherType.Cloudy:\n this.cloud.setEffect(type, {\n cloudalpha: 0.8,\n cloudscale: 8.0,\n speed: 0.3,\n flash: 0.0,\n })\n break\n case EWeatherType.Overcast:\n this.cloud.setEffect(type, {\n cloudalpha: 1.8,\n cloudscale: 1.0,\n speed: 0.4,\n flash: 1.0,\n })\n break\n case EWeatherType.Sand_Dust_Calm:\n this.cloud.setEffect(type, {\n cloudalpha: 1.6,\n cloudscale: 3.0,\n speed: 0.5,\n flash: 0,\n })\n break\n case EWeatherType.Foggy:\n this.cloud.setEffect(type, {\n cloudalpha: 2.0,\n cloudscale: 8.0,\n speed: 0.2,\n flash: 0.0,\n })\n break\n }\n }\n\n /**\n * 雾、沙尘暴\n * @param type\n */\n private _createFogMesh(type: string) {\n const { scene } = use.useScene()\n if (!this.fog)\n this.fog = new Fog2DMesh()\n\n let color: [number, number, number], alpha\n switch (type) {\n case EWeatherType.Foggy: // 雾\n color = [0.9, 0.9, 0.9]\n alpha = 0.4\n break\n case EWeatherType.Sand_Dust_Calm: // 沙尘暴\n color = [1.0, 0.69, 0.48]\n alpha = 0.6\n break\n }\n this.fog.setColor(color!)\n this.fog.setAlpha(alpha!)\n scene?.add(this.fog)\n const unFogFrame = use.useframe(() => {\n this.fog.update()\n })\n this.eventListener.add(unFogFrame)\n }\n\n /**\n * 雨、雪\n * @param type\n */\n private _createSnowMesh(type: string) {\n const { scene } = use.useScene()\n if (!this.snow)\n this.snow = new SnowMesh()\n switch (type) {\n case EWeatherType.Rain: // 雨\n this.snow.setEffect({\n speed: [0, 5, 0],\n size: 2,\n icon: Rain_Icon,\n count: 3000,\n })\n break\n case EWeatherType.Rain_Thunderstorm: // 强雷阵雨\n this.snow.setEffect({\n speed: [0, 10, 0],\n size: 2,\n icon: Rain_Icon,\n count: 6000,\n })\n break\n case EWeatherType.Snow: // 雪\n this.snow.setEffect({\n speed: [0, 2, 0],\n size: 10,\n icon: Snow_Icon,\n count: 1000,\n })\n break\n case EWeatherType.Snow_Blizzard: // 暴雪\n this.snow.setEffect({\n speed: [0, 4, 0],\n size: 10,\n icon: Snow_Icon,\n count: 2000,\n })\n break\n }\n scene?.add(this.snow)\n const unSnowFrame = use.useframe(() => {\n this.snow.update()\n })\n this.eventListener.add(unSnowFrame)\n }\n\n private _reset() {\n if (this.fog)\n this.fog.removeFromParent()\n if (this.snow)\n this.snow.removeFromParent()\n this.eventListener && this.eventListener.forEach(unEvent => unEvent())\n this.eventListener.clear()\n }\n\n private _destroy() {\n this._reset()\n this.sky.removeFromParent()\n this.sky.remove()\n this.cloud.removeFromParent()\n this.cloud.remove()\n }\n\n remove() {\n this._destroy()\n this.remove()\n }\n\n removeFromParent() {\n this._destroy()\n this.removeFromParent()\n }\n}\n\nexport default Weather"],"mappings":";+CACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAASA,WAAW,EAAEC,GAAG,QAAQ,eAAe;AAChD,SAASC,YAAY;AACrB,SAASC,SAAS,EAAEC,SAAS;AAC7B,OAAOC,SAAS;AAChB,OAAOC,SAAS;AAChB,OAAOC,OAAO;AACd,OAAOC,QAAQ;AAEf,IAAMC,IAAI,GAAG,IAAIT,WAAW,EAAE;AAAA,IACxBU,OAAO;EAQX,mBAAc;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA,uCAFiB,IAAIC,GAAG,EAAE;IAGtC,IAAI,CAACC,MAAM,GAAG,IAAI,CAACC,IAAI,EAAE;EAC3B;EAAC;IAAA;IAAA;MAAA,uEAED;QAAA;QAAA;QAAA;UAAA;YAAA;cAAA;cAAA,OACqBJ,IAAI,CAACK,QAAQ,CAAC,qBAAqB,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC;YAAA;cAA1EC,IAAI;cACJC,IAAI,GAAGD,IAAI,CAACE,KAAK;cAEvB,IAAI,CAACC,GAAG,GAAG,IAAIX,OAAO,CAACS,IAAI,CAACG,KAAK,EAAE,CAAC;cACpC,IAAI,CA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I,EACX,IAAI,CAACA,IAAI,CAACK,gBAAgB,EAAE;MAC9B,IAAI,CAACN,aAAa,IAAI,IAAI,CAACA,aAAa,CAACO,OAAO,CAAC,UAAAC,OAAO;QAAA,OAAIA,OAAO,EAAE;MAAA,EAAC;MACtE,IAAI,CAACR,aAAa,CAACS,KAAK,EAAE;IAC5B;EAAC;IAAA;IAAA,OAED,oBAAmB;MACjB,IAAI,CAAClC,MAAM,EAAE;MACb,IAAI,CAACR,GAAG,CAACuC,gBAAgB,EAAE;MAC3B,IAAI,CAACvC,GAAG,CAAC2C,MAAM,EAAE;MACjB,IAAI,CAACzC,KAAK,CAACqC,gBAAgB,EAAE;MAC7B,IAAI,CAACrC,KAAK,CAACyC,MAAM,EAAE;IACrB;EAAC;IAAA;IAAA,OAED,kBAAS;MACP,IAAI,CAACC,QAAQ,EAAE;MACf,IAAI,CAACD,MAAM,EAAE;IACf;EAAC;IAAA;IAAA,OAED,4BAAmB;MACjB,IAAI,CAACC,QAAQ,EAAE;MACf,IAAI,CAACL,gBAAgB,EAAE;IACzB;EAAC;EAAA;AAAA;AAGH,eAAe/C,OAAO"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Group } from '@anov/3d-core';
|
|
2
|
+
import { Mesh } from '@anov/3d-core';
|
|
3
|
+
import type { ICloudOption } from '../utils/constant';
|
|
4
|
+
declare class CloudMesh extends Mesh {
|
|
5
|
+
option: ICloudOption;
|
|
6
|
+
uniforms: any;
|
|
7
|
+
mesh: Group;
|
|
8
|
+
loaded: Promise<Boolean>;
|
|
9
|
+
constructor(mesh: Group);
|
|
10
|
+
/**
|
|
11
|
+
* 设置天气的Uniforms
|
|
12
|
+
* @param option
|
|
13
|
+
*/
|
|
14
|
+
private setUniforms;
|
|
15
|
+
setAlpha(alpha: number): void;
|
|
16
|
+
setScale(scale: number): void;
|
|
17
|
+
setSpeed(speed: number): void;
|
|
18
|
+
setFlash(flash: number): void;
|
|
19
|
+
setEffect(type: string, ops: ICloudOption): void;
|
|
20
|
+
update(): void;
|
|
21
|
+
}
|
|
22
|
+
export default CloudMesh;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
import { Mesh, RepeatWrapping, ShaderMaterial, TextureLoader } from '@anov/3d-core';
|
|
18
|
+
import cloudShader from "../shaders/cloud";
|
|
19
|
+
import { CloudDensity } from "../utils/constant";
|
|
20
|
+
var textureLoader = new TextureLoader();
|
|
21
|
+
var _defaultOption = {
|
|
22
|
+
texture1: textureLoader.load('./T_soft_smoke.png'),
|
|
23
|
+
texture2: textureLoader.load('./T_TileNoise.png'),
|
|
24
|
+
duration: 2,
|
|
25
|
+
cloudDensity: 0.02,
|
|
26
|
+
cloudDensity2: 1.6,
|
|
27
|
+
cloudalpha: 0.8,
|
|
28
|
+
cloudscale: 8.0,
|
|
29
|
+
speed: 0.3,
|
|
30
|
+
color: [0.9, 0.9, 0.9],
|
|
31
|
+
flash: 0.3
|
|
32
|
+
};
|
|
33
|
+
var CloudMesh = /*#__PURE__*/function (_Mesh) {
|
|
34
|
+
_inherits(CloudMesh, _Mesh);
|
|
35
|
+
var _super = _createSuper(CloudMesh);
|
|
36
|
+
function CloudMesh(mesh) {
|
|
37
|
+
var _this;
|
|
38
|
+
_classCallCheck(this, CloudMesh);
|
|
39
|
+
_this = _super.call(this);
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "option", _defaultOption);
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "uniforms", {});
|
|
42
|
+
_defineProperty(_assertThisInitialized(_this), "mesh", void 0);
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "loaded", void 0);
|
|
44
|
+
_this.mesh = mesh;
|
|
45
|
+
if (_this.option.texture1) _this.option.texture1.wrapS = _this.option.texture1.wrapT = RepeatWrapping;
|
|
46
|
+
if (_this.option.texture2) _this.option.texture2.wrapS = _this.option.texture2.wrapT = RepeatWrapping;
|
|
47
|
+
_this.setUniforms(_objectSpread(_objectSpread({}, _this.option), {}, {
|
|
48
|
+
iTime: 0
|
|
49
|
+
}));
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
_this.mesh.children[0].material = new ShaderMaterial({
|
|
52
|
+
uniforms: _this.uniforms,
|
|
53
|
+
vertexShader: cloudShader.vertexShader,
|
|
54
|
+
fragmentShader: cloudShader.fragmentShader,
|
|
55
|
+
side: 2,
|
|
56
|
+
transparent: true,
|
|
57
|
+
depthWrite: false
|
|
58
|
+
});
|
|
59
|
+
_this.mesh.scale.set(997, 997, 997);
|
|
60
|
+
return _this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 设置天气的Uniforms
|
|
65
|
+
* @param option
|
|
66
|
+
*/
|
|
67
|
+
_createClass(CloudMesh, [{
|
|
68
|
+
key: "setUniforms",
|
|
69
|
+
value: function setUniforms(option) {
|
|
70
|
+
var _this2 = this;
|
|
71
|
+
Object.assign(this.option, option);
|
|
72
|
+
Object.keys(option).forEach(function (key) {
|
|
73
|
+
_this2.uniforms[key] = {
|
|
74
|
+
value: option[key]
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "setAlpha",
|
|
80
|
+
value: function setAlpha(alpha) {
|
|
81
|
+
this.setUniforms({
|
|
82
|
+
cloudalpha: alpha
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "setScale",
|
|
87
|
+
value: function setScale(scale) {
|
|
88
|
+
this.setUniforms({
|
|
89
|
+
cloudscale: scale
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "setSpeed",
|
|
94
|
+
value: function setSpeed(speed) {
|
|
95
|
+
this.setUniforms({
|
|
96
|
+
speed: speed
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "setFlash",
|
|
101
|
+
value: function setFlash(flash) {
|
|
102
|
+
this.setUniforms({
|
|
103
|
+
flash: flash
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "setEffect",
|
|
108
|
+
value: function setEffect(type, ops) {
|
|
109
|
+
var density = CloudDensity[type] || {};
|
|
110
|
+
this.setUniforms(_objectSpread(_objectSpread({}, density), ops));
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "update",
|
|
114
|
+
value: function update() {
|
|
115
|
+
var iTime = this.uniforms.iTime;
|
|
116
|
+
iTime.value += 0.01;
|
|
117
|
+
}
|
|
118
|
+
}]);
|
|
119
|
+
return CloudMesh;
|
|
120
|
+
}(Mesh);
|
|
121
|
+
export default CloudMesh;
|
|
122
|
+
//# sourceMappingURL=CloudMesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Mesh","RepeatWrapping","ShaderMaterial","TextureLoader","cloudShader","CloudDensity","textureLoader","_defaultOption","texture1","load","texture2","duration","cloudDensity","cloudDensity2","cloudalpha","cloudscale","speed","color","flash","CloudMesh","mesh","option","wrapS","wrapT","setUniforms","iTime","children","material","uniforms","vertexShader","fragmentShader","side","transparent","depthWrite","scale","set","Object","assign","keys","forEach","key","value","alpha","type","ops","density"],"sources":["../../../src/weather/objects/CloudMesh.ts"],"sourcesContent":["import type { Group, Texture } from '@anov/3d-core'\nimport { Mesh, RepeatWrapping, ShaderMaterial, TextureLoader, use } from '@anov/3d-core'\nimport cloudShader from '../shaders/cloud'\nimport type { ICloudOption } from '../utils/constant'\nimport { CloudDensity } from '../utils/constant'\n\nconst textureLoader = new TextureLoader()\n\nconst _defaultOption: ICloudOption = {\n texture1: textureLoader.load('./T_soft_smoke.png'),\n texture2: textureLoader.load('./T_TileNoise.png'),\n duration: 2,\n cloudDensity: 0.02,\n cloudDensity2: 1.6,\n cloudalpha: 0.8,\n cloudscale: 8.0,\n speed: 0.3,\n color: [0.9, 0.9, 0.9],\n flash: 0.3,\n}\n\nclass CloudMesh extends Mesh {\n option: ICloudOption = _defaultOption\n\n uniforms: any = {}\n mesh!: Group\n loaded!: Promise<Boolean>\n\n constructor(mesh: Group) {\n super()\n this.mesh = mesh\n if (this.option.texture1)\n this.option.texture1.wrapS = this.option.texture1.wrapT = RepeatWrapping\n if (this.option.texture2)\n this.option.texture2.wrapS = this.option.texture2.wrapT = RepeatWrapping\n this.setUniforms({\n ...this.option,\n iTime: 0,\n })\n // @ts-ignore\n this.mesh.children[0].material = new ShaderMaterial({\n uniforms: this.uniforms,\n vertexShader: cloudShader.vertexShader,\n fragmentShader: cloudShader.fragmentShader,\n side: 2,\n transparent: true,\n depthWrite: false,\n })\n this.mesh.scale.set(997, 997, 997)\n }\n\n /**\n * 设置天气的Uniforms\n * @param option\n */\n private setUniforms(option: ICloudOption) {\n Object.assign(this.option, option)\n\n Object.keys(option).forEach((key: string) => {\n this.uniforms[key] = { value: option[key] }\n })\n }\n\n public setAlpha(alpha: number) {\n this.setUniforms({ cloudalpha: alpha })\n }\n\n public setScale(scale: number) {\n this.setUniforms({ cloudscale: scale })\n }\n\n public setSpeed(speed: number) {\n this.setUniforms({ speed })\n }\n\n public setFlash(flash: number) {\n this.setUniforms({ flash })\n }\n\n public setEffect(type: string, ops: ICloudOption) {\n const density = CloudDensity[type] || {}\n this.setUniforms({ ...density, ...ops })\n }\n\n public update() {\n const { iTime } = this.uniforms\n iTime.value += 0.01\n }\n}\n\nexport default CloudMesh"],"mappings":";;;;;;;;;;;;;;;;AACA,SAASA,IAAI,EAAEC,cAAc,EAAEC,cAAc,EAAEC,aAAa,QAAa,eAAe;AACxF,OAAOC,WAAW;AAElB,SAASC,YAAY;AAErB,IAAMC,aAAa,GAAG,IAAIH,aAAa,EAAE;AAEzC,IAAMI,cAA4B,GAAG;EACnCC,QAAQ,EAAEF,aAAa,CAACG,IAAI,CAAC,oBAAoB,CAAC;EAClDC,QAAQ,EAAEJ,aAAa,CAACG,IAAI,CAAC,mBAAmB,CAAC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|
|
3
|
-
color?: [number, number, number];
|
|
4
|
-
alpha?: number;
|
|
5
|
-
speed?: number;
|
|
6
|
-
}
|
|
2
|
+
import type { IFogOption } from '../utils/constant';
|
|
7
3
|
declare class Fog2DMesh extends Mesh {
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
option: IFogOption;
|
|
5
|
+
uniforms: any;
|
|
6
|
+
constructor(ops?: IFogOption);
|
|
7
|
+
private setUniforms;
|
|
10
8
|
setColor(color: [number, number, number]): void;
|
|
11
9
|
setAlpha(alpha: number): void;
|
|
12
10
|
setSpeed(speed: number): void;
|
|
11
|
+
update(): void;
|
|
13
12
|
}
|
|
14
13
|
export default Fog2DMesh;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
import { Mesh, PlaneGeometry, ShaderMaterial } from '@anov/3d-core';
|
|
18
|
+
import fogShader from "../shaders/fog";
|
|
19
|
+
var _defaultOption = {
|
|
20
|
+
fogcolor: [0.9, 0.9, 0.9],
|
|
21
|
+
alpha: 0.5,
|
|
22
|
+
speed: 0.01
|
|
23
|
+
};
|
|
24
|
+
var Fog2DMesh = /*#__PURE__*/function (_Mesh) {
|
|
25
|
+
_inherits(Fog2DMesh, _Mesh);
|
|
26
|
+
var _super = _createSuper(Fog2DMesh);
|
|
27
|
+
function Fog2DMesh(ops) {
|
|
28
|
+
var _this;
|
|
29
|
+
_classCallCheck(this, Fog2DMesh);
|
|
30
|
+
_this = _super.call(this);
|
|
31
|
+
_defineProperty(_assertThisInitialized(_this), "option", _defaultOption);
|
|
32
|
+
_defineProperty(_assertThisInitialized(_this), "uniforms", void 0);
|
|
33
|
+
_this.geometry = new PlaneGeometry(10, 10);
|
|
34
|
+
Object.assign(_this.option, ops);
|
|
35
|
+
_this.setUniforms(_objectSpread(_objectSpread({}, _this.option), {}, {
|
|
36
|
+
iTime: 0
|
|
37
|
+
}));
|
|
38
|
+
_this.material = new ShaderMaterial({
|
|
39
|
+
uniforms: _this.uniforms,
|
|
40
|
+
vertexShader: fogShader.vertexShader,
|
|
41
|
+
fragmentShader: fogShader.fragmentShader,
|
|
42
|
+
side: 2,
|
|
43
|
+
transparent: true,
|
|
44
|
+
depthWrite: false
|
|
45
|
+
});
|
|
46
|
+
_this.renderOrder = 1;
|
|
47
|
+
return _this;
|
|
48
|
+
}
|
|
49
|
+
_createClass(Fog2DMesh, [{
|
|
50
|
+
key: "setUniforms",
|
|
51
|
+
value: function setUniforms(option) {
|
|
52
|
+
var _this2 = this;
|
|
53
|
+
if (!this.uniforms) this.uniforms = {};
|
|
54
|
+
Object.assign(this.option, option);
|
|
55
|
+
Object.keys(option).forEach(function (key) {
|
|
56
|
+
_this2.uniforms[key] = {
|
|
57
|
+
value: option[key]
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "setColor",
|
|
63
|
+
value: function setColor(color) {
|
|
64
|
+
this.setUniforms({
|
|
65
|
+
fogcolor: color
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "setAlpha",
|
|
70
|
+
value: function setAlpha(alpha) {
|
|
71
|
+
this.setUniforms({
|
|
72
|
+
alpha: alpha
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "setSpeed",
|
|
77
|
+
value: function setSpeed(speed) {
|
|
78
|
+
this.setUniforms({
|
|
79
|
+
speed: speed
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "update",
|
|
84
|
+
value: function update() {
|
|
85
|
+
var _this$option$speed = this.option.speed,
|
|
86
|
+
speed = _this$option$speed === void 0 ? 0.01 : _this$option$speed;
|
|
87
|
+
var iTime = this.uniforms.iTime;
|
|
88
|
+
iTime.value += speed;
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
return Fog2DMesh;
|
|
92
|
+
}(Mesh);
|
|
93
|
+
export default Fog2DMesh;
|
|
94
|
+
//# sourceMappingURL=Fog2DMesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Mesh","PlaneGeometry","ShaderMaterial","fogShader","_defaultOption","fogcolor","alpha","speed","Fog2DMesh","ops","geometry","Object","assign","option","setUniforms","iTime","material","uniforms","vertexShader","fragmentShader","side","transparent","depthWrite","renderOrder","keys","forEach","key","value","color"],"sources":["../../../src/weather/objects/Fog2DMesh.ts"],"sourcesContent":["import { Mesh, PlaneGeometry, ShaderMaterial, use } from '@anov/3d-core'\nimport fogShader from '../shaders/fog'\nimport type { IFogOption } from '../utils/constant'\n\nconst _defaultOption: IFogOption = {\n fogcolor: [0.9, 0.9, 0.9],\n alpha: 0.5,\n speed: 0.01,\n}\n\nclass Fog2DMesh extends Mesh {\n option: IFogOption = _defaultOption\n uniforms: any\n\n constructor(ops?: IFogOption) {\n super()\n this.geometry = new PlaneGeometry(10, 10)\n\n Object.assign(this.option, ops)\n this.setUniforms({ ...this.option, iTime: 0 })\n\n this.material = new ShaderMaterial({\n uniforms: this.uniforms,\n vertexShader: fogShader.vertexShader,\n fragmentShader: fogShader.fragmentShader,\n side: 2,\n transparent: true,\n depthWrite: false,\n })\n this.renderOrder = 1\n }\n\n private setUniforms(option: IFogOption) {\n if (!this.uniforms)\n this.uniforms = {}\n\n Object.assign(this.option, option)\n\n Object.keys(option).forEach((key: string) => {\n this.uniforms[key] = { value: option[key] }\n })\n }\n\n setColor(color: [number, number, number]) {\n this.setUniforms({ fogcolor: color })\n }\n\n setAlpha(alpha: number) {\n this.setUniforms({ alpha })\n }\n\n setSpeed(speed: number) {\n this.setUniforms({ speed })\n }\n\n update() {\n const { speed = 0.01 } = this.option\n const { iTime } = this.uniforms\n iTime.value += speed\n }\n}\n\nexport default Fog2DMesh"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAASA,IAAI,EAAEC,aAAa,EAAEC,cAAc,QAAa,eAAe;AACxE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