ThreeJs 加载人物模型, 在ios 上显示的时候,偶尔会出现人物贴图加载不出来, 导致模型变成了黑色的
原文链接:查询了很久, 添加这个参数就好了注意 : 在mac 上会导致这个判断是false 状态, 所以要直接看到效果,可以直接把里面的代码提出来//修复部分纹理随机黑色问题const IS_IOS =/^(iPad|iPhone|iPod)/.test(window.navigator.platform) ||(/^Mac/.test(window.navigator.platform) &am
·
原文链接:
查询了很久, 添加这个参数就好了
注意 : 在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条内容
所有评论(0)