ThreeJs 加载人物模型, 在ios 上显示的时候,偶尔会出现人物贴图加载不出来, 导致模型变成了黑色的

原文链接:
查询了很久, 添加这个参数就好了
注意 : 在mac 上会导致这个判断是false 状态, 所以要直接看到效果,可以直接把里面的代码提出来

//修复部分纹理随机黑色问题
            const IS_IOS =
                /^(iPad|iPhone|iPod)/.test(window.navigator.platform) ||
                (/^Mac/.test(window.navigator.platform) && window.navigator.maxTouchPoints > 1);
            if (IS_IOS) {
                window.createImageBitmap = undefined;
            }

后续还是发现有部分黑色模型出现
添加部分加载的时候的参数修改

flock = new THREE.AnimationObjectGroup;
=========================================================")
            var loader = new THREE.GLTFLoader();

            loader.load(
                // resource URL
                url,
                // called when the resource is loaded
                function (gltf) {

                    //======================================================================================================================
                    //              处理模型变黑
                    //======================================================================================================================
                    gltf.scene.traverse(function (child) {
                        if (child.isMesh) {
                            child.material.emissive = child.material.color;
                            child.material.emissiveIntensity = 1;
                            child.material.emissiveMap = child.material.map;
                            child.material.transparent = true;
                            child.isLineSegments = true;
                            child.material.wireframe = false;
                            // child.material.alphaTest = 0.2
                        }
                    });
                    //======================================================================================================================
                    //              处理模型变黑
                    //======================================================================================================================


                    // 创建相机锁定点
                    var ss = new THREE.Vector3(gltf.scene.position.x, gltf.scene.position.y, gltf.scene.position.z);
                    camera.lookAt(ss); //设置相机方向(指向的场景对象)

                    gltf.scene.position.y = -10;

                    // 模型等比放大
                    gltf.scene.scale.set(15, 15, 15);



                    group.add(gltf.scene)

                    scene.add(group);

                    flock.add(scene);

                    //mixer.clipAction 返回一个可以控制动画的AnimationAction对象  参数需要一个AnimationClip 对象
                    //AnimationAction.setDuration 设置一个循环所需要的时间,当前设置了一秒
                    if(gltf.animations.length > 0){
                        mixer.clipAction(gltf.animations[0]).play();
                    }
                },
                // called while loading is progressing
                function (xhr) {
                    console.log((xhr.loaded / xhr.total * 100) + '% loaded')

                },
                // called when loading has errors
                function (error) {
                    console.log('An error happened');
                }
            );
        }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值