I am currently developing an application that enables users to upload 3D models in the obj/mtl format. In this application, the admin can preview what the loaded object will look like in our viewer. I am working on adding controls for users to specify the initial y-position of the loaded object and the initial z-position of the camera. While I have successfully implemented the camera part, I am facing challenges with setting the y-position. Below is a snippet of my code:
var obj3d;
loader.load( model_obj, model_mtl, function ( object ) {
object.position.y = y_init;
scene.add( object );
render();
obj3d = object;
$('#initial_y').change(function() {
obj3d.position.y = $(this).val();
});
}, onProgress, onError );
The problem arises when I try to access the Object3D
outside the load
function, as it seems the reference is no longer available. This results in a JavaScript error message:
Cannot access property 'position' of undefined.
If anyone could offer assistance with this issue, it would be greatly appreciated!