1
This commit is contained in:
@ -277,6 +277,7 @@
|
||||
<button class="option-btn" data-option="louver-2">百叶2</button>
|
||||
<button class="option-btn" data-option="louver-3">百叶3</button>
|
||||
<button class="option-btn" data-option="louver-4">百叶4</button>
|
||||
<button class="option-btn" data-option="louver-4">卷帘小</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -418,7 +419,7 @@
|
||||
const modelUrl = `https://sdk.zguiy.com/resurces/model/${currentText}.glb`;
|
||||
console.log('替换百叶模型:', modelUrl);
|
||||
try {
|
||||
await kernel.model.replace('百叶', modelUrl);
|
||||
await kernel.model.replace('卷帘小', modelUrl);
|
||||
console.log(`百叶模型已替换为 ${currentText}`);
|
||||
} catch (error) {
|
||||
console.error(`百叶模型替换失败:`, error);
|
||||
@ -512,7 +513,8 @@
|
||||
document.getElementById('remove-model-btn').addEventListener('click', () => {
|
||||
const pickedMesh = window.getCurrentPickedMesh();
|
||||
if (pickedMesh) {
|
||||
const success = kernel.model.remove(pickedMesh);
|
||||
const meshName = pickedMesh.name;
|
||||
const success = kernel.model.remove(meshName);
|
||||
if (success) {
|
||||
console.log('模型已移除');
|
||||
// 关闭信息框
|
||||
|
||||
16
index.js
16
index.js
@ -16,10 +16,9 @@ const config = {
|
||||
|
||||
kernel.init(config);
|
||||
|
||||
kernel.model.add("百叶窗小","https://sdk.zguiy.com/resurces/model/百叶窗小.glb")
|
||||
kernel.model.add("卷帘大","https://sdk.zguiy.com/resurces/model/卷帘大.glb")
|
||||
kernel.model.add("卷帘小","https://sdk.zguiy.com/resurces/model/卷帘小.glb")
|
||||
kernel.model.add("小桌","https://sdk.zguiy.com/resurces/model/小桌.glb")
|
||||
kernel.model.add("卷帘大", "https://sdk.zguiy.com/resurces/model/卷帘大.glb")
|
||||
kernel.model.add("卷帘小", "https://sdk.zguiy.com/resurces/model/卷帘小.glb")
|
||||
kernel.model.add("小桌", "https://sdk.zguiy.com/resurces/model/小桌.glb")
|
||||
|
||||
kernel.on('model:load:progress', (data) => {
|
||||
console.log('模型加载事件', data);
|
||||
@ -34,9 +33,6 @@ kernel.on('model:loaded', (data) => {
|
||||
if (progressContainer) {
|
||||
progressContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
kernel.on('all:ready', (data) => {
|
||||
@ -46,12 +42,10 @@ kernel.on('all:ready', (data) => {
|
||||
attribute: 'alpha',
|
||||
value: 0.5,
|
||||
});
|
||||
|
||||
|
||||
kernel.hotspot.render([
|
||||
{
|
||||
id: "h1",
|
||||
type:'hotspot',
|
||||
type: 'hotspot',
|
||||
name: "卷帘门",
|
||||
meshName: "Valve_01",
|
||||
icon: "https://bpic.588ku.com/element_pic/20/06/30/d1046b01afc0b9586844350d131f4daf.jpg!/fw/253/quality/90/unsharp/true/compress/true",
|
||||
@ -90,7 +84,7 @@ kernel.on('model:click', (data) => {
|
||||
document.getElementById('info-position').textContent = `坐标: [${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}]`;
|
||||
|
||||
// 将DOM附加到点击的3D坐标(会自动显示)
|
||||
kernel.domTo3D.attach('model-info', infoDiv, [position.x, position.y, position.z], { x: -2, y: -2});
|
||||
kernel.domTo3D.attach('model-info', infoDiv, [position.x, position.y, position.z], { x: -2, y: -2 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -291,6 +291,21 @@ export class AppModel extends Monobehiver {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 mesh 名称查找 mesh 对象
|
||||
* @param meshName mesh 名称
|
||||
* @returns mesh 对象,未找到返回 undefined
|
||||
*/
|
||||
private findMeshByName(meshName: string): AbstractMesh | undefined {
|
||||
const keys = this.modelDic.Keys();
|
||||
for (const key of keys) {
|
||||
const meshes = this.modelDic.Get(key);
|
||||
const found = meshes?.find(m => m.name === meshName);
|
||||
if (found) return found;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 mesh 查找所属的模型名称
|
||||
* @param mesh 网格对象
|
||||
@ -308,11 +323,24 @@ export class AppModel extends Monobehiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 mesh 移除所属的整个模型
|
||||
* @param mesh 网格对象
|
||||
* 根据 mesh 或 mesh 名称移除所属的整个模型
|
||||
* @param meshOrName 网格对象或网格名称
|
||||
* @returns 是否成功移除
|
||||
*/
|
||||
remove(mesh: AbstractMesh): boolean {
|
||||
remove(meshOrName: AbstractMesh | string): boolean {
|
||||
let mesh: AbstractMesh | undefined;
|
||||
|
||||
// 判断传入的是对象还是字符串
|
||||
if (typeof meshOrName === 'string') {
|
||||
mesh = this.findMeshByName(meshOrName);
|
||||
if (!mesh) {
|
||||
console.warn(`未找到名为 ${meshOrName} 的网格`);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
mesh = meshOrName;
|
||||
}
|
||||
|
||||
const modelName = this.findModelNameByMesh(mesh);
|
||||
if (modelName) {
|
||||
this.removeByName(modelName);
|
||||
@ -328,6 +356,8 @@ export class AppModel extends Monobehiver {
|
||||
* @param newModelUrl 新模型URL
|
||||
*/
|
||||
async replaceModel(modelName: string, newModelUrl: string): Promise<LoadResult> {
|
||||
console.log( modelName,this.modelDic);
|
||||
|
||||
this.removeByName(modelName);
|
||||
return await this.addSingle(modelName, newModelUrl);
|
||||
}
|
||||
|
||||
@ -93,6 +93,6 @@ export class MainApp {
|
||||
async dispose(): Promise<void> {
|
||||
this.appModel?.clean();
|
||||
this.appEnv?.clean();
|
||||
this.appHotspot?.clear();
|
||||
// this.appHotspot?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user