hart-estate-widget 0.0.49 → 0.0.52
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/build/assets/css/app.css +1 -1
- package/build/assets/css/app.css.map +1 -1
- package/build/assets/sass/components/panorama.sass +38 -33
- package/build/assets/sass/components/tabs.sass +7 -6
- package/build/assets/sass/index.sass +2 -2
- package/build/components/Application.js +42 -25
- package/build/components/Buttons/FullScreenButton.js +7 -3
- package/build/components/Buttons/TabButton.js +4 -6
- package/build/components/ImageTab.js +3 -5
- package/build/components/Instructions.js +15 -13
- package/build/components/Loader.js +4 -5
- package/build/components/ModelTab.js +89 -54
- package/build/components/PanoramaTab.js +332 -207
- package/build/components/RotationTab.js +75 -33
- package/build/components/Widget.js +44 -28
- package/build/config/defaultConfig.js +2 -4
- package/build/enums/deviceOrientationStatuses.js +11 -0
- package/build/enums/deviceWidth.js +11 -0
- package/build/enums/imageExtentions.js +6 -11
- package/build/index.js +0 -2
- package/build/store/apiStore.js +177 -40
- package/build/store/fullScreenStore.js +90 -20
- package/build/store/houseStore.js +792 -693
- package/build/store/index.js +70 -44
- package/build/store/modelStore.js +194 -141
- package/build/threesixty/events.js +94 -71
- package/build/threesixty/index.js +138 -112
- package/build/utils/csg/csg-lib.js +383 -298
- package/build/utils/csg/csg-worker.js +23 -33
- package/build/utils/csg/three-csg.js +103 -106
- package/build/utils/helpers.js +12 -0
- package/build/utils/modelHelpers.js +46 -40
- package/build/utils/panoramaHelpers.js +48 -32
- package/package.json +7 -14
- package/build/enums/deviceOrientationStatus.js +0 -11
@@ -5,306 +5,374 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.Vertex = exports.Vector = exports.Polygon = exports.Plane = exports.CSG = void 0;
|
7
7
|
|
8
|
-
require("core-js/modules/es.array.reverse.js");
|
9
|
-
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
11
9
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
11
|
|
14
|
-
class
|
15
|
-
constructor() {
|
16
|
-
this.polygons = [];
|
17
|
-
}
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18
13
|
|
19
|
-
|
20
|
-
let csg = new CSG();
|
21
|
-
csg.polygons = this.polygons.map(p => p.clone());
|
22
|
-
return csg;
|
23
|
-
}
|
14
|
+
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, descriptor.key, descriptor); } }
|
24
15
|
|
25
|
-
|
26
|
-
return this.polygons;
|
27
|
-
}
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
a.clipTo(b);
|
33
|
-
b.clipTo(a);
|
34
|
-
b.invert();
|
35
|
-
b.clipTo(a);
|
36
|
-
b.invert();
|
37
|
-
a.build(b.allPolygons());
|
38
|
-
return CSG.fromPolygons(a.allPolygons());
|
39
|
-
}
|
18
|
+
var CSG = /*#__PURE__*/function () {
|
19
|
+
function CSG() {
|
20
|
+
_classCallCheck(this, CSG);
|
40
21
|
|
41
|
-
|
42
|
-
let a = new Node(this.clone().polygons);
|
43
|
-
let b = new Node(csg.clone().polygons);
|
44
|
-
a.invert();
|
45
|
-
a.clipTo(b);
|
46
|
-
b.clipTo(a);
|
47
|
-
b.invert();
|
48
|
-
b.clipTo(a);
|
49
|
-
b.invert();
|
50
|
-
a.build(b.allPolygons());
|
51
|
-
a.invert();
|
52
|
-
return CSG.fromPolygons(a.allPolygons());
|
22
|
+
this.polygons = [];
|
53
23
|
}
|
54
24
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
25
|
+
_createClass(CSG, [{
|
26
|
+
key: "clone",
|
27
|
+
value: function clone() {
|
28
|
+
var csg = new CSG();
|
29
|
+
csg.polygons = this.polygons.map(function (p) {
|
30
|
+
return p.clone();
|
31
|
+
});
|
32
|
+
return csg;
|
33
|
+
}
|
34
|
+
}, {
|
35
|
+
key: "toPolygons",
|
36
|
+
value: function toPolygons() {
|
37
|
+
return this.polygons;
|
38
|
+
}
|
39
|
+
}, {
|
40
|
+
key: "union",
|
41
|
+
value: function union(csg) {
|
42
|
+
var a = new Node(this.clone().polygons);
|
43
|
+
var b = new Node(csg.clone().polygons);
|
44
|
+
a.clipTo(b);
|
45
|
+
b.clipTo(a);
|
46
|
+
b.invert();
|
47
|
+
b.clipTo(a);
|
48
|
+
b.invert();
|
49
|
+
a.build(b.allPolygons());
|
50
|
+
return CSG.fromPolygons(a.allPolygons());
|
51
|
+
}
|
52
|
+
}, {
|
53
|
+
key: "subtract",
|
54
|
+
value: function subtract(csg) {
|
55
|
+
var a = new Node(this.clone().polygons);
|
56
|
+
var b = new Node(csg.clone().polygons);
|
57
|
+
a.invert();
|
58
|
+
a.clipTo(b);
|
59
|
+
b.clipTo(a);
|
60
|
+
b.invert();
|
61
|
+
b.clipTo(a);
|
62
|
+
b.invert();
|
63
|
+
a.build(b.allPolygons());
|
64
|
+
a.invert();
|
65
|
+
return CSG.fromPolygons(a.allPolygons());
|
66
|
+
}
|
67
|
+
}, {
|
68
|
+
key: "intersect",
|
69
|
+
value: function intersect(csg) {
|
70
|
+
var a = new Node(this.clone().polygons);
|
71
|
+
var b = new Node(csg.clone().polygons);
|
72
|
+
a.invert();
|
73
|
+
b.clipTo(a);
|
74
|
+
b.invert();
|
75
|
+
a.clipTo(b);
|
76
|
+
b.clipTo(a);
|
77
|
+
a.build(b.allPolygons());
|
78
|
+
a.invert();
|
79
|
+
return CSG.fromPolygons(a.allPolygons());
|
80
|
+
} // Return a new CSG solid with solid and empty space switched. This solid is
|
81
|
+
// not modified.
|
82
|
+
|
83
|
+
}, {
|
84
|
+
key: "inverse",
|
85
|
+
value: function inverse() {
|
86
|
+
var csg = this.clone();
|
87
|
+
csg.polygons.forEach(function (p) {
|
88
|
+
return p.flip();
|
89
|
+
});
|
90
|
+
return csg;
|
91
|
+
}
|
92
|
+
}]);
|
75
93
|
|
76
|
-
|
94
|
+
return CSG;
|
95
|
+
}();
|
77
96
|
|
78
97
|
exports.CSG = CSG;
|
79
98
|
|
80
99
|
CSG.fromPolygons = function (polygons) {
|
81
|
-
|
100
|
+
var csg = new CSG();
|
82
101
|
csg.polygons = polygons;
|
83
102
|
return csg;
|
84
103
|
};
|
85
104
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
105
|
+
var Vector = /*#__PURE__*/function () {
|
106
|
+
function Vector() {
|
107
|
+
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
108
|
+
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
109
|
+
var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
110
|
+
|
111
|
+
_classCallCheck(this, Vector);
|
112
|
+
|
91
113
|
this.x = x;
|
92
114
|
this.y = y;
|
93
115
|
this.z = z;
|
94
116
|
}
|
95
117
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
118
|
+
_createClass(Vector, [{
|
119
|
+
key: "copy",
|
120
|
+
value: function copy(v) {
|
121
|
+
this.x = v.x;
|
122
|
+
this.y = v.y;
|
123
|
+
this.z = v.z;
|
124
|
+
return this;
|
125
|
+
}
|
126
|
+
}, {
|
127
|
+
key: "clone",
|
128
|
+
value: function clone() {
|
129
|
+
return new Vector(this.x, this.y, this.z);
|
130
|
+
}
|
131
|
+
}, {
|
132
|
+
key: "negate",
|
133
|
+
value: function negate() {
|
134
|
+
this.x *= -1;
|
135
|
+
this.y *= -1;
|
136
|
+
this.z *= -1;
|
137
|
+
return this;
|
138
|
+
}
|
139
|
+
}, {
|
140
|
+
key: "add",
|
141
|
+
value: function add(a) {
|
142
|
+
this.x += a.x;
|
143
|
+
this.y += a.y;
|
144
|
+
this.z += a.z;
|
145
|
+
return this;
|
146
|
+
}
|
147
|
+
}, {
|
148
|
+
key: "sub",
|
149
|
+
value: function sub(a) {
|
150
|
+
this.x -= a.x;
|
151
|
+
this.y -= a.y;
|
152
|
+
this.z -= a.z;
|
153
|
+
return this;
|
154
|
+
}
|
155
|
+
}, {
|
156
|
+
key: "times",
|
157
|
+
value: function times(a) {
|
158
|
+
this.x *= a;
|
159
|
+
this.y *= a;
|
160
|
+
this.z *= a;
|
161
|
+
return this;
|
162
|
+
}
|
163
|
+
}, {
|
164
|
+
key: "dividedBy",
|
165
|
+
value: function dividedBy(a) {
|
166
|
+
this.x /= a;
|
167
|
+
this.y /= a;
|
168
|
+
this.z /= a;
|
169
|
+
return this;
|
170
|
+
}
|
171
|
+
}, {
|
172
|
+
key: "lerp",
|
173
|
+
value: function lerp(a, t) {
|
174
|
+
return this.add(tv0.copy(a).sub(this).times(t));
|
175
|
+
}
|
176
|
+
}, {
|
177
|
+
key: "unit",
|
178
|
+
value: function unit() {
|
179
|
+
return this.dividedBy(this.length());
|
180
|
+
}
|
181
|
+
}, {
|
182
|
+
key: "length",
|
183
|
+
value: function length() {
|
184
|
+
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2));
|
185
|
+
}
|
186
|
+
}, {
|
187
|
+
key: "normalize",
|
188
|
+
value: function normalize() {
|
189
|
+
return this.unit();
|
190
|
+
}
|
191
|
+
}, {
|
192
|
+
key: "cross",
|
193
|
+
value: function cross(b) {
|
194
|
+
var a = this;
|
195
|
+
var ax = a.x,
|
161
196
|
ay = a.y,
|
162
197
|
az = a.z;
|
163
|
-
|
198
|
+
var bx = b.x,
|
164
199
|
by = b.y,
|
165
200
|
bz = b.z;
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
201
|
+
this.x = ay * bz - az * by;
|
202
|
+
this.y = az * bx - ax * bz;
|
203
|
+
this.z = ax * by - ay * bx;
|
204
|
+
return this;
|
205
|
+
}
|
206
|
+
}, {
|
207
|
+
key: "dot",
|
208
|
+
value: function dot(b) {
|
209
|
+
return this.x * b.x + this.y * b.y + this.z * b.z;
|
210
|
+
}
|
211
|
+
}]);
|
175
212
|
|
176
|
-
|
213
|
+
return Vector;
|
214
|
+
}();
|
177
215
|
|
178
216
|
exports.Vector = Vector;
|
179
|
-
|
180
|
-
|
217
|
+
var tv0 = new Vector();
|
218
|
+
var tv1 = new Vector();
|
219
|
+
|
220
|
+
var Vertex = /*#__PURE__*/function () {
|
221
|
+
function Vertex(pos, normal, uv, color) {
|
222
|
+
_classCallCheck(this, Vertex);
|
181
223
|
|
182
|
-
class Vertex {
|
183
|
-
constructor(pos, normal, uv, color) {
|
184
224
|
this.pos = new Vector().copy(pos);
|
185
225
|
this.normal = new Vector().copy(normal);
|
186
226
|
uv && (this.uv = new Vector().copy(uv)) && (this.uv.z = 0);
|
187
227
|
color && (this.color = new Vector().copy(color));
|
188
228
|
}
|
189
229
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
}
|
230
|
+
_createClass(Vertex, [{
|
231
|
+
key: "clone",
|
232
|
+
value: function clone() {
|
233
|
+
return new Vertex(this.pos, this.normal, this.uv, this.color);
|
234
|
+
}
|
235
|
+
}, {
|
236
|
+
key: "flip",
|
237
|
+
value: function flip() {
|
238
|
+
this.normal.negate();
|
239
|
+
}
|
240
|
+
}, {
|
241
|
+
key: "interpolate",
|
242
|
+
value: function interpolate(other, t) {
|
243
|
+
return new Vertex(this.pos.clone().lerp(other.pos, t), this.normal.clone().lerp(other.normal, t), this.uv && other.uv && this.uv.clone().lerp(other.uv, t), this.color && other.color && this.color.clone().lerp(other.color, t));
|
244
|
+
}
|
245
|
+
}]);
|
201
246
|
|
202
|
-
|
247
|
+
return Vertex;
|
248
|
+
}();
|
203
249
|
|
204
250
|
exports.Vertex = Vertex;
|
205
251
|
|
206
|
-
|
207
|
-
|
252
|
+
var Plane = /*#__PURE__*/function () {
|
253
|
+
function Plane(normal, w) {
|
254
|
+
_classCallCheck(this, Plane);
|
255
|
+
|
208
256
|
this.normal = normal;
|
209
257
|
this.w = w;
|
210
258
|
}
|
211
259
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
260
|
+
_createClass(Plane, [{
|
261
|
+
key: "clone",
|
262
|
+
value: function clone() {
|
263
|
+
return new Plane(this.normal.clone(), this.w);
|
264
|
+
}
|
265
|
+
}, {
|
266
|
+
key: "flip",
|
267
|
+
value: function flip() {
|
268
|
+
this.normal.negate();
|
269
|
+
this.w = -this.w;
|
270
|
+
}
|
271
|
+
}, {
|
272
|
+
key: "splitPolygon",
|
273
|
+
value: function splitPolygon(polygon, coplanarFront, coplanarBack, front, back) {
|
274
|
+
var COPLANAR = 0;
|
275
|
+
var FRONT = 1;
|
276
|
+
var BACK = 2;
|
277
|
+
var SPANNING = 3;
|
278
|
+
var polygonType = 0;
|
279
|
+
var types = [];
|
280
|
+
|
281
|
+
for (var i = 0; i < polygon.vertices.length; i++) {
|
282
|
+
var t = this.normal.dot(polygon.vertices[i].pos) - this.w;
|
283
|
+
var type = t < -Plane.EPSILON ? BACK : t > Plane.EPSILON ? FRONT : COPLANAR;
|
284
|
+
polygonType |= type;
|
285
|
+
types.push(type);
|
286
|
+
}
|
287
|
+
|
288
|
+
switch (polygonType) {
|
289
|
+
case COPLANAR:
|
290
|
+
(this.normal.dot(polygon.plane.normal) > 0 ? coplanarFront : coplanarBack).push(polygon);
|
291
|
+
break;
|
292
|
+
|
293
|
+
case FRONT:
|
294
|
+
front.push(polygon);
|
295
|
+
break;
|
296
|
+
|
297
|
+
case BACK:
|
298
|
+
back.push(polygon);
|
299
|
+
break;
|
300
|
+
|
301
|
+
case SPANNING:
|
302
|
+
var f = [];
|
303
|
+
var b = [];
|
304
|
+
|
305
|
+
for (var _i = 0; _i < polygon.vertices.length; _i++) {
|
306
|
+
var j = (_i + 1) % polygon.vertices.length;
|
307
|
+
var ti = types[_i],
|
308
|
+
tj = types[j];
|
309
|
+
var vi = polygon.vertices[_i],
|
310
|
+
vj = polygon.vertices[j];
|
311
|
+
if (ti != BACK) f.push(vi);
|
312
|
+
if (ti != FRONT) b.push(ti != BACK ? vi.clone() : vi);
|
313
|
+
|
314
|
+
if ((ti | tj) == SPANNING) {
|
315
|
+
var _t = (this.w - this.normal.dot(vi.pos)) / this.normal.dot(tv0.copy(vj.pos).sub(vi.pos));
|
316
|
+
|
317
|
+
var v = vi.interpolate(vj, _t);
|
318
|
+
f.push(v);
|
319
|
+
b.push(v.clone());
|
320
|
+
}
|
267
321
|
}
|
268
|
-
}
|
269
322
|
|
270
|
-
|
271
|
-
|
272
|
-
|
323
|
+
if (f.length >= 3) front.push(new Polygon(f, polygon.shared));
|
324
|
+
if (b.length >= 3) back.push(new Polygon(b, polygon.shared));
|
325
|
+
break;
|
326
|
+
}
|
273
327
|
}
|
274
|
-
}
|
328
|
+
}]);
|
275
329
|
|
276
|
-
|
330
|
+
return Plane;
|
331
|
+
}();
|
277
332
|
|
278
333
|
exports.Plane = Plane;
|
279
334
|
Plane.EPSILON = 1e-5;
|
280
335
|
|
281
336
|
Plane.fromPoints = function (a, b, c) {
|
282
|
-
|
337
|
+
var n = tv0.copy(b).sub(a).cross(tv1.copy(c).sub(a)).normalize();
|
283
338
|
return new Plane(n.clone(), n.dot(a));
|
284
339
|
};
|
285
340
|
|
286
|
-
|
287
|
-
|
341
|
+
var Polygon = /*#__PURE__*/function () {
|
342
|
+
function Polygon(vertices, shared) {
|
343
|
+
_classCallCheck(this, Polygon);
|
344
|
+
|
288
345
|
this.vertices = vertices;
|
289
346
|
this.shared = shared;
|
290
347
|
this.plane = Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
|
291
348
|
}
|
292
349
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
}
|
350
|
+
_createClass(Polygon, [{
|
351
|
+
key: "clone",
|
352
|
+
value: function clone() {
|
353
|
+
return new Polygon(this.vertices.map(function (v) {
|
354
|
+
return v.clone();
|
355
|
+
}), this.shared);
|
356
|
+
}
|
357
|
+
}, {
|
358
|
+
key: "flip",
|
359
|
+
value: function flip() {
|
360
|
+
this.vertices.reverse().forEach(function (v) {
|
361
|
+
return v.flip();
|
362
|
+
});
|
363
|
+
this.plane.flip();
|
364
|
+
}
|
365
|
+
}]);
|
301
366
|
|
302
|
-
|
367
|
+
return Polygon;
|
368
|
+
}();
|
303
369
|
|
304
370
|
exports.Polygon = Polygon;
|
305
371
|
|
306
|
-
|
307
|
-
|
372
|
+
var Node = /*#__PURE__*/function () {
|
373
|
+
function Node(polygons) {
|
374
|
+
_classCallCheck(this, Node);
|
375
|
+
|
308
376
|
this.plane = null;
|
309
377
|
this.front = null;
|
310
378
|
this.back = null;
|
@@ -312,76 +380,93 @@ class Node {
|
|
312
380
|
if (polygons) this.build(polygons);
|
313
381
|
}
|
314
382
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
this.plane && this.plane.flip();
|
328
|
-
this.front && this.front.invert();
|
329
|
-
this.back && this.back.invert();
|
330
|
-
let temp = this.front;
|
331
|
-
this.front = this.back;
|
332
|
-
this.back = temp;
|
333
|
-
}
|
334
|
-
|
335
|
-
clipPolygons(polygons) {
|
336
|
-
if (!this.plane) return polygons.slice();
|
337
|
-
let front = [],
|
338
|
-
back = [];
|
339
|
-
|
340
|
-
for (let i = 0; i < polygons.length; i++) {
|
341
|
-
this.plane.splitPolygon(polygons[i], front, back, front, back);
|
383
|
+
_createClass(Node, [{
|
384
|
+
key: "clone",
|
385
|
+
value: function clone() {
|
386
|
+
var node = new Node();
|
387
|
+
node.plane = this.plane && this.plane.clone();
|
388
|
+
node.front = this.front && this.front.clone();
|
389
|
+
node.back = this.back && this.back.clone();
|
390
|
+
node.polygons = this.polygons.map(function (p) {
|
391
|
+
return p.clone();
|
392
|
+
});
|
393
|
+
return node;
|
342
394
|
}
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
let polygons = this.polygons.slice();
|
357
|
-
if (this.front) polygons = polygons.concat(this.front.allPolygons());
|
358
|
-
if (this.back) polygons = polygons.concat(this.back.allPolygons());
|
359
|
-
return polygons;
|
360
|
-
}
|
361
|
-
|
362
|
-
build(polygons) {
|
363
|
-
if (!polygons.length) return;
|
364
|
-
if (!this.plane) this.plane = polygons[0].plane.clone();
|
365
|
-
let front = [],
|
366
|
-
back = [];
|
367
|
-
|
368
|
-
for (let i = 0; i < polygons.length; i++) {
|
369
|
-
this.plane.splitPolygon(polygons[i], this.polygons, this.polygons, front, back);
|
395
|
+
}, {
|
396
|
+
key: "invert",
|
397
|
+
value: function invert() {
|
398
|
+
for (var i = 0; i < this.polygons.length; i++) {
|
399
|
+
this.polygons[i].flip();
|
400
|
+
}
|
401
|
+
|
402
|
+
this.plane && this.plane.flip();
|
403
|
+
this.front && this.front.invert();
|
404
|
+
this.back && this.back.invert();
|
405
|
+
var temp = this.front;
|
406
|
+
this.front = this.back;
|
407
|
+
this.back = temp;
|
370
408
|
}
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
this.
|
409
|
+
}, {
|
410
|
+
key: "clipPolygons",
|
411
|
+
value: function clipPolygons(polygons) {
|
412
|
+
if (!this.plane) return polygons.slice();
|
413
|
+
var front = [],
|
414
|
+
back = [];
|
415
|
+
|
416
|
+
for (var i = 0; i < polygons.length; i++) {
|
417
|
+
this.plane.splitPolygon(polygons[i], front, back, front, back);
|
418
|
+
}
|
419
|
+
|
420
|
+
if (this.front) front = this.front.clipPolygons(front);
|
421
|
+
if (this.back) back = this.back.clipPolygons(back);else back = [];
|
422
|
+
return front.concat(back);
|
375
423
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
this.
|
424
|
+
}, {
|
425
|
+
key: "clipTo",
|
426
|
+
value: function clipTo(bsp) {
|
427
|
+
this.polygons = bsp.clipPolygons(this.polygons);
|
428
|
+
if (this.front) this.front.clipTo(bsp);
|
429
|
+
if (this.back) this.back.clipTo(bsp);
|
380
430
|
}
|
381
|
-
}
|
431
|
+
}, {
|
432
|
+
key: "allPolygons",
|
433
|
+
value: function allPolygons() {
|
434
|
+
var polygons = this.polygons.slice();
|
435
|
+
if (this.front) polygons = polygons.concat(this.front.allPolygons());
|
436
|
+
if (this.back) polygons = polygons.concat(this.back.allPolygons());
|
437
|
+
return polygons;
|
438
|
+
}
|
439
|
+
}, {
|
440
|
+
key: "build",
|
441
|
+
value: function build(polygons) {
|
442
|
+
if (!polygons.length) return;
|
443
|
+
if (!this.plane) this.plane = polygons[0].plane.clone();
|
444
|
+
var front = [],
|
445
|
+
back = [];
|
446
|
+
|
447
|
+
for (var i = 0; i < polygons.length; i++) {
|
448
|
+
this.plane.splitPolygon(polygons[i], this.polygons, this.polygons, front, back);
|
449
|
+
}
|
450
|
+
|
451
|
+
if (front.length) {
|
452
|
+
if (!this.front) this.front = new Node();
|
453
|
+
this.front.build(front);
|
454
|
+
}
|
455
|
+
|
456
|
+
if (back.length) {
|
457
|
+
if (!this.back) this.back = new Node();
|
458
|
+
this.back.build(back);
|
459
|
+
}
|
460
|
+
}
|
461
|
+
}]);
|
382
462
|
|
383
|
-
|
463
|
+
return Node;
|
464
|
+
}();
|
384
465
|
|
385
466
|
CSG.fromJSON = function (json) {
|
386
|
-
return CSG.fromPolygons(json.polygons.map(
|
467
|
+
return CSG.fromPolygons(json.polygons.map(function (p) {
|
468
|
+
return new Polygon(p.vertices.map(function (v) {
|
469
|
+
return new Vertex(v.pos, v.normal, v.uv);
|
470
|
+
}), p.shared);
|
471
|
+
}));
|
387
472
|
};
|