@configura/web-core 3.0.0-alpha.1 → 3.0.0-alpha.2

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.
@@ -151,16 +151,15 @@ export class Bump3D extends GMaterialProp3D {
151
151
  }
152
152
  }
153
153
  function readBaseMaterialProps(log, prop, obj) {
154
- var _a, _b, _c, _d;
155
154
  const imageUrl = imageUrlFromDex(log, obj);
156
155
  if (imageUrl !== undefined) {
157
156
  prop.setTextureUrl(imageUrl);
158
157
  }
159
158
  prop.c = obj.get("c");
160
- prop.uScale = (_a = obj.get("uScale")) !== null && _a !== void 0 ? _a : prop.uScale;
161
- prop.vScale = (_b = obj.get("vScale")) !== null && _b !== void 0 ? _b : prop.vScale;
162
- prop.uOffset = (_c = obj.get("uOffset")) !== null && _c !== void 0 ? _c : prop.uOffset;
163
- prop.vOffset = (_d = obj.get("vOffset")) !== null && _d !== void 0 ? _d : prop.vOffset;
159
+ prop.uScale = obj.get("uScale") ?? prop.uScale;
160
+ prop.vScale = obj.get("vScale") ?? prop.vScale;
161
+ prop.uOffset = obj.get("uOffset") ?? prop.uOffset;
162
+ prop.vOffset = obj.get("vOffset") ?? prop.vOffset;
164
163
  const angleF = obj.get("rot");
165
164
  if (angleF !== undefined) {
166
165
  prop.rot = angleF.radians;
@@ -5,7 +5,6 @@ import { GMaterial3D, GMaterial3DTexture, imageUrlFromDex, textureWrapFromDex, }
5
5
  // tslint:disable:max-classes-per-file
6
6
  export class GMaterialPBR extends GMaterial3D {
7
7
  constructor(log, obj) {
8
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9
8
  super(log, obj);
10
9
  if (obj === undefined) {
11
10
  return;
@@ -33,12 +32,12 @@ export class GMaterialPBR extends GMaterial3D {
33
32
  log.warn(`Unsupported ${txtType} texture channel: ${channel}`, "Fallback to b.");
34
33
  channel = "b"; // B channel in ORM texture
35
34
  }
36
- this.metallic = new PBRMetallic((_a = loadNumber(log, txtType, prop, "factor")) !== null && _a !== void 0 ? _a : 1, texture, channel);
35
+ this.metallic = new PBRMetallic(loadNumber(log, txtType, prop, "factor") ?? 1, texture, channel);
37
36
  }
38
37
  txtType = "normal" /* pbrNormal */;
39
38
  prop = pbr.get(txtType);
40
39
  if (prop instanceof DexObj) {
41
- this.normal = new PBRNormal((_b = loadNumber(log, txtType, prop, "scale")) !== null && _b !== void 0 ? _b : 1, loadTexture(log, txtType, prop), loadChannels(log, txtType, prop));
40
+ this.normal = new PBRNormal(loadNumber(log, txtType, prop, "scale") ?? 1, loadTexture(log, txtType, prop), loadChannels(log, txtType, prop));
42
41
  }
43
42
  txtType = "opacity" /* pbrOpacity */;
44
43
  prop = pbr.get(txtType);
@@ -49,7 +48,7 @@ export class GMaterialPBR extends GMaterial3D {
49
48
  log.warn(`Unsupported ${txtType} texture channel: ${channel}`, "Fallback to a.");
50
49
  channel = "a"; // Alpha channel, safest fallback
51
50
  }
52
- this.opacity = new PBROpacity((_c = loadNumber(log, txtType, prop, "factor")) !== null && _c !== void 0 ? _c : 1, loadOpacityMode(log, txtType, prop), (_d = loadNumber(log, txtType, prop, "maskThreshold")) !== null && _d !== void 0 ? _d : 0.5, texture, channel, loadBool(log, txtType, prop, "useAlphaFromBase"));
51
+ this.opacity = new PBROpacity(loadNumber(log, txtType, prop, "factor") ?? 1, loadOpacityMode(log, txtType, prop), loadNumber(log, txtType, prop, "maskThreshold") ?? 0.5, texture, channel, loadBool(log, txtType, prop, "useAlphaFromBase"));
53
52
  }
54
53
  txtType = "occlusion" /* pbrOcclusion */;
55
54
  prop = pbr.get(txtType);
@@ -60,12 +59,12 @@ export class GMaterialPBR extends GMaterial3D {
60
59
  log.warn(`Unsupported ${txtType} texture channel: ${channel}`, "Fallback to r.");
61
60
  channel = "r"; // R channel in ORM texture
62
61
  }
63
- this.occlusion = new PBROcclusion((_e = loadNumber(log, txtType, prop, "strength")) !== null && _e !== void 0 ? _e : 0, texture, channel);
62
+ this.occlusion = new PBROcclusion(loadNumber(log, txtType, prop, "strength") ?? 0, texture, channel);
64
63
  }
65
64
  txtType = "refraction" /* pbrRefraction */;
66
65
  prop = pbr.get(txtType);
67
66
  if (prop instanceof DexObj) {
68
- this.refraction = new PBRRefraction((_f = loadNumber(log, txtType, prop, "ior")) !== null && _f !== void 0 ? _f : 1);
67
+ this.refraction = new PBRRefraction(loadNumber(log, txtType, prop, "ior") ?? 1);
69
68
  }
70
69
  txtType = "roughness" /* pbrRoughness */;
71
70
  prop = pbr.get(txtType);
@@ -76,7 +75,7 @@ export class GMaterialPBR extends GMaterial3D {
76
75
  log.warn(`Unsupported ${txtType} texture channel: ${channel}`, "Fallback to g.");
77
76
  channel = "g"; // G channel in ORM texture
78
77
  }
79
- this.roughness = new PBRRoughness((_g = loadNumber(log, txtType, prop, "factor")) !== null && _g !== void 0 ? _g : 1, texture, channel);
78
+ this.roughness = new PBRRoughness(loadNumber(log, txtType, prop, "factor") ?? 1, texture, channel);
80
79
  }
81
80
  // PBRMaterial in CmSym will combine the Occlusion, Roughness and Metallness textures into a
82
81
  // combined "ORM" texture. This is important since Babylon (like glTF 2.0) does not support
@@ -84,8 +83,8 @@ export class GMaterialPBR extends GMaterial3D {
84
83
  //
85
84
  // The PBRMaterial specification in CmSym does not in itself guarantee this, so keep the
86
85
  // check below to notice if this requirement is no longer meet in the future.
87
- const metallicUrl = (_j = (_h = this.metallic) === null || _h === void 0 ? void 0 : _h.texture) === null || _j === void 0 ? void 0 : _j.textureUrl;
88
- const roughnessUrl = (_l = (_k = this.roughness) === null || _k === void 0 ? void 0 : _k.texture) === null || _l === void 0 ? void 0 : _l.textureUrl;
86
+ const metallicUrl = this.metallic?.texture?.textureUrl;
87
+ const roughnessUrl = this.roughness?.texture?.textureUrl;
89
88
  if (metallicUrl !== undefined &&
90
89
  roughnessUrl !== undefined &&
91
90
  metallicUrl.value !== roughnessUrl.value) {
@@ -172,7 +171,6 @@ export var MIPS_TEXTURE_LEVEL;
172
171
  * are optional) or there was an problem loading the texture.
173
172
  */
174
173
  function loadTexture(log, type, dex) {
175
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
176
174
  const scope = type + ".texture";
177
175
  const dexTxt = dex.get("texture");
178
176
  if (dexTxt === undefined) {
@@ -190,19 +188,19 @@ function loadTexture(log, type, dex) {
190
188
  const transform = dexTxt.get("transform");
191
189
  if (transform instanceof DexObj) {
192
190
  const inner = scope + ".transform";
193
- txt.uScale = (_a = loadNumber(log, inner, transform, "uScale")) !== null && _a !== void 0 ? _a : txt.uScale;
194
- txt.vScale = (_b = loadNumber(log, inner, transform, "vScale")) !== null && _b !== void 0 ? _b : txt.vScale;
195
- txt.uOffset = (_c = loadNumber(log, inner, transform, "uOffset")) !== null && _c !== void 0 ? _c : txt.uOffset;
196
- txt.vOffset = (_d = loadNumber(log, inner, transform, "vOffset")) !== null && _d !== void 0 ? _d : txt.vOffset;
197
- txt.rot = (_e = loadAngle(log, inner, transform, "rot")) !== null && _e !== void 0 ? _e : txt.rot;
191
+ txt.uScale = loadNumber(log, inner, transform, "uScale") ?? txt.uScale;
192
+ txt.vScale = loadNumber(log, inner, transform, "vScale") ?? txt.vScale;
193
+ txt.uOffset = loadNumber(log, inner, transform, "uOffset") ?? txt.uOffset;
194
+ txt.vOffset = loadNumber(log, inner, transform, "vOffset") ?? txt.vOffset;
195
+ txt.rot = loadAngle(log, inner, transform, "rot") ?? txt.rot;
198
196
  }
199
197
  const sampler = dexTxt.get("sampler");
200
198
  if (sampler instanceof DexObj) {
201
199
  const inner = scope + ".sampler";
202
- txt.wrapU = (_f = textureWrapFromDex(sampler)) !== null && _f !== void 0 ? _f : txt.wrapU;
203
- txt.wrapV = (_g = textureWrapFromDex(sampler)) !== null && _g !== void 0 ? _g : txt.wrapV;
204
- txt.minFilter = (_h = loadTextureFilter(log, inner, sampler, "minFilter")) !== null && _h !== void 0 ? _h : txt.minFilter;
205
- txt.magFilter = (_j = loadTextureFilter(log, inner, sampler, "magFilter")) !== null && _j !== void 0 ? _j : txt.magFilter;
200
+ txt.wrapU = textureWrapFromDex(sampler) ?? txt.wrapU;
201
+ txt.wrapV = textureWrapFromDex(sampler) ?? txt.wrapV;
202
+ txt.minFilter = loadTextureFilter(log, inner, sampler, "minFilter") ?? txt.minFilter;
203
+ txt.magFilter = loadTextureFilter(log, inner, sampler, "magFilter") ?? txt.magFilter;
206
204
  }
207
205
  else if (sampler !== undefined) {
208
206
  // TODO: Verify with Jimmie that the Sampler is optional (spec not clear, examples
@@ -286,7 +284,7 @@ function loadAngle(log, scope, dex, name) {
286
284
  log.warn(`Angle property not valid (${scope}.${name}): ${obj}`);
287
285
  return undefined;
288
286
  }
289
- return obj === null || obj === void 0 ? void 0 : obj.radians;
287
+ return obj?.radians;
290
288
  }
291
289
  /**
292
290
  * Loads and returns the ColorF specified by the name parameter.
@@ -107,7 +107,7 @@ export function createUVBoxCoordinates(env, positions, bounds, normals) {
107
107
  return createUV(env, positions, bounds, undefined, calculateSideMapFromNormals(normals));
108
108
  }
109
109
  export function createUVBoxCoordinatesForStretched(env, positions, bounds, normals, refPositions, refBounds, refUvs) {
110
- const transforms = env === null || env === void 0 ? void 0 : env.transforms;
110
+ const transforms = env?.transforms;
111
111
  const xyzCount = positions.length;
112
112
  const vertexCount = xyzCount / 3;
113
113
  const uvCount = vertexCount * 2;
@@ -123,7 +123,7 @@ export function createUVBoxCoordinatesForStretched(env, positions, bounds, norma
123
123
  return createUV(env, positions, bounds, refBounds, calculateSideMapFromRefUvs(transforms, normals, refPositions, refBounds, refUvs));
124
124
  }
125
125
  function createUV(env, positions, bounds, refBounds, sideMap) {
126
- const transforms = env === null || env === void 0 ? void 0 : env.transforms;
126
+ const transforms = env?.transforms;
127
127
  const xyzCount = positions.length;
128
128
  const vertexCount = xyzCount / 3;
129
129
  const uvCount = vertexCount * 2;
@@ -12,9 +12,9 @@ export function createUVCylinderCoordinatesForStretched(env, positions, bounds,
12
12
  }
13
13
  function createUV(env, positions, bounds, normals, refPositions, refBounds, refUvs) {
14
14
  const refPositionsFallbackToPositions = refPositions || positions;
15
- const transforms = env === null || env === void 0 ? void 0 : env.transforms;
16
- const transformSide = transforms === null || transforms === void 0 ? void 0 : transforms[0];
17
- const transformTopBottom = transforms === null || transforms === void 0 ? void 0 : transforms[1];
15
+ const transforms = env?.transforms;
16
+ const transformSide = transforms?.[0];
17
+ const transformTopBottom = transforms?.[1];
18
18
  const xyzCount = positions.length;
19
19
  const vertexCount = xyzCount / 3;
20
20
  if (refPositions !== undefined && refPositions.length !== xyzCount) {
@@ -40,7 +40,6 @@ export function createUVPlaneCoordinatesForStretched(env, positions, refPosition
40
40
  return createUV(env, positions, refPositions);
41
41
  }
42
42
  function createUV(env, positions, refPositions) {
43
- var _a;
44
43
  if (env === undefined) {
45
44
  throw new Error("env needed for plane mapper");
46
45
  }
@@ -51,7 +50,7 @@ function createUV(env, positions, refPositions) {
51
50
  }
52
51
  refPositions = refPositions || positions;
53
52
  const normal = env.normal;
54
- const transform = (_a = env.transforms) === null || _a === void 0 ? void 0 : _a[0];
53
+ const transform = env.transforms?.[0];
55
54
  const mappingPlaneVectors = calculateMappingPlaneVectors([normal.x, normal.y, normal.z]);
56
55
  let refMinU = Number.POSITIVE_INFINITY;
57
56
  let refMaxU = Number.NEGATIVE_INFINITY;
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { v4 } from "uuid";
11
2
  import { Semver } from "../../io/Semver.js";
12
3
  import { DexObj } from "../dex/DexObj.js";
@@ -595,11 +586,9 @@ function loadVersion(obj) {
595
586
  }
596
587
  throw Error(`obj: ${obj} can't load version`);
597
588
  }
598
- export function loadSymFile(logger, url, manager, abortSignal) {
599
- return __awaiter(this, void 0, void 0, function* () {
600
- const root = yield manager.load(logger, url, abortSignal);
601
- return makeSymFromDex(logger, root);
602
- });
589
+ export async function loadSymFile(logger, url, manager, abortSignal) {
590
+ const root = await manager.load(logger, url, abortSignal);
591
+ return makeSymFromDex(logger, root);
603
592
  }
604
593
  export function makeSymFromDex(logger, root) {
605
594
  const node = toSymNode(logger, root);
@@ -11,12 +11,10 @@ export class SymBox extends SymComponent {
11
11
  this.id = "symBox";
12
12
  }
13
13
  get p0() {
14
- var _a;
15
- return (_a = this._box) === null || _a === void 0 ? void 0 : _a.p0;
14
+ return this._box?.p0;
16
15
  }
17
16
  get p1() {
18
- var _a;
19
- return (_a = this._box) === null || _a === void 0 ? void 0 : _a.p1;
17
+ return this._box?.p1;
20
18
  }
21
19
  load(logger, obj, _env, force = false) {
22
20
  const p0 = Point.cast(obj.get("p0"));
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { GMaterial3D } from "../../../core3D/GMaterial3D.js";
11
2
  import { GMaterialClassic } from "../../../core3D/GMaterialClassic.js";
12
3
  import { GMaterialPBR } from "../../../core3D/GMaterialPBR.js";
@@ -71,11 +62,9 @@ export function dexToMultiGMaterial3D(logger, obj) {
71
62
  throw logger.errorAsObject("unknown obj.type:", obj.type);
72
63
  }
73
64
  }
74
- export function loadMaterialFromUrl(logger, url, dexManager, abortSignal) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const root = yield dexManager.load(logger, url, abortSignal);
77
- return finishMaterial(logger, url, root);
78
- });
65
+ export async function loadMaterialFromUrl(logger, url, dexManager, abortSignal) {
66
+ const root = await dexManager.load(logger, url, abortSignal);
67
+ return finishMaterial(logger, url, root);
79
68
  }
80
69
  export function makeMaterialFromBuffer(logger, buffer, dexManager) {
81
70
  const root = dexManager.arrayBufferToDexObj(logger, "", buffer);
@@ -11,12 +11,10 @@ export class SymPlane extends SymComponent {
11
11
  return this._plane;
12
12
  }
13
13
  get vector() {
14
- var _a;
15
- return (_a = this._plane) === null || _a === void 0 ? void 0 : _a.vector;
14
+ return this._plane?.vector;
16
15
  }
17
16
  get distance() {
18
- var _a;
19
- return (_a = this._plane) === null || _a === void 0 ? void 0 : _a.distance;
17
+ return this._plane?.distance;
20
18
  }
21
19
  load(logger, obj, _env, force = false) {
22
20
  const plane = Plane.cast(obj.get("plane"));
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { DexGmImageLoader } from "./DexLoader.js";
11
2
  import { DexObj } from "./DexObj.js";
12
3
  import { DexReader } from "./DexReader.js";
@@ -44,20 +35,18 @@ export class DexManager {
44
35
  this.loaders.set(suffix, loader);
45
36
  }
46
37
  }
47
- load(logger, url, abortSignal) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const params = {};
50
- if (abortSignal) {
51
- params.signal = abortSignal;
52
- }
53
- const response = yield fetch(url, params);
54
- if (!response.ok) {
55
- logger.error(response);
56
- throw logger.errorAsObject("response not OK!");
57
- }
58
- const buffer = yield response.arrayBuffer();
59
- return this.arrayBufferToDexObj(logger, url, buffer);
60
- });
38
+ async load(logger, url, abortSignal) {
39
+ const params = {};
40
+ if (abortSignal) {
41
+ params.signal = abortSignal;
42
+ }
43
+ const response = await fetch(url, params);
44
+ if (!response.ok) {
45
+ logger.error(response);
46
+ throw logger.errorAsObject("response not OK!");
47
+ }
48
+ const buffer = await response.arrayBuffer();
49
+ return this.arrayBufferToDexObj(logger, url, buffer);
61
50
  }
62
51
  arrayBufferToDexObj(logger, url, buffer) {
63
52
  const slice = new Uint8Array(buffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configura/web-core",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,8 +15,8 @@
15
15
  "test": "echo \"Error: run tests from root\" && exit 1"
16
16
  },
17
17
  "dependencies": {
18
- "@configura/internal": "3.0.0-alpha.1",
19
- "@configura/web-utilities": "3.0.0-alpha.1"
18
+ "@configura/internal": "3.0.0-alpha.2",
19
+ "@configura/web-utilities": "3.0.0-alpha.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/uuid": "^8.3.0",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "0d18e1a05f913a1367cba0293ee61c5a3320a509"
30
+ "gitHead": "5b72d2813b949b3ccef8f1864382b9153593962b"
31
31
  }