guillaumechereau / goxel

Goxel: Free and Open Source 3D Voxel Editor
GNU General Public License v3.0
2.8k stars 223 forks source link

Operation on variables in procedural #190

Closed tymekborowski closed 4 years ago

tymekborowski commented 4 years ago

Hello! I'm trying to write a procedural script for a simple random walk in 3d, but can't make it work. Does Goxel support incemental operations on variables, like $x = $x +1 to accumulate changin "cursor position" through iteration?

Similar solution work well in Blender+Python

shape main {
      $x = 0
      $y = 0
      $z = 0
      $direction = 1

      loop 50 [] {
            $direction = 1+-6
            if ($direction == 1) {$x = $x + 1}
            if ($direction == 2) {$x = $x - 1}
            if ($direction == 3) {$y = $y + 1}
            if ($direction == 4) {$y = $y - 1}
            if ($direction == 5) {$z = $z + 1}
            if ($direction == 6) {$z = $z - 1}
            cube [x $x y $y z $z]
      }
}
guillaumechereau commented 4 years ago

It's been a while since I wrote the procedural code, but I think this is not possible like that. The variable are reset at each iteration of the loop (this is a context free grammar).

I could achieve more or less what you try to do with this code:

shape main {
    node[life 50 z 10]
}

shape node {
    cube[]
    step[]
}

shape step
rule { node[x 1] }
rule { node[x -1] }
rule { node[y 1] }
rule { node[y -1] }
rule { node[z 1] }
rule { node[z -1] }

On a side note, the procedural support is really weak at the moment. I think there are many crashes and bugs. If you do cool things with goxel procedural please let me know it will motivate me to improve it.

tymekborowski commented 4 years ago

Wow, that was fast. Thanks a lot!!! Now I'm starting to get it :) I'll let you know if I make something cool :>