1
This commit is contained in:
59
index.js
59
index.js
@ -1,10 +1,38 @@
|
||||
import { EXRCubeTexture } from '@babylonjs/core';
|
||||
import { kernel } from './src/main.ts';
|
||||
import apiConfig from './src/config.js';
|
||||
|
||||
// 存储 kernel 实例
|
||||
let kernelInstance = null;
|
||||
|
||||
/**
|
||||
* 初始化应用逻辑 - 注入 kernel 实例
|
||||
* @param {Object} kernel - SDK kernel 实例
|
||||
* @returns {Object} kernel 实例
|
||||
*/
|
||||
export const initApp = (kernel) => {
|
||||
if (!kernel) {
|
||||
throw new Error('kernel 实例是必需的');
|
||||
}
|
||||
kernelInstance = kernel;
|
||||
console.log('应用逻辑已初始化,kernel 实例已注入');
|
||||
return kernelInstance;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取当前 kernel 实例
|
||||
*/
|
||||
const getKernel = () => {
|
||||
if (!kernelInstance) {
|
||||
throw new Error('请先调用 initApp(kernel) 初始化 kernel 实例');
|
||||
}
|
||||
return kernelInstance;
|
||||
};
|
||||
|
||||
//初始化
|
||||
export const init = async () => {
|
||||
const config = {
|
||||
export const init = async (customConfig = {}) => {
|
||||
const kernel = getKernel();
|
||||
|
||||
const defaultConfig = {
|
||||
container: document.querySelector('#renderDom'),
|
||||
modelUrlList: [],
|
||||
env: { envPath: 'https://sdk.zguiy.com/resurces/hdr/hdr.env', intensity: 1.2, rotationY: 0.3, background: true },
|
||||
@ -21,14 +49,16 @@ export const init = async () => {
|
||||
occlusionThreshold: 0.0002
|
||||
}
|
||||
};
|
||||
|
||||
// 合并用户自定义配置
|
||||
const config = { ...defaultConfig, ...customConfig };
|
||||
kernel.init(config);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//初始化加载模型
|
||||
export const getAutoLoadModelList = async () => {
|
||||
const kernel = getKernel();
|
||||
|
||||
const url = apiConfig.getApiUrl('/api/models/auto-load/list')
|
||||
console.log('API URL:', url)
|
||||
console.log('apiConfig:', apiConfig)
|
||||
@ -62,6 +92,8 @@ export const getAutoLoadModelList = async () => {
|
||||
|
||||
//获取放置区域
|
||||
export const getPlacementZone = async (sku) => {
|
||||
const kernel = getKernel();
|
||||
|
||||
const response = await fetch(apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
const result = await response.json();
|
||||
if (result.code === 200) {
|
||||
@ -104,7 +136,10 @@ export const getEvent = async (dropzone_data, sku) => {
|
||||
console.error(`查询SKU配置或替换模型失败:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
//点击放置区域执行事件 一般是换配件
|
||||
export const executeEvent = async (dropzone_data, result) => {
|
||||
const kernel = getKernel();
|
||||
|
||||
const { wallName, index, transform } = dropzone_data;
|
||||
const { position, rotation } = transform;
|
||||
@ -161,8 +196,9 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
}
|
||||
}
|
||||
|
||||
//换棚子
|
||||
//一般是换棚子/换颜色/显示放置区域
|
||||
export const executeEvent2 = async (result) => {
|
||||
const kernel = getKernel();
|
||||
|
||||
// 检查是否有模型更换事件
|
||||
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
|
||||
@ -184,8 +220,7 @@ export const executeEvent2 = async (result) => {
|
||||
};
|
||||
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
console.log('替换百叶模型类型:', category);
|
||||
|
||||
|
||||
if (placement_zone) {
|
||||
const { alpha, border_color, color, show_border, thickness, walls } = placement_zone
|
||||
@ -232,8 +267,10 @@ export const executeEvent2 = async (result) => {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//加载热点
|
||||
export const getHotspot = async () => {
|
||||
const kernel = getKernel();
|
||||
|
||||
try {
|
||||
// 从后端获取激活状态的热点列表
|
||||
const response = await fetch(apiConfig.getApiUrl('/api/hotspots?status=active&page=1&pageSize=100'));
|
||||
@ -265,7 +302,7 @@ export const getHotspot = async () => {
|
||||
console.error('获取热点数据失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
//点击右侧按钮自动判断
|
||||
export const getProductConfig = async (sku) => {
|
||||
try {
|
||||
const response = await fetch(`${apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`)}`);
|
||||
|
||||
Reference in New Issue
Block a user