1

我已经使用 python 工具将 obj 文件转换为 json 模型,我正在尝试加载它这里是代码

var camera, scene, renderer;
var mesh, aircraft;

function addModelToScene( geometry, materials )
{
    aircraft = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
    scene.add( aircraft );
}

function init()
{
    camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 20000 );
    camera.position.z = 30;
    scene = new THREE.Scene();

var jsonLoader = new THREE.JSONLoader( true );
jsonLoader.load( "XA-20.js", addModelToScene );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}

function animate()
{
    requestAnimationFrame( animate );
    aircraft.rotation.y += 0.02;
    renderer.render( scene, camera );
}

模型正在加载,但上面没有纹理模型文件很大,所以我不能在这里发布,但有材料

"materials": [  {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "plane",
"colorAmbient" : [0.117647, 0.117647, 0.117647],
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorSpecular" : [0.75294099999999997, 0.75294099999999997, 0.75294099999999997],
"illumination" : 2,
"mapBump" : "XA-20_Razorback_Strike_Fighter_N.png",
"mapDiffuse" : "XA-20_Razorback_Strike_Fighter_P01.png",
"specularCoef" : 8.0
},

{
"DbgColor" : 15597568,
"DbgIndex" : 1,
"DbgName" : "glass",
"colorAmbient" : [0.117647, 0.117647, 0.117647],
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorSpecular" : [0.75294099999999997, 0.75294099999999997, 0.75294099999999997],
"illumination" : 2,
"mapDiffuse" : "Glass_Cockpit.png",
"specularCoef" : 8.0
},.......

还有紫外线

"uvs": [[0.72626,-0.65659,0.72655,-0.62558,0.72427,-0.6262,0.72391,-0.66141,0.73223,-0.62103,0.73212,.......

我可以在哪里寻找解决方案的任何线索?

4

2 回答 2

0

jsonLoader.load 有第三个参数来设置纹理路径。将此 texturePath 设置为具有纹理的文件夹,它应该可以工作。

https://github.com/mrdoob/three.js/blob/master/src/loaders/JSONLoader.js#L16

于 2012-12-31T10:24:42.457 回答
0

就我而言,问题是我没有正确添加照明,因此模型没有足够的光来显示为彩色它确实加载了纹理但在视觉上它是不可见的,因为照明

因此,如果遇到类似问题,请先检查您的照明

于 2013-04-29T11:24:09.230 回答