首次进入页面加载时白屏状态。下载完模型后才恢复正常。
<kivicube-scene
wx:if="{{sceneShow}}"
class="kivicube"
scene-id="{{sceneId}}"
camera-position="{{cameraPosition}}"
bindready="ready"
binderror="error"
binddownloadAssetStart="downloadStart"
binddownloadAssetProgress="downloadProgress"
binddownloadAssetEnd="downloadEnd"
bindloadSceneStart="loadStart"
bindloadSceneEnd="loadEnd"
bindsceneStart="sceneStart"
bindopenUrl="openUrl"
bindphoto="photo"
/>
onLoad: function (options) {
let id = options.id;
this.setData({
sceneId: id
});
// 开始加载状态
this.setData({ isLoading: true });
downloadSceneAsset(this.data.sceneId, (progress) => {
console.log("progress", progress);
}).then(() => {
this.setData({ isLoading: false, isSceneReady: true }); // 下载完成,更新状态
}).catch((error) => {
this.setData({ isLoading: false, isSceneReady: false }); // 下载失败,更新状态
});
},
ready({ detail }) {
console.log("当前场景基础信息", detail);
if (detail && detail.sceneInfo) {
this.scene = detail.sceneInfo; // 确保正确获取场景实例
}
},
downloadStart() {},
downloadProgress() {},
downloadEnd() {
this.setData({
isSceneReady: true // 下载完成后设置场景准备好
});
},
sceneStart() {
wx.showToast({
title: "可开始体验场景",
icon: "none"
});
},
photo({ detail: photoPath }) {
wx.showLoading({
title: "拍照中",
mask: true,
});
wx.saveImageToPhotosAlbum({
filePath: photoPath,
success() {
wx.hideLoading();
console.log("保存照片成功");
},
fail(e) {
wx.hideLoading();
console.error("保存照片失败", e);
},
});
},
onUnload() {},