2013-04-03 55 views
0

嗨,我已經嘗試過不同的源代碼添加材料幾何,但如果我這樣添加代碼:three.js所 - 添加材料OBJ裝載機(WEBGL)

var material1 = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true }); 

我不明白陰影/材料到我的obj(模型)。它像一個平面的視圖。 例子:​​

// This string has to be the path to your texture file. 
loader.load('0.jpg'); 

/*** OBJ Loading ***/ 
var loader = new THREE.OBJLoader(); 

// As soon as the OBJ has been loaded this function looks for a mesh 
// inside the data and applies the texture to it. 
loader.addEventListener('load', function (event) { 
var object = event.content; 
object.traverse(function (child) { 
    if (child instanceof THREE.Mesh) { 
    child.material.map = texture; 
    } 
}); 

// object = new THREE.Mesh(geometry, [ new THREE.MeshFaceMaterial(), new THREE.MeshPhongMaterial({ color: 0xff4400, wireframe: true, wireframeLinewidth: 2 }) ]); 
object = new THREE.Mesh(geometry); 

// My initial model was too small, so I scaled it upwards. 
object.scale = new THREE.Vector3(25, 25, 25); 

// You can change the position of the object, so that it is not 
// centered in the view and leaves some space for overlay text. 
object.position.y -= 2.5; 
scene.add(object); 

}); 

// This string has to be the path to your object file. 
loader.load('0.obj'); 

// We set the renderer to the size of the window and 
// append a canvas to our HTML page. 
renderer = new THREE.WebGLRenderer(); 
renderer.setSize(window.innerWidth, window.innerHeight); 
container.appendChild(renderer.domElement); 

任何人都可以最終幫助我嗎?

回答

2

您的模型是否有UV線?在這個問題object importing in Three.js中的代碼做了完全相同的事情。

+0

Hi gaitat, 是的,它有紫外線和紋理的作品。你可以看到它的頭部是紅色的,角部像黃色。 – 2013-04-03 20:00:46

+0

你在場景中沒有燈光。只是一個環境。方向性被評論。 – gaitat 2013-04-03 20:27:28

+0

謝謝,直接。光線使它更好一些.F5 但仍然與Zbrush視圖不同: http://dev.interactive-creation-works.net/Three/character.png 最終你知道一個簡單的obj加載代碼示例,附加一個.mtl或標準墊子,如phong,basic,lambert? 你知道我可以投票給你的幫助嗎? – 2013-04-03 20:47:38

1

使用不帶線框屬性的MeshPhongMaterial(或Lambert)可以獲得可以在燈光(陰影)下播放的材質。例如。

var material1 = new THREE.MeshPhongMaterial({ color: 0x00ff00 }); 

MeshBasicMaterial始終保持平坦。

此外,您只替換紋理(貼圖),而不是負載回調/遍歷函數中的材質。如果只替換地圖,則需要將物料分配給物體,物料類型將是.obj加載程序創建的物料類型。