@xeokit/xeokit-sdk 2.6.37 → 2.6.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.6.37",
3
+ "version": "2.6.38",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -1,4 +1,4 @@
1
- import {Map} from "../../viewer/scene/utils/Map.js";
1
+ import { Map } from "../../viewer/scene/utils/Map.js";
2
2
 
3
3
  const idMap = new Map();
4
4
 
@@ -636,21 +636,27 @@ class ContextMenu {
636
636
  if (itemSubMenu) {
637
637
 
638
638
  html.push(
639
- '<li id="' + item.id + '" class="xeokit-context-menu-item" style="' +
640
- ((groupIdx === groupLen - 1) || ((j < lenj - 1)) ? 'border-bottom: 0' : 'border-bottom: 1px solid black') +
641
- '">' +
639
+ '<li id="' + item.id + '" class="xeokit-context-menu-item">' +
642
640
  actionTitle +
643
641
  ' [MORE]' +
644
642
  '</li>');
643
+ if (!((groupIdx === groupLen - 1) || (j < lenj - 1))) {
644
+ html.push(
645
+ '<li id="' + item.id + '" class="xeokit-context-menu-item-seperator"></li>'
646
+ );
647
+ }
645
648
 
646
649
  } else {
647
650
 
648
651
  html.push(
649
- '<li id="' + item.id + '" class="xeokit-context-menu-item" style="' +
650
- ((groupIdx === groupLen - 1) || ((j < lenj - 1)) ? 'border-bottom: 0' : 'border-bottom: 1px solid black') +
651
- '">' +
652
+ '<li id="' + item.id + '" class="xeokit-context-menu-item">' +
652
653
  actionTitle +
653
654
  '</li>');
655
+ if (!((groupIdx === groupLen - 1) || (j < lenj - 1))) {
656
+ html.push(
657
+ '<li id="' + item.id + '" class="xeokit-context-menu-item-seperator"></li>'
658
+ );
659
+ }
654
660
  }
655
661
  }
656
662
  }
@@ -848,14 +854,13 @@ class ContextMenu {
848
854
  const shown = getShown(this._context);
849
855
  item.shown = shown;
850
856
  if (!shown) {
851
- itemElement.style.visibility = "hidden";
852
- itemElement.style.height = "0";
853
- itemElement.style.padding = "0";
857
+ itemElement.classList.remove("xeokit-context-menu-item-visible");
858
+ itemElement.classList.add("xeokit-context-menu-item-hidden");
854
859
  continue;
855
860
  } else {
856
- itemElement.style.visibility = "visible";
857
- itemElement.style.height = "auto";
858
- itemElement.style.padding = null;
861
+ itemElement.classList.remove("ceokit-context-menu-item-hidden");
862
+ itemElement.classList.add("xeokit-context-menu-item-visible");
863
+
859
864
  }
860
865
  const enabled = getEnabled(this._context);
861
866
  item.enabled = enabled;
@@ -925,4 +930,4 @@ class ContextMenu {
925
930
  }
926
931
  }
927
932
 
928
- export {ContextMenu};
933
+ export { ContextMenu };
@@ -503,7 +503,7 @@ export class DotBIMLoaderPlugin extends Plugin {
503
503
  id: `${dbMeshId}-${faceColor}`,
504
504
  primitive: "triangles",
505
505
  positions: trianglesCoordinates,
506
- indices: [...Array(trianglesCoordinates.length).keys()]
506
+ indices: [...Array(trianglesCoordinates.length / 3).keys()]
507
507
  });
508
508
  const meshId = `${objectId}-mesh-${faceColor}`;
509
509
  const faceColorArray = faceColor.split(',').map(Number);
@@ -395,173 +395,74 @@ function loadDefaultScene(ctx) {
395
395
  error(ctx, "glTF has no default scene");
396
396
  return;
397
397
  }
398
- loadScene(ctx, scene);
399
- }
400
398
 
401
- function loadScene(ctx, scene) {
402
399
  const nodes = scene.nodes;
403
400
  if (!nodes) {
404
401
  return;
405
402
  }
406
- for (let i = 0, len = nodes.length; i < len; i++) {
407
- const node = nodes[i];
408
- countMeshUsage(ctx, node);
409
- }
410
- for (let i = 0, len = nodes.length; i < len && !ctx.nodesHaveNames; i++) {
411
- const node = nodes[i];
412
- if (testIfNodesHaveNames(node)) {
413
- ctx.nodesHaveNames = true;
414
- }
415
- }
416
- if (!ctx.nodesHaveNames) {
417
- for (let i = 0, len = nodes.length; i < len; i++) {
418
- const node = nodes[i];
419
- parseNodesWithoutNames(ctx, node, 0, null);
420
- }
421
- } else {
422
- for (let i = 0, len = nodes.length; i < len; i++) {
423
- const node = nodes[i];
424
- parseNodesWithNames(ctx, node, 0, null);
425
- }
426
- }
427
- }
428
403
 
429
- function countMeshUsage(ctx, node) {
430
- const mesh = node.mesh;
431
- if (mesh) {
432
- mesh.instances = mesh.instances ? mesh.instances + 1 : 1;
433
- }
434
- if (node.children) {
435
- const children = node.children;
436
- for (let i = 0, len = children.length; i < len; i++) {
437
- const childNode = children[i];
438
- if (!childNode) {
439
- error(ctx, "Node not found: " + i);
440
- continue;
404
+ (function accumulateMeshInstantes(nodes) {
405
+ nodes.forEach(node => {
406
+ const mesh = node.mesh;
407
+ if (mesh) {
408
+ mesh.instances ||= 0;
409
+ mesh.instances += 1;
441
410
  }
442
- countMeshUsage(ctx, childNode);
443
- }
444
- }
445
- }
446
-
447
- function testIfNodesHaveNames(node) {
448
- if (node.name) {
449
- return true;
450
- }
451
- if (node.children) {
452
- const children = node.children;
453
- for (let i = 0, len = children.length; i < len; i++) {
454
- const childNode = children[i];
455
- if (testIfNodesHaveNames(childNode)) {
456
- return true;
411
+ if (node.children) {
412
+ accumulateMeshInstantes(node.children);
457
413
  }
458
- }
459
- }
460
- return false;
461
- }
414
+ });
415
+ })(nodes);
462
416
 
463
- /**
464
- * Parses a glTF node hierarchy that is known to NOT contain "name" attributes on the nodes.
465
- * Create a SceneMesh for each mesh primitive, and a single SceneObject.
466
- */
467
- const parseNodesWithoutNames = (function () {
468
- const meshIds = [];
469
- return function (ctx, node, depth, matrix, parentNode) {
470
- matrix = parseNodeMatrix(node, matrix);
471
- if (node.mesh) {
472
- parseNodeMesh(node, ctx, matrix, meshIds);
473
- }
474
- if (node.children) {
475
- const children = node.children;
476
- for (let i = 0, len = children.length; i < len; i++) {
477
- const childNode = children[i];
478
- parseNodesWithoutNames(ctx, childNode, depth + 1, matrix, node);
479
- }
480
- }
481
- if (depth === 0) {
482
- let entityId = "entity-" + ctx.nextId++;
483
- if (meshIds && meshIds.length > 0) {
484
- ctx.sceneModel.createEntity({
485
- id: entityId,
486
- meshIds,
487
- isObject: true
488
- });
489
- if (ctx.autoMetaModel) {
490
- ctx.metaObjects.push({
491
- id: entityId,
492
- type: "Default",
493
- name: entityId,
494
- parent: ctx.sceneModel.id
495
- });
417
+ // Create a SceneMesh for each mesh primitive, and a SceneModelEntity for the root node and each named node.
418
+ const meshIdsStack = [];
419
+ let meshIds = null;
420
+ (function createSceneMeshesAndEntities(nodes, depth, parentMatrix) {
421
+ nodes.forEach(node => {
422
+ const nodeName = node.name;
423
+ let entityId = (((nodeName !== undefined) && (nodeName !== null) && nodeName)
424
+ ||
425
+ ((depth === 0) && ("entity-" + ctx.nextId++)));
426
+
427
+ if (entityId) {
428
+ while (ctx.sceneModel.objects[entityId]) {
429
+ entityId = "entity-" + ctx.nextId++;
496
430
  }
497
- meshIds.length = 0;
431
+ meshIdsStack.push(meshIds);
432
+ meshIds = [];
498
433
  }
499
- }
500
- }
501
- })();
502
-
503
- const parseNodesWithNames = (function () {
504
-
505
- const objectIdStack = [];
506
- const meshIdsStack = [];
507
- let meshIds = [];
508
434
 
509
- return function (ctx, node, depth, matrix) {
510
- matrix = parseNodeMatrix(node, matrix);
511
- if (meshIds && node.mesh) {
512
- parseNodeMesh(node, ctx, matrix, meshIds);
513
- }
435
+ const matrix = parseNodeMatrix(node, parentMatrix);
514
436
 
515
- if (node.name) {
516
- meshIds = [];
517
- let entityId = node.name;
518
- if (!!entityId && ctx.sceneModel.objects[entityId]) {
519
- // ctx.log(`Warning: Two or more glTF nodes found with same 'name' attribute: '${entityId} - will randomly-generating an object ID in XKT`);
520
- }
521
- while (!entityId || ctx.sceneModel.objects[entityId]) {
522
- entityId = "entity-" + ctx.nextId++;
437
+ if (node.mesh) {
438
+ parseNodeMesh(node, ctx, matrix, meshIds);
523
439
  }
524
- objectIdStack.push(entityId);
525
- meshIdsStack.push(meshIds);
526
- }
527
440
 
528
- if (node.children) {
529
- const children = node.children;
530
- for (let i = 0, len = children.length; i < len; i++) {
531
- const childNode = children[i];
532
- parseNodesWithNames(ctx, childNode, depth + 1, matrix);
441
+ if (node.children) {
442
+ createSceneMeshesAndEntities(node.children, depth + 1, matrix);
533
443
  }
534
- }
535
-
536
- // Post-order visit scene node
537
444
 
538
- const nodeName = node.name;
539
- if ((nodeName !== undefined && nodeName !== null) || depth === 0) {
540
- let entityId = objectIdStack.pop();
541
- if (!entityId) { // For when there are no nodes with names
542
- entityId = "entity-" + ctx.nextId++;
543
- }
544
- let entityMeshIds = meshIdsStack.pop();
545
- if (meshIds && meshIds.length > 0) {
546
- ctx.sceneModel.createEntity({
547
- id: entityId,
548
- meshIds: entityMeshIds,
549
- isObject: true
550
- });
551
- if (ctx.autoMetaModel) {
552
- ctx.metaObjects.push({
445
+ if (entityId) {
446
+ if (meshIds.length > 0) {
447
+ ctx.sceneModel.createEntity({
553
448
  id: entityId,
554
- type: "Default",
555
- name: entityId,
556
- parent: ctx.sceneModel.id
449
+ meshIds: meshIds,
450
+ isObject: true
557
451
  });
452
+ if (ctx.autoMetaModel) {
453
+ ctx.metaObjects.push({
454
+ id: entityId,
455
+ type: "Default",
456
+ name: entityId,
457
+ parent: ctx.sceneModel.id
458
+ });
459
+ }
558
460
  }
461
+ meshIds = meshIdsStack.pop();
559
462
  }
560
- meshIds = meshIdsStack.length > 0 ? meshIdsStack[meshIdsStack.length - 1] : null;
561
- }
562
- };
563
- })();
564
-
463
+ });
464
+ })(nodes, 0, null);
465
+ };
565
466
 
566
467
  /**
567
468
  * Parses transform at the given glTF node.