I want to freeze the mesh to improve performance, but I don’t know how to tell if the current mesh has an animation group, if so, its child and parent nodes should not be frozen, is there a corresponding api?
there is my code:
export function freezeNonAnimationNodes(loadedParams: IFreezeNonAnimationNodesParams) {
const now = performance.now();
const { loadedAnimationGroups, loadedTransformNodes, loadedMeshes } = loadedParams;
const checkedNodes = new Map<AbstractMesh | TransformNode, boolean>();
const nodesToFreeze: Array<AbstractMesh | TransformNode> = [];
function isNodeOrChildrenInAnimationGroup(node: any) {
if (checkedNodes.has(node)) {
return checkedNodes.has(node);
}
let inAnimationGroup = _isNodeInAnimationGroup(node);
if (!inAnimationGroup) {
for (const child of node.getChildren()) {
if (isNodeOrChildrenInAnimationGroup(child)) {
inAnimationGroup = true;
break;
}
}
}
checkedNodes.set(node, inAnimationGroup);
return inAnimationGroup;
}
function _isNodeInAnimationGroup(node: any) {
return loadedAnimationGroups.some((group: AnimationGroup) => group.targetedAnimations.some((animation) => animation.target === node));
}
loadedMeshes.forEach((mesh) => {
if (mesh.animations.length === 0 && !isNodeOrChildrenInAnimationGroup(mesh)) {
nodesToFreeze.push(mesh);
}
});
loadedTransformNodes.forEach((node) => {
if (node.animations.length === 0 && !isNodeOrChildrenInAnimationGroup(node)) {
nodesToFreeze.push(node);
}
});
and use it :
freezeNonAnimationNodes({ loadedAnimationGroups, loadedTransformNodes, loadedMeshes });
boys, could you give me some advice?