|
@@ -40,15 +40,14 @@ function A1home() {
|
|
|
// 获取地址栏参数
|
|
|
const fileName = window.location.href.split('?m=')[1]
|
|
|
|
|
|
- if (!fileName) return alert('参数错误')
|
|
|
-
|
|
|
const rgbeLoader = new RGBELoader().setPath('./modelFile/')
|
|
|
|
|
|
const usdzLoader = new USDZLoader1().setPath('./modelFile/')
|
|
|
|
|
|
let textureProgress = 0,
|
|
|
modelProgress = 0
|
|
|
- try {
|
|
|
+
|
|
|
+ if (fileName.endsWith('.usdz')) {
|
|
|
camera.current.position.set(0, 0.75, -3.5)
|
|
|
|
|
|
// 加载资源(改用回调形式)
|
|
@@ -98,9 +97,8 @@ function A1home() {
|
|
|
model.position.y = 0.25
|
|
|
model.position.z = -0.25
|
|
|
scene.current.add(model)
|
|
|
- } catch (error) {
|
|
|
- console.log(123, error)
|
|
|
- if (1 + 1 === 2) return
|
|
|
+ } else if (fileName.endsWith('.glb')) {
|
|
|
+ // if (1 + 1 === 2) return
|
|
|
console.log('usdz是二进制,转成glb格式')
|
|
|
|
|
|
camera.current.position.set(0, 0.75, 0.75)
|
|
@@ -117,14 +115,16 @@ function A1home() {
|
|
|
// 加载管理器与进度处理
|
|
|
const loadingManager = new THREE.LoadingManager()
|
|
|
loadingManager.onProgress = (url, loaded, total) => {
|
|
|
- setLoding((loaded / total) * 100)
|
|
|
+ if ((loaded / total) * 100 >= 100) {
|
|
|
+ setLoding((loaded / total) * 100)
|
|
|
+ }
|
|
|
}
|
|
|
loadingManager.onLoad = () => {}
|
|
|
|
|
|
// 加载GLB模型
|
|
|
const loader = new GLTFLoader(loadingManager)
|
|
|
loader.load(
|
|
|
- `./modelFile/${fileName.replace('usdz', 'glb')}`,
|
|
|
+ `./modelFile/${fileName}`,
|
|
|
(gltf: any) => {
|
|
|
const model = gltf.scene
|
|
|
scene.current.add(model)
|
|
@@ -148,7 +148,7 @@ function A1home() {
|
|
|
// (xhr: any) => console.log('加载进度:', xhr.loaded / xhr.total),
|
|
|
// (error: any) => console.error('加载失败:', error)
|
|
|
)
|
|
|
- }
|
|
|
+ } else alert('参数错误')
|
|
|
|
|
|
// renderer
|
|
|
|