D
D
Dmitry2016-02-28 04:43:10
three.js
Dmitry, 2016-02-28 04:43:10

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

3 answer(s)
K
Khangeldy Ilebaev, 2016-03-06
@mahabatuly

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]

A
Amir Gafurov, 2016-03-10
@amir73911

scene.remove(object)

H
hazik76, 2016-06-17
@hazik76

try calling the second one the second
var mesh2 = new THREE.Mesh( geom, new THREE.MeshFaceMaterial( mats ) );
scene.add(mesh2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question