I'm creating a class for a 3D object. I'm using jQuery for event logging and three.js for WebGL.
My class is defined as:
function Obj(filename) {
this.loadMesh(filename);
};
Obj.prototype.loadMesh = function(filename) {
var loader = new THREE.PLYLoader();
var geo;
var mesh;
loader.load(filename, function ( geometry ) {
geo = geometry;
var material = new THREE.MeshStandardMaterial( { color: 0x0055ff } );
mesh = new THREE.Mesh( geometry, material );
mesh.position.y = -0.25;
mesh.rotation.x = -Math.PI / 2;
mesh.scale.multiplyScalar( 0.04 );
});
this.geometry = geo;
this.mesh = mesh;
};
This class is called from a Scene class:
function Sce() {
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(45, 1, 0.1, 10000);
this.scene.add(this.camera);
this.light = new THREE.PointLight();
this.light.position.set(-256, 256, -256);
this.scene.add(this.light);
this.renderer = new THREE.WebGLRenderer();
this.obj3d = new Obj('file.ply');
this.scene.add(this.obj3d.mesh);
};
Which is in turn called from the jQuery ready:
$(document).ready(function () {
scene = new Sce();
});
But the variables this.geometry and this.mesh are not defined unless I put a breakpoint with Firebug at them.
I think it might be a scope problem, but I haven't been able to fix the error, does someone know what might be the problem?