1
This commit is contained in:
@ -148,9 +148,9 @@ export class AppHotspot extends Monobehiver {
|
||||
}
|
||||
|
||||
// 释放sprite资源
|
||||
if (point.sprite) {
|
||||
point.sprite.dispose();
|
||||
}
|
||||
// if (point.sprite) {
|
||||
// point.sprite.dispose();
|
||||
// }
|
||||
}
|
||||
|
||||
// 清空热点池
|
||||
|
||||
@ -149,6 +149,54 @@ export class AppModel extends Monobehiver {
|
||||
this.skeletonMerged = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模型到场景
|
||||
* @param modelUrl 模型URL路径
|
||||
*/
|
||||
async addModel(modelUrl: string): Promise<LoadResult> {
|
||||
const handleProgress = (event: ISceneLoaderProgressEvent): void => {
|
||||
const progress = event.lengthComputable && event.total > 0
|
||||
? Math.min(1, event.loaded / event.total)
|
||||
: 0;
|
||||
EventBridge.modelLoadProgress({
|
||||
loaded: progress,
|
||||
total: 1,
|
||||
url: modelUrl,
|
||||
progress,
|
||||
percentage: Number((progress * 100).toFixed(2)),
|
||||
detail: {
|
||||
url: modelUrl,
|
||||
lengthComputable: event.lengthComputable,
|
||||
loadedBytes: event.loaded,
|
||||
totalBytes: event.total
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const result = await this.loadSingleModel(modelUrl, handleProgress);
|
||||
|
||||
if (result.success) {
|
||||
EventBridge.modelLoaded({ urls: [modelUrl] });
|
||||
} else {
|
||||
EventBridge.modelLoadError({ url: modelUrl, error: result.error });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换模型:销毁旧模型并加载新模型
|
||||
* @param modelName 要替换的模型名称
|
||||
* @param newModelUrl 新模型的URL路径
|
||||
*/
|
||||
async replaceModel(modelName: string, newModelUrl: string): Promise<LoadResult> {
|
||||
// 先销毁旧模型
|
||||
this.destroyModel(modelName);
|
||||
|
||||
// 加载新模型
|
||||
return await this.addModel(newModelUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁指定模型
|
||||
* @param modelName 模型名称
|
||||
|
||||
@ -41,7 +41,7 @@ export class EventBridge {
|
||||
|
||||
// Listeners
|
||||
static onModelLoadProgress(callback: (payload: ModelLoadProgressPayload) => void, context?: unknown): Emitter {
|
||||
return on("model:load:progress", callback, context);
|
||||
return on("model:load:progress", callback, context);
|
||||
}
|
||||
|
||||
static onModelLoadError(callback: (payload: ModelLoadErrorPayload) => void, context?: unknown): Emitter {
|
||||
@ -59,14 +59,14 @@ export class EventBridge {
|
||||
static onSceneReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
|
||||
return on("scene:ready", callback, context);
|
||||
}
|
||||
static onAllReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
|
||||
static onAllReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
|
||||
return on("all:ready", callback, context);
|
||||
}
|
||||
static onHotspotClick(callback: (payload: HotspotClickPayload) => void, context?: unknown): Emitter {
|
||||
return on("hotspot:click", callback, context);
|
||||
}
|
||||
static onceSceneReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
|
||||
return once("scene:ready", callback, context);
|
||||
return once("scene:ready", callback, context);
|
||||
}
|
||||
|
||||
static off(eventName?: string, callback?: (...args: unknown[]) => void): Emitter {
|
||||
|
||||
@ -48,12 +48,12 @@ class HotSpot {
|
||||
Point_Event(prams: HotspotPrams) {
|
||||
const iconPath = prams.icon
|
||||
|
||||
|
||||
// 为每个热点创建独立的材质
|
||||
const texture = new Texture(iconPath, this.mainApp.appScene.object)
|
||||
texture.hasAlpha = true
|
||||
texture.getAlphaFromRGB = false
|
||||
|
||||
|
||||
const material = new StandardMaterial(`hotspotMaterial_${Math.random()}`, this.mainApp.appScene.object)
|
||||
material.diffuseTexture = texture
|
||||
material.emissiveTexture = texture
|
||||
@ -62,17 +62,12 @@ class HotSpot {
|
||||
material.transparencyMode = 2 // ALPHABLEND 模式
|
||||
material.disableLighting = true
|
||||
material.backFaceCulling = false
|
||||
|
||||
|
||||
// 检查纹理是否已加载
|
||||
if (texture.isReady()) {
|
||||
// 纹理已准备好,立即创建热点
|
||||
this.createPointPlane(prams, material)
|
||||
} else {
|
||||
// 纹理未准备好,等待加载完成
|
||||
texture.onLoadObservable.addOnce(() => {
|
||||
|
||||
this.createPointPlane(prams, material)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 创建点平面的具体实现
|
||||
|
||||
@ -14,10 +14,26 @@ export class KernelAdapter {
|
||||
/** 模型管理 */
|
||||
model = {
|
||||
/**
|
||||
* 销毁指定模<EFBFBD>? * @param modelName 模型名称
|
||||
* 添加模型到场景
|
||||
* @param modelUrl 模型URL路径
|
||||
*/
|
||||
add: async (modelUrl: string): Promise<void> => {
|
||||
await this.mainApp.appModel.addModel(modelUrl);
|
||||
},
|
||||
/**
|
||||
* 销毁指定模型
|
||||
* @param modelName 模型名称
|
||||
*/
|
||||
destroy: (modelName: string): void => {
|
||||
this.mainApp.appModel.destroyModel(modelName);
|
||||
},
|
||||
/**
|
||||
* 替换模型
|
||||
* @param modelName 要替换的模型名称
|
||||
* @param newModelUrl 新模型的URL路径
|
||||
*/
|
||||
replace: async (modelName: string, newModelUrl: string): Promise<void> => {
|
||||
await this.mainApp.appModel.replaceModel(modelName, newModelUrl);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user