Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

JSONLoader Callback Error #1648

awardell opened this Issue Apr 6, 2012 · 2 comments


2 participants

awardell commented Apr 6, 2012

I'm having an issue using the JSONLoader having to do with the callback function for the load method.
I'm trying to modify the file created by ThreeFab.

Here's what I do that works:

var loadBaptistery = function(baptistery_geometry) {
    var baptistery_material = new THREE.MeshPhongMaterial();
    baptistery_material.color = new THREE.Color().setRGB(1,1,1);
    baptistery_material.ambient = new THREE.Color().setRGB(0.0196078431372549,0.0196078431372549,0.0196078431372549);
    baptistery_material.specular = new THREE.Color().setRGB(0.06666666666666667,0.06666666666666667,0.06666666666666667);

    baptistery = new THREE.Mesh(baptistery_geometry, baptistery_material);
    scene.add( baptistery );

var baptistery_loader = new THREE.JSONLoader();
baptistery_loader.load( "last_baptistery2.js", loadBaptistery);

This runs without a problem. But when I try to use a higher order function as the callback function:

var create_loadAttachmentPoint = function(attachmentPointName) {
    var loadAttachmentPoint = function(attachmentPoint_geometry) {
        var attachmentpoint_material = new THREE.MeshPhongMaterial();
        attachmentpoint_material.color = new THREE.Color().setRGB(1,1,1);
        attachmentpoint_material.ambient = new THREE.Color().setRGB(0.0196078431372549,0.0196078431372549,0.0196078431372549);
        attachmentpoint_material.specular = new THREE.Color().setRGB(0.06666666666666667,0.06666666666666667,0.06666666666666667);

        this[attachmentPointName] = new THREE.Mesh(attachmentPoint_geometry, attachmentpoint_material);
        scene.add( this[attachmentPointName] );
    return loadAttachmentPoint;

var attachmentPointA_loader = new THREE.JSONLoader();
attachmentPointA_loader.load("attachmentpoint2.js", create_loadAttachmentPoint("attachmentPointA"));

something goes wrong. My line of code further down:


spits out an error message, "Uncaught TypeError: Cannot read property 'position' of undefined". The weird thing is though that when I try to access attachmentPointA from the console, it actually is defined, and it has all of the properties that it should have, including position. I can't figure out why my code can't access the object but I can. My hunch would be that I'm misusing the "this" pointer, but when I check in the chrome console it has successfully added attachmentPointA to the window and not to the JSONLoader object. This may be a very newbie error I am making, but I can't figure it out.

Thank you very much for any help!


chandlerprall commented Apr 16, 2012

The object import/loading is performed asynchronously because of the AJAX request, so the object isn't created until after you call attachmentPointA.position.set.


@awardell awardell closed this Apr 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment