I have loaded an object in my scene using ObjLoader. However, I am struggling to read the vertices of that object. I can easily read and modify the vertices of a normal cube created in three.js, but it doesn't seem to work on the object loaded by ObjLoader. I even attempted to use FaceNormalsHelper, which worked on the cube but not on my object.
Here is the code snippet:
//Creating a cube (works fine)
var geometry = new THREE.BoxGeometry(20, 20, 20);
var color = new THREE.Color("rgba(188, 141, 190, 1)");
var material = new THREE.MeshNormalMaterial({color: color.getHex()});
var cube = new THREE.Mesh(geometry, material);
var helper = new THREE.FaceNormalsHelper(cube, 20, 0x00ff00, 1);
var vert = cube.geometry.vertices[1].y;
scene.add(cube);
scene.add(helper);
//Loading my object
var manager = new THREE.LoadingManager();
manager.onProgress = function(item, loaded, total) {
console.log(item, loaded, total);
};
var texture = new THREE.Texture();
var onProgress = function(xhr) {
if (xhr.lengthComputable) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log(Math.round(percentComplete, 2) + '% downloaded');
}
};
var onError = function(xhr) {};
var loader = new THREE.ImageLoader(manager);
loader.load('objects/texture.jpg', function(image) {
texture.image = image;
texture.needsUpdate = true;
});
var objLoader = new THREE.OBJLoader(manager);
objLoader.load('objects/scan_leg_repair.obj', function(object) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.material.map = texture;
}
});
object.position.y = -100;
object.rotation.x = -1.5;
object.rotation.z = 3;
scene.add(object);
//Below are the unsuccessful attempts
//var vert2 = object.geometry.vertices[1].y;
//var vert3 = object.children[0].geometry.vertices[1].y;
//var helper = new THREE.FaceNormalsHelper(object, 20, 0x00ff00, 1);
//var helper = new THREE.FaceNormalsHelper(object.children[0], 20, 0x00ff00, 1);
//scene.add(helper);
}, onProgress, onError);
Thank you very much!