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
This commit is contained in:
committed by
GitHub
parent
779ac74c4c
commit
06c5529024
@@ -52,6 +52,7 @@ export class ObjectLoader2Factory {
|
||||
headers?: Headers
|
||||
options?: ObjectLoader2FactoryOptions
|
||||
attributeMask?: ObjectAttributeMask
|
||||
objectTypeMask?: string[]
|
||||
}): ObjectLoader2 {
|
||||
const log = ObjectLoader2Factory.getLogger(params.options?.logger)
|
||||
let database
|
||||
@@ -90,6 +91,7 @@ export class ObjectLoader2Factory {
|
||||
headers: params.headers,
|
||||
fetch: params.options?.fetch,
|
||||
attributeMask: params.attributeMask,
|
||||
objectTypeMask: params.objectTypeMask,
|
||||
logger
|
||||
}),
|
||||
database,
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface ServerDownloaderOptions {
|
||||
logger: CustomLogger
|
||||
fetch?: Fetcher
|
||||
attributeMask?: ObjectAttributeMask
|
||||
objectTypeMask?: string[] // Temporary until server filters are elevated and ready
|
||||
}
|
||||
|
||||
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 {
|
||||
#decoder = new TextDecoder('utf-8', { fatal: true })
|
||||
#decodedBytesCount = 0
|
||||
|
||||
#rawString: string = 'Objects.Other.RawEncoding'
|
||||
#rawEncoding: Uint8Array
|
||||
#rawStrings: Array<string> = []
|
||||
#rawEncodings: Array<Uint8Array> = []
|
||||
|
||||
constructor(options: ServerDownloaderOptions) {
|
||||
this.#options = options
|
||||
@@ -61,7 +62,12 @@ export default class ServerDownloader implements Downloader {
|
||||
}/${this.#options.objectId}/single`
|
||||
|
||||
const encoder = new TextEncoder()
|
||||
this.#rawEncoding = encoder.encode(this.#rawString)
|
||||
if (options.objectTypeMask) {
|
||||
this.#rawStrings.push(...options.objectTypeMask)
|
||||
this.#rawEncodings.push(
|
||||
...options.objectTypeMask.map((val) => encoder.encode(val))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
initialize(params: {
|
||||
@@ -220,18 +226,21 @@ Chrome's behavior: Chrome generally handles larger data sizes without this speci
|
||||
throw new ObjectLoaderRuntimeError(`${baseId} is not a base`)
|
||||
}
|
||||
}
|
||||
|
||||
#isValidString(json: string): boolean {
|
||||
if (!json.includes(this.#rawString)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
for (const rawString of this.#rawStrings)
|
||||
if (json.includes(rawString)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
#isValidBytes(json: Uint8Array): boolean {
|
||||
if (indexOf(json, this.#rawEncoding) === -1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
for (const rawEncoding of this.#rawEncodings)
|
||||
if (indexOf(json, rawEncoding) !== -1) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
#concatUint8Arrays(a: Uint8Array, b: Uint8Array): Uint8Array {
|
||||
|
||||
@@ -97,7 +97,6 @@ export function indexOf(
|
||||
if (needle.length === 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
// The last possible starting position for a match
|
||||
const limit = haystack.length - needle.length
|
||||
|
||||
@@ -113,6 +112,5 @@ export function indexOf(
|
||||
return i // Found a full match at index i
|
||||
}
|
||||
}
|
||||
|
||||
return -1 // No match found
|
||||
}
|
||||
|
||||
@@ -1293,7 +1293,10 @@ export default class Sandbox {
|
||||
objUrl,
|
||||
authToken,
|
||||
true,
|
||||
undefined
|
||||
undefined,
|
||||
undefined,
|
||||
{ exclude: ['encodedValue'] },
|
||||
['Objects.Other.RawEncoding']
|
||||
)
|
||||
let dataProgress = 0
|
||||
let renderedCount = 0
|
||||
@@ -1389,14 +1392,14 @@ export default class Sandbox {
|
||||
serverUrl,
|
||||
streamId,
|
||||
objectId,
|
||||
token
|
||||
token,
|
||||
attributeMask: { exclude: ['encodedValue'] },
|
||||
objectTypeMask: ['Objects.Other.RawEncoding']
|
||||
})
|
||||
let count = 0
|
||||
|
||||
for await (const {} of loader.getObjectIterator()) {
|
||||
if (count % 1000 === 0) {
|
||||
console.log('Got ' + count + ' ' + (performance.now() - t0) / 1000)
|
||||
}
|
||||
for await (const res of loader.getObjectIterator()) {
|
||||
console.log(res)
|
||||
count++
|
||||
}
|
||||
await loader.disposeAsync()
|
||||
|
||||
@@ -641,6 +641,24 @@ const getStream = () => {
|
||||
|
||||
// Gergo's new house
|
||||
// 'https://app.speckle.systems/projects/4743372784/models/2aeaa357e6'
|
||||
|
||||
// Fake RTE instances
|
||||
// 'https://app.speckle.systems/projects/1b96a34aae/models/a7c177f45d@334523bdd6'
|
||||
|
||||
// Revit instances
|
||||
// 'https://app.speckle.systems/projects/1b96a34aae/models/a8698c0c67'
|
||||
|
||||
// Views v3 rhino
|
||||
// 'https://app.speckle.systems/projects/b6e95c0c63/models/6f7c51cf74@46365a886d'
|
||||
// Views v3 revit
|
||||
// 'https://app.speckle.systems/projects/b6e95c0c63/models/f9fbf66e16@c5469b787e'
|
||||
|
||||
// 'https://app.speckle.systems/projects/e8593e1ac8/models/489951fef0'
|
||||
|
||||
// instances IFC
|
||||
// 'https://app.speckle.systems/projects/f3a42bdf24/models/0e23cfdea3@664e8d20e6'
|
||||
|
||||
// 'https://app.speckle.systems/projects/1b96a34aae/models/9bf8e1a49d@2e917b2dc7'
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ export class SpeckleLoader extends Loader {
|
||||
enableCaching?: boolean,
|
||||
resourceData?: unknown,
|
||||
logger?: (message?: string, ...args: unknown[]) => void,
|
||||
attributeMask?: ObjectAttributeMask
|
||||
attributeMask?: ObjectAttributeMask,
|
||||
objectTypeMask?: string[]
|
||||
) {
|
||||
super(resource, resourceData)
|
||||
this.tree = targetTree
|
||||
@@ -46,7 +47,8 @@ export class SpeckleLoader extends Loader {
|
||||
authToken,
|
||||
enableCaching,
|
||||
resourceData,
|
||||
attributeMask
|
||||
attributeMask,
|
||||
objectTypeMask
|
||||
)
|
||||
} catch (e) {
|
||||
Logger.error(e)
|
||||
@@ -61,7 +63,8 @@ export class SpeckleLoader extends Loader {
|
||||
authToken?: string,
|
||||
_enableCaching?: boolean,
|
||||
resourceData?: unknown,
|
||||
attributeMask?: ObjectAttributeMask
|
||||
attributeMask?: ObjectAttributeMask,
|
||||
objectTypeMask?: string[]
|
||||
): ObjectLoader2 {
|
||||
resourceData
|
||||
let token = undefined
|
||||
@@ -97,7 +100,8 @@ export class SpeckleLoader extends Loader {
|
||||
streamId,
|
||||
objectId,
|
||||
token,
|
||||
attributeMask
|
||||
attributeMask,
|
||||
objectTypeMask
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user