As a beginner in three.js, I have successfully created a 3D obj model file. Now, I am facing the challenge of returning the object(3D .obj) to another function and making sure the original color is visible on the .obj 3D model.
Javascript
this.draw3DObj = function (startX, startY, endX, endY, objType) {
switch (objType) {
case "window":
var loader = new THREE.OBJLoader();
var material = new THREE.MeshNormalMaterial({
color: 0xbcb9b1,
side: THREE.DoubleSide
});
loader.load('model/window.obj', function(object) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.material = material;
}
});
scene1.add(object);
object.position.x = width;
object.position.y = depth;
object.position.z = height;
},
function(xhr) {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
function(error) {
console.log('An error happened');
}
);
break;
}
return object; // How can I successfully return this object?
};