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) {
enabledChildren.push(currentNode);
} else {
currentNode.children.forEach(traverse);
}
}
traverse(node);
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.
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.
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.