From 3e15fbe9d6c141e580e85bfe97bd11cb253c4d0d Mon Sep 17 00:00:00 2001 From: 06wj <06wj@163.com> Date: Tue, 30 Jun 2020 13:52:44 +0800 Subject: [PATCH] fix: ResourceManager.destroyUnsuedResource parameter become optional --- src/renderer/WebGLResourceManager.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/renderer/WebGLResourceManager.js b/src/renderer/WebGLResourceManager.js index 0aabfb30..6255f3fa 100644 --- a/src/renderer/WebGLResourceManager.js +++ b/src/renderer/WebGLResourceManager.js @@ -78,32 +78,35 @@ const WebGLResourceManager = Class.create(/** @lends WebGLResourceManager.protot }, /** - * 获取用到的资源 - * @param {Stage} stage + * 获取 rootNode 用到的资源 + * @param {Node} [rootNode] 根节点,不传返回空数组 * @return {Object[]} */ - getUsedResources(stage) { + getUsedResources(rootNode) { const resources = []; - stage.traverse((node) => { - if (node.isMesh && !node.isDestroyed) { - this.getMeshResources(node, resources); - } - }); + if (rootNode) { + rootNode.traverse((node) => { + if (node.isMesh && !node.isDestroyed) { + this.getMeshResources(node, resources); + } + }); + } return resources; }, /** - * 销毁没被使用的资源 + * 销毁没被 rootNode 使用的资源,通常传 stage。 + * @param {Node} [rootNode] 根节点,不传代表所有资源都没被使用过。 * @return {WebGLResourceManager} this */ - destroyUnsuedResource(stage) { + destroyUnsuedResource(rootNode) { const needDestroyResources = this._needDestroyResources; if (needDestroyResources.length === 0) { return this; } - const usedResources = this.getUsedResources(stage); + const usedResources = this.getUsedResources(rootNode); needDestroyResources.forEach((resource) => { if (usedResources.indexOf(resource) < 0) {