I wouldn't attempt the 3D you have done and am not the greatest source code writer in the world but when electronics logic (ICs), came along I had to relearn how to do design because I was always an analog man. All we had at first were NAND gates so you had to come up with the equation for a circuit that you were designing such as a flip-flop using nothing but NAND gates.
The truth table for a 2 input NAND is 0+0=1
0+1=0
1+0=0
1+1=0
By assigning boolean terms A, B, & C to the ins and outs, you could get it into an algebraic term and then into a formula for a complicated circuit. I hope you didn't already know all this so I won't feel like an idiot.