问题描述:当前threejs是92版本 但是当前版本还没有能够直接加载带贴图文件的drc格式的loader;
解决办法:先加载mtl文件将obj文件分解(按照mtl文件内材质贴图信息进行分解)再将分解的obj文件转成drc全部加载一遍就能解决贴图的办法 ;
代码:
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() ); var modelObject = new THREE.Object3D(); var loadNum = 0; var mtlLoader = new THREE.MTLLoader(); // new THREE.MTLLoader() mtlLoader.setPath( '__PUBLIC__/wap/dracoModel/0518xialian/' ); mtlLoader.load( 'cs.mtl', function ( materials ) { materials.preload(); new THREE.OBJLoader() .setMaterials( materials ) .setPath( '__PUBLIC__/wap/dracoModel/0518xialian/' ) .load( 'cs.obj', function ( object ) { // object.position.x = -0.55; // object.position.y = -0; // object.position.z = 1.1; object.scale.x = 0.0005; object.scale.y = 0.0005; object.scale.z = 0.0005; scene.add( object ); }, onProgress, onError ); // dracoLoader.load( '__PUBLIC__/wap/images/bunny.drc', function ( geometry ) { // dracoLoader.load( '__PUBLIC__/wap/dracoModel/9015/1.drc', function ( geometry ) { // geometry.computeVertexNormals(); // var material = new THREE.MeshStandardMaterial( { vertexColors: THREE.VertexColors } ); // var mesh = new THREE.Mesh( geometry, material ); // mesh.castShadow = true; // mesh.receiveShadow = true; //// mesh.position.x = -10; //// mesh.position.y = -5; //// mesh.position.z = -10; // mesh.scale.x = 0.005; // mesh.scale.y = 0.005; // mesh.scale.z = 0.005; // scene.add( mesh ); // // // Release decoder resources. // THREE.DRACOLoader.releaseDecoderModule(); // // } ); //将素材加载到场景中回掉函数 var loaderCallback = function(geometry) { var material = null; // console.log(loadNum); if(loadNum === drcNameArray.length-1){ scene.add(modelObject); }else{ geometry.computeVertexNormals(); var midName = drcNameArray[loadNum].split('.')[1]; // midName = midName.slice(0,2); material = materials.materials[midName]; console.log(midName); // console.log(drcNameArray[loadNum].split('.')[1]); // console.log(materials.materials); var mesh = new THREE.Mesh( geometry, material ); mesh.castShadow = true; mesh.receiveShadow = true; mesh.scale.x = 0.0003; mesh.scale.y = 0.0003; mesh.scale.z = 0.0003; // // Release decoder resources. // THREE.DRACOLoader.releaseDecoderModule(); modelObject.add(mesh); loadNum++; // console.log(loadNum) dracoLoader.load("__PUBLIC__/wap/dracoModel/hongpei01/drc/" + [drcNameArray[loadNum]],loaderCallback,function(){}); } // item.halfSize = getObjectHalfSize(modelObject); }; // dracoLoader.load("__PUBLIC__/wap/dracoModel/hongpei01/drc/" + drcNameArray[0],loaderCallback,function(){}); //将素材加载到场景中回掉函数end } );
描述:目前我们是这么解决的;