three.js JSONLoader材质未显示 [英] three.js JSONLoader Material Not Showing
本文介绍了three.js JSONLoader材质未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Maya导入对象,这是json文件
I am trying to import an object from Maya and here is the json file
{
"metadata" :
{
"formatVersion" : 3.1,
"sourceFile" : "myobj.obj",
"generatedBy" : "OBJConverter",
"vertices" : 22470,
"faces" : 42837,
"normals" : 128511,
"colors" : 0,
"uvs" : 52126,
"materials" : 1
},
"scale" : 1.000000,
"materials": [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "lambert2SG",
"colorAmbient" : [0.0, 0.0, 0.0],
"colorDiffuse" : [0.0, 0.0, 0.0],
"illumination" : 4,
"mapDiffuse" : "mytexture.tga",
"opticalDensity" : 1.0
}],
"vertices": [...] //Omitted because there are too many
"morphTargets": [],
"morphColors": [],
"normals": [...],
"colors": [],
"uvs": [...],
"faces": [...]
}
这是我加载JSON文件的方式:
and here is how I load the JSON file:
这是我初始化场景并加载json文件的方式.我有一个很大的距离,因为物体很大:
Here is how I initialize the scene and load the json file. I have a large far point because objects are huge:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
var controls = new THREE.OrbitControls(camera);
document.body.appendChild(renderer.domElement);
var jsonLoader = new THREE.JSONLoader();
var mesh;
var render = function () {
stats.update();
controls.update();
requestAnimationFrame(render);
renderer.render(scene, camera);
}
jsonLoader.load("Mesh/myobj.js", function(geometry, materials){
console.log(materials); // This prints an array, whose first element is a MeshLambertMaterial.
mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial( materials ));
// If I remove the second parameter,
//the object renders correctly without texture.
//Otherwise the screen shows nothing.
console.log(geometry);
scene.add(mesh);
});
render();
camera.position.y = 10000;
对不起,如果我做了一些愚蠢的事情.我是three.js的新手. 如果将纹理应用于对象,屏幕上将不显示任何内容.我已经尽力找到了所有可以找到的东西.请帮忙!
Sorry if I've done something stupid. I am new to three.js. The screen displays nothing if I apply texture to the object. I've tried everything I can find. Please help!
推荐答案
您是否已将相机正确添加到场景中? scene.add(camera);
Have you added your camera to scene properly? scene.add(camera);
这篇关于three.js JSONLoader材质未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文