fixed URL xeokit tries to download attachments from with subdirectory (#8837)
* fixed URL xeokit tries to download attachments from with subdirectory * DRYing up path to IFC model attachment files in XeokitServer Also finally typing XeokitServer in TypeScript. * Cleanup after review: - Remove unnecessary imports - Use string interpolation in PathHelper Co-authored-by: Wieland Lindenthal <w.lindenthal@forkmerge.com>pull/8851/head
parent
593cc7ad05
commit
4b720c0abb
@ -1 +0,0 @@ |
||||
export class XeokitServer {} |
@ -1,78 +0,0 @@ |
||||
import {utils} from "@xeokit/xeokit-sdk/src/viewer/scene/utils"; |
||||
/** |
||||
* Default server client which loads content via HTTP from the file system. |
||||
*/ |
||||
class XeokitServer { |
||||
|
||||
/** |
||||
* |
||||
* @param cfg |
||||
* @param.cfg.dataDir Base directory for content. |
||||
*/ |
||||
constructor(cfg = {}) { |
||||
this._dataDir = cfg.dataDir || ""; |
||||
} |
||||
|
||||
/** |
||||
* Gets the manifest of all projects. |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getProjects(done, _error) { |
||||
done({ projects: window.gon.ifc_models.projects }); |
||||
} |
||||
|
||||
/** |
||||
* Gets a manifest for a project. |
||||
* @param projectId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getProject(projectData, done, _error) { |
||||
var manifestData = { |
||||
id: projectData[0].id, |
||||
name: projectData[0].name, |
||||
models: window.gon.ifc_models.models, |
||||
viewerContent: { |
||||
modelsLoaded: window.gon.ifc_models.shown_models |
||||
}, |
||||
viewerConfigs: { |
||||
saoEnabled: true // Needs to be enabled by default if we want to use it selectively on the available models.
|
||||
} |
||||
}; |
||||
|
||||
done(manifestData); |
||||
} |
||||
|
||||
/** |
||||
* Gets metadata for a model within a project. |
||||
* @param projectId |
||||
* @param modelId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getMetadata(_projectId, modelId, done, error) { |
||||
const attachmentId = window.gon.ifc_models.metadata_attachment_ids[modelId]; |
||||
console.log(`Loading model metadata for: ${attachmentId}`); |
||||
utils.loadJSON(this.attachmentUrl(attachmentId), done, error); |
||||
} |
||||
|
||||
/** |
||||
* Gets geometry for a model within a project. |
||||
* @param projectId |
||||
* @param modelId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getGeometry(projectId, modelId, done, error) { |
||||
const attachmentId = window.gon.ifc_models.xkt_attachment_ids[modelId]; |
||||
console.log(`Loading model geometry for: ${attachmentId}`); |
||||
utils.loadArraybuffer(this.attachmentUrl(attachmentId), done, error); |
||||
} |
||||
|
||||
attachmentUrl(attachmentId) { |
||||
return "/api/v3/attachments/" + attachmentId + "/content"; |
||||
} |
||||
} |
||||
|
||||
export {XeokitServer}; |
@ -0,0 +1,76 @@ |
||||
// @ts-ignore
|
||||
import {utils} from "@xeokit/xeokit-sdk/src/viewer/scene/utils"; |
||||
import {PathHelperService} from "../../../common/path-helper/path-helper.service"; |
||||
import {IFCGonDefinition} from "../pages/viewer/ifc-models-data.service"; |
||||
|
||||
/** |
||||
* Default server client which loads content via HTTP from the file system. |
||||
*/ |
||||
export class XeokitServer { |
||||
private ifcModels:IFCGonDefinition; |
||||
/** |
||||
* |
||||
* @param config |
||||
* @param.config.pathHelper instance of PathHelperService. |
||||
*/ |
||||
constructor(private pathHelper:PathHelperService) { |
||||
this.ifcModels = window.gon.ifc_models; |
||||
} |
||||
|
||||
/** |
||||
* Gets the manifest of all projects. |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getProjects(done:Function, _error:Function) { |
||||
done({ projects: this.ifcModels.projects }); |
||||
} |
||||
|
||||
/** |
||||
* Gets a manifest for a project. |
||||
* @param projectId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getProject(projectData:any, done:Function, _error:Function) { |
||||
var manifestData = { |
||||
id: projectData[0].id, |
||||
name: projectData[0].name, |
||||
models: this.ifcModels.models, |
||||
viewerContent: { |
||||
modelsLoaded: this.ifcModels.shown_models |
||||
}, |
||||
viewerConfigs: { |
||||
saoEnabled: true // Needs to be enabled by default if we want to use it selectively on the available models.
|
||||
} |
||||
}; |
||||
|
||||
done(manifestData); |
||||
} |
||||
|
||||
/** |
||||
* Gets metadata for a model within a project. |
||||
* @param projectId |
||||
* @param modelId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getMetadata(_projectId:string, modelId:number, done:Function, error:Function) { |
||||
const attachmentId = this.ifcModels.metadata_attachment_ids[modelId]; |
||||
console.log(`Loading model metadata for: ${attachmentId}`); |
||||
utils.loadJSON(this.pathHelper.attachmentContentPath(attachmentId), done, error); |
||||
} |
||||
|
||||
/** |
||||
* Gets geometry for a model within a project. |
||||
* @param projectId |
||||
* @param modelId |
||||
* @param done |
||||
* @param error |
||||
*/ |
||||
getGeometry(projectId:string, modelId:number, done:Function, error:Function) { |
||||
const attachmentId = this.ifcModels.xkt_attachment_ids[modelId]; |
||||
console.log(`Loading model geometry for: ${attachmentId}`); |
||||
utils.loadArraybuffer(this.pathHelper.attachmentContentPath(attachmentId), done, error); |
||||
} |
||||
} |
Loading…
Reference in new issue