Hey there!
I'm currently working on labeling my 3DObject so that I can easily print their names later on. The click functionality and outline feature are all functioning properly, but for some reason, the userData field remains empty.
Below is the snippet of code I am using:
function checkIfClicked(event) {
mouse.x = (event.offsetX / renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.offsetY / renderer.domElement.clientHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects([model], true);
if (intersects.length > 0) {
click_level += 1;
selectedObject = intersects[0].object;
console.log(selectedObject.userData.name); //Issue arises here
outlinePass.selectedObjects = [selectedObject];
if (click_level > 1) {
if (confirm("You are going to be redirected to Zalando.be")) {
document.location.href = "http://www.zalando.be";
}
}
}
else {
click_level = 0;
outlinePass.selectedObjects = [];
}
}
Moreover, in my main code after loading the 3DObject:
object.userData = { name: "homme" };
model = object;
console.log(model.userData); //This one works just fine