three-base 1.0.80 → 1.0.82

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.
@@ -4,64 +4,142 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-04-15 12:38:09
6
6
  */
7
+ var __extends = (this && this.__extends) || (function () {
8
+ var extendStatics = function (d, b) {
9
+ extendStatics = Object.setPrototypeOf ||
10
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
+ return extendStatics(d, b);
13
+ };
14
+ return function (d, b) {
15
+ if (typeof b !== "function" && b !== null)
16
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
+ extendStatics(d, b);
18
+ function __() { this.constructor = d; }
19
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
+ };
21
+ })();
22
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ };
31
+ var __generator = (this && this.__generator) || function (thisArg, body) {
32
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
33
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
+ function verb(n) { return function (v) { return step([n, v]); }; }
35
+ function step(op) {
36
+ if (f) throw new TypeError("Generator is already executing.");
37
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
+ if (y = 0, t) op = [op[0] & 2, t.value];
40
+ switch (op[0]) {
41
+ case 0: case 1: t = op; break;
42
+ case 4: _.label++; return { value: op[1], done: false };
43
+ case 5: _.label++; y = op[1]; op = [0]; continue;
44
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
+ default:
46
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
+ if (t[2]) _.ops.pop();
51
+ _.trys.pop(); continue;
52
+ }
53
+ op = body.call(thisArg, _);
54
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
+ }
57
+ };
7
58
  import html2canvas from "html2canvas";
8
59
  import { CanvasTexture, DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector2 } from "three";
9
60
  import { degToRad } from "three/src/math/MathUtils";
10
61
  import threeLoader from "./threeLoader";
11
62
  // html 文本面板
12
- export default class PlaneWithHtml extends Mesh {
13
- constructor(html = "", backgroundColor = "#00000000") {
14
- super();
15
- this.setHtml(html, backgroundColor);
63
+ var PlaneWithHtml = /** @class */ (function (_super) {
64
+ __extends(PlaneWithHtml, _super);
65
+ function PlaneWithHtml(html, backgroundColor) {
66
+ if (html === void 0) { html = ""; }
67
+ if (backgroundColor === void 0) { backgroundColor = "#00000000"; }
68
+ var _this = _super.call(this) || this;
69
+ _this.visible = false;
70
+ _this.size = new Vector2(10, 10);
71
+ _this.geometry = (function () {
72
+ var geometry = new PlaneGeometry(10, 10, 1, 1);
73
+ geometry.rotateX(degToRad(-90));
74
+ return geometry;
75
+ })();
76
+ _this.material = new MeshBasicMaterial({
77
+ side: DoubleSide,
78
+ transparent: true
79
+ });
80
+ _this.div = (function () {
81
+ var div = document.createElement("div");
82
+ div.style.position = "fixed";
83
+ div.style.top = "100%";
84
+ div.style.left = "100%";
85
+ div.style.pointerEvents = "none";
86
+ div.style.userSelect = "none";
87
+ div.style.lineHeight = "1";
88
+ div.style.whiteSpace = "nowrap";
89
+ return div;
90
+ })();
91
+ _this.setHtml(html, backgroundColor);
92
+ return _this;
16
93
  }
17
- visible = false;
18
- size = new Vector2(10, 10);
19
- geometry = (() => {
20
- const geometry = new PlaneGeometry(10, 10, 1, 1);
21
- geometry.rotateX(degToRad(-90));
22
- return geometry;
23
- })();
24
- material = new MeshBasicMaterial({
25
- side: DoubleSide,
26
- transparent: true
27
- });
28
- div = (() => {
29
- const div = document.createElement("div");
30
- div.style.position = "fixed";
31
- div.style.top = "100%";
32
- div.style.left = "100%";
33
- div.style.pointerEvents = "none";
34
- div.style.userSelect = "none";
35
- div.style.lineHeight = "1";
36
- div.style.whiteSpace = "nowrap";
37
- return div;
38
- })();
39
94
  // 设置网格尺寸
40
- setGeoSize(width, height) {
95
+ PlaneWithHtml.prototype.setGeoSize = function (width, height) {
41
96
  this.size.set(width, height);
42
97
  this.geometry.dispose();
43
- const geometry = new PlaneGeometry(width, height, 1, 1);
98
+ var geometry = new PlaneGeometry(width, height, 1, 1);
44
99
  geometry.rotateX(degToRad(-90));
45
100
  this.geometry = geometry;
46
- }
47
- async setHtml(html = "", backgroundColor = "#00000000") {
48
- this.div.innerHTML = html;
49
- document.body.appendChild(this.div);
50
- await new Promise((resolve, reject) => {
51
- html2canvas(this.div, {
52
- backgroundColor,
53
- removeContainer: true
54
- }).then(async (canvas) => {
55
- this.setGeoSize(canvas.width, canvas.height);
56
- this.material.map = new CanvasTexture(canvas);
57
- this.material.map.anisotropy = threeLoader.anisotropy;
58
- this.material.needsUpdate = true;
59
- this.visible = true;
60
- await new Promise(resolve => requestAnimationFrame(resolve));
61
- this.div.remove();
62
- resolve();
101
+ };
102
+ PlaneWithHtml.prototype.setHtml = function (html, backgroundColor) {
103
+ if (html === void 0) { html = ""; }
104
+ if (backgroundColor === void 0) { backgroundColor = "#00000000"; }
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var _this = this;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ this.div.innerHTML = html;
111
+ document.body.appendChild(this.div);
112
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
113
+ html2canvas(_this.div, {
114
+ backgroundColor: backgroundColor,
115
+ removeContainer: true
116
+ }).then(function (canvas) { return __awaiter(_this, void 0, void 0, function () {
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0:
120
+ this.setGeoSize(canvas.width, canvas.height);
121
+ this.material.map = new CanvasTexture(canvas);
122
+ this.material.map.anisotropy = threeLoader.anisotropy;
123
+ this.material.needsUpdate = true;
124
+ this.visible = true;
125
+ return [4 /*yield*/, new Promise(function (resolve) { return requestAnimationFrame(resolve); })];
126
+ case 1:
127
+ _a.sent();
128
+ this.div.remove();
129
+ resolve();
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ }); });
134
+ })];
135
+ case 1:
136
+ _a.sent();
137
+ this.dispatchEvent({ type: "loaded" });
138
+ return [2 /*return*/];
139
+ }
63
140
  });
64
141
  });
65
- this.dispatchEvent({ type: "loaded" });
66
- }
67
- }
142
+ };
143
+ return PlaneWithHtml;
144
+ }(Mesh));
145
+ export default PlaneWithHtml;
@@ -4,6 +4,21 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-04-21 17:22:59
6
6
  */
7
+ var __extends = (this && this.__extends) || (function () {
8
+ var extendStatics = function (d, b) {
9
+ extendStatics = Object.setPrototypeOf ||
10
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
+ return extendStatics(d, b);
13
+ };
14
+ return function (d, b) {
15
+ if (typeof b !== "function" && b !== null)
16
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
+ extendStatics(d, b);
18
+ function __() { this.constructor = d; }
19
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
+ };
21
+ })();
7
22
  import { Sprite, PointLight as THREEPointLight } from "three";
8
23
  import threeSpritetext from "three-spritetext";
9
24
  import threeLoader from "../threeLoader";
@@ -15,49 +30,54 @@ import pointLight_mapPNG from "./pointLight_map.png";
15
30
  * @class PointLight
16
31
  * @extends {THREEPointLight}
17
32
  */
18
- export default class PointLight extends THREEPointLight {
19
- constructor(color = "#fff", intensity, distance, decay) {
20
- super(color, intensity, distance, decay);
33
+ var PointLight = /** @class */ (function (_super) {
34
+ __extends(PointLight, _super);
35
+ function PointLight(color, intensity, distance, decay) {
36
+ if (color === void 0) { color = "#fff"; }
37
+ var _this = _super.call(this, color, intensity, distance, decay) || this;
38
+ // 灯光辅助器
39
+ _this.pointLinghtHelper = threeUtils.isDev && (function () {
40
+ var pointLinghtHelper = new Sprite();
41
+ pointLinghtHelper.scale.set(0.05, 0.05, 0.05);
42
+ pointLinghtHelper.material.color = _this.color;
43
+ pointLinghtHelper.material.map = threeLoader.getTexture(pointLight_mapPNG);
44
+ pointLinghtHelper.material.sizeAttenuation = false;
45
+ pointLinghtHelper.userData = {
46
+ cursor: "pointer"
47
+ };
48
+ pointLinghtHelper.addEventListener("mouseenter", function () {
49
+ if (_this.label) {
50
+ _this.label.visible = true;
51
+ }
52
+ });
53
+ pointLinghtHelper.addEventListener("mouseleave", function () {
54
+ if (_this.label) {
55
+ _this.label.visible = false;
56
+ }
57
+ });
58
+ _this.add(pointLinghtHelper);
59
+ return pointLinghtHelper;
60
+ })();
61
+ _this.label = threeUtils.isDev && (function () {
62
+ var label = new threeSpritetext("点光源\n\n\n");
63
+ label.renderOrder = Infinity;
64
+ // label.backgroundColor = "rgba(0, 0, 0, 0.5)";
65
+ label.padding = 4;
66
+ label.strokeColor = "#333";
67
+ label.strokeWidth = 2;
68
+ // label.borderRadius = 4;
69
+ // label.borderWidth = 1;
70
+ label.position.set(0, 0, 0);
71
+ label.visible = false;
72
+ label.material.color = _this.color;
73
+ label.material.depthTest = false;
74
+ label.material.sizeAttenuation = false;
75
+ label.scale.multiplyScalar(0.002);
76
+ _this.add(label);
77
+ return label;
78
+ })();
79
+ return _this;
21
80
  }
22
- // 灯光辅助器
23
- pointLinghtHelper = threeUtils.isDev && (() => {
24
- const pointLinghtHelper = new Sprite();
25
- pointLinghtHelper.scale.set(0.05, 0.05, 0.05);
26
- pointLinghtHelper.material.color = this.color;
27
- pointLinghtHelper.material.map = threeLoader.getTexture(pointLight_mapPNG);
28
- pointLinghtHelper.material.sizeAttenuation = false;
29
- pointLinghtHelper.userData = {
30
- cursor: "pointer"
31
- };
32
- pointLinghtHelper.addEventListener("mouseenter", () => {
33
- if (this.label) {
34
- this.label.visible = true;
35
- }
36
- });
37
- pointLinghtHelper.addEventListener("mouseleave", () => {
38
- if (this.label) {
39
- this.label.visible = false;
40
- }
41
- });
42
- this.add(pointLinghtHelper);
43
- return pointLinghtHelper;
44
- })();
45
- label = threeUtils.isDev && (() => {
46
- const label = new threeSpritetext("点光源\n\n\n");
47
- label.renderOrder = Infinity;
48
- // label.backgroundColor = "rgba(0, 0, 0, 0.5)";
49
- label.padding = 4;
50
- label.strokeColor = "#333";
51
- label.strokeWidth = 2;
52
- // label.borderRadius = 4;
53
- // label.borderWidth = 1;
54
- label.position.set(0, 0, 0);
55
- label.visible = false;
56
- label.material.color = this.color;
57
- label.material.depthTest = false;
58
- label.material.sizeAttenuation = false;
59
- label.scale.multiplyScalar(0.002);
60
- this.add(label);
61
- return label;
62
- })();
63
- }
81
+ return PointLight;
82
+ }(THREEPointLight));
83
+ export default PointLight;
package/lib/Sky/Sky.js CHANGED
@@ -4,25 +4,44 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2022-12-27 09:54:23
6
6
  */
7
+ var __extends = (this && this.__extends) || (function () {
8
+ var extendStatics = function (d, b) {
9
+ extendStatics = Object.setPrototypeOf ||
10
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
+ return extendStatics(d, b);
13
+ };
14
+ return function (d, b) {
15
+ if (typeof b !== "function" && b !== null)
16
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
+ extendStatics(d, b);
18
+ function __() { this.constructor = d; }
19
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
+ };
21
+ })();
7
22
  import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
8
23
  import threeLoader from "../threeLoader";
9
24
  import blueskyJPG from "./blueSky.jpg";
10
25
  /**
11
26
  * 天空球
12
27
  */
13
- export default class Sky extends Mesh {
14
- constructor() {
15
- super(Sky.geometry);
28
+ var Sky = /** @class */ (function (_super) {
29
+ __extends(Sky, _super);
30
+ function Sky() {
31
+ var _this = _super.call(this, Sky.geometry) || this;
32
+ _this.material = new MeshBasicMaterial({
33
+ side: DoubleSide,
34
+ map: threeLoader.getTexture(blueskyJPG)
35
+ });
36
+ return _this;
16
37
  }
17
- static geometry = new SphereGeometry(500000, 100, 100);
18
- material = new MeshBasicMaterial({
19
- side: DoubleSide,
20
- map: threeLoader.getTexture(blueskyJPG)
21
- });
22
38
  /**
23
39
  *设置贴图
24
40
  */
25
- setMap(src) {
41
+ Sky.prototype.setMap = function (src) {
26
42
  this.material.map = threeLoader.getTexture(src);
27
- }
28
- }
43
+ };
44
+ Sky.geometry = new SphereGeometry(500000, 100, 100);
45
+ return Sky;
46
+ }(Mesh));
47
+ export default Sky;