Answer the question
In order to leave comments, you need to log in
Three.js - how to remove js model from scene? (or just hide?
I have 2 models loaded.
The task is to hide one of the models by clicking on the button (link a href).
Here is the model upload code:
********************************************* ***********************
ar init = function() {
var canv = document.getElementsByTagName("canvas")[0];
var renderer = new THREE.WebGLRenderer({canvas:canv, antialias: true});
renderer.setSize(w, h);
renderer.setClearColor(new THREE.Color(0xeeeeee), 1);
var scene = new THREE.Scene();
varloader1 = new THREE.JSONLoader( );
var onGeometry = function(geom, mats) {
var mesh = new THREE.Mesh( geom, new THREE.MeshFaceMaterial( mats ) );
scene.add(mesh);
};
loader1.load("flat2.js", onGeometry);
var loader2 = new THREE.JSONLoader( );
var onGeometry = function(geom, mats) {
var mesh = new THREE.Mesh( geom, new THREE.MeshFaceMaterial( mats ) );
scene.add(mesh);
};
loader2.load("table.js", onGeometry);
var render = function() {
renderer.render(scene,camera);
requestAnimationFrame(render);
};
requestAnimationFrame(render);
};
window.onload = init;
window.onresize = init;
******************************************************* ******************
Here's what I'm trying to write to the link command:
$("#link").click(function () {
init.scene.remove( object.loader2 );
});
******************************************************* ********************
But, for some reason, it doesn't work... Doesn't remove (doesn't hide) the model from the scene.
Where am I making a mistake? How to do it right?
Answer the question
In order to leave comments, you need to log in
I don't know for sure, maybe you need to select the object correctly first. C using
scene.getObjectByName or scene.getObjectById or scene.children[object index]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question