微信小程序 webview引入three 3d切换场景,ios手机出现闪屏刷新问题

1. 运行环境

  1. 微信小程序 webview 引入three 3D
  2. IOS 手机

2. 问题描述?

使用微信小程序webview 切换 three.js 切换场景的时候出现闪屏刷新的问题,但是在 ios 手机的 safari 游览器可以正常切换。

问题:

  1. 为啥不用threex
    1. 动画里面的灯光、雾、还有动作那些老出现白屏,才用的原生;
    2. 一个场景最低的内存都在 60 MB 左右
  2. 在一个页面切换场景的时候,清除了内存占用

3. 您期望得到的结果?

使用微信小程序webview 可以正确切换 three.js 场景,大佬们有没有解决方案。

4. 代码贴图

在切换场景的时候清除占用内存

onhashchange = async()=>{
    /**
     * ios废置场景对象
     */
    if(model){
        model.traverse(child=>{
            if(child.isMesh){
                child.geometry.dispose();
                if(child.material.isMaterial){
                    if(child.material.map){
                        child.material.map.dispose();
                    }
                    if(child.material.lightMap){
                        child.material.lightMap.dispose();
                    }
                    if(child.material.bumpMap){
                        child.material.bumpMap.dispose();
                    }
                    if(child.material.normalMap){
                        child.material.normalMap.dispose();
                    }
                    if(child.material.specularMap){
                        child.material.specularMap.dispose();
                    }
                }else{
                    for(const material of child.material){
                        if(material.map){
                            material.map.dispose();
                        }
                        if(material.lightMap){
                            material.lightMap.dispose();
                        }
                        if(material.bumpMap){
                            material.bumpMap.dispose();
                        }
                        if(material.normalMap){
                            material.normalMap.dispose();
                        }
                        if(material.specularMap){
                            material.specularMap.dispose();
                        }
                    }
                }
            }
        });
        scene.remove(model);
        model = null;
        thisGltf = null;
    }
    if(arr.length > 0){
        await removeRole(arr);
        arr = [];
        bird1 = null;
        bird2 = null;
        bird3 = null;
        bird4 = null;
        bird5 = null;
        qqgGongNv1 = null;
        qqgGongNv2 = null;
        qqgGongNv3 = null;
        qqgTaijian1 = null;
        qqgTaijian2 = null;
        qqgTaijian3 = null;
        qqgTaijian4 = null;
        taijianBlue = null;
    }
//    paiziAnmationAppear("zhongzhouxian",thisGltf.animations,false,0);
//    paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,true);
//    bird1.mixer.timeScale = 1;
//    bird2.mixer.timeScale = 1;
//    bird3.mixer.timeScale = 1;
//    bird4.mixer.timeScale = 1;
//    await addRole([ bird1.scene,bird2.scene,bird3.scene,bird4.scene, ]);
//    await visibleRole([ bird1.scene,bird2.scene,bird3.scene,bird4.scene, ],true);
//    bird1.action.get("hunagying_daiji").play();
//    bird2.action.get("hunagying_daiji").play();
//    bird3.action.get("hunagying_daiji").play();
//    bird4.action.get("hunagying_daiji").play();
    dispatchEvent(new CustomEvent("loadingEnd"));
    if(!(location.hash === "#taihedian" || location.hash === "#qianchaosandadian" || location.hash === "#damingjianzhuqun")){
        iconHide();
        sddBack = false;
    }
    btn.visible = false;
    btn2.visible = false;
    guidePicture = 0;
    guideBtnplay = false;
    btnPlayAnimation = true;
    btnPictureAnimation = true;
    cancelAnimationFrame($touchend);
    cancelAnimationFrame($touchendBack);
//    cancelAnimationFrame($touchend);
    npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
    npc.action.stop();
    npc.action.get(`${ role }_daiji`).play(); //girl_daiji
    // 切换场景
    guide.material.map = await textureLoader(`/assets/guide.png`);//jshint ignore:line
    await sceneToggle(location.hash.replace("#",""));
};

所有的代码

//jshint -W117
import { mixer,Role } from "/class/Role.js";
import { outlinePass, } from "/object/composer.js";
//import { place } from "/object/palace/index.js";
import { directionalLight,FOG,scene,skybox,skyGeometryBox } from "/object/scene.js";
import { iconHide } from "/ui/bc.js";
import { vrHide,vrShow } from "/ui/btn.js";
import { AnimationClip,AnimationMixer,LinearFilter,LoopOnce,Mesh,MeshBasicMaterial,PlaneGeometry,Quaternion,Sprite,Vector3} from "three";
import { camera,CAMERA_ROTATION } from "./camera.js";
import { textureLoader,gltfLoader } from "./loader.js";
//import { bird1,bird2,bird3,bird4,bird5,dacheng1,dacheng2,dacheng3,dacheng4,dacheng5,dacheng6,npc,qqgGongNv1,qqgGongNv2,qqgGongNv3,qqgTaijian1,qqgTaijian2,qqgTaijian3,qqgTaijian4,sddTaijian1,sddTaijian2,sddTaijian3,sddTaijian4,taijian,taijian2,taijian3,taijian4,taijian5,taijian6,taijianBlue,taijianBlue1,taijianBlue2,taijianBlue3,taijianBlue4,taijianBlue5,taijianBlue6,taijianBlue7,taijianBlue8,taishanghuang,yongzheng,yxdTaijian,yxdtaijianBlue } from "./role/index.js";
//import { bird1,bird2,bird3,bird4,bird5,npc,yongzheng,yxdTaijian,yxdtaijianBlue } from "./role/index.js";
import { addRole,kaimenAnimation,paiziAnmationAppear,paiziAnmationDisappear,removeRole,visibleRole } from "./roleAnimation.js";
let bird1,bird2,bird3,bird4,bird5,dacheng1,dacheng2,dacheng3,dacheng4,dacheng5,dacheng6,qqgGongNv1,qqgGongNv2,qqgGongNv3,qqgTaijian1,qqgTaijian2,qqgTaijian3,qqgTaijian4,sddTaijian1,sddTaijian2,sddTaijian3,sddTaijian4,taijian,taijian2,taijian3,taijian4,taijian5,taijian6,taijianBlue,taijianBlue1,taijianBlue2,taijianBlue3,taijianBlue4,taijianBlue5,taijianBlue6,taijianBlue7,taijianBlue8,taishanghuang,yongzheng,yxdTaijian,yxdtaijianBlue;
let arr = [];
const role = new URL(location).searchParams.get("role");
export const npc = await Role.load("npc",`/assets/xr/${ role }.glb`);//jshint ignore:line
npc.scene.traverse(child=>{
    if(child.isMesh){
        //颜色
//        child.material.color = new Color(0xffe6cc);
//        //光照贴图
//        child.material.lightMap = lightMap;
//        //环境贴图
//        child.material.envMap = envMap;
        //粗糙度
//        child.material.roughness = 0.75;
        //产生阴影
        child.castShadow = true;
        child.minFilter = LinearFilter;
        child.magFilter = LinearFilter;
    }
});
for(const clip of npc.animations){
    const { name } = clip;
    npc.action.set(name,npc.mixer.clipAction(clip));
}
switch(role){
    case "boy":
        npc.action.get("boy_daiji").play();
        break;
    case "girl":
        npc.action.get("girl_daiji").play();
        break;
}
npc.scene.lookAt(camera.position);
npc.mixer.timeScale = 1;
scene.add(npc.scene);

export const data = {
    camera:{
        position:new Vector3(),
    },
};
scene.fog = FOG;
npc.mixer.timeScale = 1;
let model,thisGltf,sddBack = false,audioBgFlag = false;
export let chuxianAction,xiaoshiAction,btnPictureAnimation = false,btnPlayAnimation = false,npcbtnPlayPositionTo,$touchend,flag = false,$touchendBack,npcBackAniamtion,$audioLoop,time = 0,guidePicture = 0,guideBtnplay = 1;
let btnScalX,btnScalY,btnScalZ,btnPositionX,btnPositionY,btnPositionZ,btn2PositionX,btn2PositionY,btn2PositionZ;
const guideX = 0.4,guideY = 2,guideZ = -1;
//介绍
const geometry1 = new PlaneGeometry(1,1);
const map1 = await textureLoader(`/assets/vrbtn.png`);//jshint ignore:line
const material1 = new MeshBasicMaterial({ map:map1,transparent:true, });
export const btn = new Mesh(geometry1,material1);
btn.name = "btn";
scene.add(btn);
//宫殿全貌
const geometry2 = new PlaneGeometry(1,1);
const map2 = await textureLoader(`/assets/btn-picture.png`);//jshint ignore:line
const material2 = new MeshBasicMaterial({ map:map2,transparent:true, });
export const btn2 = new Mesh(geometry2,material2);
btn2.name = "btn2";
scene.add(btn2);
if(location.hash === "#yangxindian"){
    btn.visible = false;
    btn2.visible = false;
}
//const btn2 = new Sprite();
//指引0
export const guide = new Sprite();
guide.material.map = await textureLoader(`/assets/guide.png`);//jshint ignore:line
guide.visible = true;
guide.name = " guide";
guide.scale.set(1,0.2,1);
scene.add(guide);
/**
 * 音频播放
 */
const audioGuide = new Audio();
export async function guideAudio(src,sddFlag){
    audio.pause();
    audioGuide.src = src;
    await audioGuide.play();
    if(sddFlag && (location.hash === "#taihedian" || location.hash === "#qianchaosandadian" || location.hash === "#damingjianzhuqun")){
        audioBgFlag = false;
        requestAnimationFrame(function loop(){
            if(audioGuide.currentTime === audioGuide.duration){
                dispatchEvent(new CustomEvent("fingerBack"));
                cancelAnimationFrame($audioLoop);
            }else{
                $audioLoop = requestAnimationFrame(loop);
            }
        });
    }
}
audioGuide.addEventListener("ended",async()=>{
    //介绍音频播放完毕 播放背景音
    audio.src = '/assets/audio/audio_bg.mp3';
    audio.loop = true;
    await audio.play();
    audioBgFlag = true;
})
/**
 * 监听变化
 * @returns {Promise<void>}
 */
onhashchange = async()=>{
    /**
     * ios废置场景对象
     */
    if(model){
        model.traverse(child=>{
            if(child.isMesh){
                child.geometry.dispose();
                if(child.material.isMaterial){
                    if(child.material.map){
                        child.material.map.dispose();
                    }
                    if(child.material.lightMap){
                        child.material.lightMap.dispose();
                    }
                    if(child.material.bumpMap){
                        child.material.bumpMap.dispose();
                    }
                    if(child.material.normalMap){
                        child.material.normalMap.dispose();
                    }
                    if(child.material.specularMap){
                        child.material.specularMap.dispose();
                    }
                }else{
                    for(const material of child.material){
                        if(material.map){
                            material.map.dispose();
                        }
                        if(material.lightMap){
                            material.lightMap.dispose();
                        }
                        if(material.bumpMap){
                            material.bumpMap.dispose();
                        }
                        if(material.normalMap){
                            material.normalMap.dispose();
                        }
                        if(material.specularMap){
                            material.specularMap.dispose();
                        }
                    }
                }
            }
        });
        scene.remove(model);
        model = null;
        thisGltf = null;
    }
    if(arr.length > 0){
        await removeRole(arr);
        arr = [];
        bird1 = null;
        bird2 = null;
        bird3 = null;
        bird4 = null;
        bird5 = null;
        qqgGongNv1 = null;
        qqgGongNv2 = null;
        qqgGongNv3 = null;
        qqgTaijian1 = null;
        qqgTaijian2 = null;
        qqgTaijian3 = null;
        qqgTaijian4 = null;
        taijianBlue = null;
    }
//    paiziAnmationAppear("zhongzhouxian",thisGltf.animations,false,0);
//    paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,true);
//    bird1.mixer.timeScale = 1;
//    bird2.mixer.timeScale = 1;
//    bird3.mixer.timeScale = 1;
//    bird4.mixer.timeScale = 1;
//    await addRole([ bird1.scene,bird2.scene,bird3.scene,bird4.scene, ]);
//    await visibleRole([ bird1.scene,bird2.scene,bird3.scene,bird4.scene, ],true);
//    bird1.action.get("hunagying_daiji").play();
//    bird2.action.get("hunagying_daiji").play();
//    bird3.action.get("hunagying_daiji").play();
//    bird4.action.get("hunagying_daiji").play();
    dispatchEvent(new CustomEvent("loadingEnd"));
    if(!(location.hash === "#taihedian" || location.hash === "#qianchaosandadian" || location.hash === "#damingjianzhuqun")){
        iconHide();
        sddBack = false;
    }
    btn.visible = false;
    btn2.visible = false;
    guidePicture = 0;
    guideBtnplay = false;
    btnPlayAnimation = true;
    btnPictureAnimation = true;
    cancelAnimationFrame($touchend);
    cancelAnimationFrame($touchendBack);
//    cancelAnimationFrame($touchend);
    npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
    npc.action.stop();
    npc.action.get(`${ role }_daiji`).play(); //girl_daiji
    // 切换场景
    guide.material.map = await textureLoader(`/assets/guide.png`);//jshint ignore:line
    await sceneToggle(location.hash.replace("#",""));
};

function startsWithSpecificLetters(str,specificLetters){
    // 获取字符串的前几个字符
    const prefix = str.substring(0,specificLetters.length);
    // 检查前缀是否等于特定的字母
    return prefix === specificLetters;
}
/**
 * 宫殿出现动画
 * @param key
 * @param model
 * @param gltfAnimation
 * @param play
 * @constructor
 */
async function appearAnimation(key,model,gltfAnimation,play){
    mixer.set(key,new AnimationMixer(model));
    gltfAnimation.forEach(animate=>{
        const name = animate.name;
        const array = name.split("_");
        if(name.includes("chuxian") && !name.includes("paizi")){
            chuxianAction = mixer.get(key).clipAction(animate);
            chuxianAction.clampWhenFinished = true;
            chuxianAction.loop = LoopOnce;
            if(play){
                chuxianAction.play();
            }else{
                chuxianAction.stop();
            }
        }
    });
}
/**
 * 相机移动函数
 */

async function move(position,rotation,npcFlag,ordinary,src){
    if(location.hash === "#taihedian" || location.hash === "#qianchaosandadian" || location.hash === "#damingjianzhuqun" || location.hash === "#liugong"){
        time += 0.06;
    }else{
        if(!audioBgFlag){
            time = audio.paused?time + 0.06:audio.currentTime / audio.duration;
        }
        if(ordinary){
            time += 0.06;
        }
    }
//    time += 0.06; //new
    const { start:sp,end:ep } = position,{ start:sr,end:er } = rotation;
    camera.position.copy(new Vector3().lerpVectors(sp,ep,time));
    camera.quaternion.copy(new Quaternion().slerpQuaternions(sr,er,time));
    if(time < 1){
        move.$ = requestAnimationFrame(move.bind(this,position,rotation,npcFlag,ordinary,src));
    }else{
        camera.position.copy(ep);
        time = 0;
        //new
//        if(src && !npcFlag){
//            console.log(src);
//            audio.pause();
//            audioBgFlag = false;
//            audioGuide.src = "";
//            audio.loop = false;
//            audio.src = src;
//            await audio.play();
//            let time =setInterval(()=>{
//                console.log("setInterval",audio.duration,audio.currentTime);
//                if(audio.paused){
//                    dispatchEvent(new CustomEvent("indrouceEnd"));
//                    console.log("audio paused");
//                    audio.src = '/assets/audio/audio_bg.mp3';
//                    audio.loop = true;
//                    audio.play();
//                    audioBgFlag = true;
//                    clearInterval(time);
//                }
//            });
//        }
        if(!audioBgFlag){
            audio.src = '/assets/audio/audio_bg.mp3';
            audio.loop = true;
            await audio.play();
            audioBgFlag = true;
        }
        if(sddBack){
            iconHide();
        }
    }
}
export async function moveTo(position,rotation,npcFlag,ordinary,src){
    move({
        start:camera.position.clone(),end:position.clone(),
    },{
        start:camera.quaternion.clone(),end:new Quaternion().setFromEuler(rotation),
    },npcFlag,ordinary,src);
    if(npcFlag){
        await npcIndrouceAnimation(1,`${ role }_daiji`,src);
    }
}
/**
 * 宫殿介绍动画
 */
function npcIndrouceAnimation(speed,npcAction,src){
    const npcPosition = npc.scene.position.clone();
    let $npcAniamtion,offset,i = 0;
    npc.mixer.timeScale = 2;
    npc.action.stop();
    npc.action.get(`${ role }_zhuanshen`).clampWhenFinished = true;
    npc.action.get(`${ role }_zhuanshen`).loop = LoopOnce;
    npc.action.get(`${ role }_zhuanshen`).play();
    requestAnimationFrame(function loop(){
        if(npc.action.get(`${ role }_zhuanshen`)._clip.duration === npc.action.get(`${ role }_zhuanshen`).time){
            npc.mixer.timeScale = 1;
            npc.action.stop();
            npc.action.get(`${ role }_zoulu`).play();
            npc.scene.lookAt(npcbtnPlayPositionTo);
            cancelAnimationFrame($npcAniamtion);
            offset = 0.06 / npcPosition.distanceTo(npcbtnPlayPositionTo) / speed;
            cancelAnimationFrame($touchend);
            requestAnimationFrame(function loop(){
                npc.scene.position.copy(new Vector3().lerpVectors(npcPosition,npcbtnPlayPositionTo,i));
                i += offset;
                if(i < 1){
                    $touchend = requestAnimationFrame(loop);
                }else{
                    npc.action.stop();
                    npc.action.get(`${ role }_zhuanshen`).clampWhenFinished = true;
                    npc.action.get(`${ role }_zhuanshen`).loop = LoopOnce;
                    npc.action.get(`${ role }_zhuanshen`).play();
                    requestAnimationFrame(function loop(){
                        if(npc.action.get(`${ role }_zhuanshen`)._clip.duration === npc.action.get(`${ role }_zhuanshen`).time){
                            npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
                            npc.action.stop();
                            npc.action.get(npcAction).play();
                            npc.action.get(npcAction).clampWhenFinished = true;
                            npc.action.get(npcAction).loop = LoopOnce;
                            cancelAnimationFrame($npcAniamtion);
                            //new
//                            if(src){
//                                console.log(src);
//                                audio.pause();
//                                audioBgFlag = false;
//                                audioGuide.src = "";
//                                audio.src = src;
//                                audio.loop = false;
//                                audio.play();
//                                npc.action.stop();
//                                npc.action.get(`${ role }_xiangyoujieshao`).clampWhenFinished = true;
//                                npc.action.get(`${ role }_xiangyoujieshao`).loop = true;
//                                npc.action.get(`${ role }_xiangyoujieshao`).play();
//                                let time= setInterval(()=>{
//                                    console.log("setInterval",audio.duration,audio.currentTime);
//                                    if(audio.paused){
//                                        dispatchEvent(new CustomEvent("indrouceEnd"));
//                                        npc.action.get(`${ role }_xiangyoujieshao`).loop = false;
//                                        npc.action.stop();
//                                        npc.action.get(`${ role }_daiji`).play();
//                                        console.log("audio paused");
//                                        audio.src = '/assets/audio/audio_bg.mp3';
//                                        audio.loop = true;
//                                        audio.play();
//                                        audioBgFlag = true;
//                                        clearInterval(time);
//                                    }
//                                });
//                            }
                        }else{
                            $npcAniamtion = requestAnimationFrame(loop);
                        }
                    });
                }
            });
        }else{
            $npcAniamtion = requestAnimationFrame(loop);
        }
    });
}
/**
 * 宫殿介绍
 * @param src
 * @returns {Promise<void>}
 */
export async function btnPlay(src){
    audio.pause(); //old
    audioBgFlag = false; //old
    audioGuide.src = ""; //old
    vrShow();
    btnPictureAnimation = false;
    btnPlayAnimation = true;
    cancelAnimationFrame($touchendBack);
    cancelAnimationFrame(npcBackAniamtion);
    guide.visible = false;
    flag = true;
    audio.src = src; //old
    await audio.play(); //old
    if(location.hash === "#yangxindian" && guideBtnplay){
        guideBtnplay = false;
        guidePicture = true;
        guide.material.map = await textureLoader(`/assets/picture-guide.png`);//jshint ignore:line
    }
    let arr = [];
    switch(location.hash){
        case "#liugong":
            moveTo(new Vector3(0,150,100),camera.rotation.set(-0.9,0,0),false,"",src);
            break;
        case "#shouhuangdian":
            npc.action.stop();
            const action = npc.action.get(`${ role }_xiangyoujieshao`);
            action.clampWhenFinished = true;
            action.loop = LoopOnce;
            action.play();
            npcbtnPlayPositionTo = new Vector3(0.7,npc.scene.position.y,1);
            moveTo(new Vector3(0,2.5,5.5),camera.rotation.set(0.1,0,0),true,"",src);
//            npcIndrouceAnimation(1,"girl_daiji");
            break;
        case "#yangxindian":
            arr = [
                yxdtaijianBlue.scene,yongzheng.scene,yxdTaijian.scene,
            ];
            await visibleRole(arr,true);
            npcbtnPlayPositionTo = new Vector3(1,npc.scene.position.y,1);
            moveTo(new Vector3(0,1.25,3),CAMERA_ROTATION,true,"",src);
//            npcIndrouceAnimation(1,"girl_daiji");
            break;
        case "#huangjidian":
            arr = [
                taijianBlue1.scene,taijianBlue2.scene,
                taijian.scene,taijian2.scene,
                dacheng1.scene,dacheng2.scene,dacheng3.scene,dacheng4.scene,dacheng5.scene,dacheng6.scene,
                taishanghuang.scene,
            ];
            await visibleRole(arr,true);
            npcbtnPlayPositionTo = new Vector3(1.3,npc.scene.position.y,-13);
            moveTo(new Vector3(0,4,-6),camera.rotation.set(0.2,-0.05,0),true,"",src);
//            npcIndrouceAnimation(0.5,"girl_daiji");
            kaimenAnimation("zhongzhouxian",thisGltf.animations,true,taijian,taijian2,dacheng1,"zoulu","qishen","pingyi",0,2.3,-22.5,1.5,taishanghuang,"pingshen");
            break;
        case "#qianqinggong":
            arr = [
                taijianBlue.scene,
                qqgTaijian1.scene,qqgTaijian2.scene,qqgTaijian3.scene,qqgTaijian4.scene,taijian3.scene,taijian4.scene,
            ];
            await visibleRole(arr,true);
            bird5.scene.visible = false;
            npcbtnPlayPositionTo = new Vector3(1,npc.scene.position.y,22);
            moveTo(new Vector3(0,3,25.5),CAMERA_ROTATION,true,"",src);
//            npcIndrouceAnimation(1,"girl_daiji");
            break;
        default:
    }
}
/**
 * 宫殿全貌动画
 */
export async function btnPicture(cameraRoationY,cameraRoationX,cameraRoationZ,moveX,moveY,moveZ,key){
    scene.background = null;
    scene.add(skyGeometryBox);
    switch(key){
        case "qianqinggong":
            await visibleRole([ qqgTaijian3.scene,qqgTaijian4.scene,qqgGongNv1.scene,qqgGongNv2.scene,qqgGongNv3.scene, ],true);
            break;
        case "huangjidian":
            await visibleRole([ taijianBlue1.scene,taijianBlue2.scene,taijian.scene,taijian2.scene, ],true);
            break;
        case "liugong":
            scene.fog = null;
            break;
    }
    btnPictureAnimation = true;
    btnPlayAnimation = false;
    guide.visible = false;
    flag = true;
    vrShow();
    camera.rotation.y = cameraRoationY;
    camera.rotation.x = cameraRoationX;
    camera.rotation.z = cameraRoationZ;
    await moveTo(new Vector3(moveX,moveY,moveZ),camera.rotation,"",true);
//    paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,false);
//    paiziAnmationAppear("zhongzhouxian",thisGltf.animations,true,100);
}
/**
 * 三大殿介绍后期处理
 */
let qingFlag = false,sddKey = null,sddSrc;
let passInterval,passTimeout;
function sddComposer(selectedChild){
    if(passInterval){
        clearInterval(passInterval);
    }
    if(passTimeout){
        clearTimeout(passTimeout);
    }
    outlinePass.selectedObjects = [];
    if(selectedChild === []){
        return;
    }
    let i = 0;
    setTimeout(()=>{
        passInterval = setInterval(()=>{
            i += 1;
            outlinePass.selectedObjects = selectedChild;
            if(i > 2){
                clearInterval(passInterval);
                clearTimeout(passTimeout);
                return;
            }
            passTimeout = setTimeout(()=>{
                outlinePass.selectedObjects = [];
            },500);
        },1000);
    },1000);
}
/**
 * 三大殿介绍切换宫殿动画
 */
async function sddModelAnimation(targetKey,src){
    scene.background = null;
    scene.add(skyGeometryBox);
    location.hash = `#${ targetKey }`;
    let targetKeyValue,arr = [ sddTaijian1.scene,sddTaijian2.scene,sddTaijian3.scene,sddTaijian4.scene, ];
    switch(targetKey){
        case "taihedian":
            targetKeyValue = "taihedian01";
            await visibleRole(arr,true);
            break;
        case "qianchaosandadian":
            targetKeyValue = "qianchaosandadian";
            await visibleRole(arr,false);
            break;
        case "damingjianzhuqun":
            targetKeyValue = "damingdian";
            await visibleRole(arr,false);
            break;
    }
    audioGuide.src = "";
    sddBack = false;
    guide.visible = false;
    const selectedChild = [];
    flag = true;
    vrShow();
    await moveTo(new Vector3(73,20,-17.5),camera.rotation.set(-0.02,1.3,0),"",true);
    await guideAudio(src,true);
    if(targetKeyValue === "taihedian01" && !qingFlag){
        model.position.set(-5,0,0);
        thisGltf.scenes[0].children.forEach(i=>{
            if(i.name === targetKeyValue){
                i.children.forEach(i=>{
                    if(i.name === "taihedian" || i.name === "zhonghedian" || i.name === "baohedian" || i.name === "houqiang" || i.name === "zhongqiang"){
                        selectedChild.push(i);
                    }
                });
            }
        });
        qingFlag = true;
        sddKey = targetKeyValue;
        sddComposer(selectedChild);
        paiziAnmationAppear("zhongzhouxian",thisGltf.animations,true,100);
        return;
    }
    qingFlag = true;
    if(sddKey === targetKeyValue){
        thisGltf.scenes[0].children.forEach(i=>{
            if(i.name === sddKey){
                i.visible = true;
            }
        });
    }else{
        if(sddKey){
            thisGltf.scenes[0].children.forEach(i=>{
                if(i.name === sddKey){
                    i.visible = false;
                }
                if(i.name === targetKeyValue){
                    i.visible = true;
                }
            });
        }
        if(model){
            scene.remove(model);
            model = null;
        }
        const gltf = place[0].gltf;
        thisGltf = gltf;
        model = gltf.scene;
        scene.add(model);
        await appearAnimation("zhongzhouxian",model,gltf.animations,true);
        paiziAnmationAppear("zhongzhouxian",thisGltf.animations,true,100);
        thisGltf.scenes[0].children.forEach(i=>i.visible = i.name === targetKeyValue);
        if(targetKeyValue === "taihedian01"){
            model.position.set(-5,0,0);
        }
        if(targetKeyValue === "qianchaosandadian"){
            model.position.set(-10,0,-40);
        }
        if(targetKeyValue === "damingdian"){
            model.position.set(-10,0,-27);
        }
        sddKey = targetKeyValue;
    }
    if(targetKeyValue === "taihedian01"){
        thisGltf.scenes[0].children.forEach(i=>{
            if(i.name === "taihedian01"){
                i.children.forEach(i=>{
                    if(i.name === "taihedian" || i.name === "zhonghedian" || i.name === "baohedian" || i.name === "houqiang" || i.name === "zhongqiang"){
                        selectedChild.push(i);
                    }
                });
            }
        });
    }
    if(targetKeyValue === "qianchaosandadian"){
        thisGltf.scenes[0].children.forEach(i=>{
            if(i.name === "qianchaosandadian"){
                i.children.forEach(i=>{
                    if(i.name === "fengtiandian" || i.name === "huagaidian" || i.name === "jinshendian"){
                        selectedChild.push(i);
                    }
                });
            }
        });
    }
    if(targetKeyValue === "damingdian"){
        thisGltf.scenes[0].children.forEach(i=>{
            if(i.name === "damingdian"){
                i.children.forEach(i=>{
                    if(i.name === "qiandian" || i.name === "zhongdian" || i.name === "houdian"){
                        selectedChild.push(i);
                    }
                });
            }
        });
    }
    sddComposer(selectedChild);
}
/**
 * 三大殿介绍切换宫殿动画监听
 */
addEventListener("qing",async()=>{
    FOG.far = 500;
    sddSrc = `/assets/xr/audio/${ role }/qing.wav`;
    await sddModelAnimation("taihedian",sddSrc);
});
addEventListener("ming",async()=>{
    FOG.far = 480;
    sddSrc = `/assets/xr/audio/${ role }/ming.wav`;
    await sddModelAnimation("qianchaosandadian",sddSrc);
});
addEventListener("yuan",async()=>{
    FOG.far = 480;
    sddSrc = `/assets/xr/audio/${ role }/yuan.wav`;
    await sddModelAnimation("damingjianzhuqun",sddSrc);
});
/**
 * 西六宫返回
 */
addEventListener("xiback",async()=>{
//    dispatchEvent(new CustomEvent("backVR")); //new
    scene.background = skybox;
    scene.remove(skyGeometryBox);
    cancelAnimationFrame($touchend);
    scene.fog = FOG;
    FOG.far = 150;
    flag = false;
    if(!audioBgFlag){
        audio.pause();
        audio.src = '/assets/audio/audio_bg.mp3';
        audio.loop = true;
        await audio.play();
        audioBgFlag = true;
    }
    audio.currentTime = 0;
    cancelAnimationFrame(move.$);
    vrHide();
    npc.scene.position.set(-110,0,-36);
    btn.position.set(-112,2.3,-38);//西六宫
    btn2.position.set(-110.5,2.3,-38);//西六宫
    moveTo(new Vector3(-111,2,-32),camera.rotation.set(0,0,0),"",true);
    btnScalX = 1.5;
    btnScalY = 0.5;
    btnScalZ = 0.5;
//    btnAnmationAppear(btn, btnScalX, btnScalY, btnScalZ);
//    btnAnmationAppear(btn2, btnScalX, btnScalY, btnScalZ);
    btn.visible = true;
    btn2.visible = true;
    if(btnPictureAnimation){
//        paiziAnmationAppear("zhongzhouxian",thisGltf.animations,false,0);
//        paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,true);
    }
});
/**
 * 东六宫返回
 */
addEventListener("dongback",async()=>{
//    dispatchEvent(new CustomEvent("backVR")); //new
    scene.background = skybox;
    scene.remove(skyGeometryBox);
    cancelAnimationFrame($touchend);
    scene.fog = FOG;
    FOG.far = 150;
    flag = false;
    if(!audioBgFlag){
        audio.pause();
        audio.src = '/assets/audio/audio_bg.mp3';
        audio.loop = true;
        await audio.play();
        audioBgFlag = true;
    }
    audio.currentTime = 0;
    cancelAnimationFrame(move.$);
    vrHide();
    npc.scene.position.set(112,0,-36);
    btn.position.set(110.5,2.3,-38);
    btn2.position.set(112,2.3,-38);
    await moveTo(new Vector3(111,2,-32),camera.rotation.set(0,0,0),"",true);
    btnScalX = 1.5;
    btnScalY = 0.5;
    btnScalZ = 0.5;
    btn.visible = true;
    btn2.visible = true;
    if(btnPictureAnimation){
//        paiziAnmationAppear("zhongzhouxian",thisGltf.animations,false,0);
//        paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,true);
    }
});
/**
 * npc返回VR动画
 * @param distance
 * @param npcPositionTo
 * @param speed
 */
function npcBackAnimation(distance,npcPositionTo,speed){
    const npcPosition = npc.scene.position.clone();
    if(npcPosition.distanceTo(npcbtnPlayPositionTo) < distance){
        npc.action.stop();
        npc.action.get(`${ role }_zoulu`).play();
        npc.scene.lookAt(npcPositionTo);
        let i = 0,offset = 0.06 / npcPosition.distanceTo(npcPositionTo) / speed;
        cancelAnimationFrame($touchendBack);
        requestAnimationFrame(function loop(){
            npc.scene.position.copy(new Vector3().lerpVectors(npcPosition,npcPositionTo,i));
            i += offset;
            if(i < 1){
                $touchendBack = requestAnimationFrame(loop);
            }else{
                vrHide();
                npc.action.stop();
                npc.action.get(`${ role }_daiji`).play();
                npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
                flag = false;
                if(location.hash === "#yangxindian" && guidePicture && time === 0){
                    guide.visible = true;
                    npc.action.stop();
                    npc.action.get(`${ role }_xiangyoujieshao`).loop = LoopOnce;
                    npc.action.get(`${ role }_xiangyoujieshao`).play();
//                    guideAudio("/assets/xr/audio/girl/yangxindian01.mp3", false);
                    guidePicture = false;
                }
            }
        });
    }else{
        npc.mixer.timeScale = 2;
        npc.action.stop();
        npc.action.get(`${ role }_zhuanshen`).clampWhenFinished = true;
        npc.action.get(`${ role }_zhuanshen`).loop = LoopOnce;
        npc.action.get(`${ role }_zhuanshen`).play();
        requestAnimationFrame(function loop(){
            if(npc.action.get(`${ role }_zhuanshen`)._clip.duration === npc.action.get(`${ role }_zhuanshen`).time){
                npc.action.stop();
                npc.action.get(`${ role }_zoulu`).play();
                npc.scene.lookAt(npcPositionTo);
                cancelAnimationFrame(npcBackAniamtion);
                npc.mixer.timeScale = 1;
                let i = 0,offset = 0.06 / npcPosition.distanceTo(npcPositionTo) / speed;
                cancelAnimationFrame($touchendBack);
                requestAnimationFrame(function loop(){
                    npc.scene.position.copy(new Vector3().lerpVectors(npcPosition,npcPositionTo,i));
                    i += offset;
                    if(i < 1){
                        $touchendBack = requestAnimationFrame(loop);
                    }else{
                        vrHide();
                        npc.action.stop();
                        npc.action.get(`${ role }_daiji`).play();
                        npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
                        flag = false;
                        if(location.hash === "#yangxindian" && guidePicture && time === 0){
                            guide.visible = true;
                            npc.action.stop();
                            npc.action.get(`${ role }_xiangyoujieshao`).play();
//                    guideAudio("/assets/xr/audio/girl/yangxindian01.mp3", false);
                            guidePicture = false;
                        }
                    }
                });
            }else{
                npcBackAniamtion = requestAnimationFrame(loop);
            }
        });
    }
}
/**
 * 返回VR
 */
addEventListener("back",async()=>{
//    dispatchEvent(new CustomEvent("backVR")); //new
    scene.background = skybox;
    scene.remove(skyGeometryBox);
    audioGuide.src = "";
    if(!btnPlayAnimation){
        flag = false;
        vrHide();
    }
    cancelAnimationFrame($touchend);
    if(!audioBgFlag){
        audio.pause();
        setTimeout(()=>{
            audio.src = '/assets/audio/audio_bg.mp3';
            audio.loop = true;
            audio.play();
            audioBgFlag = true;
        });
    }
    audio.currentTime = 0;
    cancelAnimationFrame(move.$);
    let npcPositionTo,key,arr = [];
    switch(location.hash){
        case "#shouhuangdian":
            npcPositionTo = new Vector3(4.5,0.3,7);
            key = "shouhuangdian";
            moveTo(new Vector3(4,2.5,12),camera.rotation.set(0.1,0.5,0),"",true);
            if(btnPlayAnimation){
                npcBackAnimation(0.023,npcPositionTo,1);
            }
            btnScalX = 3;
            btnScalY = 1;
            btnScalZ = 1;
            break;
        case "#yangxindian":
            npcPositionTo = new Vector3(2,0.1,5);
            moveTo(data.camera.position,CAMERA_ROTATION,"",true);
            if(btnPlayAnimation){
                npcBackAnimation(0.044,npcPositionTo,1);
            }
            arr = [
                yxdtaijianBlue.scene,yongzheng.scene,yxdTaijian.scene,
            ];
            await visibleRole(arr,false);
            key = "yangxindian";
            btnScalX = 2.5;
            btnScalY = 1;
            btnScalZ = 1;
            break;
        case "#huangjidian":
            arr = [
                taijianBlue1.scene,taijianBlue2.scene,
                taijian.scene,taijian2.scene,
                dacheng1.scene,dacheng2.scene,dacheng3.scene,dacheng4.scene,dacheng5.scene,dacheng6.scene,
                taishanghuang.scene,
            ];
            await visibleRole(arr,false);
            dacheng1.scene.position.set(0.1,2.3,-17);
            dacheng1.action.stop();
            dacheng1.action.get("daiji").play();
            npcPositionTo = new Vector3(1,2,-2);
            moveTo(new Vector3(0,4,2),CAMERA_ROTATION,"",true);
            if(btnPlayAnimation){
                npcBackAnimation(0.085,npcPositionTo,0.5);
                kaimenAnimation("zhongzhouxian",thisGltf.animations,false);
            }
            key = "huangjidian";
            btnScalX = 2.5;
            btnScalY = 1;
            btnScalZ = 1;
            break;
        case "#qianqinggong":
            arr = [
                bird5.scene,
                taijianBlue.scene,
                qqgTaijian1.scene,qqgTaijian2.scene,qqgTaijian3.scene,qqgTaijian4.scene,taijian3.scene,taijian4.scene,
                qqgGongNv1.scene,qqgGongNv2.scene,qqgGongNv3.scene,
            ];
            await visibleRole(arr,false);
            npcPositionTo = new Vector3(1,1,27);
            moveTo(new Vector3(0,2.8,30.5),CAMERA_ROTATION,"",true);
            if(btnPlayAnimation){
                npcBackAnimation(0.20,npcPositionTo,1);
            }
            key = "qianqinggong";
            btnScalX = 4;
            btnScalY = 1.5;
            btnScalZ = 1.5;
            break;
        case "#taihedian":
            arr = [ sddTaijian1.scene,sddTaijian2.scene,sddTaijian3.scene,sddTaijian4.scene, ];
            await visibleRole(arr,false);
            key = "taihedian";
            qingFlag = false;
            sddBack = true;
            sddKey = null;
            flag = false;
            sddComposer([]);
            npc.scene.scale.set(1.6,1.6,1.6);
            npc.scene.position.set(1,0.15,58);
            npc.scene.rotation.set(0,-0.5,0);
            model.position.set(0,0,0);
            await moveTo(new Vector3(0,2.5,62),camera.rotation.set(0.1,0.1,0),"",true);
            vrHide();
            break;
        case "#qianchaosandadian":
        case "#damingjianzhuqun":
            key = "taihedian";
            location.hash = "#taihedian";
            qingFlag = false;
            sddBack = true;
            sddKey = null;
            flag = false;
            sddComposer([]);
            model.position.set(0,0,0);
            break;
        default:
    }
    if(key !== "taihedian"){
        btn.visible = true;
        btn2.visible = true;
    }
    if(btnPictureAnimation){
//        paiziAnmationAppear("zhongzhouxian",thisGltf.animations,false,0);
//        paiziAnmationDisappear("zhongzhouxian",thisGltf.animations,true);
    }
});

let enterSceneCount = true;
export async function sceneToggle(key){
    scene.fog = FOG;
    if(qingFlag || key === "qianchaosandadian" || key === "damingjianzhuqun"){
        return;
    }
    let keyValue;
    switch(key){
        case "liugong":
            keyValue = "dongxiliugong";
            break;
        case "shouhuangdian":
            keyValue = "shouhuangdian";
            break;
        case "qianqinggong":
            keyValue = "qianqinggong001";
            break;
        case "huangjidian":
            keyValue = "huangjidian";
            break;
        case "yangxindian":
            keyValue = "yangxindian";
            break;
        case "taihedian":
            keyValue = "taihedian01";
            break;
    }
    npc.mixer.timeScale = 1;
//    btn.visible = false;
//    let arr = [ yxdtaijianBlue.scene,taijian.scene,taijian2.scene,
//        qqgTaijian1.scene,qqgTaijian2.scene,qqgTaijian3.scene,qqgTaijian4.scene,
//        taijian3.scene,taijian4.scene,taijian5.scene,taijian6.scene,yongzheng.scene,yxdTaijian.scene,
//        sddTaijian1.scene,sddTaijian2.scene,sddTaijian3.scene,sddTaijian4.scene,
//        qqgGongNv1.scene,qqgGongNv2.scene,qqgGongNv3.scene,
//        bird1.scene,bird2.scene,bird3.scene,bird4.scene,bird5.scene,
//        taijianBlue.scene,taijianBlue1.scene,taijianBlue2.scene,taijianBlue3.scene,taijianBlue4.scene,taijianBlue5.scene,taijianBlue6.scene,
//        taijianBlue7.scene,taijianBlue8.scene,
//        dacheng1.scene,dacheng2.scene,dacheng3.scene,dacheng4.scene,dacheng5.scene,dacheng6.scene,
//        taishanghuang.scene,
//    ];
//    const gltf = place[0].gltf;
//    thisGltf = gltf;
//    model = gltf.scene;
    const gltf = await gltfLoader(`/assets/xr2/${ keyValue }/${ keyValue }.gltf`);
    thisGltf = gltf;
    model = gltf.scene;
    scene.add(model);
//    await appearAnimation("zhongzhouxian",model,gltf.animations,true);
    await appearAnimation(keyValue,model,gltf.animations,true);
//    gltf.scenes[0].children.forEach(i=>i.visible = i.name === keyValue);
    model.traverse(child=>{
        const name = child.name;
        const array = name.split("_");
        if(startsWithSpecificLetters(name,"taizi") || startsWithSpecificLetters(name,"dimian") || startsWithSpecificLetters(name,"lu") || array.includes("dimian") || array.includes("lu")){
            child.receiveShadow = true;
        }else{
            child.castShadow = true;
            child.receiveShadow = true;
        }
        if(keyValue === "yangxindian" && name.includes("taizi")){
            child.receiveShadow = true;
            child.castShadow = false;
        }
        child.minFilter = LinearFilter;
        child.magFilter = LinearFilter;
        if(startsWithSpecificLetters(name,"paizi") || array.includes("paizi")){
            child.castShadow = false;
            child.receiveShadow = false;
        }
    });
    npc.scene.visible = true;
    camera.rotation.copy(CAMERA_ROTATION);
    switch(key){
        case "liugong":
            FOG.far = 150;
//            directionalLight.position.set(150.575, 90.974, 100);
//            arr = [ taijianBlue3.scene,taijianBlue4.scene,taijianBlue5.scene,taijianBlue6.scene,
//                taijianBlue7.scene,taijianBlue8.scene, ];
//            await addRole(arr);
//            await visibleRole(arr,true);
            camera.rotation.set(0,0,0);
            camera.position.set(-111,2,-32);//西六宫位置
            npc.scene.scale.set(1.1,1.1,1.1);
            npc.scene.position.set(-110,0,-36);//西六宫位置
            npc.scene.lookAt(new Vector3(camera.position.x,npc.scene.position.y,camera.position.z));
            btn.visible = true;
            btn2.visible = true;
            btn.material.map = await textureLoader(`/assets/dxg-introduce.png`);//jshint ignore:line
            btn.scale.set(1.5,0.5,0.5);
            btn2.scale.set(1.5,0.5,0.5);
            btn.position.set(-112,2.3,-38);//西六宫
            btn2.position.set(-110.5,2.3,-38);//西六宫
            break;
        case "shouhuangdian":
            FOG.near = 10;
            FOG.far = 300;
            directionalLight.position.set(2.575,11.974,16);
            npc.scene.scale.set(1.3,1.3,1.3);
            npc.scene.position.set(4.5,0.3,7);
            npc.scene.rotation.set(0,-0.1,0);
            camera.position.set(4,2.5,12);
            camera.rotation.set(0.1,0.5,0);
            guide.visible = false;
            btn.material.map = await textureLoader(`/assets/shd-introduce.png`);//jshint ignore:line
            btn.scale.set(3,1,1);
            btn2.scale.set(3,1,1);
            btn.position.set(0,4.2,0);
            btn2.position.set(3.3,4.2,0);
            btn.visible = true;
            btn2.visible = true;
//            const shouhuangdianZhengdian = AnimationClip.findByName(gltf.animations,"shouhuangdian_zhengdian");
//            const shouhuangdianZhengdianAction = mixer.get("zhongzhouxian").clipAction(shouhuangdianZhengdian);
//            shouhuangdianZhengdianAction.clampWhenFinished = true;
//            shouhuangdianZhengdianAction.loop = LoopOnce;
//            shouhuangdianZhengdianAction.play();
            addEventListener("loadingEnd",()=>{
                setTimeout(()=>{
                    audio.src = '/assets/audio/audio_bg.mp3';
                    audio.loop = true;
                    audio.play();
                    audioBgFlag = true;
                });
            });
            break;
        case "qianqinggong":
            FOG.near = 10;
            FOG.far = 220;
            btn.visible = true;
            btn2.visible = true;
            directionalLight.position.set(16.575,74.974,100);
            npc.scene.scale.set(1,1,1);
            npc.scene.position.set(1.5,1,27);
            npc.scene.rotation.set(0,-0.5,0);
            camera.position.set(0,2.8,30.5);
            guide.visible = false;
            btn.material.map = await textureLoader(`/assets/hsg-introduce.png`);//jshint ignore:line
            btn.scale.set(4,1.5,1.5);
            btn2.scale.set(4,1.5,1.5);
            btn.position.set(-2,3.8,15);
            btn2.position.set(2,3.8,15);
            btn.visible = true;
            btn2.visible = true;
            npc.action.stop();
            const action = npc.action.get(`${ role }_dazhaohu`);
            setTimeout(async()=>{
            bird5 = await Role.load("bird5","/assets/xr/role/huangying.glb");//jshint ignore:line
            bird5.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            bird5.scene.position.set(-1.55,2.45,27);
            bird5.scene.rotation.set(0,-1.5,0);
            qqgGongNv1 = await Role.load("qqgGongNv1","/assets/xr/role/gongnv.glb");//jshint ignore:line
            qqgGongNv1.scene.position.set(16,0.5,-63);
            qqgGongNv1.scene.scale.set(1,1,1);
            qqgGongNv1.scene.rotation.set(0,3.25,0);
            qqgGongNv1.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            qqgGongNv2 = await Role.load("qqgGongNv2","/assets/xr/role/gongnv.glb");//jshint ignore:line
            qqgGongNv2.scene.position.set(1,1.8,-66);
            qqgGongNv2.scene.scale.set(1,1,1);
            qqgGongNv2.scene.rotation.set(0,-1.5,0);
            qqgGongNv2.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
                if(child.name.includes("saochu")){
                    child.visible = false;
                }
            });
            qqgGongNv3 = await Role.load("qqgGongNv3","/assets/xr/role/gongnv.glb");//jshint ignore:line
            qqgGongNv3.scene.position.set(-1,1.8,-66);
            qqgGongNv3.scene.scale.set(1,1,1);
            qqgGongNv3.scene.rotation.set(0,1.5,0);
            qqgGongNv3.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
                if(child.name.includes("saochu")){
                    child.visible = false;
                }
            });
            qqgTaijian1 = await Role.load("qqgTaijian1","/assets/xr/role/taijian2.glb");//jshint ignore:line
            qqgTaijian1.scene.position.set(2.1,1.6,-5);
            qqgTaijian1.scene.rotation.set(0,-1.25,0);
            qqgTaijian1.scene.scale.set(1,1,1);
            qqgTaijian1.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            qqgTaijian2 = await Role.load("qqgTaijian2","/assets/xr/role/taijian2.glb");//jshint ignore:line
            qqgTaijian2.scene.position.set(-1.8,1.6,-5);
            qqgTaijian2.scene.rotation.set(0,1.25,0);
            qqgTaijian2.scene.scale.set(1,1,1);
            qqgTaijian2.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            qqgTaijian3 = await Role.load("qqgTaijian3","/assets/xr/role/taijian2.glb");//jshint ignore:line
            qqgTaijian3.scene.position.set(-1,1.6,-45);
            qqgTaijian3.scene.rotation.set(0,1.25,0);
            qqgTaijian3.scene.scale.set(1,1,1);
            qqgTaijian3.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            qqgTaijian4 = await Role.load("qqgTaijian4","/assets/xr/role/taijian2.glb");//jshint ignore:line
            qqgTaijian4.scene.position.set(1,1.6,-45);
            qqgTaijian4.scene.rotation.set(0,-1.25,0);
            qqgTaijian4.scene.scale.set(1,1,1);
            qqgTaijian4.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });

            taijian3 = await Role.load("taijian3","/assets/xr/role/taijian2.glb");//jshint ignore:line
            taijian3.scene.position.set(-7.7,0,16);
            taijian3.scene.scale.set(1,1,1);
            taijian3.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            taijian4 = await Role.load("taijian4","/assets/xr/role/taijian2.glb");//jshint ignore:line
            taijian4.scene.position.set(8.1,0,15.5);
            taijian4.scene.scale.set(1,1,1);
            taijian4.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            taijianBlue = await Role.load("taijianBlue0","/assets/xr/role/taijian1.glb");//jshint ignore:line
            taijianBlue.scene.position.set(-8,0,22);
            taijianBlue.scene.scale.set(1,1,1);
            taijianBlue.scene.rotation.set(0,1.25,0);
            taijianBlue.scene.traverse(child=>{
                child.castShadow = true;
                child.minFilter = LinearFilter;
                child.magFilter = LinearFilter;
            });
            arr = [
                bird5.scene,
                qqgGongNv1.scene,qqgGongNv2.scene,qqgGongNv3.scene,
                taijianBlue.scene,
                qqgTaijian1.scene,qqgTaijian2.scene,qqgTaijian3.scene,qqgTaijian4.scene,taijian3.scene,taijian4.scene,
            ];
            await addRole(arr);
            await visibleRole(arr,false);
            bird5.scene.visible = true;
            bird5.mixer.timeScale = 1;
            bird5.action.get("hunagying_daiji").play();
            qqgGongNv1.action.get("saodi").play();
            qqgGongNv2.action.get("Tpose").play();
            qqgGongNv3.action.get("Tpose").play();
            qqgTaijian1.action.get("taijian_daiji").play();
            qqgTaijian2.action.get("taijian_daiji").play();
            qqgTaijian3.action.get("taijian_daiji").play();
            qqgTaijian4.action.get("taijian_daiji").play();
            taijian3.action.get("taijian_daiji").play();
            taijian4.action.get("taijian_daiji").play();
            taijianBlue.action.get("saodi").play();
            });
            if(chuxianAction.isRunning()){
                action.clampWhenFinished = true;
                action.loop = LoopOnce;
                action.play();
            }
            let qqgNpcAnimationDetection,qqgBirdAnimationDetection;
            requestAnimationFrame(function loop(){
                if(action._clip.duration === action.time){
                    bird5.action.stop();
                    bird5.action.get("hunagying_qifei").play();
                    bird5.action.get("hunagying_qifei").loop = LoopOnce;
                    cancelAnimationFrame(qqgNpcAnimationDetection);
                    requestAnimationFrame(function loop(){
                        if(bird5.action.get("hunagying_qifei")._clip.duration - bird5.action.get("hunagying_qifei").time < 0.1){
                            bird5.mixer.timeScale = 0;
                            visibleRole([ bird5.scene, ],false);
                            cancelAnimationFrame(qqgBirdAnimationDetection);
                        }else{
                            qqgBirdAnimationDetection = requestAnimationFrame(loop);
                        }
                    });
                }else{
                    qqgNpcAnimationDetection = requestAnimationFrame(loop);
                }
            });
            break;
        case "huangjidian":
            FOG.far = 700;
            directionalLight.position.set(16.575,74.974,100);
//            arr = [
//                taijianBlue1.scene,taijianBlue2.scene,
//                taijian.scene,taijian2.scene,
//                dacheng1.scene,dacheng2.scene,dacheng3.scene,dacheng4.scene,dacheng5.scene,dacheng6.scene,
//                taishanghuang.scene,
//            ];
//            await addRole(arr);
//            await visibleRole(arr,false);
            npc.scene.scale.set(1.2,1.2,1.2);
            npc.scene.position.set(1.5,1.9,-2);
            npc.scene.rotation.set(0,-0.25,0);
            camera.position.set(0,4,2);
            guide.visible = false;
            btn.material.map = await textureLoader(`/assets/introduce.png`);//jshint ignore:line
            btn.scale.set(2.5,1,1);
            btn2.scale.set(2.5,1,1);
            btn.position.set(-1.25,4.5,-8);
            btn2.position.set(1.25,4.5,-8);
            btn.visible = true;
            btn2.visible = true;
            break;
        case "yangxindian":
            FOG.far = 100;
            directionalLight.position.set(2.575,11.974,16);
                setTimeout(async()=>{
                    yxdTaijian = await Role.load("yxdtaijian","/assets/xr/role/taijian2.glb");//jshint ignore:line
                    yxdTaijian.scene.scale.set(1,1.2,1);
                    yxdTaijian.scene.position.set(0,1.6,-13);
                    yxdTaijian.scene.rotation.set(0,-0.25,0);
                    yxdtaijianBlue = await Role.load("yxdtaijianBlue","/assets/xr/role/taijian1.glb");//jshint ignore:line
                    yxdtaijianBlue.scene.position.set(-3,0.2,3);
                    yxdtaijianBlue.scene.scale.set(1,1,1);
                    yxdtaijianBlue.scene.traverse(child=>{
                        child.castShadow = true;
                        child.minFilter = LinearFilter;
                        child.magFilter = LinearFilter;
                    });
                    bird1 = await Role.load("bird1","/assets/xr/role/huangying.glb");//jshint ignore:line
                    bird2 = await Role.load("bird2","/assets/xr/role/huangying.glb");//jshint ignore:line
                    bird3 = await Role.load("bird3","/assets/xr/role/huangying.glb");//jshint ignore:line
                    bird4 = await Role.load("bird4","/assets/xr/role/huangying.glb");//jshint ignore:line
                    bird1.scene.traverse(child=>{
                        child.castShadow = true;
                        child.minFilter = LinearFilter;
                        child.magFilter = LinearFilter;
                    });
                    bird2.scene.traverse(child=>{
                        child.castShadow = true;
                        child.minFilter = LinearFilter;
                        child.magFilter = LinearFilter;
                    });
                    bird3.scene.traverse(child=>{
                        child.castShadow = true;
                        child.minFilter = LinearFilter;
                        child.magFilter = LinearFilter;
                    });
                    bird4.scene.traverse(child=>{
                        child.castShadow = true;
                        child.minFilter = LinearFilter;
                        child.magFilter = LinearFilter;
                    });
                    bird1.scene.position.set(-12.5,8,-2.6);
                    bird2.scene.position.set(-12,5.7,0);
                    bird3.scene.position.set(-13,5.7,0);
                    bird4.scene.position.set(-16,5.7,2.5);
                    bird1.scene.scale.set(1.2,1.2,1.2);
                    bird2.scene.scale.set(1.2,1.2,1.2);
                    bird3.scene.scale.set(1.2,1.2,1.2);
                    bird4.scene.scale.set(1.2,1.2,1.2);
                    yongzheng = await Role.load("yongzheng","/assets/xr/role/yongzheng_yangxindian.glb");//jshint ignore:line
                    yongzheng.scene.scale.set(1,1.2,1);
                    yongzheng.scene.position.set(0,1.6,-13);
                    yongzheng.scene.rotation.set(0,-0.25,0);

                    arr = [ yxdtaijianBlue.scene,yongzheng.scene,yxdTaijian.scene,bird1.scene,bird2.scene,bird3.scene,bird4.scene, ];
                    await addRole(arr);
                    await visibleRole(arr,true);
                    await visibleRole([ yxdtaijianBlue.scene,yongzheng.scene,yxdTaijian.scene, ],false);
                    yxdTaijian.action.get("taijian_momo").play();
                    yongzheng.action.get("yongzheng_daiji").play();
                    yxdtaijianBlue.action.get("saodi").play();
                    bird1.action.get("hunagying_daiji").play();
                    bird2.action.get("hunagying_daiji").play();
                    bird3.action.get("hunagying_daiji").play();
                    bird4.action.get("hunagying_daiji").play();
                });
            data.camera.position.set(0,2,9);
            npc.scene.scale.set(1,1,1);
            npc.scene.position.set(2,0.1,5);
            npc.scene.rotation.set(0,-0.25,0);
            btn.material.map = await textureLoader(`/assets/yxd-introduce.png`);//jshint ignore:line
            btn.scale.set(2.5,1,1);
            btn2.scale.set(2.5,1,1);
            btn.position.set(-1.25,3,-2);
            btn2.position.set(1.25,3,-2);
            guide.position.set(npc.scene.position.x + 0.4,npc.scene.position.y + 2,npc.scene.position.z - 1);
            guide.scale.set(1.8,0.5,1.8);
            camera.position.copy(data.camera.position);
            if(chuxianAction.isRunning()){
                if(enterSceneCount){
                    guide.visible = false;
                    btn.visible = true;
                    btn2.visible = true;
                }
                addEventListener("loadingEnd",()=>{
                    setTimeout(async()=>{
                        guide.visible = true;
                        const action = npc.action.get(`${ role }_xiangyoujieshao`);
                        action.clampWhenFinished = true;
                        action.loop = LoopOnce;
                        action.play();
                        await guideAudio("/assets/xr/audio/girl/yangxindian01.mp3",false), 1500;
                    });//jshint ignore:line
                });
            }
            break;
        case "taihedian":
            FOG.near = 10;
            FOG.far = 260;
            directionalLight.position.set(16.575,74.974,100);
//            arr = [ sddTaijian1.scene,sddTaijian2.scene,sddTaijian3.scene,sddTaijian4.scene, ];
//            await addRole(arr);
//            await visibleRole(arr,false);
            if(sddBack){
                npc.scene.scale.set(1.6,1.6,1.6);
                npc.scene.position.set(1,0.15,58);
                npc.scene.rotation.set(0,-0.5,0);
                await moveTo(new Vector3(0,2.5,62),camera.rotation.set(0.1,0.1,0),"",true);
                vrHide();
            }else{
                npc.scene.scale.set(1.6,1.6,1.6);
                npc.scene.position.set(1,0.15,58);
                npc.scene.rotation.set(0,-0.5,0);
                camera.position.set(0,2.5,62);
                camera.rotation.set(0.1,0.1,0);
                if(chuxianAction.isRunning()){
                    guide.material.map = await textureLoader(`/assets/gd-guide.png`);
                    guide.visible = true;
                    guide.position.set(npc.scene.position.x + 0.5,npc.scene.position.y * 14 + 1.2,npc.scene.position.z - 1);
                    guide.scale.set(1,0.3,1);
                    const action = npc.action.get(`${ role }_xiangyoujieshao`);
                    action.clampWhenFinished = true;
                    action.loop = LoopOnce;
                    action.play();
//                    await guideAudio("/assets/xr/audio/girl/yangxindian01.mp3", false);
                    dispatchEvent(new CustomEvent("finger"));
                }
            }
            break;
    }
    if(enterSceneCount){
        dispatchEvent(new CustomEvent("resourcesSuccess"));
        enterSceneCount = false;
    }
}
//export { bird1,bird2,bird3,bird4}

解决了这个问题,我发200红包:sob:

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

看到代码里面出现那么多被注释的代码,一下子就愤怒了

2周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!