@@ -531,50 +531,64 @@ export class ObjectPicker {
531531 if ( unitSpacesObjectKeys . length != 0 ) {
532532 // Case where the unit links to spaces
533533
534- unitSpacesMeshes = unitSpacesObjectKeys . map ( ( objectKey ) => {
535- return this . cjHelper . getMesh ( objectKey ) ;
536- } ) ;
537- const unitSpacesBuildingObjectKeys = unitSpacesObjectKeys . map (
538- ( objectKey ) => {
539- return this . cjHelper . findParentBuildingObjectKey (
534+ // unitSpacesMeshes = unitSpacesObjectKeys.map((objectKey) => {
535+ // if (this.cjHelper.isBuildingRoom(objectKey)) {
536+ // return this.cjHelper.getMesh(objectKey);
537+ // } else if (this.cjHelper.isBuildingStorey(objectKey)) {
538+ // const rooms = this.cjHelper.getChildrenObjectKeys(objectKey);
539+ // return rooms.map((roomKey) => {
540+ // return this.cjHelper.getMesh(roomKey);
541+ // });
542+ // } else {
543+ // console.error("The specified object is not a BuildingRoom or BuildingStorey.")
544+ // }
545+ // });
546+
547+ // Find the spaces of the unit and their parent building
548+ unitSpacesMeshes = [ ] ;
549+ const unitSpacesBuildingKeys = [ ] ;
550+ for ( const objectKey of unitSpacesObjectKeys ) {
551+ if ( this . cjHelper . isBuildingRoom ( objectKey ) ) {
552+ unitSpacesMeshes . push ( this . cjHelper . getMesh ( objectKey ) ) ;
553+ unitSpacesBuildingKeys . push ( this . cjHelper . findParentBuildingObjectKey (
540554 objectKey
541- ) ;
555+ ) ) ;
556+ } else if ( this . cjHelper . isBuildingStorey ( objectKey ) ) {
557+ const rooms = this . cjHelper . getChildrenObjectKeys ( objectKey ) ;
558+ rooms . forEach ( ( roomKey ) => {
559+ unitSpacesMeshes . push ( this . cjHelper . getMesh ( roomKey ) ) ;
560+ unitSpacesBuildingKeys . push ( this . cjHelper . findParentBuildingObjectKey (
561+ roomKey
562+ ) ) ;
563+
564+ } ) ;
565+ } else {
566+ console . error ( "The specified object is not a BuildingRoom or BuildingStorey." )
542567 }
543- ) ;
568+ }
569+
570+ // const unitSpacesBuildingKeys = unitSpacesObjectKeys.map(
571+ // (objectKey) => {
572+ // return this.cjHelper.findParentBuildingObjectKey(
573+ // objectKey
574+ // );
575+ // }
576+ // );
544577
545578 // Check if all the unit spaces are in the same building
546579 if (
547- ! unitSpacesBuildingObjectKeys . every (
548- ( v ) => v === unitSpacesBuildingObjectKeys [ 0 ]
580+ ! unitSpacesBuildingKeys . every (
581+ ( v ) => v === unitSpacesBuildingKeys [ 0 ]
549582 )
550583 ) {
551584 console . error (
552585 "A unit with spaces in multiple buildings is not supported."
553586 ) ;
554587 return ;
555588 }
556- buildingObjectKey = unitSpacesBuildingObjectKeys [ 0 ] ;
589+ buildingObjectKey = unitSpacesBuildingKeys [ 0 ] ;
557590 buildingMesh = this . cjHelper . getMesh ( buildingObjectKey ) ;
558591
559- // // Find the most frequent storey code
560- // const unitSpacesStoreyCodes = unitSpacesObjectKeys.map(
561- // (objectKey) => {
562- // return this.cjHelper.getStoreyCode(objectKey);
563- // }
564- // );
565- // var counts = {};
566- // var compare = 0;
567- // for (const spaceStoreyCode of unitSpacesStoreyCodes) {
568- // if (counts[spaceStoreyCode] === undefined) {
569- // counts[spaceStoreyCode] = 1;
570- // } else {
571- // counts[spaceStoreyCode] += 1;
572- // }
573- // if (counts[spaceStoreyCode] > compare) {
574- // compare = counts[spaceStoreyCode];
575- // storeyCode = spaceStoreyCode;
576- // }
577- // }
578592 } else {
579593 // Case where the unit has no spaces
580594
@@ -597,7 +611,6 @@ export class ObjectPicker {
597611 storeyCode = this . cjHelper . getUnitMainStoreyCode ( pickedObjectKey ) ;
598612 }
599613
600-
601614 // Highlight the meshes
602615 this . pickHighlighter . highlight ( unitSpacesMeshes ) ;
603616
0 commit comments