After inserting a mesh into the scene, I encountered an issue whenever I attempted to adjust its scale or position. An error message stating that the mesh is null would consistently pop up.
mesh2.position.set(0,0,-5);
mesh2.scale.set(0.2, 0.3, 0.2);
Uncaught TypeError: Cannot read property 'position' of null
For further details, you can visit testing2.site44.com.
I am seeking assistance as I have invested countless hours attempting to resolve this issue.
function init()
{
var scene = new THREE.Scene();
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setClearColor(new THREE.Color('#005b96'), 1)
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
document.body.appendChild( renderer.domElement );
renderer.domElement.id = "canvas_threeJS";
//Add camera to the scene
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR =1000;
var camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
camera.position.set(0,3,8);
camera.lookAt(new THREE.Vector3(0,0,-5));
scene.add(camera);
//Add ambient light
var ambientLight = new THREE.AmbientLight("#6497b1");
scene.add(ambientLight);
//Handle window resize
//Add main light
var light = new THREE.PointLight("#b3cde0",.6);
light.position.set(-5,13,-1);
scene.add(light);
var mesh2 = null;
var loader = new THREE.JSONLoader();
loader.load('assets/models/spaceship001.json', function(geometry) {
mesh2 = new THREE.Mesh(geometry);
scene.add(mesh2);
console.log("done loading model");
});
mesh2.position.set(0,0,-5);
// mesh2.scale.set(0.2, 0.3, 0.2);
//Start position of a level group
var levelSpawn = -100;
//Get visible width at levelSpawn position
var vFOV = camera.fov * Math.PI / 180;
var height = 2 * Math.tan( vFOV / 2 )*levelSpawn;
var aspect = window.innerWidth / window.innerHeight;
var width = height * aspect;
//Start rendering
update();
function update()
{
//Update 3D scene
renderer.render( scene, camera );
//Continue rendering
requestAnimationFrame( update );
}
}