Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为node添加renderable 属性, 用来实现"不渲染当前node及其子节点" 的功能 #17159

Closed
finscn opened this issue Jun 15, 2024 · 4 comments
Labels
Feature Request Needs Triage Needs to be assigned by the team

Comments

@finscn
Copy link
Contributor

finscn commented Jun 15, 2024

Use Case

需求:
只是不渲染 当前node及其子节点, 但是上面的 组件正常运转 (所以 node.active 无法满足需求).
目前 设置node.Layer = 0 能实现类似功能, 但是比较低效, 因为要深度遍历所有子节点 来改变 所有子节点的Layer.
而且如果子节点的 Layer 不一样, 还要备份之前的值, 用来还原. (而且 Layer 好像不能避免 walk() ???)

希望能提供一个更纯粹的属性来控制渲染.
比如 node.renderable , 那么在2D场景下 可以在 walk 时进行如下判断.

public walk (node: Node, level = 0): void {
        if (!node.activeInHierarchy || !node.renderable2D) {
            return;
        }
        // .....
}

当然 其实有时候也希望3D场景预备这个能力

Problem Description

如上所述

Proposed Solution

No response

How it works

No response

Alternatives Considered

Additional Information

No response

@finscn finscn added Feature Request Needs Triage Needs to be assigned by the team labels Jun 15, 2024
@minggo
Copy link
Contributor

minggo commented Jun 17, 2024

ECS 机制下不适合在 Node 里加逻辑去控制。可以通过 Node.getComponentsInChildren() 找到渲染组件,然后去 disable 掉。

@minggo minggo closed this as completed Jun 17, 2024
@kaxifakl
Copy link
Contributor

kaxifakl commented Jun 17, 2024

ECS 机制下不适合在 Node 里加逻辑去控制。可以通过 Node.getComponentsInChildren() 找到渲染组件,然后去 disable 掉。

那能不能把这个标记加在RenderEntity中,Node.getComponentsInChildren()深度遍历的消耗也是很大的

@finscn
Copy link
Contributor Author

finscn commented Jun 17, 2024

ECS 机制下不适合在 Node 里加逻辑去控制。可以通过 Node.getComponentsInChildren() 找到渲染组件,然后去 disable 掉。

那不还是遍历所有子节点 以及会执行 很多的 walk 吗? 性能太低了

@finscn
Copy link
Contributor Author

finscn commented Jun 21, 2024

@minggo 希望正针对这个需求 进一步讨论下.

https://forum.cocos.org/t/topic/158944/ 我在论坛发了个帖子.

renderable 这个名字不好, 可以不用这个名字,但是希望有一个类似的属性.

如果不想增加属性, 希望能提供一个 便于 开发者重写的方式.
现在要在项目里 完全重写 walk 很难 而且walk 过于复杂.

比如

public walk (node: Node, level = 0): void {
    if (!node.activeInHierarchy) {
        return;
    }
    // ....
}

改为

public canWalk(node: Node, level = 0): void {
    return node.activeInHierarchy
}

public walk (node: Node, level = 0): void {
    if (!this.canWalk(node) {
        return;
    }
    // ....
}

这样开发者如果有我这种特殊需求, 可以重写 canWalk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

3 participants