Repository navigation
Closed
Description
I don't know if I have the wrong expectation, but I would like to have the polygons to inherit their colors from the original CSG. I can look into it if this is something that should work.
Right now the colors seems to be random, and they become different every time:
@Test
public void polygonsShouldGetColorFromCSG() {
CSG cube = new Cube()
.toCSG()
.setColor(Color.BLUE);
assertEquals(Color.BLUE, cube.getColor());
String colorAsString = Color.BLUE.getRed() + " " + Color.BLUE.getGreen() + " " + Color.BLUE.getBlue();
cube.getPolygons().forEach(polygon -> {
assertTrue(polygon.getStorage().getValue("material:color").isPresent());
assertEquals("Expected the polygon to get the same color as the CSG", colorAsString, polygon.getStorage().getValue("material:color").get());
});
}The result from the test gives different results every run, here is one example:
Expected the polygon to get the same color as the CSG expected:<[0.0 0.0 1].0> but was:<[1.0 0.6470588445663452 0].0>
Expected :0.0 0.0 1.0
Actual :1.0 0.6470588445663452 0.0
<Click to see difference>
In the long run I would like to be able to colorize the output like in this example:
CSG cube = new Cube(0.5).toCSG();
CSG sphere = new Sphere(0.36, 64, 32).toCSG();
CSG corners = cube.difference(sphere);
CSG result = cube.difference(corners)
.setColor(Color.GRAY);
CSG text = CSG.text("Z-", 2)
.setColor(Color.BLUE)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).rot(180, 0, 0).translate(-14, -10, 28));
result = result.dumbUnion(text);
text = CSG.text("Z+", 2)
.setColor(Color.BLUE)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).translate(-14, -10, 28));
result = result.dumbUnion(text);
text = CSG.text("Y+", 2)
.setColor(Color.GREEN)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).rot(90, 0, 180).translate(-14, -10, 28));
result = result.dumbUnion(text);
text = CSG.text("Y-", 2)
.setColor(Color.GREEN)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).rot(270, 0, 0).translate(-14, -10, 28));
result = result.dumbUnion(text);
text = CSG.text("X-", 2)
.setColor(Color.RED)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).rot(270, 90, 0).translate(-14, -10, 28));
result = result.dumbUnion(text);
text = CSG.text("X+", 2)
.setColor(Color.RED)
.transformed(new Transform().scale(0.01).scale(1, 1, 1).rot(270, 270, 0).translate(-14, -10, 28));
result = result.dumbUnion(text);Metadata
Metadata
Assignees
Labels
No labels
Activity
breiler commentedon Aug 10, 2024
Thanks for the merge!
It works ok for simple shapes, however the texts won't change color. I think that it boils down to the problem given in this scenario. Is it resonable that all polygons would change color to red when setting the color to the unioned shape?
madhephaestus commentedon Aug 11, 2024
Oh, so is the idea that you are trying to have some polygons within the shape to be one color, and other polygons another color? I think the issue you are running into is that the storage object is synced at the end of an operation. I think this is a good idea. In order to make it work we may need to remove the color from the storage object and put it instead in a new, separate variable in both the CSG and Polygon object. That way passing polygons around will preserve the color of that specific polygon through CSG operations. Id be happy to merge a PR with that change. It may have a side effect of increasing the memory footprint of the csg objects. I feel this feature is worth that change.
breiler commentedon Aug 11, 2024
Yes, and with the previous PR this now works. Gere is an example where I make a cube and color each face and then round its corners. The polygons that had different colors such as RED, GREEN and BLUE will keep its color information after the operations:
I don't want the colors to be synced, I like them to be retained from the original. The problem that I encountered is that once a gemometric operation has been done (such as with a union) there is no way to access the color of all the polygons in a neat way. I expect that the colors should be able to be overridden if I choose to.
This problem only gets clear when creating an object where the polygons do not share the same storage. Take this for instance, I would expect this to create a text which is black:
But each component of the extruded text will get their own storage (), so setting the color will have no effect (it will use the default randomly generated color from PropertyStorage.java#L65).