问题
I'm using ObjectLoader to load my scene (exported using ObjectExporter). How can I apply textures to my objects while loading?
回答1:
Use ObjectLoader to load the object, and then use it's geometry to create a mesh with a loaded texture:
var loader = new THREE.ObjectLoader();
loader.load("models/ship.json",
function (obj) {
var material = new THREE.MeshLambertMaterial({
map: THREE.ImageUtils.loadTexture('models/textures/ship.jpg')});
var mesh = new THREE.Mesh(obj.geometry, material);
scene.add(mesh);
}
);
回答2:
OBJMTLLoader.js
var loader = new THREE.OBJMTLLoader();
loader.load("../assets/models/shark/Shark.obj", "../assets/models/shark/Shark.mtl", function (shark) {
来源:https://stackoverflow.com/questions/19444172/adding-texture-an-image-when-loading-with-objectloader