@thatopen/components 2.4.0-alpha.7 → 2.4.0-alpha.9

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.
@@ -35,8 +35,10 @@ export declare class SimpleRaycaster implements Disposable {
35
35
  * @param items - the [meshes](https://threejs.org/docs/#api/en/objects/Mesh)
36
36
  * to query. If not provided, it will query all the meshes stored in
37
37
  * {@link Components.meshes}.
38
+ * @param position - the screen position to use for raycasting. If not provided,
39
+ * the last pointer (mouse/touch) position will be used.
38
40
  */
39
- castRay(items?: THREE.Object3D[]): THREE.Intersection | null;
41
+ castRay(items?: THREE.Object3D[], position?: THREE.Vector2): THREE.Intersection | null;
40
42
  /**
41
43
  * Casts a ray from a given origin in a given direction and returns the first item found.
42
44
  * This method also takes into account the clipping planes used by the renderer.
@@ -35,7 +35,7 @@ export declare class Viewpoint implements BCFViewpoint {
35
35
  * A map of colors and components GUIDs that should be colorized when displaying a viewpoint.
36
36
  * For this to work, call viewpoint.colorize()
37
37
  */
38
- readonly componentColors: DataMap<string, string[]>;
38
+ readonly componentColors: DataMap<THREE.Color, string[]>;
39
39
  /**
40
40
  * Boolean flags to allow fine control over the visibility of spaces.
41
41
  * A typical use of these flags is when DefaultVisibility=true but spaces should remain hidden.
@@ -163,6 +163,7 @@ export declare class Viewpoint implements BCFViewpoint {
163
163
  * @throws An error if the world's renderer is not available.
164
164
  */
165
165
  updateCamera(): void;
166
+ applyVisibility(): void;
166
167
  /**
167
168
  * Applies color to the components in the viewpoint based on their GUIDs.
168
169
  *
@@ -173,14 +174,13 @@ export declare class Viewpoint implements BCFViewpoint {
173
174
  * The color is applied using the `Classifier.setColor` method, which sets the color of the specified fragments.
174
175
  * The color is provided as a hexadecimal string, prefixed with a '#'.
175
176
  */
176
- colorize(): void;
177
+ applyColors(): void;
177
178
  /**
178
179
  * Resets the colors of all components in the viewpoint to their original color.
179
- * This method iterates through the `componentColors` map, retrieves the fragment IDs
180
- * corresponding to each color, and then uses the `Classifier` to reset the color of those fragments.
181
180
  */
182
181
  resetColors(): void;
183
182
  private createComponentTags;
183
+ private createColorTags;
184
184
  /**
185
185
  * Serializes the viewpoint into a buildingSMART compliant XML string for export.
186
186
  *
package/dist/index.cjs CHANGED
@@ -9554,13 +9554,15 @@ class SimpleRaycaster {
9554
9554
  * @param items - the [meshes](https://threejs.org/docs/#api/en/objects/Mesh)
9555
9555
  * to query. If not provided, it will query all the meshes stored in
9556
9556
  * {@link Components.meshes}.
9557
+ * @param position - the screen position to use for raycasting. If not provided,
9558
+ * the last pointer (mouse/touch) position will be used.
9557
9559
  */
9558
- castRay(items = Array.from(this.world.meshes)) {
9560
+ castRay(items = Array.from(this.world.meshes), position = this.mouse.position) {
9559
9561
  if (!this.world) {
9560
9562
  throw new Error("A world is needed to cast rays!");
9561
9563
  }
9562
9564
  const camera = this.world.camera.three;
9563
- this.three.setFromCamera(this.mouse.position, camera);
9565
+ this.three.setFromCamera(position, camera);
9564
9566
  return this.intersect(items);
9565
9567
  }
9566
9568
  /**
@@ -24443,6 +24445,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24443
24445
  this.webIfc.SetLogLevel(logLevel);
24444
24446
  }
24445
24447
  this.webIfc.OpenModelFromCallback(loadCallback, this.settings.webIfc);
24448
+ this._nextAvailableID = this.webIfc.GetMaxExpressID(0);
24446
24449
  }
24447
24450
  async streamAllGeometries() {
24448
24451
  console.log("Converting geometries to tiles...");
@@ -24552,7 +24555,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24552
24555
  const factor = isOpaque ? 1 : -1;
24553
24556
  const transpGeometryID = geometryID * factor;
24554
24557
  if (!this._visitedGeometries.has(transpGeometryID)) {
24555
- this.getGeometry(webIfc, geometryID, transpGeometryID);
24558
+ this.getGeometry(webIfc, geometryID, isOpaque);
24556
24559
  }
24557
24560
  this.registerGeometryData(
24558
24561
  group,
@@ -24571,7 +24574,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24571
24574
  }
24572
24575
  this._assets.push(asset);
24573
24576
  }
24574
- getGeometry(webIfc, id, transpGeometryID) {
24577
+ getGeometry(webIfc, id, isOpaque) {
24575
24578
  const geometry = webIfc.GetGeometry(0, id);
24576
24579
  const index = webIfc.GetIndexArray(
24577
24580
  geometry.GetIndexData(),
@@ -24591,6 +24594,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24591
24594
  normal[i / 2 + 1] = vertexData[i + 4];
24592
24595
  normal[i / 2 + 2] = vertexData[i + 5];
24593
24596
  }
24597
+ const factor = isOpaque ? 1 : -1;
24594
24598
  if (index.length === 0) {
24595
24599
  const boundingBox2 = new Float32Array([
24596
24600
  0,
@@ -24619,6 +24623,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24619
24623
  });
24620
24624
  const geomIndex = this._visitedGeometries.size;
24621
24625
  const uuid = THREE__namespace.MathUtils.generateUUID();
24626
+ const transpGeometryID = id * factor;
24622
24627
  this._visitedGeometries.set(transpGeometryID, { uuid, index: geomIndex });
24623
24628
  this._geometryCount++;
24624
24629
  geometry.delete();
@@ -24668,6 +24673,7 @@ const _IfcGeometryTiler = class _IfcGeometryTiler extends Component {
24668
24673
  }
24669
24674
  const geomIndex = this._visitedGeometries.size;
24670
24675
  const uuid = THREE__namespace.MathUtils.generateUUID();
24676
+ const transpGeometryID = geometryID * factor;
24671
24677
  this._visitedGeometries.set(transpGeometryID, { uuid, index: geomIndex });
24672
24678
  this._geometryCount++;
24673
24679
  firstSplit = false;
@@ -24887,9 +24893,9 @@ class Viewpoint {
24887
24893
  */
24888
24894
  __publicField(this, "clippingPlanes", new DataSet());
24889
24895
  __publicField(this, "camera", {
24890
- aspectRatio: 0,
24891
- fov: 0,
24892
- direction: { x: 0, y: 0, z: 80 },
24896
+ aspectRatio: 1,
24897
+ fov: 60,
24898
+ direction: { x: 0, y: 0, z: 0 },
24893
24899
  position: { x: 0, y: 0, z: 0 }
24894
24900
  });
24895
24901
  /**
@@ -25129,6 +25135,19 @@ class Viewpoint {
25129
25135
  if (camera instanceof OrthoPerspectiveCamera) {
25130
25136
  camera.projection.set(this.projection);
25131
25137
  }
25138
+ const basePosition = new THREE__namespace.Vector3(
25139
+ this.camera.position.x,
25140
+ this.camera.position.y,
25141
+ this.camera.position.z
25142
+ );
25143
+ const baseTarget = new THREE__namespace.Vector3(
25144
+ this.camera.direction.x,
25145
+ this.camera.direction.y,
25146
+ this.camera.direction.z
25147
+ );
25148
+ if (basePosition.equals(new THREE__namespace.Vector3()) && baseTarget.equals(new THREE__namespace.Vector3())) {
25149
+ return;
25150
+ }
25132
25151
  const position = this.position;
25133
25152
  const direction = this.direction;
25134
25153
  let target = {
@@ -25150,10 +25169,6 @@ class Viewpoint {
25150
25169
  target = bb.getSphere().center;
25151
25170
  bb.reset();
25152
25171
  }
25153
- const hider = this._components.get(Hider);
25154
- hider.set(this.defaultVisibility);
25155
- hider.set(!this.defaultVisibility, this.exception);
25156
- hider.set(true, selection);
25157
25172
  await camera.controls.setLookAt(
25158
25173
  position.x,
25159
25174
  position.y,
@@ -25214,6 +25229,12 @@ class Viewpoint {
25214
25229
  const manager = this._components.get(Viewpoints);
25215
25230
  manager.list.set(this.guid, this);
25216
25231
  }
25232
+ applyVisibility() {
25233
+ const hider = this._components.get(Hider);
25234
+ hider.set(this.defaultVisibility);
25235
+ hider.set(!this.defaultVisibility, this.exception);
25236
+ hider.set(true, this.selection);
25237
+ }
25217
25238
  /**
25218
25239
  * Applies color to the components in the viewpoint based on their GUIDs.
25219
25240
  *
@@ -25224,24 +25245,17 @@ class Viewpoint {
25224
25245
  * The color is applied using the `Classifier.setColor` method, which sets the color of the specified fragments.
25225
25246
  * The color is provided as a hexadecimal string, prefixed with a '#'.
25226
25247
  */
25227
- colorize() {
25248
+ applyColors() {
25228
25249
  const manager = this._components.get(Viewpoints);
25229
25250
  const fragments = this._components.get(FragmentsManager);
25230
25251
  const classifier = this._components.get(Classifier);
25231
25252
  for (const [color, guids] of this.componentColors) {
25232
25253
  const fragmentIdMap = fragments.guidToFragmentIdMap(guids);
25233
- const threeColor = new THREE__namespace.Color(`#${color}`);
25234
- classifier.setColor(
25235
- fragmentIdMap,
25236
- threeColor,
25237
- manager.config.overwriteColors
25238
- );
25254
+ classifier.setColor(fragmentIdMap, color, manager.config.overwriteColors);
25239
25255
  }
25240
25256
  }
25241
25257
  /**
25242
25258
  * Resets the colors of all components in the viewpoint to their original color.
25243
- * This method iterates through the `componentColors` map, retrieves the fragment IDs
25244
- * corresponding to each color, and then uses the `Classifier` to reset the color of those fragments.
25245
25259
  */
25246
25260
  resetColors() {
25247
25261
  const fragments = this._components.get(FragmentsManager);
@@ -25284,6 +25298,23 @@ class Viewpoint {
25284
25298
  }
25285
25299
  return tags;
25286
25300
  }
25301
+ createColorTags() {
25302
+ let colorTags = "";
25303
+ for (const [color, components] of this.componentColors.entries()) {
25304
+ const hex = `#${color.getHexString()}`;
25305
+ const tags = components.map((globalId) => `
25306
+ <Component IfcGuid="${globalId}" />`).join("\n");
25307
+ colorTags += `<Color Color="${hex}">
25308
+ ${tags}
25309
+ </Color>`;
25310
+ }
25311
+ if (colorTags.length !== 0) {
25312
+ return `<Coloring>
25313
+ ${colorTags}
25314
+ </Coloring>`;
25315
+ }
25316
+ return `<Coloring />`;
25317
+ }
25287
25318
  /**
25288
25319
  * Serializes the viewpoint into a buildingSMART compliant XML string for export.
25289
25320
  *
@@ -25342,6 +25373,7 @@ class Viewpoint {
25342
25373
  const viewSetupHints = `<ViewSetupHints SpacesVisible="${this.spacesVisible ?? false}" SpaceBoundariesVisible="${this.spaceBoundariesVisible ?? false}" OpeningsVisible="${this.openingsVisible ?? false}" />`;
25343
25374
  const selectionTags = (await this.createComponentTags("selection")).trim();
25344
25375
  const exceptionTags = (await this.createComponentTags("exception")).trim();
25376
+ const colorTags = this.createColorTags();
25345
25377
  return `<?xml version="1.0" encoding="UTF-8"?>
25346
25378
  <VisualizationInfo Guid="${this.guid}">
25347
25379
  <Components>
@@ -25351,6 +25383,7 @@ class Viewpoint {
25351
25383
  ${version === "3" ? viewSetupHints : ""}
25352
25384
  ${exceptionTags.length !== 0 ? `<Exceptions>${exceptionTags}</Exceptions>` : ""}
25353
25385
  </Visibility>
25386
+ ${colorTags}
25354
25387
  </Components>
25355
25388
  ${cameraXML}
25356
25389
  </VisualizationInfo>`;
@@ -27303,6 +27336,7 @@ const createEntityFacets = (components, elements) => {
27303
27336
  if (element.cardinality)
27304
27337
  facet.cardinality = element.cardinality;
27305
27338
  facet.predefinedType = getParameterValue(element.predefinedType);
27339
+ facet.instructions = element.instructions;
27306
27340
  facets.push(facet);
27307
27341
  }
27308
27342
  return facets;
@@ -27318,6 +27352,7 @@ const createAttributeFacets = (components, elements) => {
27318
27352
  if (element.cardinality)
27319
27353
  facet.cardinality = element.cardinality;
27320
27354
  facet.value = getParameterValue(element.value);
27355
+ facet.instructions = element.instructions;
27321
27356
  facets.push(facet);
27322
27357
  }
27323
27358
  return facets;
@@ -27341,6 +27376,7 @@ const createClassificationFacets = (components, elements) => {
27341
27376
  }
27342
27377
  facet.value = value;
27343
27378
  facet.uri = element.uri;
27379
+ facet.instructions = element.instructions;
27344
27380
  facets.push(facet);
27345
27381
  }
27346
27382
  return facets;
@@ -27364,6 +27400,7 @@ const createPropertyFacets = (components, elements) => {
27364
27400
  facet.value = value;
27365
27401
  facet.dataType = element.dataType;
27366
27402
  facet.uri = element.uri;
27403
+ facet.instructions = element.instructions;
27367
27404
  facets.push(facet);
27368
27405
  }
27369
27406
  return facets;
@@ -27403,12 +27440,14 @@ const _IDSSpecifications = class _IDSSpecifications extends Component {
27403
27440
  *
27404
27441
  * @returns The newly created IDSSpecification instance.
27405
27442
  */
27406
- create(name, ifcVersion) {
27443
+ create(name, ifcVersion, identifier) {
27407
27444
  const specification = new IDSSpecification(
27408
27445
  this.components,
27409
27446
  name,
27410
27447
  ifcVersion
27411
27448
  );
27449
+ if (identifier)
27450
+ specification.identifier = identifier;
27412
27451
  this.list.set(specification.identifier, specification);
27413
27452
  return specification;
27414
27453
  }
@@ -27428,7 +27467,7 @@ const _IDSSpecifications = class _IDSSpecifications extends Component {
27428
27467
  if (specifications && specifications.specification) {
27429
27468
  const specs = Array.isArray(specifications.specification) ? specifications.specification : [specifications.specification];
27430
27469
  for (const spec of specs) {
27431
- const { name, ifcVersion } = spec;
27470
+ const { name, ifcVersion, description, instructions, identifier } = spec;
27432
27471
  if (!(name && ifcVersion))
27433
27472
  continue;
27434
27473
  const applicabilities = [];
@@ -27447,8 +27486,10 @@ const _IDSSpecifications = class _IDSSpecifications extends Component {
27447
27486
  }
27448
27487
  }
27449
27488
  }
27489
+ let requirementsDescription;
27450
27490
  if (requirements) {
27451
27491
  const { maxOccurs, ...rest } = requirements;
27492
+ requirementsDescription = requirements.description;
27452
27493
  const facets = Array.isArray(rest) ? rest : [rest];
27453
27494
  for (const facet of facets) {
27454
27495
  for (const facetName in facet) {
@@ -27476,7 +27517,14 @@ const _IDSSpecifications = class _IDSSpecifications extends Component {
27476
27517
  }
27477
27518
  }
27478
27519
  if (applicabilities.length > 0 && reqs.length > 0) {
27479
- const specification = this.create(name, ifcVersion.split(/\s+/));
27520
+ const specification = this.create(
27521
+ name,
27522
+ ifcVersion.split(/\s+/),
27523
+ identifier
27524
+ );
27525
+ specification.description = description;
27526
+ specification.instructions = instructions;
27527
+ specification.requirementsDescription = requirementsDescription;
27480
27528
  specification.applicability.add(...applicabilities);
27481
27529
  specification.requirements.add(...reqs);
27482
27530
  result.push(specification);