Exporting Only Enabled Children with GltfExporter

I want to export the output using GltfExporter by fetching all my models that are enabled. However, I haven’t been successful. There are many child and children elements, but I only want to extract the enabled children and export their output.

If there’s another way to download the parts visible on the screen (regardless of the camera angle), I’m open to using that as well, but I haven’t found one yet.

 function collectEnabledChildren(node) {
                    let enabledChildren = [];
                    function traverse(currentNode) {
                        if (currentNode.enabled && currentNode.children.length > !0) {
                        } else {

                    return enabledChildren;

                let enabledChildren = collectEnabledChildren(pc.app.root);

Having a quick look at the code, it exports all entities under the root one you specify. But it skips exporting geometry for Render and Model component for those that are disabled.

So perhaps instead of disabling the entity, disable the entity.render or entity.model, which ever you use.

The project is large and I’ve made definitions in many places.

I just want to select all visible entities; do you have any other script suggestions?

You could from code reparent all enabled entities under one root, export it, and then reparent them back perhaps.

Note that my initial suggestion can be done using code, so the fact the project is large would make no difference.

Actually, I can export the entire root model, extract the enabled ones, and then replace them, but the disabled ones also come along. When I try to delete the disabled ones, the enabled ones get deleted as well.

function removeChildrenWithDisabledComponents(entity) {
  const toRemove = [];

  entity.children.slice().forEach(child => {

    if ((child.enabled === false && child.children.length === 0)) {
    } else if (child.enabled === false && child.children.length > 0) {

  return toRemove;

Isn’t there a way to select all the models that appear on the screen?

Perhaps, you could check visibleThisFrame property of the mesh instances:

but I’m using entity not mesh

An entity by itself cannot be seen on the screen. It has to have a model or a render component, which holds a visual mesh that you actually see. That component has a mesh, which has one or more mesh instances.