main_local.js
2026-09-08 17:56
SView原生渲染入口脚本,在window.onload中调用,进行配置文件的读取,设置打开命令参数,调用打开命令进行文件打开
- 获取管理器并初始化配置路径
let configManager = sview0.getFrame().getConfigManager();
let commandsManager = sview0.getFrame().getCommandsManager();
initConfigPath();
- 读取配置文件
// 读取配置
configManager.load(sysConfigPath).then((ret) => {
FunctionListener.configLoaded("system");
let pmiServerUrl = M3D.Config.Parameters.getInstance().getStringParameter("pmiServerUrl");
if (pmiServerUrl) {
M3D.Shapes.ComText.option.pmiServer = pmiServerUrl;
}
configManager.load(docConfigPath).then((ret) => {
FunctionListener.configLoaded("doc");
//更新设置界面参数
sview0.getViewer().getScene().getBackground().updateConfig();
window.language = SView.UIManager.languageInfo = SView.FrameConfigure.getInstance().
getNumberParameter(M3D.Config.language) === 1 ? SView.UIManager.languageConstants.EN : SView.UIManager.languageConstants.CN;
configManager.loadPropertiesConfigs(customPropertyPath,propertiesConfigPath).then((ret) => {
//直接异步加载即可,后续如果有配置model名称的配置,则需要在加载完成后再执行打开逻辑
});
configManager.loadCommandConfigs(/*"File", "OpenSampleFile"*/).then((ret) => {
FunctionListener.configLoaded("command");
});
});
});
- 获取打开命令
let openCommand = null;
if (ret) {
openCommand = commandsManager.getCommand(SView.Commands.CommandNames.OPENSAMPLEFILE);
} else {
//没有配置文件的情况
let array = new Map();
array.set("fullClassName", "SView.Commands.OpenCommand");
openCommand = commandsManager.getCommand(SView.Commands.CommandNames.OPENSAMPLEFILE, array);
}
- 设置命令参数
if (svlxInfo.length === 1) {
openCommand.fileInfo = svlxInfo[0];
} else {
for (let fileInfo of svlxInfo) {
if (fileInfo.directPara.get('downloadUrl')) {
openCommand.addPath(fileInfo.directPara.get('downloadUrl'));
}
}
}
- 执行打开命令
commandsManager.execute(SView.Commands.CommandNames.OPENSAMPLEFILE);
- 直接进入模型比较时处理逻辑
直接进入模型比较时不需要再单独执行打开命令,打开命令需要放在模型比较之后
//直接进入模型比较时调用
sview0.isCompare = true;
executeCommand("modelCompareButton");
//比较的模型地址
let path2 = basePath + "/models/Wankel Engine纹理材质贴图动画2(子件路径插值).svlx";
filename2 = path2.slice(path2.lastIndexOf("/") + 1);
modelCompare(null, path2);
openState[0] = 0;
commandsManager.execute(SView.Commands.CommandNames.OPENSAMPLEFILE);

全部评论