Config
用于Viewer3D引擎初始化的配置管理类,提供图形引擎的各种配置选项。包括模型路径、加载模式、射线检测、CAD图模映射等设置。
类定义
class Config静态属性
LoadType
加载模式枚举,定义模型加载的两种模式,用于控制模型数据的来源。
类型: {object}
静态: true
只读: true
属性:
SaaS{string} - SaaS模式,从服务器加载模型数据Local{string} - 本地模式,从本地文件系统加载模型数据
示例:
// 使用加载模式
config.currentLoadType = Config.LoadType.SaaS;
// 检查当前加载模式
if (config.currentLoadType === Config.LoadType.Local) {
console.log('使用本地模式加载');
}构造函数
constructor(modelToken, container)
创建配置实例,初始化配置对象,设置模型名称、渲染容器和默认配置参数。
参数:
modelToken{string} - 模型的名字或者Token,用于标识和访问模型文件container{HTMLElement} - 渲染容器的DOM元素,用于显示3D场景
抛出:
- {Error} 当container不是有效的HTMLElement时抛出错误
示例:
// 创建配置实例
const config = new Config('building_model', document.getElementById('viewer'));
// 使用配置创建Viewer3D实例
const viewer = new Viewer3D(config);属性
container
渲染容器元素,用于显示3D场景的DOM容器元素,Viewer3D将在此容器中渲染内容。
类型: {HTMLElement}
只读: true
STAIC_PATH
静态资源路径,模型文件存储的基础路径,用于构建各种模型文件的访问路径。
类型: {string}
默认值: './public/models/'
modelName
模型名称或Token,用于标识和访问特定模型的唯一标识符,用于构建文件路径。
类型:
currentLoadType
当前加载模式,指定模型数据的加载方式,可以是SaaS模式或本地模式。
类型: {string}
默认值: Config.LoadType.SaaS
enabledRaycaster
射线检测功能启用状态,控制加载的模型是否支持射线检测,用于鼠标交互和对象拾取。
类型: {boolean}
默认值: true
cadParams
CAD图模映射参数配置,包含图模映射信息的数组,用于关联CAD图纸和3D模型。
类型: {Array<DrawingMapModelConfig>|undefined}
方法
clone()
克隆当前配置对象,创建当前配置对象的深拷贝,返回一个新的Config实例。
返回值:
- {Config} 返回一个新的Config实例,包含当前实例的所有属性值
示例:
// 克隆配置对象
const originalConfig = new Config('model1', container);
originalConfig.setStaticPath('./custom/path/');
const clonedConfig = originalConfig.clone();
// clonedConfig 包含相同的配置,但可以独立修改
clonedConfig.modelName = 'model2';setCadParams(params)
设置CAD图模映射参数配置,配置CAD图纸与3D模型之间的映射关系,用于关联2D图纸和3D模型。
参数:
params{Array<DrawingMapModelConfig>} - 包含图模映射信息的数组
示例:
// 设置CAD图模映射
config.setCadParams([
{drawingId: 'floor1', modelId: 'floor1_model', description: '一楼平面图'},
{drawingId: 'floor2', modelId: 'floor2_model', description: '二楼平面图'}
]);setStaticPath(path)
设置静态资源路径,配置模型文件存储的基础路径,用于构建各种模型文件的访问路径。
参数:
path{string} - 静态资源的基础路径
示例:
// 设置静态资源路径
config.setStaticPath('./assets/models/');
// 路径设置后,所有文件路径都会基于此路径构建
console.log(config.commonPath); // './assets/models/building_model/'计算属性
commonPath
获取模型数据资源的公共路径,返回模型文件的基础路径,格式为:{静态路径}/{模型名称}/
类型: {string}
只读: true
示例:
// 如果 STAIC_PATH = './public/models/', modelName = 'building'
// 返回 './public/models/building/'
const path = config.commonPath;
console.log('模型公共路径:', path);cadPath
获取CAD文件路径,返回CAD文件存储的路径,格式为:{公共路径}CAD/
类型: {string}
只读: true
示例:
// 如果 commonPath = './public/models/building/'
// 返回 './public/models/building/CAD/'
const cadPath = config.cadPath;
console.log('CAD文件路径:', cadPath);modelIndexFileName
获取模型索引文件名称,返回模型索引文件的名称,格式为:{模型名称}_index.nivio
类型: {string}
只读: true
示例:
// 如果 modelName = 'building'
// 返回 'building_index.nivio'
const indexFile = config.modelIndexFileName;
console.log('索引文件名:', indexFile);modelTreeFileName
获取模型结构树文件名称,返回模型结构树文件的名称,格式为:{模型名称}_treeModel.zip
类型: {string}
只读: true
示例:
// 如果 modelName = 'building'
// 返回 'building_treeModel.zip'
const treeFile = config.modelTreeFileName;
console.log('结构树文件名:', treeFile);modelPropertyFileName
获取模型属性文件名称,返回模型属性文件的名称,格式为:{模型名称}_Properties.zip
类型: {string}
只读: true
示例:
// 如果 modelName = 'building'
// 返回 'building_Properties.zip'
const propertyFile = config.modelPropertyFileName;
console.log('属性文件名:', propertyFile);modelIndexFileUrl
获取模型索引文件的完整URL,返回模型索引文件的完整访问路径,用于加载模型索引文件。
类型: {string}
只读: true
示例:
// 如果 commonPath = './public/models/building/', modelName = 'building'
// 返回 './public/models/building/building_index.nivio'
const indexUrl = config.modelIndexFileUrl;
console.log('索引文件URL:', indexUrl);glTFModelFileUrl
获取glTF模型文件的完整URL,返回glTF模型文件的完整访问路径,用于非流式加载。
类型: {string}
只读: true
示例:
// 如果 commonPath = './public/models/building/', modelName = 'building'
// 返回 './public/models/building/building.glb'
const gltfUrl = config.glTFModelFileUrl;
console.log('glTF文件URL:', gltfUrl);modelPropertyFileUrl
获取模型属性文件的完整URL,返回模型属性文件的完整访问路径,用于加载模型属性数据。
类型: {string}
只读: true
示例:
// 如果 commonPath = './public/models/building/', modelName = 'building'
// 返回 './public/models/building/building_Properties.zip'
const propertyUrl = config.modelPropertyFileUrl;
console.log('属性文件URL:', propertyUrl);modelTreeFileUrl
获取模型结构树文件的完整URL,返回模型结构树文件的完整访问路径,用于加载模型结构树数据。
类型: {string}
只读: true
示例:
// 如果 commonPath = './public/models/building/', modelName = 'building'
// 返回 './public/models/building/building_treeModel.zip'
const treeUrl = config.modelTreeFileUrl;
console.log('结构树文件URL:', treeUrl);类型定义
DrawingMapModelConfig
图模映射配置对象
类型:
属性:
drawingId{string} - 图纸IDmodelId{string} - 模型IDdescription{string} [可选] - 描述信息
相关链接
- Viewer3D - 主引擎类
- Utils - 工具类
- NIVIOBIMLoader - 模型加载器
- SceneManager - 场景管理器
- RenderManager - 渲染管理器