openscad

Why is a triangle hidden inside a transparent cube


I have this OpenSCAD script:

color([1, 1, 1, 0.2]) cube(80, center=false);

p1 = [80/2, 0, 0];
p2 = [80, 80/2, 0];
p3 = [80, 0, 80/2];

color([0, 1, 0, 0.9]) polyhedron(points=[p1, p2, p3], faces=[[0, 1, 2]]);

For some reason the triangle is hidden inside the transparent cube:

Triangle is hidden inside transparent cube

But when I comment out the cube statement, the triangle can be seen:

Triangle can be seen

Why should a triangle be hidden inside a transparent cube? How can I display the triangle inside the transparent cube?


Solution

  • This code worked. Looks like triangle should be drawn first and then the cube:

    p1 = [80/2, 0, 0];
    p2 = [80, 80/2, 0];
    p3 = [80, 0, 80/2];
    
    color([0, 1, 0, 0.9]) polyhedron(points=[p1, p2, p3], faces=[[0, 1, 2]]);
    color([1, 1, 1, 0.2]) cube(80, center=false);
    

    Now both triangle and cube are shown properly:

    Problem solved: screenshot