Removing cloned geometry

Home Forums Programming Removing cloned geometry

This topic contains 9 replies, has 3 voices, and was last updated by Yuri Kovelenov Yuri Kovelenov 4 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #20049
    Avatar
    mugga
    Newbie

    I need some help in creating a filter function.

    I’m trying to create a live filter in conjunction with an csv list.
    I got multiple properly named objects in 3d. When I’m activating the filtering, a dummy objects gets cloned and positioned regarding the already “named” placed objects.

    This is working great, but when I’m changing the filter, I want to remove the already cloned objects.

    The only way I would see at the moment, is to read all the objects in the scene and removing the not used anymore ones. But I wondering if there is a better/simpler way.

    I’ve attached the puzzle I’m currently using for the creation of the clones.

    Attachments:
    You must be logged in to view attached files.
    #20051
    Avatar
    jem
    Licensee

    @mugga, the easiest way to manage clones is to maintain their names on a list. You can then write a function to delete all or some of the clones.

    There is a problem with your puzzles. You are cloning an object, but you are not recording the cloned object’s name anywhere. Without the clone’s name, you will struggle to delete it.

    The clone object puzzle is a function that returns the name of the new cloned object. I suggest that you assign the result of the “clone object” puzzle to a local variable, add that variable to a list for later use, and then set the cloned objects position.

    You can use a custom JS function to easily delete the clones. See:

    How do I remove objects from scene

    Attachments:
    You must be logged in to view attached files.
    #20061
    Yuri Kovelenov
    Yuri Kovelenov
    Developer

    @jem thanks for helping out!

    Good news: we are going to ship the remove object puzzle with the next release. It won’t do the dispose operation though (for now). It appears, there is no need to dispose geometry and materials for the cloned objects, because these resources are shared with the original object. When we remove and dispose the clones, the engine automatically restores that disposed geometry and materials (from data stored in JavaScript variables) in order to render the original object.

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #20068
    Avatar
    mugga
    Newbie

    @jem
    Thank you very much for the explanations and examples. That was excactly my problem, I didnt know how to save the names for the clones. But now I got it working.

    Maybe you can help me with another thing. I would now also like to change the material (diffuse color) for every clone based on a calculated rgb value.
    The function for getting the rgb values, should already work, but cant change the color for the individual objects.

    #20095
    Avatar
    jem
    Licensee

    @mugga, I think that you will run into issues trying to change the color of each clone independently. Color is an attribute of a material. All clones will have the same material as their source. That is, there will only be one material, not many copies of the same material. If you were to change the color of the material, the color of all of the clones would be affected. You will need a unique material for each clone. If you only had a minimal number of clones, you could create a few materials in Blender ahead of time and apply one of them to each clone. I suspect that you will have far too many clones to make that approach practical. You can create a JavaScript function to make new materials on-the-fly and apply them to the clones as you create the clones. Here is a link that explains some of JS material system if you are interested.
    https://threejsfundamentals.org/threejs/lessons/threejs-materials.html
    https://www.soft8soft.com/docs/manual/en/programmers_guide/Programming-basics.html
    https://www.soft8soft.com/docs/api/en/materials/MeshLambertMaterial.html
    Most three.js examples will work in the Verge3D engine. Just change the name of the library object from “THREE.” to “v3d.”

    #20100
    Avatar
    jem
    Licensee

    @mugga, the code is simple, so I just wrote the function. The setObjectColor function expects RGB values as ints between 0-255. If you have some other color format, the code is easy to adapt. This code goes in the ExternalInterface section of your main JS file.

    Attachments:
    You must be logged in to view attached files.
    #20207
    Avatar
    mugga
    Newbie

    @jem
    Awesome, thank you very much for all your help. I could adapt your code and make it work for my usecase.

    Only thing which is quite strange is that when I’m using anything other than “MeshBasicMaterial” the objects turn black. The scene is only lit via envmap/hdri. Do I have to copy the scene envmap to the new material?

    #20280
    Avatar
    jem
    Licensee

    @mugga, yes, this makes sense. I think that you will have to use the MeshNodeMaterial if you are only using HDRIs for lighting. Materials exported from Blender or 3ds use MeshNodeMaterial. This material is complex and challenging to create from scratch in JS code, but I do have an easy solution to this issue. Write some JS code to clone the material, change the RGB values of the base color, and then apply the newly cloned material to the newly created cloned object. This technique is simpler to implement than it sounds. I do not know how you set up your material nodes in Blender, but I will make two assumptions. First, the object from which you create the clones uses a Principled BSDF shader. Second, an RGB value node called “RGB” sets the base color in the Principled BSDF shader. I have included a screenshot of this node set up.

    Now, we need to rewrite the custom setObjectColor() function. Here is the new code:

    This code is partialy based on the example in the documentation:
    https://www.soft8soft.com/docs/api/en/materials/MeshNodeMaterial.html
    I have attached an updated project (dummy.zip) that has the new JS code and is only illuminated with an HDRI environment.
    Please give this a try and let us all know if it works for you.

    Attachments:
    You must be logged in to view attached files.
    #20306
    Avatar
    mugga
    Newbie

    Thank you very much for all your help jem. I had to modify it a little bit for my needs, but its working perfect. :good:

    #20307
    Yuri Kovelenov
    Yuri Kovelenov
    Developer

    thanks for the clear explanation Jem! :good:

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.