We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

How do I remove objects from scene

Home Forums Puzzles How do I remove objects from scene

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #18501
    madbat
    Customer

    Hey!

    I can append scene and clone objects, But how do I remove objects that I have cloned?
    Like what you do with verge3d :)

    // Patrik

    #18508

    Hi,

    You can do it with JavaScript as per method #2 of our JavaScript guide:

        app.ExternalInterface.removeObject = function(objName) {
            var obj = app.scene.getObjectByName(objName);
            app.scene.remove(obj);
        }

    Here is a Puzzle snippet for calling this function:

    Chief 3D Verger | LinkedIn | Twitter

    #18514
    zjbcool
    Customer

    Oh,I think we can create a partical system using puzzle now.

    #18520

    partical system using puzzle now

    Would be interesting to see if this can work :good:

    Chief 3D Verger | LinkedIn | Twitter

    #18531
    jem
    Customer

    Hi Yuri,
    I do not wish to complicate this topic, but I do wonder if the remove() function is sufficient to completely remove an object and its data from memory? There are a few threads about this on Stack Exchange and a page in the Three documentation (https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects). I wrote a function to do this that removes the object from the scene and also disposes of the data. My hope was this approach would free up memory better than using remove() alone. What is the opinion of the Soft8soft team?
    Thank you.

    	//A function to fully dispose of objects.
    	//This is useful to dispose of cloned objects.
    	app.ExternalInterface.disposeOfObjects = function (objects) {
    		for (var i = 0; i < objects.length; i++) {
    			if (typeof objects !== 'undefined') {
    				var meshToBeDeleted = app.scene.getObjectByName(objects);
    				app.scene.remove(meshToBeDeleted);
    				meshToBeDeleted.geometry.dispose();
    				meshToBeDeleted.material.dispose();
    				meshToBeDeleted = undefined;
    			}
    		}
    	};

    Jeremy Wernick

    #18533

    if the remove() function is sufficient to completely remove an object and its data from memory?

    Indeed, calling dispose() for both geometry and the material is necessary to free memory occupied by an object’s resources. Thank for sharing the snippet! :good:

    Chief 3D Verger | LinkedIn | Twitter

    #18535
    jem
    Customer

    Oops. I was editing my previous post in an attempt to fix the formatting of the JavaScript code and the forum software seems to have deleted the post. Apparently square brackets can cause issues. At risk of double posting, here is my original post that Yuri responded to (with the JS code now included as an image).
    ———————-
    Hi Yuri,
    I do not wish to complicate this topic, but I do wonder if the remove() function is sufficient to completely remove an object and its data from memory? There are a few threads about this on Stack Exchange and a page in the Three documentation (https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects). I wrote a function to do this that removes the object from the scene and also disposes of the data. My hope was this approach would free up memory better than using remove() alone. What is the opinion of the Soft8soft team?
    Thank you.

    Jeremy Wernick

    #18538

    It happens sometimes with the syntax highlighting add-on we’re using. We should probably find a better one. :scratch:

    Chief 3D Verger | LinkedIn | Twitter

    #18545
    madbat
    Customer

    Thanks for quick reply. :good:

    #33480
    matthew
    Customer

    Hello,

    I am not proficient in JS and cannot figure out how to remove every clone created besides the last one created (every next one still exists after I click the remove button). Here are my puzzles:

    #33483

    hi,

    looks like the image was not attached. :unsure:

    Chief 3D Verger | LinkedIn | Twitter

    #33484
    matthew
    Customer

    Oh sorry, I hope here it is:

    Puzzles

    #33487
    matthew
    Customer

    For some reason I cannot attach an image. Maybe this will work:

    Puzzles-Verge3-D

    #33488

    Got it! In fact, there is no longer need to use code, since an object can now be removed with this puzzle:

    https://www.soft8soft.com/docs/manual/en/puzzles/Objects.html#remove

    Chief 3D Verger | LinkedIn | Twitter

    #33489
    matthew
    Customer

    That’s great Yuri, however problem still remains. I need to remove every cloned object at each click of the button. For example – if I create 4 clones I want to be able to delete them all with each click deleting last one object added. Right now I can only delete exactly the last object cloned and rest of them remain on the scene. Puzzles below:

    Puzzles-Verge3-D-2

    How do I target every object in the list of cloned objects – and delete them one by one? I assume the problem is with the cloning puzzle itself. There should be a loop adding an object inside the array/list for each click but I can’t seem to figure it out – pls help ^_^

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.