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-2">百叶2</button>
|
||||||
<button class="option-btn" data-option="louver-3">百叶3</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">百叶4</button>
|
||||||
|
<button class="option-btn" data-option="louver-4">卷帘小</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -418,7 +419,7 @@
|
|||||||
const modelUrl = `https://sdk.zguiy.com/resurces/model/${currentText}.glb`;
|
const modelUrl = `https://sdk.zguiy.com/resurces/model/${currentText}.glb`;
|
||||||
console.log('替换百叶模型:', modelUrl);
|
console.log('替换百叶模型:', modelUrl);
|
||||||
try {
|
try {
|
||||||
await kernel.model.replace('百叶', modelUrl);
|
await kernel.model.replace('卷帘小', modelUrl);
|
||||||
console.log(`百叶模型已替换为 ${currentText}`);
|
console.log(`百叶模型已替换为 ${currentText}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`百叶模型替换失败:`, error);
|
console.error(`百叶模型替换失败:`, error);
|
||||||
@ -512,7 +513,8 @@
|
|||||||
document.getElementById('remove-model-btn').addEventListener('click', () => {
|
document.getElementById('remove-model-btn').addEventListener('click', () => {
|
||||||
const pickedMesh = window.getCurrentPickedMesh();
|
const pickedMesh = window.getCurrentPickedMesh();
|
||||||
if (pickedMesh) {
|
if (pickedMesh) {
|
||||||
const success = kernel.model.remove(pickedMesh);
|
const meshName = pickedMesh.name;
|
||||||
|
const success = kernel.model.remove(meshName);
|
||||||
if (success) {
|
if (success) {
|
||||||
console.log('模型已移除');
|
console.log('模型已移除');
|
||||||
// 关闭信息框
|
// 关闭信息框
|
||||||
|
|||||||
6
index.js
6
index.js
@ -16,7 +16,6 @@ const config = {
|
|||||||
|
|
||||||
kernel.init(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")
|
||||||
@ -34,9 +33,6 @@ kernel.on('model:loaded', (data) => {
|
|||||||
if (progressContainer) {
|
if (progressContainer) {
|
||||||
progressContainer.style.display = 'none';
|
progressContainer.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
kernel.on('all:ready', (data) => {
|
kernel.on('all:ready', (data) => {
|
||||||
@ -46,8 +42,6 @@ kernel.on('all:ready', (data) => {
|
|||||||
attribute: 'alpha',
|
attribute: 'alpha',
|
||||||
value: 0.5,
|
value: 0.5,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
kernel.hotspot.render([
|
kernel.hotspot.render([
|
||||||
{
|
{
|
||||||
id: "h1",
|
id: "h1",
|
||||||
|
|||||||
@ -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 查找所属的模型名称
|
* 根据 mesh 查找所属的模型名称
|
||||||
* @param mesh 网格对象
|
* @param mesh 网格对象
|
||||||
@ -308,11 +323,24 @@ export class AppModel extends Monobehiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 mesh 移除所属的整个模型
|
* 根据 mesh 或 mesh 名称移除所属的整个模型
|
||||||
* @param mesh 网格对象
|
* @param meshOrName 网格对象或网格名称
|
||||||
* @returns 是否成功移除
|
* @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);
|
const modelName = this.findModelNameByMesh(mesh);
|
||||||
if (modelName) {
|
if (modelName) {
|
||||||
this.removeByName(modelName);
|
this.removeByName(modelName);
|
||||||
@ -328,6 +356,8 @@ export class AppModel extends Monobehiver {
|
|||||||
* @param newModelUrl 新模型URL
|
* @param newModelUrl 新模型URL
|
||||||
*/
|
*/
|
||||||
async replaceModel(modelName: string, newModelUrl: string): Promise<LoadResult> {
|
async replaceModel(modelName: string, newModelUrl: string): Promise<LoadResult> {
|
||||||
|
console.log( modelName,this.modelDic);
|
||||||
|
|
||||||
this.removeByName(modelName);
|
this.removeByName(modelName);
|
||||||
return await this.addSingle(modelName, newModelUrl);
|
return await this.addSingle(modelName, newModelUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,6 @@ export class MainApp {
|
|||||||
async dispose(): Promise<void> {
|
async dispose(): Promise<void> {
|
||||||
this.appModel?.clean();
|
this.appModel?.clean();
|
||||||
this.appEnv?.clean();
|
this.appEnv?.clean();
|
||||||
this.appHotspot?.clear();
|
// this.appHotspot?.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user