main.js
SView main entry script: basePath setup, model path setup, and other processing are performed in window.onload. In versions before 10.3.35, do this directly in the window.onload method.
Set basePath to point to the location of the H5 plugin package.
let basePath = decodeURIComponent(window.location.href.slice(0, window.location.href.lastIndexOf("/") + 1)); // When configured with IIS, the path must point to the SView project level
Parse the model path; the H5 plugin package obtains the model address through a cookie.
var path;
var isArray = 'false';
var isSvlx;
var cookie = document.cookie;
var cookieArray = cookie.split(";");
for (var i = 0; i < cookieArray.length; i++) {
let keyValue = cookieArray[i].split("=");
keyValue[0] = keyValue[0].replace(/\s*/g, "");
if (keyValue[0] == "path") {
path = keyValue[1];
}
if (keyValue[0] == "isArray") {
isArray = keyValue[1];
}
if (keyValue[0] == "isSvlx") {
isSvlx = keyValue[1];
}
}
if (!path) {
path = basePath + "/models/Children's bed.svlx.svlx"
}
if (isArray == 'false') {
filePaths.push(path);
} else {
let paths = path.split(",");
for (let i = 0; i < paths.length; i++) {
filePaths.push(paths[i]);
}
}
Version 10.3.35 and later:
function initBasePath(path) {
if (SVIEW_USE_MODE === SViewUseMode.SOURCE) {
basePath = window.location.origin + "/SView/SView";
} else if (SVIEW_USE_MODE === SViewUseMode.PACKAGE
|| SVIEW_USE_MODE === SViewUseMode.SECOND_DEV
){
// This is the main case; you can set it yourself, pointing to the address of the H5 plugin package
basePath = decodeURIComponent(window.location.href.slice(0, window.location.href.lastIndexOf("/") + 1)); // When configured with IIS, the path must point to the SView project level
}
}
function initModelPath() {
let filePaths = [];
if (SVIEW_USE_MODE === SViewUseMode.SOURCE) {
// Local run: set the model path directly
let filePath1 = basePath + "/models/3d_pmi.svlx";
let fileName = filePath1.slice(filePath1.lastIndexOf("/") + 1, filePath1.length);
let fileType = filePath1.split(".").pop().toLocaleLowerCase();
filePaths.push([filePath1, fileName, fileType]);
let filePath2;
if (filePath2) {
filePaths.push(filePath2);
}
} else if (SVIEW_USE_MODE === SViewUseMode.PACKAGE) {
// Package run: obtain the model path through a cookie
var path;
var isArray = 'false';
var isSvlx;
path = getCookie("path");
isArray = getCookie("isArray");
isSvlx = getCookie("isSvlx");
if (!path) {
path = basePath + "/models/Children's bed.svlx";
}
if (isArray == 'false') {
let fileName = path.slice(path.lastIndexOf("/") + 1, path.length);
let fileType = path.split(".").pop().toLocaleLowerCase();
filePaths.push([path, fileName, fileType]);
} else {
let paths = path.split(",");
for (let i = 0; i < paths.length; i++) {
let filePath = paths[i];
let fileName = filePath.slice(filePath.lastIndexOf("/") + 1, filePath.length);
filePaths.push([filePath, fileName, fileType]);
}
}
}
return filePaths;
}
function initConfigPath() {
// System configuration file path
sysConfigPath = basePath + "/config/systemParameters.json";
// Document configuration file path
docConfigPath = basePath + "/config/documentParameters.json";
// Custom property configuration file path
customPropertyPath = basePath + "/config/propertiesParameters.json";
// Default property configuration file path
propertiesConfigPath = basePath + "/config/propertiesParameters.json";
// Command configuration file path
if (renderType === RenderType.Server ) {
commandConfigPath = basePath + "/config/sviewrsCommandParameters.json";
} else {
commandConfigPath = basePath + "/config/commandParameters.json";
}
}