TSL: Add switch/case.#30935
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
The solution seems even more elegant than the of GLSL, but I fear it will not be compatible with all use cases, switch( value ) {
case 0:
a = 1;
case 1:
b = 1;
break;
} |
|
I've added support for the following use case: So meaning cases with the same block. However, other permutations of switch/case like the one you have shared in #30935 (comment) are more tricky to implement and we quickly reach a point where the code gets quite complex. Right now, the code in I'm not sure how common the different switch/case permutations are but I don't think we have to support all of them. It's best if you decide if |
|
@Mugen87 What do you think we do |
I'm not sure to understand how can i do things in case 1 => no break => add to case 1 my stuff in case 2 ? maybe add
|
|
To be honest, I don't like the classic |
I've implemented this approach in the last commit. You can now assign an arbitrary number of values to a single case. I actually prefer this approach compared to the previous one 👍 . I agree to exclude the fallthrough syntax. I was never a fan of it in any programming languages since it tends to produce hard-to-follow code, imo. |
|
Updated the TSL wiki page: https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language#switch-case |
* TSL: Add switch/case. * StackNode: Support Case() sequence. * StackNode: Refactor `Case()`.
* TSL: Add switch/case. * StackNode: Support Case() sequence. * StackNode: Refactor `Case()`.
Related issue: #30900
Description
The PR adds switch/case syntax to TSL.
The values of the switch and case statements can be primitives or node objects.