@pacem/pacem-3d 1.0.0-abel
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/LICENSE +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-3d.js +7718 -0
- package/dist/browser/pacem-3d.js.map +1 -0
- package/dist/browser/pacem-3d.min.js +2 -0
- package/dist/browser/pacem-3d.min.js.map +1 -0
- package/dist/bundle/pacem-3d.min.mjs +345 -0
- package/dist/bundle/pacem-3d.mjs +7737 -0
- package/dist/bundle/pacem-3d.mjs.map +7 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/converters.js +40 -0
- package/dist/esm/decorators.js +29 -0
- package/dist/esm/detector.js +73 -0
- package/dist/esm/geometry.js +102 -0
- package/dist/esm/index-components-drawing3d.js +22 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-drawing3d.js +6 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-root.js +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/stage.js +280 -0
- package/dist/esm/types.js +482 -0
- package/package.json +39 -0
- package/typings/index.d.ts +1084 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Watch, PropertyConverters, CustomElement, PacemEventTarget, PropertyChangeEvent, CustomElementUtils, CustomUIEvent, P, Utils, Components } from '@pacem/pacem-core';
|
|
8
|
+
import { Geometry } from '@pacem/pacem-numerical';
|
|
9
|
+
import { Point3DConverter, Point3DOrNumberConverter, QuaternionConverter } from './converters';
|
|
10
|
+
import { Pacem3DElement } from './stage';
|
|
11
|
+
import { TAG_MIDDLE_NAME } from './constants';
|
|
12
|
+
export function isStage(object) {
|
|
13
|
+
return !Utils.isNull(object) && 'render' in object && typeof object['render'] === 'function';
|
|
14
|
+
}
|
|
15
|
+
export function isRenderable(object) {
|
|
16
|
+
return isStage(object?.stage);
|
|
17
|
+
}
|
|
18
|
+
export function isUi3DObject(object) {
|
|
19
|
+
return 'transformMatrix' in object && isRenderable(object);
|
|
20
|
+
}
|
|
21
|
+
export function isCamera(object) {
|
|
22
|
+
return 'type' in object && 'up' in object && 'lookAt' in object && isRenderable(object);
|
|
23
|
+
}
|
|
24
|
+
export function isPerspectiveCamera(object) {
|
|
25
|
+
return isCamera(object) && 'type' in object && object.type === 'perspective';
|
|
26
|
+
}
|
|
27
|
+
export function isOrthographicCamera(object) {
|
|
28
|
+
return isCamera(object) && 'type' in object && object.type === 'orthographic';
|
|
29
|
+
}
|
|
30
|
+
export function isLight(object) {
|
|
31
|
+
return 'type' in object && (object.type === 'ambient' || object.type === 'omni' || object.type === 'direction' || object.type == 'spot') && isRenderable(object);
|
|
32
|
+
}
|
|
33
|
+
export function isMesh(object) {
|
|
34
|
+
return 'geometry' in object && isUi3DObject(object);
|
|
35
|
+
}
|
|
36
|
+
export function isGeometry(object) {
|
|
37
|
+
return 'positions' in object && Utils.isArray(object.positions);
|
|
38
|
+
}
|
|
39
|
+
export function isMeshGeometry(object) {
|
|
40
|
+
return ('triangleIndices' in object && Utils.isArray(object.triangleIndices)
|
|
41
|
+
|| 'normals' in object && Utils.isArray(object.normals)
|
|
42
|
+
|| 'textureCoordinates' in object && Utils.isArray(object.textureCoordinates)) && isGeometry(object);
|
|
43
|
+
}
|
|
44
|
+
export function isGroup(object) {
|
|
45
|
+
return 'childRenderables' in object && Utils.isArray(object['childRenderables']) && isUi3DObject(object);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the normals to a mesh geometry by computing each face's unit orthogonal vector.
|
|
49
|
+
* @param geometry
|
|
50
|
+
*/
|
|
51
|
+
export function computeSharpVertexNormals(geometry) {
|
|
52
|
+
const normals = [];
|
|
53
|
+
if (!Utils.isNullOrEmpty(geometry)) {
|
|
54
|
+
const indices = geometry.triangleIndices;
|
|
55
|
+
if (indices.length % 3 !== 0) {
|
|
56
|
+
throw new RangeError(`Invalid mesh geometry: ${indices.length} is not multiple of 3.`);
|
|
57
|
+
}
|
|
58
|
+
for (let j = 2; j < indices.length; j += 3) {
|
|
59
|
+
const u = indices[j - 2], v = indices[j - 1], w = indices[j];
|
|
60
|
+
const a = geometry.positions[u], b = geometry.positions[v], c = geometry.positions[w];
|
|
61
|
+
const normal = computePlaneNormal(a, b, c);
|
|
62
|
+
normals.push(normal, normal, normal);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
geometry.normals = normals;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Computes the unit vector orthogonal to the plane identified by 3 points.
|
|
69
|
+
* @param a
|
|
70
|
+
* @param b
|
|
71
|
+
* @param c
|
|
72
|
+
*/
|
|
73
|
+
export function computePlaneNormal(a, b, c) {
|
|
74
|
+
// TODO: check input correctness (distinct points)
|
|
75
|
+
const vAB = Geometry.LinearAlgebra.Vector3D.subtract(a, b), vAC = Geometry.LinearAlgebra.Vector3D.subtract(a, c);
|
|
76
|
+
const orthogonal = Geometry.LinearAlgebra.Vector3D.cross(vAB, vAC);
|
|
77
|
+
return Geometry.LinearAlgebra.Vector3D.unit(orthogonal);
|
|
78
|
+
}
|
|
79
|
+
export class UI3DEvent extends CustomUIEvent {
|
|
80
|
+
constructor(type, eventInit, originalEvent, point) {
|
|
81
|
+
super(type, eventInit, originalEvent);
|
|
82
|
+
this.#point = point;
|
|
83
|
+
}
|
|
84
|
+
#point;
|
|
85
|
+
/** Gets the event's source position in 3d coordinates. */
|
|
86
|
+
get point() {
|
|
87
|
+
return this.#point;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export class DragEvent extends UI3DEvent {
|
|
91
|
+
}
|
|
92
|
+
export class RenderableEvent extends UI3DEvent {
|
|
93
|
+
constructor(type, args, originalEvent, p) {
|
|
94
|
+
super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, p);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export var StalePropertyFlag;
|
|
98
|
+
(function (StalePropertyFlag) {
|
|
99
|
+
StalePropertyFlag["Position"] = "position";
|
|
100
|
+
StalePropertyFlag["Transform"] = "transform";
|
|
101
|
+
StalePropertyFlag["Geometry"] = "geometry";
|
|
102
|
+
StalePropertyFlag["Children"] = "children";
|
|
103
|
+
StalePropertyFlag["Material"] = "material";
|
|
104
|
+
StalePropertyFlag["Light"] = "light";
|
|
105
|
+
StalePropertyFlag["Camera"] = "camera";
|
|
106
|
+
StalePropertyFlag["Visibility"] = "visibility";
|
|
107
|
+
})(StalePropertyFlag || (StalePropertyFlag = {}));
|
|
108
|
+
export function isInteraction(object) {
|
|
109
|
+
return typeof object === 'object' && 'time' in object && typeof object['time'] === 'number';
|
|
110
|
+
}
|
|
111
|
+
//namespace Pacem.Components.Drawing3D {
|
|
112
|
+
const Constants = {
|
|
113
|
+
OBJECT_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-object',
|
|
114
|
+
LIGHT_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-light',
|
|
115
|
+
PERSPECTIVE_CAMERA_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-perspective-camera',
|
|
116
|
+
ORTHO_CAMERA_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-orthographic-camera',
|
|
117
|
+
LINE_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-line',
|
|
118
|
+
MESH_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-mesh',
|
|
119
|
+
GROUP_SELECTOR: P + '-' + TAG_MIDDLE_NAME + '-group',
|
|
120
|
+
DEFAULT_COORDS: { x: 0, y: 0, z: 0 }
|
|
121
|
+
};
|
|
122
|
+
export class RenderableElement extends Components.PacemCrossItemsContainerElement {
|
|
123
|
+
constructor() {
|
|
124
|
+
super(...arguments);
|
|
125
|
+
this.position = Constants.DEFAULT_COORDS;
|
|
126
|
+
this.#staleFlags = [];
|
|
127
|
+
}
|
|
128
|
+
validate(_) {
|
|
129
|
+
// by default no children allowed (Group will except)
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
findContainer() {
|
|
133
|
+
// override
|
|
134
|
+
return this.parent || this.stage;
|
|
135
|
+
}
|
|
136
|
+
get stage() {
|
|
137
|
+
return this['_scene'] = this['_scene'] || CustomElementUtils.findAncestorOfType(this, Pacem3DElement);
|
|
138
|
+
}
|
|
139
|
+
get parent() {
|
|
140
|
+
return this['_drawableParent'] = this['_drawableParent'] || CustomElementUtils.findAncestor(this, i => i instanceof RenderableElement);
|
|
141
|
+
}
|
|
142
|
+
disconnectedCallback() {
|
|
143
|
+
delete this['_scene'];
|
|
144
|
+
delete this['_drawableParent'];
|
|
145
|
+
super.disconnectedCallback();
|
|
146
|
+
}
|
|
147
|
+
propertyChangedCallback(name, old, val, first) {
|
|
148
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
149
|
+
switch (name) {
|
|
150
|
+
case 'hide':
|
|
151
|
+
this.setAsDirty(StalePropertyFlag.Visibility);
|
|
152
|
+
break;
|
|
153
|
+
case 'items':
|
|
154
|
+
this.setAsDirty(StalePropertyFlag.Children);
|
|
155
|
+
break;
|
|
156
|
+
case 'position':
|
|
157
|
+
this.setAsDirty(StalePropertyFlag.Position);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
#staleFlags;
|
|
162
|
+
get flags() {
|
|
163
|
+
return this.#staleFlags;
|
|
164
|
+
}
|
|
165
|
+
/** Calls for a redraw of the current element in the next rendering process. */
|
|
166
|
+
setAsDirty(...flags) {
|
|
167
|
+
// set the flags that identify the stale part of the object to be updated.
|
|
168
|
+
for (let flag of flags) {
|
|
169
|
+
if (!this.flags.includes(flag)) {
|
|
170
|
+
this.flags.push(flag);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this.stage?.render(this);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
__decorate([
|
|
177
|
+
Watch({ emit: false, converter: Point3DConverter })
|
|
178
|
+
], RenderableElement.prototype, "position", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
Watch({ emit: false, reflectBack: true, converter: PropertyConverters.String })
|
|
181
|
+
], RenderableElement.prototype, "tag", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
184
|
+
], RenderableElement.prototype, "inert", void 0);
|
|
185
|
+
export class Ui3DElement extends RenderableElement {
|
|
186
|
+
// #endregion
|
|
187
|
+
propertyChangedCallback(name, old, val, first) {
|
|
188
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
189
|
+
switch (name) {
|
|
190
|
+
case 'transformMatrix':
|
|
191
|
+
this.setAsDirty(StalePropertyFlag.Transform);
|
|
192
|
+
break;
|
|
193
|
+
case 'translateZ':
|
|
194
|
+
case 'translateX':
|
|
195
|
+
case 'translateY':
|
|
196
|
+
this.offset = { x: this.translateX, y: this.translateY, z: this.translateZ };
|
|
197
|
+
break;
|
|
198
|
+
case 'scaleX':
|
|
199
|
+
case 'scaleY':
|
|
200
|
+
case 'scaleZ':
|
|
201
|
+
this.scale = { x: this.scaleX, y: this.scaleY, z: this.scaleZ };
|
|
202
|
+
break;
|
|
203
|
+
case 'scale':
|
|
204
|
+
case 'offset':
|
|
205
|
+
case 'rotate':
|
|
206
|
+
this._computeTransformMatrix();
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
_computeTransformMatrix() {
|
|
211
|
+
const MAT3D = Geometry.LinearAlgebra.Matrix3D, VEC3D = Geometry.LinearAlgebra.Vector3D, QUAT = Geometry.LinearAlgebra.Quaternion;
|
|
212
|
+
// scale
|
|
213
|
+
const scale = this.scale ?? VEC3D.from(1, 1, 1);
|
|
214
|
+
let m = MAT3D.scale(MAT3D.identity(), scale);
|
|
215
|
+
// rotate
|
|
216
|
+
if (!Utils.isNull(this.rotate)) {
|
|
217
|
+
const rot = QUAT.toRotationMatrix(this.rotate);
|
|
218
|
+
m = MAT3D.multiply(m, rot);
|
|
219
|
+
}
|
|
220
|
+
// translate
|
|
221
|
+
const offset = this.offset ?? VEC3D.from(0, 0, 0);
|
|
222
|
+
m = MAT3D.translate(m, offset);
|
|
223
|
+
this.transformMatrix = m;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
__decorate([
|
|
227
|
+
Watch({ emit: false, converter: QuaternionConverter })
|
|
228
|
+
], Ui3DElement.prototype, "rotate", void 0);
|
|
229
|
+
__decorate([
|
|
230
|
+
Watch({ emit: false, converter: Point3DOrNumberConverter })
|
|
231
|
+
], Ui3DElement.prototype, "scale", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
Watch({ emit: false, converter: Point3DOrNumberConverter })
|
|
234
|
+
], Ui3DElement.prototype, "offset", void 0);
|
|
235
|
+
__decorate([
|
|
236
|
+
Watch({ emit: false })
|
|
237
|
+
], Ui3DElement.prototype, "transformMatrix", void 0);
|
|
238
|
+
__decorate([
|
|
239
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
240
|
+
], Ui3DElement.prototype, "scaleX", void 0);
|
|
241
|
+
__decorate([
|
|
242
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
243
|
+
], Ui3DElement.prototype, "scaleY", void 0);
|
|
244
|
+
__decorate([
|
|
245
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
246
|
+
], Ui3DElement.prototype, "scaleZ", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
249
|
+
], Ui3DElement.prototype, "translateX", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
252
|
+
], Ui3DElement.prototype, "translateY", void 0);
|
|
253
|
+
__decorate([
|
|
254
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
255
|
+
], Ui3DElement.prototype, "translateZ", void 0);
|
|
256
|
+
let Pacem3DGroupElement = class Pacem3DGroupElement extends Ui3DElement {
|
|
257
|
+
validate(child) {
|
|
258
|
+
// overrides default denial
|
|
259
|
+
return child instanceof RenderableElement;
|
|
260
|
+
}
|
|
261
|
+
#children = [];
|
|
262
|
+
get childRenderables() {
|
|
263
|
+
return this.#children;
|
|
264
|
+
}
|
|
265
|
+
propertyChangedCallback(name, old, val, first) {
|
|
266
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
267
|
+
switch (name) {
|
|
268
|
+
case 'items':
|
|
269
|
+
case 'datasource':
|
|
270
|
+
this.#children = (val || []);
|
|
271
|
+
this.setAsDirty(StalePropertyFlag.Children);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
__decorate([
|
|
277
|
+
Watch({ emit: false })
|
|
278
|
+
], Pacem3DGroupElement.prototype, "datasource", void 0);
|
|
279
|
+
Pacem3DGroupElement = __decorate([
|
|
280
|
+
CustomElement({ tagName: Constants.GROUP_SELECTOR })
|
|
281
|
+
], Pacem3DGroupElement);
|
|
282
|
+
export { Pacem3DGroupElement };
|
|
283
|
+
let Pacem3DMeshElement = class Pacem3DMeshElement extends Ui3DElement {
|
|
284
|
+
propertyChangedCallback(name, old, val, first) {
|
|
285
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
286
|
+
switch (name) {
|
|
287
|
+
case 'geometry':
|
|
288
|
+
this.setAsDirty(StalePropertyFlag.Geometry);
|
|
289
|
+
break;
|
|
290
|
+
case 'material':
|
|
291
|
+
case 'backMaterial':
|
|
292
|
+
this.setAsDirty(StalePropertyFlag.Material);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
__decorate([
|
|
298
|
+
Watch({ emit: false, converter: PropertyConverters.Json })
|
|
299
|
+
], Pacem3DMeshElement.prototype, "geometry", void 0);
|
|
300
|
+
__decorate([
|
|
301
|
+
Watch({ emit: false, converter: PropertyConverters.Json })
|
|
302
|
+
], Pacem3DMeshElement.prototype, "material", void 0);
|
|
303
|
+
__decorate([
|
|
304
|
+
Watch({ emit: false, converter: PropertyConverters.Json })
|
|
305
|
+
], Pacem3DMeshElement.prototype, "backMaterial", void 0);
|
|
306
|
+
Pacem3DMeshElement = __decorate([
|
|
307
|
+
CustomElement({ tagName: Constants.MESH_SELECTOR })
|
|
308
|
+
], Pacem3DMeshElement);
|
|
309
|
+
export { Pacem3DMeshElement };
|
|
310
|
+
let Pacem3DObjectElement = class Pacem3DObjectElement extends Ui3DElement {
|
|
311
|
+
propertyChangedCallback(name, old, val, first) {
|
|
312
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
313
|
+
if (name === 'content' || name === 'type') {
|
|
314
|
+
this.setAsDirty(StalePropertyFlag.Geometry, StalePropertyFlag.Material);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
__decorate([
|
|
319
|
+
Watch({ emit: false })
|
|
320
|
+
], Pacem3DObjectElement.prototype, "content", void 0);
|
|
321
|
+
__decorate([
|
|
322
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
323
|
+
], Pacem3DObjectElement.prototype, "type", void 0);
|
|
324
|
+
Pacem3DObjectElement = __decorate([
|
|
325
|
+
CustomElement({ tagName: Constants.OBJECT_SELECTOR })
|
|
326
|
+
], Pacem3DObjectElement);
|
|
327
|
+
export { Pacem3DObjectElement };
|
|
328
|
+
let Pacem3DLightElement = class Pacem3DLightElement extends RenderableElement {
|
|
329
|
+
constructor() {
|
|
330
|
+
super(...arguments);
|
|
331
|
+
this.intensity = .85;
|
|
332
|
+
this.target = Constants.DEFAULT_COORDS;
|
|
333
|
+
this.color = '#fff';
|
|
334
|
+
this.type = 'omni';
|
|
335
|
+
}
|
|
336
|
+
propertyChangedCallback(name, old, val, first) {
|
|
337
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
338
|
+
switch (name) {
|
|
339
|
+
case 'type':
|
|
340
|
+
case 'color':
|
|
341
|
+
case 'intensity':
|
|
342
|
+
case 'target':
|
|
343
|
+
this.setAsDirty(StalePropertyFlag.Light);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
__decorate([
|
|
349
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
350
|
+
], Pacem3DLightElement.prototype, "intensity", void 0);
|
|
351
|
+
__decorate([
|
|
352
|
+
Watch({ emit: false, converter: Point3DConverter })
|
|
353
|
+
], Pacem3DLightElement.prototype, "target", void 0);
|
|
354
|
+
__decorate([
|
|
355
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
356
|
+
], Pacem3DLightElement.prototype, "color", void 0);
|
|
357
|
+
__decorate([
|
|
358
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
359
|
+
], Pacem3DLightElement.prototype, "type", void 0);
|
|
360
|
+
Pacem3DLightElement = __decorate([
|
|
361
|
+
CustomElement({ tagName: Constants.LIGHT_SELECTOR })
|
|
362
|
+
], Pacem3DLightElement);
|
|
363
|
+
export { Pacem3DLightElement };
|
|
364
|
+
export class Pacem3DCameraElement extends RenderableElement {
|
|
365
|
+
constructor() {
|
|
366
|
+
super(...arguments);
|
|
367
|
+
this.near = 0.1;
|
|
368
|
+
this.far = 1000.0;
|
|
369
|
+
this.up = Geometry.LinearAlgebra.Vector3D.j();
|
|
370
|
+
this.lookAt = Constants.DEFAULT_COORDS;
|
|
371
|
+
}
|
|
372
|
+
#sphere;
|
|
373
|
+
_resetBoundingSphere() {
|
|
374
|
+
const oldValue = this.#sphere;
|
|
375
|
+
const eye = this.position, center = this.lookAt;
|
|
376
|
+
const radius = Utils.isNullOrEmpty(eye) || Utils.isNullOrEmpty(center) ? 0
|
|
377
|
+
: Geometry.LinearAlgebra.Vector3D.mag(Geometry.LinearAlgebra.Vector3D.subtract(eye, center));
|
|
378
|
+
const currentValue = this.#sphere = { center, radius };
|
|
379
|
+
this.dispatchEvent(new PropertyChangeEvent({ currentValue, propertyName: 'boundingSphere', oldValue }));
|
|
380
|
+
}
|
|
381
|
+
get boundingSphere() {
|
|
382
|
+
return this.#sphere;
|
|
383
|
+
}
|
|
384
|
+
propertyChangedCallback(name, old, val, first) {
|
|
385
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
386
|
+
switch (name) {
|
|
387
|
+
case 'lookAt':
|
|
388
|
+
case 'position':
|
|
389
|
+
this._resetBoundingSphere();
|
|
390
|
+
case 'near':
|
|
391
|
+
case 'far':
|
|
392
|
+
case 'up':
|
|
393
|
+
this.setAsDirty(StalePropertyFlag.Camera);
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
__decorate([
|
|
399
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
400
|
+
], Pacem3DCameraElement.prototype, "near", void 0);
|
|
401
|
+
__decorate([
|
|
402
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
403
|
+
], Pacem3DCameraElement.prototype, "far", void 0);
|
|
404
|
+
__decorate([
|
|
405
|
+
Watch({ emit: false, converter: Point3DConverter })
|
|
406
|
+
], Pacem3DCameraElement.prototype, "up", void 0);
|
|
407
|
+
__decorate([
|
|
408
|
+
Watch({ emit: false, converter: Point3DConverter })
|
|
409
|
+
], Pacem3DCameraElement.prototype, "lookAt", void 0);
|
|
410
|
+
let Pacem3DPerspectiveCameraElement = class Pacem3DPerspectiveCameraElement extends Pacem3DCameraElement {
|
|
411
|
+
constructor() {
|
|
412
|
+
super(...arguments);
|
|
413
|
+
this.fov = 45;
|
|
414
|
+
this.aspect = 1;
|
|
415
|
+
}
|
|
416
|
+
get type() {
|
|
417
|
+
return "perspective";
|
|
418
|
+
}
|
|
419
|
+
get aspectRatio() {
|
|
420
|
+
return this.aspect;
|
|
421
|
+
}
|
|
422
|
+
propertyChangedCallback(name, old, val, first) {
|
|
423
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
424
|
+
switch (name) {
|
|
425
|
+
case 'fov':
|
|
426
|
+
case 'aspect':
|
|
427
|
+
this.setAsDirty(StalePropertyFlag.Camera);
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
__decorate([
|
|
433
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
434
|
+
], Pacem3DPerspectiveCameraElement.prototype, "fov", void 0);
|
|
435
|
+
__decorate([
|
|
436
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
437
|
+
], Pacem3DPerspectiveCameraElement.prototype, "aspect", void 0);
|
|
438
|
+
Pacem3DPerspectiveCameraElement = __decorate([
|
|
439
|
+
CustomElement({ tagName: Constants.PERSPECTIVE_CAMERA_SELECTOR })
|
|
440
|
+
], Pacem3DPerspectiveCameraElement);
|
|
441
|
+
export { Pacem3DPerspectiveCameraElement };
|
|
442
|
+
let Pacem3DOrthographicCameraElement = class Pacem3DOrthographicCameraElement extends Pacem3DCameraElement {
|
|
443
|
+
constructor() {
|
|
444
|
+
super(...arguments);
|
|
445
|
+
this.top = 1;
|
|
446
|
+
this.left = -1;
|
|
447
|
+
this.bottom = -1;
|
|
448
|
+
this.right = 1;
|
|
449
|
+
}
|
|
450
|
+
get type() {
|
|
451
|
+
return "orthographic";
|
|
452
|
+
}
|
|
453
|
+
propertyChangedCallback(name, old, val, first) {
|
|
454
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
455
|
+
switch (name) {
|
|
456
|
+
case 'top':
|
|
457
|
+
case 'left':
|
|
458
|
+
case 'bottom':
|
|
459
|
+
case 'right':
|
|
460
|
+
this.setAsDirty(StalePropertyFlag.Camera);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
__decorate([
|
|
466
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
467
|
+
], Pacem3DOrthographicCameraElement.prototype, "top", void 0);
|
|
468
|
+
__decorate([
|
|
469
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
470
|
+
], Pacem3DOrthographicCameraElement.prototype, "left", void 0);
|
|
471
|
+
__decorate([
|
|
472
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
473
|
+
], Pacem3DOrthographicCameraElement.prototype, "bottom", void 0);
|
|
474
|
+
__decorate([
|
|
475
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
476
|
+
], Pacem3DOrthographicCameraElement.prototype, "right", void 0);
|
|
477
|
+
Pacem3DOrthographicCameraElement = __decorate([
|
|
478
|
+
CustomElement({ tagName: Constants.ORTHO_CAMERA_SELECTOR })
|
|
479
|
+
], Pacem3DOrthographicCameraElement);
|
|
480
|
+
export { Pacem3DOrthographicCameraElement };
|
|
481
|
+
export class Pacem3DAdapterElement extends PacemEventTarget {
|
|
482
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pacem/pacem-3d",
|
|
3
|
+
"files": [
|
|
4
|
+
"dist/browser/*.*",
|
|
5
|
+
"dist/bundle/*.*",
|
|
6
|
+
"dist/esm/*.*",
|
|
7
|
+
"typings/*.*",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE",
|
|
10
|
+
"NOTICE",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@pacem/pacem-foundation": "*",
|
|
16
|
+
"@pacem/pacem-core": "*",
|
|
17
|
+
"@pacem/pacem-numerical": "*"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/esm/index.js",
|
|
20
|
+
"module": "./dist/esm/index.js",
|
|
21
|
+
"typings": "./typings/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/esm/index.js",
|
|
25
|
+
"types": "./typings/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"version": "1.0.0-abel",
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Pacem",
|
|
31
|
+
"url": "https://pacem.it"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"homepage": "https://js.pacem.it",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/pacem-it/pacem.git"
|
|
38
|
+
}
|
|
39
|
+
}
|