From de48e2c453d967647c2b77db6159536c758b4fa4 Mon Sep 17 00:00:00 2001 From: Alexandru Popovici Date: Mon, 29 May 2023 16:23:09 +0300 Subject: [PATCH] Base objects in Blocks (#1600) * Fixed a displaying issue with blocks that contain non-direct-convertible objects. * Revert "Fixed a displaying issue with blocks that contain non-direct-convertible objects." This reverts commit dc44a07d79e605e42e605befde1b09fdc95429d5. * Different approach on fixing the Base object with display values in Blocks which should not generate regression since it's restricted only to blocks and works the same way for other situations except this one * Added 'elements' lookup as well * Check if display values or elements exist before destructuring them --- packages/viewer-sandbox/src/main.ts | 5 ++- .../viewer/src/modules/converter/Converter.ts | 33 ++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/viewer-sandbox/src/main.ts b/packages/viewer-sandbox/src/main.ts index d44835d2c..a01d1eecf 100644 --- a/packages/viewer-sandbox/src/main.ts +++ b/packages/viewer-sandbox/src/main.ts @@ -262,7 +262,10 @@ const getStream = () => { // 'https://latest.speckle.dev/streams/92b620fb17/commits/f9063fe647' // 'https://speckle.xyz/streams/be0f962efb/objects/37639741c363a123100eda8044f2fe3f' // 'https://latest.speckle.dev/streams/92b620fb17/objects/a4e2fad01e69cd886ecbfedf221f5301' - 'https://latest.speckle.dev/streams/3f895e614f/commits/7e16d2ab71' + // 'https://latest.speckle.dev/streams/3f895e614f/commits/7e16d2ab71' + // 'https://latest.speckle.dev/streams/c1faab5c62/objects/d3466547df9df86397eb4dff7ac9713f' + // 'https://latest.speckle.dev/streams/c1faab5c62/commits/140c443886' + 'https://latest.speckle.dev/streams/e258b0e8db/commits/108971810d' ) } diff --git a/packages/viewer/src/modules/converter/Converter.ts b/packages/viewer/src/modules/converter/Converter.ts index 36e07b3db..d7e1319ad 100644 --- a/packages/viewer/src/modules/converter/Converter.ts +++ b/packages/viewer/src/modules/converter/Converter.ts @@ -359,6 +359,34 @@ export default class Coverter { // return hash // } + /** This is only used for Blocks to search for convertible objects, without using the main 'traverse' function + * It's only looking for 'elements' and 'displayValues' + * I think it can be used for RevitInstances as well to replace it's current lookup, but I'm afraid to do it + */ + private async displayableLookup(obj, node) { + if (this.directNodeConverterExists(obj)) { + await this.convertToNode(obj, node) + } else { + const displayValues = this.getDisplayValue(obj) + const elements = this.getElementsValue(obj) + const entries = [ + ...(displayValues ? displayValues : []), + ...(elements ? elements : []) + ] + for (const entry of entries) { + const value = await this.resolveReference(entry) + const valueNode: TreeNode = this.tree.parse({ + id: this.getNodeId(value), + raw: Object.assign({}, value), + atomic: false, + children: [] + }) + this.tree.addNode(valueNode, node) + await this.displayableLookup(value, valueNode) + } + } + } + private async BlockInstanceToNode(obj, node) { const definition = await this.resolveReference(this.getBlockDefinition(obj)) node.model.raw.definition = definition @@ -372,11 +400,8 @@ export default class Coverter { children: [] }) this.tree.addNode(childNode, node) - // console.warn( - // `Added child node with id ${childNode.model.id} to parent node ${node.model.id}` - // ) - await this.convertToNode(ref, childNode) + this.displayableLookup(ref, childNode) } }