我有一个Three.js项目与增强现实,现在我尝试加载具有纹理的模型。出于某种原因,我的模型是黑色的,没有纹理。我在搅拌机中检查了输出图像的框,我还看到在t-rex(模型中使用的)的.js文件中列出了纹理,但我的应用程序不会加载它。Three.js不可能加载纹理
编辑(添加的代码) 我使用加载模型的代码:
new THREE.JSONLoader().load("models/trex.json", function(geometry) {
var material = new THREE.MeshFaceMaterial();
var dino = new THREE.Mesh(geometry, material);
dino.position.z = -50;
dino.scale.x = dino.scale.y = dino.scale.z = 2;
dino.updateMatrix();
dino.overdraw = true;
marker.object3d.add(dino);
});
我补充这标记对象,因为我与标记工作,如果我表现的标志我想在标记上绘制trex(或右上方)。
的TREX模型是一样的,因为这一个,但我已经在搅拌机打开它,并使用了最新版本的搅拌器来three.js所出口:http://alteredqualia.com/three/examples/webgl_trex.html
而且我trex.json文件看起来像这样:
{
"metadata" :
{
"formatVersion" : 3.1,
"generatedBy" : "Blender 2.63 Exporter",
"vertices" : 23273,
"faces" : 23268,
"normals" : 20842,
"colors" : 0,
"uvs" : [11497],
"materials" : 1,
"morphTargets" : 0,
"bones" : 0
},
"scale" : 0.0500,
"materials": [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material.001",
"blending" : "NormalBlending",
"colorAmbient" : [0.2933282256126404, 0.2933282256126404, 0.2933282256126404],
"colorDiffuse" : [0.2933282256126404, 0.2933282256126404, 0.2933282256126404],
"colorSpecular" : [0.13438941538333893, 0.13438941538333893, 0.13438941538333893],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "trex_image_copy.png",
"mapNormal" : "trex_image_bump.png",
"mapNormalFactor" : 12.0,
"mapSpecular" : "trex_image_spec.png",
"shading" : "Phong",
"specularCoef" : 511,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
},
{
"DbgColor" : 15597568,
"DbgIndex" : 1,
"DbgName" : "Material",
"blending" : "NormalBlending",
"colorAmbient" : [0.7257574200630188, 0.7257574200630188, 0.7257574200630188],
"colorDiffuse" : [0.7257574200630188, 0.7257574200630188, 0.7257574200630188],
"colorSpecular" : [0.0, 0.0, 0.0],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "trex_image_copy.png",
"mapLight" : "trex_image_eye.png",
"mapLightWrap" : ["repeat", "repeat"],
"shading" : "Lambert",
"specularCoef" : 1,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
},
{
"DbgColor" : 60928,
"DbgIndex" : 2,
"DbgName" : "Material",
"blending" : "NormalBlending",
"colorAmbient" : [0.7257574200630188, 0.7257574200630188, 0.7257574200630188],
"colorDiffuse" : [0.7257574200630188, 0.7257574200630188, 0.7257574200630188],
"colorSpecular" : [0.0, 0.0, 0.0],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "trex_image_copy.png",
"mapLight" : "trex_image_eye.png",
"mapLightWrap" : ["repeat", "repeat"],
"shading" : "Lambert",
"specularCoef" : 1,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
}],
"vertices":
我tryed画一个框,然后添加纹理,即工作,但加载从JSON格式的文件,然后显示纹理不工作。
非常感谢!
问题代码在哪里?我无法在main.js中找到对trex.json的引用。另外,不要只是给一个巨大的存档,你可以粘贴你的模型加载代码,所以很容易快速浏览是否有东西在那里闻起来。下载zip文件可能会让很多潜在的帮手感到沮丧,并且一个小型的独立测试用例可能是首选,而不是一个完整的项目。 – Tapio
您是在本地或在网络服务器上尝试此操作吗? – Neil
@Tapio我这样做是因为我怀疑代码中有其他错误。在第151行附近搜索trex.json。无论如何,我会更新这个问题,谢谢! – DanFritz