I've been struggling for weeks to manipulate OBJLOADED objects in a three.js scene using keyboard buttons. My goal is to translate and rotate the objects based on key inputs, such as pressing 'A' to translate objA along the X-axis and 'B' to translate objB.
function addObject(model) {
var mtlLoader = new THREE.MTLLoader();
var objLoader = new THREE.OBJLoader();
mtlLoader.load(model+'.mtl', function (materials) {
materials.preload();
objLoader.setMaterials(materials);
objLoader.load(model+'.obj', function (object) {
object.name =model;
scene.add(object);
// I'm struggling with returning an object here
});
});
}
var obj1 = scene.getObjectByName('objA');
if(obj1.name=='objA'){
alert('Yes');
}
I can't seem to get this code to work as intended. Any suggestions or solutions would be greatly appreciated!