I can't add physics to a loaded JSON model. The model is displaying but I can't add the addEventListener( 'collision', handleCollision )
to it. The console says "undefined"
when I add the listener. I tried it with a normal non-loaded Physijs.BoxMesh
and it works perfectly. But if i load a json model as a Physijs.BoxMesh
it says "undefinded"
. Can someone help me ? You can see in my code, that I create a non-loaded cube and a loaded json_cube.
cube.addEventListener( 'collision', handleCollision ); -> works.
json_cube.addEventListener( 'collision', handleCollision ); -> do not work.
// cube
var material = new THREE.MeshBasicMaterial({map: THREE.ImageUtils.loadTexture("Textures/crate.jpg")});
var cube = new Physijs.BoxMesh(new THREE.CubeGeometry(20, 20, 20), material);
cube.position.x = 0;
cube.position.y = 50;
cube.position.z = 0;
scene.add(cube);
//JSON Cube
var loader = new THREE.JSONLoader();
var json_cube = loader.load("uvcube.json", function ( geometry, material ) {
materials = new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture("Textures/new_layout.png")
});
json_cube = new Physijs.BoxMesh( geometry, materials);
json_cube.scale.set( 10, 10, 10 );
json_cube.position.x =0;
json_cube.position.y =50;
json_cube.position.z =40;
scene.add(json_cube);
});