Skip to content

Commit 06c5529

Browse files
Alex/ol2 no hardcode (#5730)
* fix(object-loader): WIP on removing the hardocoding. * feat(object-loader-2): Object skipping by type is not added as an option. By default OL2 will not skip any objects. Added server filters and skippable objects to sandbox loading
1 parent 779ac74 commit 06c5529

File tree

6 files changed

+57
-23
lines changed

6 files changed

+57
-23
lines changed

packages/objectloader2/src/core/objectLoader2Factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ObjectLoader2Factory {
5252
headers?: Headers
5353
options?: ObjectLoader2FactoryOptions
5454
attributeMask?: ObjectAttributeMask
55+
objectTypeMask?: string[]
5556
}): ObjectLoader2 {
5657
const log = ObjectLoader2Factory.getLogger(params.options?.logger)
5758
let database
@@ -90,6 +91,7 @@ export class ObjectLoader2Factory {
9091
headers: params.headers,
9192
fetch: params.options?.fetch,
9293
attributeMask: params.attributeMask,
94+
objectTypeMask: params.objectTypeMask,
9395
logger
9496
}),
9597
database,

packages/objectloader2/src/core/stages/serverDownloader.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ServerDownloaderOptions {
1414
logger: CustomLogger
1515
fetch?: Fetcher
1616
attributeMask?: ObjectAttributeMask
17+
objectTypeMask?: string[] // Temporary until server filters are elevated and ready
1718
}
1819

1920
const MAX_SAFARI_DECODE_BYTES = 2 * 1024 * 1024 * 1024 - 1024 * 1024 // 2GB minus a margin
@@ -32,8 +33,8 @@ export default class ServerDownloader implements Downloader {
3233
#decoder = new TextDecoder('utf-8', { fatal: true })
3334
#decodedBytesCount = 0
3435

35-
#rawString: string = 'Objects.Other.RawEncoding'
36-
#rawEncoding: Uint8Array
36+
#rawStrings: Array<string> = []
37+
#rawEncodings: Array<Uint8Array> = []
3738

3839
constructor(options: ServerDownloaderOptions) {
3940
this.#options = options
@@ -61,7 +62,12 @@ export default class ServerDownloader implements Downloader {
6162
}/${this.#options.objectId}/single`
6263

6364
const encoder = new TextEncoder()
64-
this.#rawEncoding = encoder.encode(this.#rawString)
65+
if (options.objectTypeMask) {
66+
this.#rawStrings.push(...options.objectTypeMask)
67+
this.#rawEncodings.push(
68+
...options.objectTypeMask.map((val) => encoder.encode(val))
69+
)
70+
}
6571
}
6672

6773
initialize(params: {
@@ -220,18 +226,21 @@ Chrome's behavior: Chrome generally handles larger data sizes without this speci
220226
throw new ObjectLoaderRuntimeError(`${baseId} is not a base`)
221227
}
222228
}
229+
223230
#isValidString(json: string): boolean {
224-
if (!json.includes(this.#rawString)) {
225-
return true
226-
}
227-
return false
231+
for (const rawString of this.#rawStrings)
232+
if (json.includes(rawString)) {
233+
return false
234+
}
235+
return true
228236
}
229237

230238
#isValidBytes(json: Uint8Array): boolean {
231-
if (indexOf(json, this.#rawEncoding) === -1) {
232-
return true
233-
}
234-
return false
239+
for (const rawEncoding of this.#rawEncodings)
240+
if (indexOf(json, rawEncoding) !== -1) {
241+
return false
242+
}
243+
return true
235244
}
236245

237246
#concatUint8Arrays(a: Uint8Array, b: Uint8Array): Uint8Array {

packages/objectloader2/src/types/functions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export function indexOf(
9797
if (needle.length === 0) {
9898
return 0
9999
}
100-
101100
// The last possible starting position for a match
102101
const limit = haystack.length - needle.length
103102

@@ -113,6 +112,5 @@ export function indexOf(
113112
return i // Found a full match at index i
114113
}
115114
}
116-
117115
return -1 // No match found
118116
}

packages/viewer-sandbox/src/Sandbox.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,10 @@ export default class Sandbox {
12931293
objUrl,
12941294
authToken,
12951295
true,
1296-
undefined
1296+
undefined,
1297+
undefined,
1298+
{ exclude: ['encodedValue'] },
1299+
['Objects.Other.RawEncoding']
12971300
)
12981301
let dataProgress = 0
12991302
let renderedCount = 0
@@ -1389,14 +1392,14 @@ export default class Sandbox {
13891392
serverUrl,
13901393
streamId,
13911394
objectId,
1392-
token
1395+
token,
1396+
attributeMask: { exclude: ['encodedValue'] },
1397+
objectTypeMask: ['Objects.Other.RawEncoding']
13931398
})
13941399
let count = 0
13951400

1396-
for await (const {} of loader.getObjectIterator()) {
1397-
if (count % 1000 === 0) {
1398-
console.log('Got ' + count + ' ' + (performance.now() - t0) / 1000)
1399-
}
1401+
for await (const res of loader.getObjectIterator()) {
1402+
console.log(res)
14001403
count++
14011404
}
14021405
await loader.disposeAsync()

packages/viewer-sandbox/src/main.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,24 @@ const getStream = () => {
641641

642642
// Gergo's new house
643643
// 'https://app.speckle.systems/projects/4743372784/models/2aeaa357e6'
644+
645+
// Fake RTE instances
646+
// 'https://app.speckle.systems/projects/1b96a34aae/models/a7c177f45d@334523bdd6'
647+
648+
// Revit instances
649+
// 'https://app.speckle.systems/projects/1b96a34aae/models/a8698c0c67'
650+
651+
// Views v3 rhino
652+
// 'https://app.speckle.systems/projects/b6e95c0c63/models/6f7c51cf74@46365a886d'
653+
// Views v3 revit
654+
// 'https://app.speckle.systems/projects/b6e95c0c63/models/f9fbf66e16@c5469b787e'
655+
656+
// 'https://app.speckle.systems/projects/e8593e1ac8/models/489951fef0'
657+
658+
// instances IFC
659+
// 'https://app.speckle.systems/projects/f3a42bdf24/models/0e23cfdea3@664e8d20e6'
660+
661+
// 'https://app.speckle.systems/projects/1b96a34aae/models/9bf8e1a49d@2e917b2dc7'
644662
)
645663
}
646664

packages/viewer/src/modules/loaders/Speckle/SpeckleLoader.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class SpeckleLoader extends Loader {
3535
enableCaching?: boolean,
3636
resourceData?: unknown,
3737
logger?: (message?: string, ...args: unknown[]) => void,
38-
attributeMask?: ObjectAttributeMask
38+
attributeMask?: ObjectAttributeMask,
39+
objectTypeMask?: string[]
3940
) {
4041
super(resource, resourceData)
4142
this.tree = targetTree
@@ -46,7 +47,8 @@ export class SpeckleLoader extends Loader {
4647
authToken,
4748
enableCaching,
4849
resourceData,
49-
attributeMask
50+
attributeMask,
51+
objectTypeMask
5052
)
5153
} catch (e) {
5254
Logger.error(e)
@@ -61,7 +63,8 @@ export class SpeckleLoader extends Loader {
6163
authToken?: string,
6264
_enableCaching?: boolean,
6365
resourceData?: unknown,
64-
attributeMask?: ObjectAttributeMask
66+
attributeMask?: ObjectAttributeMask,
67+
objectTypeMask?: string[]
6568
): ObjectLoader2 {
6669
resourceData
6770
let token = undefined
@@ -97,7 +100,8 @@ export class SpeckleLoader extends Loader {
97100
streamId,
98101
objectId,
99102
token,
100-
attributeMask
103+
attributeMask,
104+
objectTypeMask
101105
})
102106
}
103107

0 commit comments

Comments
 (0)