@anov/3d-ability 0.0.136 → 0.0.137

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 (31) hide show
  1. package/dist/business/index.d.ts +0 -1
  2. package/dist/business/index.js +1 -1
  3. package/dist/business/index.js.map +1 -1
  4. package/package.json +1 -1
  5. package/dist/business/TrafficComponents/RealismTraffic/RealismTraffic.d.ts +0 -93
  6. package/dist/business/TrafficComponents/RealismTraffic/RealismTraffic.js +0 -343
  7. package/dist/business/TrafficComponents/RealismTraffic/RealismTraffic.js.map +0 -1
  8. package/dist/business/TrafficComponents/RealismTraffic/index.d.ts +0 -8
  9. package/dist/business/TrafficComponents/RealismTraffic/index.js +0 -2
  10. package/dist/business/TrafficComponents/RealismTraffic/index.js.map +0 -1
  11. package/dist/business/TrafficComponents/StreamerTraffic/StreamerTraffic.d.ts +0 -57
  12. package/dist/business/TrafficComponents/StreamerTraffic/StreamerTraffic.js +0 -200
  13. package/dist/business/TrafficComponents/StreamerTraffic/StreamerTraffic.js.map +0 -1
  14. package/dist/business/TrafficComponents/StreamerTraffic/fragmentShader.d.ts +0 -1
  15. package/dist/business/TrafficComponents/StreamerTraffic/fragmentShader.js +0 -2
  16. package/dist/business/TrafficComponents/StreamerTraffic/fragmentShader.js.map +0 -1
  17. package/dist/business/TrafficComponents/StreamerTraffic/index.d.ts +0 -11
  18. package/dist/business/TrafficComponents/StreamerTraffic/index.js +0 -2
  19. package/dist/business/TrafficComponents/StreamerTraffic/index.js.map +0 -1
  20. package/dist/business/TrafficComponents/StreamerTraffic/vertexShader.d.ts +0 -1
  21. package/dist/business/TrafficComponents/StreamerTraffic/vertexShader.js +0 -2
  22. package/dist/business/TrafficComponents/StreamerTraffic/vertexShader.js.map +0 -1
  23. package/dist/business/TrafficComponents/base.d.ts +0 -22
  24. package/dist/business/TrafficComponents/base.js +0 -64
  25. package/dist/business/TrafficComponents/base.js.map +0 -1
  26. package/dist/business/TrafficComponents/index.d.ts +0 -2
  27. package/dist/business/TrafficComponents/index.js +0 -3
  28. package/dist/business/TrafficComponents/index.js.map +0 -1
  29. package/dist/business/TrafficComponents/utils.d.ts +0 -10
  30. package/dist/business/TrafficComponents/utils.js +0 -48
  31. package/dist/business/TrafficComponents/utils.js.map +0 -1
@@ -1,7 +1,6 @@
1
1
  export * from './Poi';
2
2
  export * from './Spline';
3
3
  export * from './Area';
4
- export * from './TrafficComponents';
5
4
  export * from './Batch';
6
5
  export * from './MaterialSwitch';
7
6
  export * from './Flyline';
@@ -1,7 +1,7 @@
1
1
  export * from "./Poi";
2
2
  export * from "./Spline";
3
3
  export * from "./Area";
4
- export * from "./TrafficComponents";
4
+ // export * from './TrafficComponents'
5
5
  export * from "./Batch";
6
6
  export * from "./MaterialSwitch";
7
7
  export * from "./Flyline";
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/business/index.ts"],"sourcesContent":["export * from './Poi'\nexport * from './Spline'\nexport * from './Area'\nexport * from './TrafficComponents'\nexport * from './Batch'\nexport * from './MaterialSwitch'\nexport * from './Flyline'\nexport * from './HeatMap'\nexport * from './Mark'\nexport * from './SplitBuilding'\nexport * from './InfoPanel'\nexport * from './VideoPanel'\nexport * from './Box'\nexport * from './Sphere'\nexport * from './Line'\nexport * from './Cylinder'\nexport * from './Plane'\nexport * from './Water'"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"names":[],"sources":["../../src/business/index.ts"],"sourcesContent":["export * from './Poi'\nexport * from './Spline'\nexport * from './Area'\n// export * from './TrafficComponents'\nexport * from './Batch'\nexport * from './MaterialSwitch'\nexport * from './Flyline'\nexport * from './HeatMap'\nexport * from './Mark'\nexport * from './SplitBuilding'\nexport * from './InfoPanel'\nexport * from './VideoPanel'\nexport * from './Box'\nexport * from './Sphere'\nexport * from './Line'\nexport * from './Cylinder'\nexport * from './Plane'\nexport * from './Water'"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anov/3d-ability",
3
- "version": "0.0.136",
3
+ "version": "0.0.137",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -1,93 +0,0 @@
1
- import type { CurvePath, Vector3 } from '@anov/3d-core';
2
- import { BaseTraffic } from '../base';
3
- import type { RealismTrafficInterface } from '.';
4
- type ResourceParams = {
5
- url: string;
6
- };
7
- type LanelineControl = {
8
- index: number;
9
- direction?: number;
10
- };
11
- type RealismTrafficParams = {
12
- path: CurvePath<Vector3>;
13
- width?: number;
14
- divide?: number;
15
- resource: ResourceParams[];
16
- baseTime?: number;
17
- totalNum?: number;
18
- control?: LanelineControl[];
19
- corner?: number;
20
- };
21
- /**
22
- * 写实风格车辆交通组件
23
- */
24
- export declare class RealismTraffic extends BaseTraffic implements RealismTrafficInterface {
25
- /** 车辆模型池 */
26
- private _resource;
27
- /** 基准时间 */
28
- private _baseTime;
29
- /** 车辆数量 */
30
- private _totalNum;
31
- private _startingPoints;
32
- private _startingLookatPoints;
33
- private _startingProgressPoints;
34
- private _startinglanelinePoints;
35
- private _visible;
36
- private _control;
37
- private _lanelineControl;
38
- /** 基准载具池 */
39
- private _benchmarkVehicles;
40
- /** 实际载具 */
41
- private _vehicles;
42
- /** 车道线 */
43
- lanelines: CurvePath<Vector3>[];
44
- get width(): number;
45
- set width(w: number);
46
- get divide(): number;
47
- set divide(num: number);
48
- visible: boolean;
49
- get baseTime(): number;
50
- constructor(params: RealismTrafficParams);
51
- /**
52
- * load benchmark model
53
- */
54
- private loadBenchmarkModel;
55
- /**
56
- * get max vehicle length
57
- */
58
- private getMaxVehicleLength;
59
- /**
60
- * check reasonable location
61
- */
62
- private generateRandomPool;
63
- /**
64
- * build random pool
65
- */
66
- private buildRandomPool;
67
- /**
68
- * handle requestAnimationFrame pause
69
- */
70
- private handleVisibilityChange;
71
- /**
72
- * generate random movement starting point
73
- */
74
- private generateInitPosition;
75
- /**
76
- * place vehicle
77
- */
78
- private placeVehicle;
79
- /**
80
- * run
81
- * @param laneline
82
- * @param model
83
- * @param progress
84
- * @param laneIndex
85
- */
86
- private run;
87
- /**
88
- * normalized vehicle size
89
- */
90
- private normalizedVehicleSize;
91
- removeFromParent(): this;
92
- }
93
- export {};
@@ -1,343 +0,0 @@
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
- var _class, _descriptor;
3
- 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 }); }
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 _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
- 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); }
10
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
- 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); }; }
12
- 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); }
13
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
- 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; } }
15
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
- 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; }
17
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
- 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); }
19
- 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; }
20
- 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.'); }
21
- /* eslint-disable max-statements-per-line */
22
-
23
- import { Box3, LoaderModule, utils } from '@anov/3d-core';
24
- import { BaseTraffic } from "../base";
25
- var moveWithLine = utils.moveWithLine;
26
- var loaderModule = new LoaderModule();
27
- var overrideVisible = function overrideVisible(target, propertyKey) {
28
- var getter = function getter() {
29
- return target._visible;
30
- };
31
- var setter = function setter(newValue) {
32
- target._visible = newValue;
33
- if (newValue === false) {
34
- var _target$_control;
35
- (_target$_control = target._control) !== null && _target$_control !== void 0 ? _target$_control : [].forEach(function (control) {
36
- control.stop();
37
- });
38
- } else {
39
- var _target$_control2;
40
- (_target$_control2 = target._control) !== null && _target$_control2 !== void 0 ? _target$_control2 : [].forEach(function (control) {
41
- control.continue();
42
- });
43
- }
44
- };
45
- Object.defineProperty(target, propertyKey, {
46
- get: getter,
47
- set: setter,
48
- enumerable: true,
49
- configurable: true
50
- });
51
- };
52
-
53
- /**
54
- * 写实风格车辆交通组件
55
- */
56
- export var RealismTraffic = (_class = /*#__PURE__*/function (_BaseTraffic) {
57
- _inherits(RealismTraffic, _BaseTraffic);
58
- var _super = _createSuper(RealismTraffic);
59
- function RealismTraffic(params) {
60
- var _this;
61
- _classCallCheck(this, RealismTraffic);
62
- _this = _super.call(this, params);
63
- /** 车辆模型池 */
64
- _defineProperty(_assertThisInitialized(_this), "_resource", void 0);
65
- /** 基准时间 */
66
- _defineProperty(_assertThisInitialized(_this), "_baseTime", void 0);
67
- /** 车辆数量 */
68
- _defineProperty(_assertThisInitialized(_this), "_totalNum", 5);
69
- _defineProperty(_assertThisInitialized(_this), "_startingPoints", []);
70
- _defineProperty(_assertThisInitialized(_this), "_startingLookatPoints", []);
71
- _defineProperty(_assertThisInitialized(_this), "_startingProgressPoints", []);
72
- _defineProperty(_assertThisInitialized(_this), "_startinglanelinePoints", []);
73
- _defineProperty(_assertThisInitialized(_this), "_visible", true);
74
- _defineProperty(_assertThisInitialized(_this), "_control", []);
75
- _defineProperty(_assertThisInitialized(_this), "_lanelineControl", []);
76
- /** 基准载具池 */
77
- _defineProperty(_assertThisInitialized(_this), "_benchmarkVehicles", []);
78
- /** 实际载具 */
79
- _defineProperty(_assertThisInitialized(_this), "_vehicles", []);
80
- /** 车道线 */
81
- _defineProperty(_assertThisInitialized(_this), "lanelines", []);
82
- _initializerDefineProperty(_assertThisInitialized(_this), "visible", _descriptor, _assertThisInitialized(_this));
83
- var path = params.path,
84
- _params$width = params.width,
85
- width = _params$width === void 0 ? 2 : _params$width,
86
- _params$divide = params.divide,
87
- divide = _params$divide === void 0 ? 1 : _params$divide,
88
- resource = params.resource,
89
- _params$totalNum = params.totalNum,
90
- totalNum = _params$totalNum === void 0 ? 5 : _params$totalNum,
91
- _params$baseTime = params.baseTime,
92
- baseTime = _params$baseTime === void 0 ? 10 : _params$baseTime,
93
- _params$control = params.control,
94
- control = _params$control === void 0 ? [] : _params$control,
95
- _params$corner = params.corner,
96
- corner = _params$corner === void 0 ? 10 : _params$corner;
97
- _this._path = path;
98
- _this._width = width;
99
- _this._divide = divide;
100
- _this._resource = resource;
101
- _this._totalNum = totalNum;
102
- _this._baseTime = baseTime;
103
- _this._lanelineControl = control;
104
- _this._corner = corner;
105
- if (width === 0 || divide === 0) {
106
- console.error('宽度或车道数不能为0');
107
- throw new Error('宽度或车道数不能为0');
108
- }
109
- _this.generateLaneLines();
110
- _this.loadBenchmarkModel();
111
- _this.handleVisibilityChange();
112
- return _this;
113
- }
114
-
115
- /**
116
- * load benchmark model
117
- */
118
- _createClass(RealismTraffic, [{
119
- key: "width",
120
- get: function get() {
121
- return this._width;
122
- },
123
- set: function set(w) {
124
- this._width = w;
125
- this.generateLaneLines();
126
- this.loadBenchmarkModel();
127
- }
128
- }, {
129
- key: "divide",
130
- get: function get() {
131
- return this._divide;
132
- },
133
- set: function set(num) {
134
- this._divide = num;
135
- this.generateLaneLines();
136
- this.loadBenchmarkModel();
137
- }
138
- }, {
139
- key: "baseTime",
140
- get: function get() {
141
- return this._baseTime;
142
- }
143
- }, {
144
- key: "loadBenchmarkModel",
145
- value: function loadBenchmarkModel() {
146
- var _this2 = this;
147
- this._benchmarkVehicles = [];
148
- if (!this._resource.length) return;
149
- var promises = this._resource.map(function (_ref) {
150
- var _utils$storeManagemen;
151
- var url = _ref.url;
152
- return loaderModule.loadGLTF({
153
- url: url,
154
- draco: true,
155
- // todo sdk 接口支持 decoderPath
156
- dracoPath: (_utils$storeManagemen = utils.storeManagement.get('decoderPath')) !== null && _utils$storeManagemen !== void 0 ? _utils$storeManagemen : '/draco/'
157
- });
158
- });
159
- Promise.allSettled(promises).then(function (res) {
160
- res.forEach(function (modelRes) {
161
- if (modelRes.status === 'fulfilled') _this2._benchmarkVehicles.push(_this2.normalizedVehicleSize(modelRes.value.scene));
162
- });
163
- var randomPool = _this2.generateRandomPool();
164
- _this2.generateInitPosition(randomPool);
165
- });
166
- }
167
-
168
- /**
169
- * get max vehicle length
170
- */
171
- }, {
172
- key: "getMaxVehicleLength",
173
- value: function getMaxVehicleLength() {
174
- var maxLength = this._benchmarkVehicles.reduce(function (max, vehicle) {
175
- var box = new Box3().setFromObject(vehicle);
176
- var currentLength = box.max.z - box.min.z;
177
- return currentLength > max ? currentLength : max;
178
- }, 0);
179
- return maxLength;
180
- }
181
-
182
- /**
183
- * check reasonable location
184
- */
185
- }, {
186
- key: "generateRandomPool",
187
- value: function generateRandomPool() {
188
- var _this3 = this;
189
- var lineLengths = this.lanelines.map(function (line) {
190
- return line.getLength();
191
- });
192
- var part = lineLengths.map(function (length) {
193
- return Math.floor(length / _this3.getMaxVehicleLength());
194
- });
195
- var capacity = part.reduce(function (pre, next) {
196
- return pre + next;
197
- }, 0);
198
- if (capacity < this._totalNum) throw new Error('载具数量不合理');
199
- return this.buildRandomPool(part);
200
- }
201
-
202
- /**
203
- * build random pool
204
- */
205
- }, {
206
- key: "buildRandomPool",
207
- value: function buildRandomPool(part) {
208
- var pool = [];
209
- part.forEach(function (part, i) {
210
- for (var j = 0; j < part; j++) {
211
- pool.push({
212
- t: 1 / part * j,
213
- line: i
214
- });
215
- }
216
- });
217
- return pool;
218
- }
219
-
220
- /**
221
- * handle requestAnimationFrame pause
222
- */
223
- }, {
224
- key: "handleVisibilityChange",
225
- value: function handleVisibilityChange() {
226
- var _this4 = this;
227
- document.addEventListener('visibilitychange', function () {
228
- if (document.hidden) {
229
- _this4._control.forEach(function (control) {
230
- control.stop();
231
- });
232
- } else {
233
- _this4._control.forEach(function (control) {
234
- control.continue();
235
- });
236
- }
237
- });
238
- }
239
-
240
- /**
241
- * generate random movement starting point
242
- */
243
- }, {
244
- key: "generateInitPosition",
245
- value: function generateInitPosition(randomPool) {
246
- for (var i = 0; i < this._totalNum; i++) {
247
- var index = Math.floor(Math.random() * randomPool.length);
248
- var current = randomPool[index];
249
- var currentLaneline = this.lanelines[current.line];
250
- var point = currentLaneline.getPointAt(current.t);
251
- this._startingPoints.push(point);
252
- this._startingLookatPoints.push(currentLaneline.getPointAt((current.t + 0.01) % 1));
253
- this._startingProgressPoints.push(current.t);
254
- this._startinglanelinePoints.push(current.line);
255
- randomPool.splice(index, 1);
256
- }
257
- this.placeVehicle();
258
- }
259
-
260
- /**
261
- * place vehicle
262
- */
263
- }, {
264
- key: "placeVehicle",
265
- value: function placeVehicle() {
266
- var _this5 = this;
267
- this._vehicles.forEach(function (vehicle, i) {
268
- vehicle.removeFromParent();
269
- _this5._control[i].remove();
270
- });
271
- this._vehicles = [];
272
- this._control = [];
273
- for (var i = 0; i < this._startingPoints.length; i++) {
274
- var randomModelIndex = Math.floor(Math.random() * this._benchmarkVehicles.length);
275
- var currentVehicle = this._benchmarkVehicles[randomModelIndex].clone();
276
- currentVehicle.position.copy(this._startingPoints[i]);
277
- currentVehicle.lookAt(this._startingLookatPoints[i]);
278
- this._vehicles.push(currentVehicle);
279
- this.add(currentVehicle);
280
- this.run(this.lanelines[this._startinglanelinePoints[i]], currentVehicle, this._startingProgressPoints[i], this._startinglanelinePoints[i]);
281
- }
282
- this.dispatchEvent({
283
- type: 'realismTraffic-loaded'
284
- });
285
- }
286
-
287
- /**
288
- * run
289
- * @param laneline
290
- * @param model
291
- * @param progress
292
- * @param laneIndex
293
- */
294
- }, {
295
- key: "run",
296
- value: function run(laneline, model, progress, laneIndex) {
297
- var lc = this._lanelineControl.find(function (lc) {
298
- return lc.index === laneIndex;
299
- });
300
- if (this.baseTime === 0) {
301
- console.log('baseTime is 0');
302
- return;
303
- }
304
- var control = moveWithLine(model, laneline, {
305
- duration: this.baseTime,
306
- direction: lc && (lc === null || lc === void 0 ? void 0 : lc.direction) === 0 ? -1 : 1
307
- });
308
- this._control.push(control);
309
- control.setProgress(progress);
310
- }
311
-
312
- /**
313
- * normalized vehicle size
314
- */
315
- }, {
316
- key: "normalizedVehicleSize",
317
- value: function normalizedVehicleSize(model) {
318
- var box = new Box3().setFromObject(model);
319
- var currentWidth = box.max.x - box.min.x;
320
- var scalingFactor = this._width / (this._divide + 1) / currentWidth * 0.7;
321
- model.scale.set(scalingFactor, scalingFactor, scalingFactor);
322
- return model;
323
- }
324
- }, {
325
- key: "removeFromParent",
326
- value: function removeFromParent() {
327
- // todo: 升级three.js后,父对象变化,会触发此函数,重组内部引起关系
328
- this.parent && this._control.forEach(function (control) {
329
- control.remove();
330
- });
331
- return _get(_getPrototypeOf(RealismTraffic.prototype), "removeFromParent", this).call(this);
332
- }
333
- }]);
334
- return RealismTraffic;
335
- }(BaseTraffic), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "visible", [overrideVisible], {
336
- configurable: true,
337
- enumerable: true,
338
- writable: true,
339
- initializer: function initializer() {
340
- return true;
341
- }
342
- })), _class);
343
- //# sourceMappingURL=RealismTraffic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Box3","LoaderModule","utils","BaseTraffic","moveWithLine","loaderModule","overrideVisible","target","propertyKey","getter","_visible","setter","newValue","_target$_control","_control","forEach","control","stop","_target$_control2","continue","Object","defineProperty","get","set","enumerable","configurable","RealismTraffic","_class","_BaseTraffic","_inherits","_super","_createSuper","params","_this","_classCallCheck","call","_defineProperty","_assertThisInitialized","_initializerDefineProperty","_descriptor","path","_params$width","width","_params$divide","divide","resource","_params$totalNum","totalNum","_params$baseTime","baseTime","_params$control","_params$corner","corner","_path","_width","_divide","_resource","_totalNum","_baseTime","_lanelineControl","_corner","console","error","Error","generateLaneLines","loadBenchmarkModel","handleVisibilityChange","_createClass","key","w","num","value","_this2","_benchmarkVehicles","length","promises","map","_ref","_utils$storeManagemen","url","loadGLTF","draco","dracoPath","storeManagement","Promise","allSettled","then","res","modelRes","status","push","normalizedVehicleSize","scene","randomPool","generateRandomPool","generateInitPosition","getMaxVehicleLength","maxLength","reduce","max","vehicle","box","setFromObject","currentLength","z","min","_this3","lineLengths","lanelines","line","getLength","part","Math","floor","capacity","pre","next","buildRandomPool","pool","i","j","t","_this4","document","addEventListener","hidden","index","random","current","currentLaneline","point","getPointAt","_startingPoints","_startingLookatPoints","_startingProgressPoints","_startinglanelinePoints","splice","placeVehicle","_this5","_vehicles","removeFromParent","remove","randomModelIndex","currentVehicle","clone","position","copy","lookAt","add","run","dispatchEvent","type","laneline","model","progress","laneIndex","lc","find","log","duration","direction","setProgress","currentWidth","x","scalingFactor","scale","parent","_get","_getPrototypeOf","prototype","_applyDecoratedDescriptor","writable","initializer"],"sources":["../../../../src/business/TrafficComponents/RealismTraffic/RealismTraffic.ts"],"sourcesContent":["/* eslint-disable max-statements-per-line */\nimport type { CurvePath, Group, Object3D, Vector3 } from '@anov/3d-core'\nimport { Box3, LoaderModule, utils } from '@anov/3d-core'\nimport { BaseTraffic } from '../base'\nimport type { RealismTrafficInterface } from '.'\n\nconst { moveWithLine } = utils\n\ntype ResourceParams = {\n url: string\n}\n\ntype LanelineControl = {\n index: number\n direction?: number\n}\n\ntype RealismTrafficParams = {\n path: CurvePath<Vector3>\n width?: number\n divide?: number\n resource: ResourceParams[]\n baseTime?: number\n totalNum?: number\n control?: LanelineControl[]\n corner?: number\n}\n\nconst loaderModule = new LoaderModule()\n\nconst overrideVisible = (target: any, propertyKey: string | symbol) => {\n const getter = () => {\n return target._visible\n }\n\n const setter = (newValue: any) => {\n target._visible = newValue\n\n if (newValue === false) {\n target._control ?? [].forEach((control) => {\n control.stop()\n })\n }\n else {\n target._control ?? [].forEach((control) => {\n control.continue()\n })\n }\n }\n\n Object.defineProperty(target, propertyKey, {\n get: getter,\n set: setter,\n enumerable: true,\n configurable: true,\n })\n}\n\n/**\n * 写实风格车辆交通组件\n */\nexport class RealismTraffic extends BaseTraffic implements RealismTrafficInterface {\n /** 车辆模型池 */\n private _resource: ResourceParams[]\n\n /** 基准时间 */\n private _baseTime: number\n\n /** 车辆数量 */\n private _totalNum = 5\n\n private _startingPoints: Vector3[] = []\n\n private _startingLookatPoints: Vector3[] = []\n\n private _startingProgressPoints: number[] = []\n\n private _startinglanelinePoints: number[] = []\n\n private _visible = true\n\n private _control: ReturnType<typeof moveWithLine>[] = []\n\n private _lanelineControl: LanelineControl[] = []\n\n /** 基准载具池 */\n private _benchmarkVehicles: Group[] = []\n\n /** 实际载具 */\n private _vehicles: Group[] = []\n\n /** 车道线 */\n public lanelines: CurvePath<Vector3>[] = []\n\n public get width(): number {\n return this._width\n }\n\n public set width(w: number) {\n this._width = w\n\n this.generateLaneLines()\n this.loadBenchmarkModel()\n }\n\n public get divide(): number {\n return this._divide\n }\n\n public set divide(num: number) {\n this._divide = num\n\n this.generateLaneLines()\n this.loadBenchmarkModel()\n }\n\n @overrideVisible\n override visible = true\n\n public get baseTime(): number {\n return this._baseTime\n }\n\n constructor(params: RealismTrafficParams) {\n super(params)\n\n const { path, width = 2, divide = 1, resource, totalNum = 5, baseTime = 10, control = [], corner = 10 } = params\n\n this._path = path\n this._width = width\n this._divide = divide\n this._resource = resource\n this._totalNum = totalNum\n this._baseTime = baseTime\n this._lanelineControl = control\n this._corner = corner\n\n if (width === 0 || divide === 0) {\n console.error('宽度或车道数不能为0')\n throw new Error('宽度或车道数不能为0')\n }\n\n this.generateLaneLines()\n this.loadBenchmarkModel()\n this.handleVisibilityChange()\n }\n\n /**\n * load benchmark model\n */\n private loadBenchmarkModel() {\n this._benchmarkVehicles = []\n\n if (!this._resource.length)\n return\n\n const promises = this._resource.map(({ url }) => {\n return loaderModule.loadGLTF({\n url,\n draco: true,\n // todo sdk 接口支持 decoderPath\n dracoPath: utils.storeManagement.get('decoderPath') ?? '/draco/',\n })\n })\n\n Promise.allSettled(promises).then((res) => {\n res.forEach((modelRes) => {\n if (modelRes.status === 'fulfilled')\n this._benchmarkVehicles.push(this.normalizedVehicleSize(modelRes.value.scene as Group))\n })\n\n const randomPool = this.generateRandomPool()\n this.generateInitPosition(randomPool)\n })\n }\n\n /**\n * get max vehicle length\n */\n private getMaxVehicleLength() {\n const maxLength = this._benchmarkVehicles.reduce((max, vehicle) => {\n const box = new Box3().setFromObject(vehicle)\n const currentLength = box.max.z - box.min.z\n\n return currentLength > max ? currentLength : max\n }, 0)\n\n return maxLength\n }\n\n /**\n * check reasonable location\n */\n private generateRandomPool() {\n const lineLengths = this.lanelines.map(line => line.getLength())\n const part = lineLengths.map(length => Math.floor(length / this.getMaxVehicleLength()))\n const capacity = part.reduce((pre, next) => { return pre + next }, 0)\n\n if (capacity < this._totalNum)\n throw new Error('载具数量不合理')\n\n return this.buildRandomPool(part)\n }\n\n /**\n * build random pool\n */\n private buildRandomPool(part: number[]) {\n const pool = []\n\n part.forEach((part, i) => {\n for (let j = 0; j < part; j++) {\n pool.push({\n t: 1 / part * j,\n line: i,\n })\n }\n })\n\n return pool\n }\n\n /**\n * handle requestAnimationFrame pause\n */\n private handleVisibilityChange() {\n document.addEventListener('visibilitychange', () => {\n if (document.hidden) {\n this._control.forEach((control) => {\n control.stop()\n })\n }\n else {\n this._control.forEach((control) => {\n control.continue()\n })\n }\n })\n }\n\n /**\n * generate random movement starting point\n */\n private generateInitPosition(randomPool) {\n for (let i = 0; i < this._totalNum; i++) {\n const index = Math.floor(Math.random() * randomPool.length)\n const current = randomPool[index]\n const currentLaneline = this.lanelines[current.line]\n const point = currentLaneline.getPointAt(current.t)\n\n this._startingPoints.push(point)\n this._startingLookatPoints.push(currentLaneline.getPointAt((current.t + 0.01) % 1))\n this._startingProgressPoints.push(current.t)\n this._startinglanelinePoints.push(current.line)\n\n randomPool.splice(index, 1)\n }\n\n this.placeVehicle()\n }\n\n /**\n * place vehicle\n */\n private placeVehicle() {\n this._vehicles.forEach((vehicle, i) => {\n vehicle.removeFromParent()\n this._control[i].remove()\n })\n\n this._vehicles = []\n this._control = []\n\n for (let i = 0; i < this._startingPoints.length; i++) {\n const randomModelIndex = Math.floor(Math.random() * this._benchmarkVehicles.length)\n const currentVehicle = this._benchmarkVehicles[randomModelIndex].clone()\n\n currentVehicle.position.copy(this._startingPoints[i])\n currentVehicle.lookAt(this._startingLookatPoints[i])\n\n this._vehicles.push(currentVehicle)\n this.add(currentVehicle)\n this.run(this.lanelines[this._startinglanelinePoints[i]], currentVehicle, this._startingProgressPoints[i], this._startinglanelinePoints[i])\n }\n\n this.dispatchEvent({\n type: 'realismTraffic-loaded',\n })\n }\n\n /**\n * run\n * @param laneline\n * @param model\n * @param progress\n * @param laneIndex\n */\n private run(laneline: CurvePath<Vector3>, model: Object3D, progress: number, laneIndex: number) {\n const lc = this._lanelineControl.find(lc => lc.index === laneIndex)\n\n if (this.baseTime === 0) {\n console.log('baseTime is 0')\n return\n }\n\n const control = moveWithLine(model, laneline, {\n duration: this.baseTime,\n direction: (lc && lc?.direction === 0) ? -1 : 1,\n })\n\n this._control.push(control)\n control.setProgress(progress)\n }\n\n /**\n * normalized vehicle size\n */\n private normalizedVehicleSize(model: Group) {\n const box = new Box3().setFromObject(model)\n const currentWidth = box.max.x - box.min.x\n const scalingFactor = (this._width / (this._divide + 1)) / currentWidth * 0.7\n\n model.scale.set(scalingFactor, scalingFactor, scalingFactor)\n\n return model\n }\n\n override removeFromParent(): this {\n // todo: 升级three.js后,父对象变化,会触发此函数,重组内部引起关系\n this.parent && this._control.forEach((control) => {\n control.remove()\n })\n\n return super.removeFromParent()\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AAEA,SAASA,IAAI,EAAEC,YAAY,EAAEC,KAAK,QAAQ,eAAe;AACzD,SAASC,WAAW;AAGpB,IAAQC,YAAY,GAAKF,KAAK,CAAtBE,YAAY;AAsBpB,IAAMC,YAAY,GAAG,IAAIJ,YAAY,CAAC,CAAC;AAEvC,IAAMK,eAAe,GAAG,SAAlBA,eAAeA,CAAIC,MAAW,EAAEC,WAA4B,EAAK;EACrE,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAA,EAAS;IACnB,OAAOF,MAAM,CAACG,QAAQ;EACxB,CAAC;EAED,IAAMC,MAAM,GAAG,SAATA,MAAMA,CAAIC,QAAa,EAAK;IAChCL,MAAM,CAACG,QAAQ,GAAGE,QAAQ;IAE1B,IAAIA,QAAQ,KAAK,KAAK,EAAE;MAAA,IAAAC,gBAAA;MACtB,C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C;IAC/B;;IAEA;AACF;AACA;EAFE;IAAAtF,GAAA;IAAAG,KAAA,EAGA,SAAAoB,sBAA8B8D,KAAY,EAAE;MAC1C,IAAMpD,GAAG,GAAG,IAAIrG,IAAI,CAAC,CAAC,CAACsG,aAAa,CAACmD,KAAK,CAAC;MAC3C,IAAMS,YAAY,GAAG7D,GAAG,CAACF,GAAG,CAACgE,CAAC,GAAG9D,GAAG,CAACI,GAAG,CAAC0D,CAAC;MAC1C,IAAMC,aAAa,GAAI,IAAI,CAAC9G,MAAM,IAAI,IAAI,CAACC,OAAO,GAAG,CAAC,CAAC,GAAI2G,YAAY,GAAG,GAAG;MAE7ET,KAAK,CAACY,KAAK,CAAC9I,GAAG,CAAC6I,aAAa,EAAEA,aAAa,EAAEA,aAAa,CAAC;MAE5D,OAAOX,KAAK;IACd;EAAC;IAAArF,GAAA;IAAAG,KAAA,EAED,SAAAqE,iBAAA,EAAkC;MAChC;MACA,IAAI,CAAC0B,MAAM,IAAI,IAAI,CAACxJ,QAAQ,CAACC,OAAO,CAAC,UAACC,OAAO,EAAK;QAChDA,OAAO,CAAC6H,MAAM,CAAC,CAAC;MAClB,CAAC,CAAC;MAEF,OAAA0B,IAAA,CAAAC,eAAA,CAAA9I,cAAA,CAAA+I,SAAA,6BAAAtI,IAAA;IACF;EAAC;EAAA,OAAAT,cAAA;AAAA,EAjRiCvB,WAAW,IAAAoC,WAAA,GAAAmI,yBAAA,CAAA/I,MAAA,CAAA8I,SAAA,cAuD5CnK,eAAe;EAAAmB,YAAA;EAAAD,UAAA;EAAAmJ,QAAA;EAAAC,WAAA,WAAAA,YAAA;IAAA,OACG,IAAI;EAAA;AAAA,KAAAjJ,MAAA"}
@@ -1,8 +0,0 @@
1
- import type { CurvePath, Vector3 } from '@anov/3d-core';
2
- export { RealismTraffic } from './RealismTraffic';
3
- export interface RealismTrafficInterface {
4
- width: number;
5
- divide: number;
6
- baseTime: number;
7
- lanelines: CurvePath<Vector3>[];
8
- }
@@ -1,2 +0,0 @@
1
- export { RealismTraffic } from "./RealismTraffic";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["RealismTraffic"],"sources":["../../../../src/business/TrafficComponents/RealismTraffic/index.ts"],"sourcesContent":["import type { CurvePath, Vector3 } from '@anov/3d-core'\n\nexport { RealismTraffic } from './RealismTraffic'\n\nexport interface RealismTrafficInterface {\n\n width: number\n\n divide: number\n\n baseTime: number\n\n lanelines: CurvePath<Vector3>[]\n}"],"mappings":"AAEA,SAASA,cAAc"}
@@ -1,57 +0,0 @@
1
- import { type CurvePath, type Vector3 } from '@anov/3d-core';
2
- import { BaseTraffic } from '../base';
3
- import type { StreamerTrafficInterface } from '.';
4
- type LanelineControl = {
5
- index: number;
6
- direction?: number;
7
- };
8
- type StreamerTrafficParams = {
9
- path: CurvePath<Vector3>;
10
- width?: number;
11
- divide?: number;
12
- divideWidth?: number;
13
- num?: number;
14
- length?: number;
15
- baseColor?: string;
16
- speed?: number;
17
- control?: LanelineControl[];
18
- corner?: number;
19
- };
20
- /**
21
- * 流光风格交通组件
22
- */
23
- export declare class StreamerTraffic extends BaseTraffic implements StreamerTrafficInterface {
24
- /** 流光速度 */
25
- private _speed;
26
- /** 流光数量 */
27
- private _num;
28
- /** 流光颜色 */
29
- private _baseColor;
30
- /** 流光宽度 */
31
- private _divideWidth;
32
- /** 流光长度 */
33
- private _length;
34
- private _streamerArr;
35
- private _lanelineControl;
36
- private _control;
37
- get speed(): number;
38
- get num(): number;
39
- get baseColor(): string;
40
- get divideWidth(): number;
41
- get width(): number;
42
- set width(w: number);
43
- get divide(): number;
44
- set divide(num: number);
45
- constructor(params: StreamerTrafficParams);
46
- /**
47
- * generate streamer
48
- */
49
- private generateStreamer;
50
- /**
51
- * run
52
- * @param material
53
- */
54
- private run;
55
- removeFromParent(): this;
56
- }
57
- export {};
@@ -1,200 +0,0 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
- 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); } }
4
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
6
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
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 { Clock, Color, DoubleSide, MathUtils, Mesh, ShaderMaterial, TubeGeometry, Vector2, use } from '@anov/3d-core';
18
- import { BaseTraffic } from "../base";
19
- import { fragmentShader } from "./fragmentShader";
20
- import { vertexShader } from "./vertexShader";
21
- /**
22
- * 流光风格交通组件
23
- */
24
- export var StreamerTraffic = /*#__PURE__*/function (_BaseTraffic) {
25
- _inherits(StreamerTraffic, _BaseTraffic);
26
- var _super = _createSuper(StreamerTraffic);
27
- function StreamerTraffic(params) {
28
- var _this;
29
- _classCallCheck(this, StreamerTraffic);
30
- _this = _super.call(this, params);
31
- /** 流光速度 */
32
- _defineProperty(_assertThisInitialized(_this), "_speed", void 0);
33
- /** 流光数量 */
34
- _defineProperty(_assertThisInitialized(_this), "_num", void 0);
35
- /** 流光颜色 */
36
- _defineProperty(_assertThisInitialized(_this), "_baseColor", void 0);
37
- /** 流光宽度 */
38
- _defineProperty(_assertThisInitialized(_this), "_divideWidth", void 0);
39
- /** 流光长度 */
40
- _defineProperty(_assertThisInitialized(_this), "_length", void 0);
41
- _defineProperty(_assertThisInitialized(_this), "_streamerArr", []);
42
- _defineProperty(_assertThisInitialized(_this), "_lanelineControl", []);
43
- _defineProperty(_assertThisInitialized(_this), "_control", []);
44
- var path = params.path,
45
- _params$width = params.width,
46
- width = _params$width === void 0 ? 4 : _params$width,
47
- _params$divide = params.divide,
48
- divide = _params$divide === void 0 ? 4 : _params$divide,
49
- _params$divideWidth = params.divideWidth,
50
- divideWidth = _params$divideWidth === void 0 ? 1 : _params$divideWidth,
51
- _params$num = params.num,
52
- num = _params$num === void 0 ? 5 : _params$num,
53
- _params$length = params.length,
54
- length = _params$length === void 0 ? 0.25 : _params$length,
55
- _params$baseColor = params.baseColor,
56
- baseColor = _params$baseColor === void 0 ? '#ff7700' : _params$baseColor,
57
- _params$speed = params.speed,
58
- speed = _params$speed === void 0 ? 100 : _params$speed,
59
- _params$corner = params.corner,
60
- corner = _params$corner === void 0 ? 10 : _params$corner,
61
- _params$control = params.control,
62
- control = _params$control === void 0 ? [] : _params$control;
63
- _this._path = path;
64
- _this._width = width;
65
- _this._divide = divide;
66
- _this._divideWidth = divideWidth / 2;
67
- _this._num = num;
68
- _this._baseColor = baseColor;
69
- _this._speed = speed;
70
- _this._corner = corner;
71
- _this._length = length;
72
- _this._lanelineControl = control;
73
- _this.generateLaneLines();
74
- _this.generateStreamer();
75
- return _this;
76
- }
77
-
78
- /**
79
- * generate streamer
80
- */
81
- _createClass(StreamerTraffic, [{
82
- key: "speed",
83
- get: function get() {
84
- return this._speed;
85
- }
86
- }, {
87
- key: "num",
88
- get: function get() {
89
- return this._num;
90
- }
91
- }, {
92
- key: "baseColor",
93
- get: function get() {
94
- return this._baseColor;
95
- }
96
- }, {
97
- key: "divideWidth",
98
- get: function get() {
99
- return this._divideWidth;
100
- }
101
- }, {
102
- key: "width",
103
- get: function get() {
104
- return this._width;
105
- },
106
- set: function set(w) {
107
- this._width = w;
108
- this.generateLaneLines();
109
- this.generateStreamer();
110
- }
111
- }, {
112
- key: "divide",
113
- get: function get() {
114
- return this._divide;
115
- },
116
- set: function set(num) {
117
- this._divide = num;
118
- this.generateLaneLines();
119
- this.generateStreamer();
120
- }
121
- }, {
122
- key: "generateStreamer",
123
- value: function generateStreamer() {
124
- this._streamerArr.forEach(function (mesh) {
125
- mesh.removeFromParent();
126
- });
127
- this._streamerArr = [];
128
- for (var i = 0; i < this.lanelines.length; i++) {
129
- var _this$_lanelineContro, _this$_lanelineContro2;
130
- var geometry = new TubeGeometry(this.lanelines[i], Math.floor(this.lanelines[i].getLength()) * 10, this._divideWidth, 5, false);
131
- var material = new ShaderMaterial({
132
- side: DoubleSide,
133
- transparent: true,
134
- uniforms: {
135
- uColor: {
136
- value: new Color(this._baseColor)
137
- },
138
- uTime: {
139
- value: MathUtils.lerp(-1, 1, Math.random())
140
- },
141
- uFade: {
142
- value: new Vector2(0, this._length + Math.random() * this._length - this._length / 2)
143
- },
144
- uNumLines: {
145
- value: this._num
146
- },
147
- uOffset: {
148
- value: Math.random()
149
- },
150
- uAlpha: {
151
- value: Math.random()
152
- },
153
- uSpeed: {
154
- value: this._speed + Math.random() * this._speed - this._speed / 2
155
- },
156
- ulength: {
157
- value: Math.floor(this.lanelines[i].getLength())
158
- },
159
- uReverse: {
160
- value: (_this$_lanelineContro = (_this$_lanelineContro2 = this._lanelineControl[i]) === null || _this$_lanelineContro2 === void 0 ? void 0 : _this$_lanelineContro2.direction) !== null && _this$_lanelineContro !== void 0 ? _this$_lanelineContro : 1.0
161
- }
162
- },
163
- vertexShader: vertexShader,
164
- fragmentShader: fragmentShader
165
- });
166
- var road = new Mesh(geometry, material);
167
-
168
- // 渲染顺序
169
- road.renderOrder = 1000;
170
- this.add(road);
171
- this.run(material);
172
- this._streamerArr.push(road);
173
- }
174
- }
175
-
176
- /**
177
- * run
178
- * @param material
179
- */
180
- }, {
181
- key: "run",
182
- value: function run(material) {
183
- var clock = new Clock();
184
- this._control.push(use.useframe(function () {
185
- material.uniforms.uTime.value = clock.getElapsedTime();
186
- }));
187
- }
188
- }, {
189
- key: "removeFromParent",
190
- value: function removeFromParent() {
191
- // todo: 升级three.js后,父对象变化,会触发此函数,重组内部引起关系
192
- this.parent && this._control.forEach(function (control) {
193
- control();
194
- });
195
- return _get(_getPrototypeOf(StreamerTraffic.prototype), "removeFromParent", this).call(this);
196
- }
197
- }]);
198
- return StreamerTraffic;
199
- }(BaseTraffic);
200
- //# sourceMappingURL=StreamerTraffic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Clock","Color","DoubleSide","MathUtils","Mesh","ShaderMaterial","TubeGeometry","Vector2","use","BaseTraffic","fragmentShader","vertexShader","StreamerTraffic","_BaseTraffic","_inherits","_super","_createSuper","params","_this","_classCallCheck","call","_defineProperty","_assertThisInitialized","path","_params$width","width","_params$divide","divide","_params$divideWidth","divideWidth","_params$num","num","_params$length","length","_params$baseColor","baseColor","_params$speed","speed","_params$corner","corner","_params$control","control","_path","_width","_divide","_divideWidth","_num","_baseColor","_speed","_corner","_length","_lanelineControl","generateLaneLines","generateStreamer","_createClass","key","get","set","w","value","_streamerArr","forEach","mesh","removeFromParent","i","lanelines","_this$_lanelineContro","_this$_lanelineContro2","geometry","Math","floor","getLength","material","side","transparent","uniforms","uColor","uTime","lerp","random","uFade","uNumLines","uOffset","uAlpha","uSpeed","ulength","uReverse","direction","road","renderOrder","add","run","push","clock","_control","useframe","getElapsedTime","parent","_get","_getPrototypeOf","prototype"],"sources":["../../../../src/business/TrafficComponents/StreamerTraffic/StreamerTraffic.ts"],"sourcesContent":["import { Clock, Color, type CurvePath, DoubleSide, MathUtils, Mesh, ShaderMaterial, TubeGeometry, Vector2, type Vector3, use } from '@anov/3d-core'\nimport { BaseTraffic } from '../base'\nimport { fragmentShader } from './fragmentShader'\nimport { vertexShader } from './vertexShader'\nimport type { StreamerTrafficInterface } from '.'\n\ntype LanelineControl = {\n index: number\n direction?: number\n}\n\ntype StreamerTrafficParams = {\n path: CurvePath<Vector3>\n width?: number\n divide?: number\n divideWidth?: number\n num?: number\n length?: number\n baseColor?: string\n speed?: number\n control?: LanelineControl[]\n corner?: number\n}\n\n/**\n * 流光风格交通组件\n */\nexport class StreamerTraffic extends BaseTraffic implements StreamerTrafficInterface {\n /** 流光速度 */\n private _speed: number\n\n /** 流光数量 */\n private _num: number\n\n /** 流光颜色 */\n private _baseColor: string\n\n /** 流光宽度 */\n private _divideWidth: number\n\n /** 流光长度 */\n private _length: number\n\n private _streamerArr: Mesh[] = []\n\n private _lanelineControl: LanelineControl[] = []\n\n private _control = []\n\n public get speed() {\n return this._speed\n }\n\n public get num() {\n return this._num\n }\n\n public get baseColor() {\n return this._baseColor\n }\n\n public get divideWidth() {\n return this._divideWidth\n }\n\n public get width(): number {\n return this._width\n }\n\n public set width(w: number) {\n this._width = w\n\n this.generateLaneLines()\n this.generateStreamer()\n }\n\n public get divide(): number {\n return this._divide\n }\n\n public set divide(num: number) {\n this._divide = num\n\n this.generateLaneLines()\n this.generateStreamer()\n }\n\n constructor(params: StreamerTrafficParams) {\n super(params)\n\n const { path, width = 4, divide = 4, divideWidth = 1, num = 5, length = 0.25, baseColor = '#ff7700', speed = 100, corner = 10, control = [] } = params\n\n this._path = path\n this._width = width\n this._divide = divide\n this._divideWidth = divideWidth / 2\n this._num = num\n this._baseColor = baseColor\n this._speed = speed\n this._corner = corner\n this._length = length\n this._lanelineControl = control\n\n this.generateLaneLines()\n this.generateStreamer()\n }\n\n /**\n * generate streamer\n */\n private generateStreamer() {\n this._streamerArr.forEach((mesh) => {\n mesh.removeFromParent()\n })\n this._streamerArr = []\n\n for (let i = 0; i < this.lanelines.length; i++) {\n const geometry = new TubeGeometry(this.lanelines[i], Math.floor(this.lanelines[i].getLength()) * 10, this._divideWidth, 5, false)\n const material = new ShaderMaterial({\n side: DoubleSide,\n transparent: true,\n uniforms: {\n uColor: { value: new Color(this._baseColor) },\n uTime: { value: MathUtils.lerp(-1, 1, Math.random()) },\n uFade: { value: new Vector2(0, this._length + Math.random() * this._length - this._length / 2) },\n uNumLines: { value: this._num },\n uOffset: { value: Math.random() },\n uAlpha: { value: Math.random() },\n uSpeed: { value: this._speed + Math.random() * this._speed - this._speed / 2 },\n ulength: { value: Math.floor(this.lanelines[i].getLength()) },\n uReverse: { value: this._lanelineControl[i]?.direction ?? 1.0 },\n },\n vertexShader,\n fragmentShader,\n })\n\n const road = new Mesh(geometry, material)\n\n // 渲染顺序\n road.renderOrder = 1000\n\n this.add(road)\n this.run(material)\n this._streamerArr.push(road)\n }\n }\n\n /**\n * run\n * @param material\n */\n private run(material) {\n const clock = new Clock()\n\n this._control.push(\n use.useframe(() => {\n material.uniforms.uTime.value = clock.getElapsedTime()\n }),\n )\n }\n\n override removeFromParent(): this {\n // todo: 升级three.js后,父对象变化,会触发此函数,重组内部引起关系\n this.parent && this._control.forEach((control) => {\n control()\n })\n\n return super.removeFromParent()\n }\n}"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAASA,KAAK,EAAEC,KAAK,EAAkBC,UAAU,EAAEC,SAAS,EAAEC,IAAI,EAAEC,cAAc,EAAEC,YAAY,EAAEC,OAAO,EAAgBC,GAAG,QAAQ,eAAe;AACnJ,SAASC,WAAW;AACpB,SAASC,cAAc;AACvB,SAASC,YAAY;AAqBrB;AACA;AACA;AACA,WAAaC,eAAe,0BAAAC,YAAA;EAAAC,SAAA,CAAAF,eAAA,EAAAC,YAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,eAAA;EA4D1B,SAAA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IAAM8E,IAAI,GAAG,IAAIpF,IAAI,CAACgE,QAAQ,EAAEI,QAAQ,CAAC;;QAEzC;QACAgB,IAAI,CAACC,WAAW,GAAG,IAAI;QAEvB,IAAI,CAACC,GAAG,CAACF,IAAI,CAAC;QACd,IAAI,CAACG,GAAG,CAACnB,QAAQ,CAAC;QAClB,IAAI,CAACZ,YAAY,CAACgC,IAAI,CAACJ,IAAI,CAAC;MAC9B;IACF;;IAEA;AACF;AACA;AACA;EAHE;IAAAjC,GAAA;IAAAI,KAAA,EAIA,SAAAgC,IAAYnB,QAAQ,EAAE;MACpB,IAAMqB,KAAK,GAAG,IAAI7F,KAAK,CAAC,CAAC;MAEzB,IAAI,CAAC8F,QAAQ,CAACF,IAAI,CAChBpF,GAAG,CAACuF,QAAQ,CAAC,YAAM;QACjBvB,QAAQ,CAACG,QAAQ,CAACE,KAAK,CAAClB,KAAK,GAAGkC,KAAK,CAACG,cAAc,CAAC,CAAC;MACxD,CAAC,CACH,CAAC;IACH;EAAC;IAAAzC,GAAA;IAAAI,KAAA,EAED,SAAAI,iBAAA,EAAkC;MAChC;MACA,IAAI,CAACkC,MAAM,IAAI,IAAI,CAACH,QAAQ,CAACjC,OAAO,CAAC,UAACpB,OAAO,EAAK;QAChDA,OAAO,CAAC,CAAC;MACX,CAAC,CAAC;MAEF,OAAAyD,IAAA,CAAAC,eAAA,CAAAvF,eAAA,CAAAwF,SAAA,6BAAAhF,IAAA;IACF;EAAC;EAAA,OAAAR,eAAA;AAAA,EA7IkCH,WAAW"}
@@ -1 +0,0 @@
1
- export declare const fragmentShader = "\nvarying vec2 vUv;\nuniform float uSpeed;\nuniform float uTime;\nuniform vec2 uFade;\nuniform vec3 uColor;\nuniform int uNumLines;\nuniform float uOffset;\nuniform float ulength;\nuniform float uReverse;\n\nvoid main() {\n vec3 color = uColor;\n float s = 0.0;\n float v = 0.0;\n float alpha = 0.0;\n float maxAlpha = 0.0; \n\n s = (-uTime * uSpeed) / ulength;\n s = mod(s, 1.0);\n\n float direction = (uReverse == 1.0) ? 1.0 : -1.0;\n float numLinesFloat = float(uNumLines);\n float baseGap = 1.0 / numLinesFloat; \n \n float dynamicLength = min(uFade.y, baseGap * 0.7); \n \n float widthFactor = smoothstep(0.1, 0.5, abs(vUv.y - 0.5));\n \n for (int i = 0; i < uNumLines; i++) {\n float start = float(i) / numLinesFloat;\n start += uOffset;\n v = vUv.x * direction + start;\n\n float d = mod((v + s), 1.0);\n \n if (d <= dynamicLength) {\n float tempAlpha = smoothstep(uFade.x, dynamicLength, d);\n maxAlpha = max(maxAlpha, tempAlpha);\n }\n }\n \n alpha = maxAlpha * widthFactor;\n\n if (alpha < 0.0001) {\n discard;\n }\n\n gl_FragColor = vec4(color, alpha);\n}\n ";
@@ -1,2 +0,0 @@
1
- export var fragmentShader = /* glsl */"\nvarying vec2 vUv;\nuniform float uSpeed;\nuniform float uTime;\nuniform vec2 uFade;\nuniform vec3 uColor;\nuniform int uNumLines;\nuniform float uOffset;\nuniform float ulength;\nuniform float uReverse;\n\nvoid main() {\n vec3 color = uColor;\n float s = 0.0;\n float v = 0.0;\n float alpha = 0.0;\n float maxAlpha = 0.0; \n\n s = (-uTime * uSpeed) / ulength;\n s = mod(s, 1.0);\n\n float direction = (uReverse == 1.0) ? 1.0 : -1.0;\n float numLinesFloat = float(uNumLines);\n float baseGap = 1.0 / numLinesFloat; \n \n float dynamicLength = min(uFade.y, baseGap * 0.7); \n \n float widthFactor = smoothstep(0.1, 0.5, abs(vUv.y - 0.5));\n \n for (int i = 0; i < uNumLines; i++) {\n float start = float(i) / numLinesFloat;\n start += uOffset;\n v = vUv.x * direction + start;\n\n float d = mod((v + s), 1.0);\n \n if (d <= dynamicLength) {\n float tempAlpha = smoothstep(uFade.x, dynamicLength, d);\n maxAlpha = max(maxAlpha, tempAlpha);\n }\n }\n \n alpha = maxAlpha * widthFactor;\n\n if (alpha < 0.0001) {\n discard;\n }\n\n gl_FragColor = vec4(color, alpha);\n}\n ";
2
- //# sourceMappingURL=fragmentShader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["fragmentShader"],"sources":["../../../../src/business/TrafficComponents/StreamerTraffic/fragmentShader.ts"],"sourcesContent":["export const fragmentShader =/* glsl */ `\nvarying vec2 vUv;\nuniform float uSpeed;\nuniform float uTime;\nuniform vec2 uFade;\nuniform vec3 uColor;\nuniform int uNumLines;\nuniform float uOffset;\nuniform float ulength;\nuniform float uReverse;\n\nvoid main() {\n vec3 color = uColor;\n float s = 0.0;\n float v = 0.0;\n float alpha = 0.0;\n float maxAlpha = 0.0; \n\n s = (-uTime * uSpeed) / ulength;\n s = mod(s, 1.0);\n\n float direction = (uReverse == 1.0) ? 1.0 : -1.0;\n float numLinesFloat = float(uNumLines);\n float baseGap = 1.0 / numLinesFloat; \n \n float dynamicLength = min(uFade.y, baseGap * 0.7); \n \n float widthFactor = smoothstep(0.1, 0.5, abs(vUv.y - 0.5));\n \n for (int i = 0; i < uNumLines; i++) {\n float start = float(i) / numLinesFloat;\n start += uOffset;\n v = vUv.x * direction + start;\n\n float d = mod((v + s), 1.0);\n \n if (d <= dynamicLength) {\n float tempAlpha = smoothstep(uFade.x, dynamicLength, d);\n maxAlpha = max(maxAlpha, tempAlpha);\n }\n }\n \n alpha = maxAlpha * widthFactor;\n\n if (alpha < 0.0001) {\n discard;\n }\n\n gl_FragColor = vec4(color, alpha);\n}\n `"],"mappings":"AAAA,OAAO,IAAMA,cAAc,GAAE,2sCAkDzB"}
@@ -1,11 +0,0 @@
1
- import type { CurvePath, Vector3 } from '@anov/3d-core';
2
- export { StreamerTraffic } from './StreamerTraffic';
3
- export interface StreamerTrafficInterface {
4
- width: number;
5
- divide: number;
6
- speed: number;
7
- lanelines: CurvePath<Vector3>[];
8
- num: number;
9
- baseColor: string;
10
- divideWidth: number;
11
- }
@@ -1,2 +0,0 @@
1
- export { StreamerTraffic } from "./StreamerTraffic";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["StreamerTraffic"],"sources":["../../../../src/business/TrafficComponents/StreamerTraffic/index.ts"],"sourcesContent":["import type { CurvePath, Vector3 } from '@anov/3d-core'\n\nexport { StreamerTraffic } from './StreamerTraffic'\n\nexport interface StreamerTrafficInterface {\n\n width: number\n\n divide: number\n\n speed: number\n\n lanelines: CurvePath<Vector3>[]\n\n num: number\n\n baseColor: string\n\n divideWidth: number\n\n}"],"mappings":"AAEA,SAASA,eAAe"}
@@ -1 +0,0 @@
1
- export declare const vertexShader = "\n varying vec2 vUv;\n void main(void) {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}";
@@ -1,2 +0,0 @@
1
- export var vertexShader = /* glsl */"\n varying vec2 vUv;\n void main(void) {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}";
2
- //# sourceMappingURL=vertexShader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["vertexShader"],"sources":["../../../../src/business/TrafficComponents/StreamerTraffic/vertexShader.ts"],"sourcesContent":["export const vertexShader = /* glsl */`\n varying vec2 vUv;\n void main(void) {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}`"],"mappings":"AAAA,OAAO,IAAMA,YAAY,GAAG,6JAK1B"}
@@ -1,22 +0,0 @@
1
- import type { CurvePath, Vector3 } from '@anov/3d-core';
2
- import { Object3D } from '@anov/3d-core';
3
- type RealismTrafficParams = {
4
- path: CurvePath<Vector3>;
5
- width?: number;
6
- divide?: number;
7
- corner?: number;
8
- };
9
- export declare class BaseTraffic extends Object3D {
10
- /** 路面宽度 */
11
- protected _width: number;
12
- /** 车道线数量 */
13
- protected _divide: number;
14
- protected _path: CurvePath<Vector3>;
15
- protected _corner: number;
16
- /** 车道线 */
17
- lanelines: CurvePath<Vector3>[];
18
- constructor(params: RealismTrafficParams);
19
- protected get baseLine(): import("../..").RoundedCornersCurve;
20
- protected generateLaneLines(): void;
21
- }
22
- export {};
@@ -1,64 +0,0 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
- 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); } }
4
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
- 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); }
6
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
- 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); }; }
8
- 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); }
9
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
- 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; } }
11
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
- 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; }
13
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
- 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); }
15
- import { Object3D } from '@anov/3d-core';
16
- import { createOffsetPath } from "./utils";
17
- export var BaseTraffic = /*#__PURE__*/function (_Object3D) {
18
- _inherits(BaseTraffic, _Object3D);
19
- var _super = _createSuper(BaseTraffic);
20
- function BaseTraffic(params) {
21
- var _this;
22
- _classCallCheck(this, BaseTraffic);
23
- _this = _super.call(this);
24
- /** 路面宽度 */
25
- _defineProperty(_assertThisInitialized(_this), "_width", void 0);
26
- /** 车道线数量 */
27
- _defineProperty(_assertThisInitialized(_this), "_divide", void 0);
28
- _defineProperty(_assertThisInitialized(_this), "_path", void 0);
29
- _defineProperty(_assertThisInitialized(_this), "_corner", 10);
30
- /** 车道线 */
31
- _defineProperty(_assertThisInitialized(_this), "lanelines", []);
32
- var path = params.path,
33
- _params$width = params.width,
34
- width = _params$width === void 0 ? 2 : _params$width,
35
- _params$divide = params.divide,
36
- divide = _params$divide === void 0 ? 1 : _params$divide,
37
- _params$corner = params.corner,
38
- corner = _params$corner === void 0 ? 10 : _params$corner;
39
- _this._path = path;
40
- _this._width = width;
41
- _this._divide = divide;
42
- _this._corner = corner;
43
- _this.generateLaneLines();
44
- return _this;
45
- }
46
- _createClass(BaseTraffic, [{
47
- key: "baseLine",
48
- get: function get() {
49
- return createOffsetPath(this._path, -this._width / 2, 0);
50
- }
51
- }, {
52
- key: "generateLaneLines",
53
- value: function generateLaneLines() {
54
- this.lanelines = [];
55
- for (var i = 0; i < this._divide; i++) {
56
- var offset = this._width / this._divide;
57
- var line = createOffsetPath(this.baseLine, offset * (i + 1), this._corner);
58
- this.lanelines.push(line);
59
- }
60
- }
61
- }]);
62
- return BaseTraffic;
63
- }(Object3D);
64
- //# sourceMappingURL=base.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Object3D","createOffsetPath","BaseTraffic","_Object3D","_inherits","_super","_createSuper","params","_this","_classCallCheck","call","_defineProperty","_assertThisInitialized","path","_params$width","width","_params$divide","divide","_params$corner","corner","_path","_width","_divide","_corner","generateLaneLines","_createClass","key","get","value","lanelines","i","offset","line","baseLine","push"],"sources":["../../../src/business/TrafficComponents/base.ts"],"sourcesContent":["import type { CurvePath, Vector3 } from '@anov/3d-core'\nimport { Object3D } from '@anov/3d-core'\nimport { createOffsetPath } from './utils'\n\ntype RealismTrafficParams = {\n path: CurvePath<Vector3>\n width?: number\n divide?: number\n corner?: number\n}\n\nexport class BaseTraffic extends Object3D {\n /** 路面宽度 */\n protected _width: number\n\n /** 车道线数量 */\n protected _divide: number\n\n protected _path: CurvePath<Vector3>\n\n protected _corner = 10\n\n /** 车道线 */\n public lanelines: CurvePath<Vector3>[] = []\n\n constructor(params: RealismTrafficParams) {\n super()\n\n const { path, width = 2, divide = 1, corner = 10 } = params\n\n this._path = path\n this._width = width\n this._divide = divide\n this._corner = corner\n\n this.generateLaneLines()\n }\n\n protected get baseLine() {\n return createOffsetPath(this._path, -this._width / 2, 0)\n }\n\n protected generateLaneLines() {\n this.lanelines = []\n\n for (let i = 0; i < this._divide; i++) {\n const offset = this._width / this._divide\n const line = createOffsetPath(this.baseLine, offset * (i + 1), this._corner)\n\n this.lanelines.push(line)\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;AACA,SAASA,QAAQ,QAAQ,eAAe;AACxC,SAASC,gBAAgB;AASzB,WAAaC,WAAW,0BAAAC,SAAA;EAAAC,SAAA,CAAAF,WAAA,EAAAC,SAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,WAAA;EActB,SAAAA,YAAYK,MAA4B,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAP,WAAA;IACxCM,KAAA,GAAAH,MAAA,CAAAK,IAAA;IAdF;IAAAC,eAAA,CAAAC,sBAAA,CAAAJ,KAAA;IAGA;IAAAG,eAAA,CAAAC,sBAAA,CAAAJ,KAAA;IAAAG,eAAA,CAAAC,sBAAA,CAAAJ,KAAA;IAAAG,eAAA,CAAAC,sBAAA,CAAAJ,KAAA,cAKoB,EAAE;IAEtB;IAAAG,eAAA,CAAAC,sBAAA,CAAAJ,KAAA,gBACyC,EAAE;IAKzC,IAAQK,IAAI,GAAyCN,MAAM,CAAnDM,IAAI;MAAAC,aAAA,GAAyCP,MAAM,CAA7CQ,KAAK;MAALA,KAAK,GAAAD,aAAA,cAAG,CAAC,GAAAA,aAAA;MAAAE,cAAA,GAA8BT,MAAM,CAAlCU,MAAM;MAANA,MAAM,GAAAD,cAAA,cAAG,CAAC,GAAAA,cAAA;MAAAE,cAAA,GAAkBX,MAAM,CAAtBY,MAAM;MAANA,MAAM,GAAAD,cAAA,cAAG,EAAE,GAAAA,cAAA;IAEhDV,KAAA,CAAKY,KAAK,GAAGP,IAAI;IACjBL,KAAA,CAAKa,MAAM,GAAGN,KAAK;IACnBP,KAAA,CAAKc,OAAO,GAAGL,MAAM;IACrBT,KAAA,CAAKe,OAAO,GAAGJ,MAAM;IAErBX,KAAA,CAAKgB,iBAAiB,CAAC,CAAC;IAAA,OAAAhB,KAAA;EAC1B;EAACiB,YAAA,CAAAvB,WAAA;IAAAwB,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAyB;MACvB,OAAO1B,gBAAgB,CAAC,IAAI,CAACmB,KAAK,EAAE,CAAC,IAAI,CAACC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1D;EAAC;IAAAK,GAAA;IAAAE,KAAA,EAED,SAAAJ,kBAAA,EAA8B;MAC5B,IAAI,CAACK,SAAS,GAAG,EAAE;MAEnB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,IAAI,CAACR,OAAO,EAAEQ,CAAC,EAAE,EAAE;QACrC,IAAMC,MAAM,GAAG,IAAI,CAACV,MAAM,GAAG,IAAI,CAACC,OAAO;QACzC,IAAMU,IAAI,GAAG/B,gBAAgB,CAAC,IAAI,CAACgC,QAAQ,EAAEF,MAAM,IAAID,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAACP,OAAO,CAAC;QAE5E,IAAI,CAACM,SAAS,CAACK,IAAI,CAACF,IAAI,CAAC;MAC3B;IACF;EAAC;EAAA,OAAA9B,WAAA;AAAA,EAxC8BF,QAAQ"}
@@ -1,2 +0,0 @@
1
- export * from './RealismTraffic';
2
- export * from './StreamerTraffic';
@@ -1,3 +0,0 @@
1
- export * from "./RealismTraffic";
2
- export * from "./StreamerTraffic";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../../src/business/TrafficComponents/index.ts"],"sourcesContent":["export * from './RealismTraffic'\nexport * from './StreamerTraffic'\n"],"mappings":"AAAA;AACA"}
@@ -1,10 +0,0 @@
1
- import type { CurvePath } from '@anov/3d-core';
2
- import { Vector3 } from '@anov/3d-core';
3
- import { RoundedCornersCurve } from '../../index';
4
- /**
5
- * offset path
6
- * @param originalPath
7
- * @param offsetDistance
8
- * @returns
9
- */
10
- export declare const createOffsetPath: (originalPath: CurvePath<Vector3>, offsetDistance: number, corner?: number) => RoundedCornersCurve;
@@ -1,48 +0,0 @@
1
- import { Vector3 } from '@anov/3d-core';
2
- import { RoundedCornersCurve } from "../../index";
3
- var closure = function closure(curves) {
4
- if (curves.length <= 1) return false;
5
- var _ref = curves[0].type === 'LineCurve3' ? curves[0].v1 : curves[0].v0,
6
- x1 = _ref.x,
7
- y1 = _ref.y,
8
- z1 = _ref.z;
9
- var _v = curves[curves.length - 1].v2,
10
- x2 = _v.x,
11
- y2 = _v.y,
12
- z2 = _v.z;
13
- return x1 === x2 && y1 === y2 && z1 === z2;
14
- };
15
-
16
- /**
17
- * offset path
18
- * @param originalPath
19
- * @param offsetDistance
20
- * @returns
21
- */
22
- export var createOffsetPath = function createOffsetPath(originalPath, offsetDistance) {
23
- var corner = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
24
- var curves = originalPath.curves;
25
- var newPoints = [];
26
- var isClosure = closure(curves);
27
- var firstNormal = new Vector3();
28
- var nextPoint = curves[0].v1;
29
- for (var i = 0; i < curves.length; i++) {
30
- if (curves[i].type === 'LineCurve3') {
31
- var v1 = nextPoint.clone();
32
- var v2 = curves[i].v2;
33
- var direction = new Vector3().subVectors(v2, v1).normalize();
34
- var normal = new Vector3().crossVectors(direction, new Vector3(0, 1, 0)).normalize();
35
- i === 0 && firstNormal.copy(normal);
36
- var offset = normal.multiplyScalar(offsetDistance);
37
- var newV1 = v1.clone().add(offset.clone());
38
- var newV2 = v2.clone().add(offset.clone());
39
- newPoints.push(newV1);
40
- nextPoint = newV2;
41
- }
42
- if (i === curves.length - 1) {
43
- if (isClosure) newPoints[0] = nextPoint.clone().add(firstNormal.multiplyScalar(offsetDistance));else newPoints.push(nextPoint);
44
- }
45
- }
46
- return new RoundedCornersCurve(newPoints, corner, isClosure);
47
- };
48
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Vector3","RoundedCornersCurve","closure","curves","length","_ref","type","v1","v0","x1","x","y1","y","z1","z","_v","v2","x2","y2","z2","createOffsetPath","originalPath","offsetDistance","corner","arguments","undefined","newPoints","isClosure","firstNormal","nextPoint","i","clone","direction","subVectors","normalize","normal","crossVectors","copy","offset","multiplyScalar","newV1","add","newV2","push"],"sources":["../../../src/business/TrafficComponents/utils.ts"],"sourcesContent":["import type { Curve, CurvePath, LineCurve3, QuadraticBezierCurve3 } from '@anov/3d-core'\nimport { Vector3 } from '@anov/3d-core'\nimport { RoundedCornersCurve } from '../../index'\n\nconst closure = (curves: Curve<Vector3>[]) => {\n if (curves.length <= 1)\n return false\n\n const { x: x1, y: y1, z: z1 } = curves[0].type === 'LineCurve3' ? (curves[0] as LineCurve3).v1 : (curves[0] as QuadraticBezierCurve3).v0\n const { x: x2, y: y2, z: z2 } = (curves[curves.length - 1] as LineCurve3).v2\n\n return x1 === x2 && y1 === y2 && z1 === z2\n}\n\n/**\n * offset path\n * @param originalPath\n * @param offsetDistance\n * @returns\n */\nexport const createOffsetPath = (originalPath: CurvePath<Vector3>, offsetDistance: number, corner = 10) => {\n const curves = originalPath.curves\n const newPoints = []\n\n const isClosure = closure(curves)\n const firstNormal = new Vector3()\n let nextPoint = (curves[0] as LineCurve3).v1\n\n for (let i = 0; i < curves.length; i++) {\n if (curves[i].type === 'LineCurve3') {\n const v1 = nextPoint.clone()\n const v2 = (curves[i] as LineCurve3).v2\n\n const direction = new Vector3().subVectors(v2, v1).normalize()\n const normal = new Vector3().crossVectors(direction, new Vector3(0, 1, 0)).normalize()\n\n i === 0 && firstNormal.copy(normal)\n\n const offset = normal.multiplyScalar(offsetDistance)\n const newV1 = v1.clone().add(offset.clone())\n const newV2 = v2.clone().add(offset.clone())\n\n newPoints.push(newV1)\n nextPoint = newV2\n }\n\n if (i === curves.length - 1) {\n if (isClosure)\n newPoints[0] = nextPoint.clone().add(firstNormal.multiplyScalar(offsetDistance))\n else\n newPoints.push(nextPoint)\n }\n }\n\n return new RoundedCornersCurve(newPo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