@pacem/pacem-3d 2.0.0-goldbach → 2.0.0-hadamard

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -36,6 +36,16 @@ export const QuaternionConverter = {
36
36
  convert: (attr) => Geometry.LinearAlgebra.Quaternion.parse(attr),
37
37
  convertBack: (prop) => `${prop.x || 0} ${prop.y || 0} ${prop.z || 0} ${prop.w || 0}`
38
38
  };
39
+ export function convertToSmoothness(value) {
40
+ switch (value) {
41
+ case true:
42
+ return 1;
43
+ case false:
44
+ return 0;
45
+ default:
46
+ return value?.clamp(0, 1) ?? 1; // undefined|null => smooth
47
+ }
48
+ }
39
49
  /** Converts an attribute string to/from either a `boolean` (`"true"`/`"false"`) or a `number`. */
40
50
  export const BooleanOrNumberConverter = {
41
51
  convert: (attr) => {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -11,6 +11,7 @@ export * from './materials/lambert';
11
11
  export * from './materials/line';
12
12
  export * from './materials/phong';
13
13
  export * from './materials/standard';
14
+ export * from './materials/physical';
14
15
  export * from './primitives/primitive';
15
16
  export * from './primitives/box';
16
17
  export * from './primitives/cone';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -9,3 +9,4 @@ export * from './decorators';
9
9
  export * from './converters';
10
10
  export * from './materials/material';
11
11
  export * from './parsers/parser';
12
+ export * from './parsers/radiance-hdr';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
package/dist/esm/stage.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
package/dist/esm/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-3d v2.0.0-goldbach (https://js.pacem.it)
2
+ * @pacem/pacem-3d v2.0.0-hadamard (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -11,6 +11,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
11
11
  };
12
12
  import { Watch, PropertyConverters, CustomElement, PacemEventTarget, PropertyChangeEvent, CustomElementUtils, CustomUIEvent, P, Utils, Components } from '@pacem/pacem-core';
13
13
  import { Geometry } from '@pacem/pacem-numerical';
14
+ import { MeshGeometry } from './geometry';
14
15
  import { Point3DConverter, Point3DOrNumberConverter, QuaternionConverter } from './converters';
15
16
  import { Pacem3DElement } from './stage';
16
17
  import { TAG_MIDDLE_NAME } from './constants';
@@ -40,7 +41,7 @@ export function isOrthographicCamera(object) {
40
41
  }
41
42
  /** Type guard checking whether `object` implements the {@link Light} contract. */
42
43
  export function isLight(object) {
43
- return 'type' in object && (object.type === 'ambient' || object.type === 'omni' || object.type === 'direction' || object.type == 'spot') && isRenderable(object);
44
+ return 'type' in object && (object.type === 'ambient' || object.type === 'environment' || object.type === 'omni' || object.type === 'direction' || object.type == 'spot') && isRenderable(object);
44
45
  }
45
46
  /** Type guard checking whether `object` implements the {@link Mesh} contract. */
46
47
  export function isMesh(object) {
@@ -80,6 +81,102 @@ export function computeSharpVertexNormals(geometry) {
80
81
  }
81
82
  geometry.normals = normals;
82
83
  }
84
+ /** `a + (b - a) * s + (c - a) * t`, the point of barycentric coordinates `(1 - s - t, s, t)` in the triangle `a, b, c`. */
85
+ function barycentricPoint(a, b, c, s, t) {
86
+ return {
87
+ x: a.x + (b.x - a.x) * s + (c.x - a.x) * t,
88
+ y: a.y + (b.y - a.y) * s + (c.y - a.y) * t,
89
+ z: a.z + (b.z - a.z) * s + (c.z - a.z) * t
90
+ };
91
+ }
92
+ /**
93
+ * Subdivides every triangle of `geometry` into `segments²` smaller ones, each edge split into `segments` equal parts
94
+ * (a barycentric grid): positions and the per-corner texture coordinates are interpolated, so the faces stay flat and
95
+ * the texture mapping unchanged, and the winding is preserved. Gives displacement maps vertices to move. The normals
96
+ * are recomputed as face normals ({@link computeSharpVertexNormals}).
97
+ * @param geometry A triangle mesh with per-corner texture coordinates (in index order).
98
+ * @param segments Parts each edge is divided into; `1` (or less) returns `geometry` itself.
99
+ * @returns A new geometry (positions shared within each original face only).
100
+ */
101
+ export function subdivideTriangles(geometry, segments) {
102
+ const n = Math.round(segments);
103
+ if (!(n > 1)) {
104
+ return geometry;
105
+ }
106
+ const { positions, triangleIndices, textureCoordinates } = geometry;
107
+ const subdividedPositions = [];
108
+ const subdividedIndices = [];
109
+ const subdividedUvs = [];
110
+ for (let corner = 0; corner + 2 < triangleIndices.length; corner += 3) {
111
+ const a = positions[triangleIndices[corner]], b = positions[triangleIndices[corner + 1]], c = positions[triangleIndices[corner + 2]];
112
+ const uvA = textureCoordinates[corner] ?? { x: 0, y: 0 }, uvB = textureCoordinates[corner + 1] ?? { x: 0, y: 0 }, uvC = textureCoordinates[corner + 2] ?? { x: 0, y: 0 };
113
+ // grid point (i, j): i steps along a→b, j along a→c, i + j <= n
114
+ const first = subdividedPositions.length;
115
+ const gridIndex = (i, j) => first + i * (n + 1) - (i * (i - 1)) / 2 + j;
116
+ for (let i = 0; i <= n; i++) {
117
+ for (let j = 0; j <= n - i; j++) {
118
+ const point = barycentricPoint(a, b, c, i / n, j / n);
119
+ subdividedPositions.push(point);
120
+ }
121
+ }
122
+ const uvAt = (i, j) => {
123
+ const s = i / n, t = j / n;
124
+ return { x: uvA.x + (uvB.x - uvA.x) * s + (uvC.x - uvA.x) * t, y: uvA.y + (uvB.y - uvA.y) * s + (uvC.y - uvA.y) * t };
125
+ };
126
+ const push = (i0, j0, i1, j1, i2, j2) => {
127
+ subdividedIndices.push(gridIndex(i0, j0), gridIndex(i1, j1), gridIndex(i2, j2));
128
+ subdividedUvs.push(uvAt(i0, j0), uvAt(i1, j1), uvAt(i2, j2));
129
+ };
130
+ for (let i = 0; i < n; i++) {
131
+ for (let j = 0; j < n - i; j++) {
132
+ // same orientation as a, b, c
133
+ push(i, j, i + 1, j, i, j + 1);
134
+ if (i + j + 2 <= n) {
135
+ push(i + 1, j, i + 1, j + 1, i, j + 1);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ const subdivided = new MeshGeometry(subdividedPositions, subdividedIndices, subdividedUvs);
141
+ computeSharpVertexNormals(subdivided);
142
+ return subdivided;
143
+ }
144
+ /**
145
+ * Blends the per-corner normals of `geometry`, the face normals set by {@link computeSharpVertexNormals}, towards the
146
+ * exact normals of the surface the mesh approximates: `normalize(mix(face, surface, smooth))`. `0` keeps the facets,
147
+ * `1` renders a round surface, values in between soften the facets' edges. The surface normal is flipped, if needed,
148
+ * to the side of the face normal, so that the faces' winding keeps deciding what's outside.
149
+ * @param geometry A mesh geometry whose normals are the face normals (one per triangle corner, in index order).
150
+ * @param surfaceNormal Gets the unit normal of the surface at a vertex `position`, given the normal of the face the corner belongs to; `null` keeps the face normal (e.g. the flat caps of a cylinder).
151
+ * @param smooth Blend factor, from `0` (faceted) to `1` (round).
152
+ */
153
+ export function smoothVertexNormals(geometry, surfaceNormal, smooth) {
154
+ const factor = Math.min(Math.max(smooth ?? 0, 0), 1);
155
+ if (!(factor > 0)) {
156
+ return;
157
+ }
158
+ const { positions, triangleIndices, normals } = geometry;
159
+ const smoothed = [];
160
+ for (let corner = 0; corner < triangleIndices.length; corner++) {
161
+ const face = normals[corner];
162
+ const position = positions[triangleIndices[corner]];
163
+ const surface = surfaceNormal(position, face);
164
+ if (Utils.isNull(surface)) {
165
+ smoothed.push(face);
166
+ continue;
167
+ }
168
+ const sameSide = Geometry.LinearAlgebra.Vector3D.dot(surface, face) >= 0;
169
+ const sign = sameSide ? 1 : -1;
170
+ const blended = {
171
+ x: face.x + (sign * surface.x - face.x) * factor,
172
+ y: face.y + (sign * surface.y - face.y) * factor,
173
+ z: face.z + (sign * surface.z - face.z) * factor
174
+ };
175
+ const normal = Geometry.LinearAlgebra.Vector3D.unit(blended);
176
+ smoothed.push(normal);
177
+ }
178
+ geometry.normals = smoothed;
179
+ }
83
180
  /**
84
181
  * Computes the unit vector orthogonal to the plane identified by 3 points.
85
182
  * @param a
@@ -134,6 +231,8 @@ export var StalePropertyFlag;
134
231
  StalePropertyFlag["Visibility"] = "visibility";
135
232
  /** The mesh's {@link Mesh.castShadow}/{@link Mesh.receiveShadow} changed. */
136
233
  StalePropertyFlag["Shadow"] = "shadow";
234
+ /** The mesh's {@link Mesh.outlineColor}/{@link Mesh.outlineWidth}/{@link Mesh.outlineUnits} changed. */
235
+ StalePropertyFlag["Outline"] = "outline";
137
236
  })(StalePropertyFlag || (StalePropertyFlag = {}));
138
237
  /** Type guard checking whether `object` implements the {@link Interaction} contract. */
139
238
  export function isInteraction(object) {
@@ -337,6 +436,12 @@ let Pacem3DMeshElement = class Pacem3DMeshElement extends Ui3DElement {
337
436
  this.castShadow = true;
338
437
  /** Gets or sets whether the mesh gets darkened by the shadows of the other meshes. */
339
438
  this.receiveShadow = true;
439
+ /** Gets or sets the color of the outline drawn around the mesh (black by default). */
440
+ this.outlineColor = '#000';
441
+ /** Gets or sets the outline thickness, in {@link outlineUnits}; `0` (default) draws no outline. */
442
+ this.outlineWidth = 0;
443
+ /** Gets or sets the unit of {@link outlineWidth}: `'world'` (default) or `'pixels'`. */
444
+ this.outlineUnits = 'world';
340
445
  }
341
446
  propertyChangedCallback(name, old, val, first) {
342
447
  super.propertyChangedCallback(name, old, val, first);
@@ -352,6 +457,11 @@ let Pacem3DMeshElement = class Pacem3DMeshElement extends Ui3DElement {
352
457
  case 'receiveShadow':
353
458
  this.setAsDirty(StalePropertyFlag.Shadow);
354
459
  break;
460
+ case 'outlineColor':
461
+ case 'outlineWidth':
462
+ case 'outlineUnits':
463
+ this.setAsDirty(StalePropertyFlag.Outline);
464
+ break;
355
465
  }
356
466
  }
357
467
  };
@@ -370,6 +480,15 @@ __decorate([
370
480
  __decorate([
371
481
  Watch({ emit: false, converter: PropertyConverters.Boolean })
372
482
  ], Pacem3DMeshElement.prototype, "receiveShadow", void 0);
483
+ __decorate([
484
+ Watch({ emit: false, converter: PropertyConverters.String })
485
+ ], Pacem3DMeshElement.prototype, "outlineColor", void 0);
486
+ __decorate([
487
+ Watch({ emit: false, converter: PropertyConverters.Number })
488
+ ], Pacem3DMeshElement.prototype, "outlineWidth", void 0);
489
+ __decorate([
490
+ Watch({ emit: false, converter: PropertyConverters.String })
491
+ ], Pacem3DMeshElement.prototype, "outlineUnits", void 0);
373
492
  Pacem3DMeshElement = __decorate([
374
493
  CustomElement({ tagName: Constants.MESH_SELECTOR })
375
494
  ], Pacem3DMeshElement);
@@ -393,7 +512,12 @@ Pacem3DObjectElement = __decorate([
393
512
  CustomElement({ tagName: Constants.OBJECT_SELECTOR })
394
513
  ], Pacem3DObjectElement);
395
514
  export { Pacem3DObjectElement };
396
- /** `<pacem-3d-light>`: a {@link RenderableElement} light source (point/omni, spot or directional) illuminating the scene. */
515
+ /**
516
+ * `<pacem-3d-light>`: a {@link RenderableElement} light source (point/omni, spot, directional, ambient or environment)
517
+ * illuminating the scene. An `environment` light (image-based lighting, WebGPU adapter) lights the scene out of the
518
+ * equirectangular HDR image at {@link map}: diffuse light from every direction plus reflections that blur with the
519
+ * surface roughness; one per scene.
520
+ */
397
521
  let Pacem3DLightElement = class Pacem3DLightElement extends RenderableElement {
398
522
  constructor() {
399
523
  super(...arguments);
@@ -401,10 +525,12 @@ let Pacem3DLightElement = class Pacem3DLightElement extends RenderableElement {
401
525
  this.intensity = .85;
402
526
  /** Gets or sets the point the light is aimed at (spotlight-specific). */
403
527
  this.target = Constants.DEFAULT_COORDS;
404
- /** Gets or sets the light color. */
528
+ /** Gets or sets the light color (a tint, for an environment light). */
405
529
  this.color = '#fff';
406
530
  /** Gets or sets the kind of light source. */
407
531
  this.type = 'omni';
532
+ /** Gets or sets the rotation of an environment light around the vertical (`y`) axis, in degrees (`0` by default). */
533
+ this.rotation = 0;
408
534
  /** Gets or sets whether the light casts shadows (directional and omni lights, WebGPU adapter). */
409
535
  this.castShadow = false;
410
536
  /** Gets or sets the side, in texels, of the light's shadow map. */
@@ -422,6 +548,8 @@ let Pacem3DLightElement = class Pacem3DLightElement extends RenderableElement {
422
548
  case 'castShadow':
423
549
  case 'shadowMapSize':
424
550
  case 'shadowBias':
551
+ case 'map':
552
+ case 'rotation':
425
553
  this.setAsDirty(StalePropertyFlag.Light);
426
554
  break;
427
555
  }
@@ -439,6 +567,12 @@ __decorate([
439
567
  __decorate([
440
568
  Watch({ emit: false, converter: PropertyConverters.String })
441
569
  ], Pacem3DLightElement.prototype, "type", void 0);
570
+ __decorate([
571
+ Watch({ emit: false, converter: PropertyConverters.String })
572
+ ], Pacem3DLightElement.prototype, "map", void 0);
573
+ __decorate([
574
+ Watch({ emit: false, converter: PropertyConverters.Number })
575
+ ], Pacem3DLightElement.prototype, "rotation", void 0);
442
576
  __decorate([
443
577
  Watch({ emit: false, converter: PropertyConverters.Boolean })
444
578
  ], Pacem3DLightElement.prototype, "castShadow", void 0);
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "types": "./typings/index.d.ts"
27
27
  }
28
28
  },
29
- "version": "2.0.0-goldbach",
29
+ "version": "2.0.0-hadamard",
30
30
  "author": {
31
31
  "name": "Pacem",
32
32
  "url": "https://pacem.it"