function to consolidate per element color to object color ? #1238
Replies: 2 comments 3 replies
-
Looking at the types in https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling/src/geometries , it appears only geom3 can have per element (poly3) colors. https://github.com/jscad/OpenJSCAD.org/blob/master/packages/modeling/src/colors/colorize.js colors all geometries. But sides from geom2 are not a geometry, just an array of 2 point lists/arrays. Single vertices cannot have color, eg. points are not a geometry object. rough sketch polygons = geom3.toPolygons(object) // copy?
if (polygons.length === 0) return object
if (! polygons[0].color) return object
pColor = polygons[0].color.join()
isUniform = polygons.every( (p) => p.color.join() === pColor )
if(! isUniform) return object
polygons.forEach( (p) => delete p.color )
return colorize( pColor.split(), geom3.fromPolygons(polygons) ) |
Beta Was this translation helpful? Give feedback.
-
So, the modeling library doesn't support per polygon colors. The focus is 3D printing so colors are assigned to geometries. But users (and we have some big users) can assign colors to polygons. And the rendering also renders those colors at the polygon level. Also, deserializers and serializers try to convert colors when found, both at the geometry level and the polygon level. It does get a little confusing at times. |
Beta Was this translation helpful? Give feedback.
-
I noticed that serializers such as the x3d serializer generate long lists of per element (polygon) colors even if all colors are identical and could be assigned more cleanly at the object level. This would improve subsequent processing. This is because serializers need to directly represent the jscad data structure, and the jscad data will have .color properties per element after operations such as booleans and perhaps others.
It would be possible to check for uniform per element colors in serializers and then serialize accordingly.
Another option is to have a more general utility that consolidates uniform per element colors and generates a new object with an object color and no element colors, say geom3.cleanColors(). If the per element colors are not uniform, or disagree with the object color, the function would do nothing, eg. return the existing object, or perhaps a clone.
Would that make sense ? Perhaps it is best to leave such decisions to the cad designer as such a function may not be considered too difficult to put together, with some js experience.
Beta Was this translation helpful? Give feedback.
All reactions