jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.65k stars 514 forks source link

feat(modeling): preserve color for offset and extrude #1275

Closed platypii closed 1 year ago

platypii commented 1 year ago

This PR preserves the color attribute when applying operations like offset and extrude and project.

This seems like a clear improvement for users of JSCAD. If you have a 2D object with color like on the left, would you expect extrusion to preserve the color? Or lose it?

extrudeColor

preserve-color.js ```js import * as jscad from '@jscad/modeling' const { colorize } = jscad.colors const { extrudeLinear } = jscad.extrusions const { square } = jscad.primitives const { translate } = jscad.transforms export const main = () => { const obj2d = [ colorize([1, 0, 0], square({ center: [0, -4] })), colorize([0, 1, 0], square({ center: [0, 0] })), colorize([0, 0, 1], square({ center: [0, 4] })), ] return [ translate([-4, 0], obj2d), translate([4, 0, 0], extrudeLinear({}, obj2d)), ] } ```

If someone really want no color, it's easy to remove using colorize. But if you want to preserve color of sub-components through an operation... there's really no good way to do it without this change.

All Submissions:

platypii commented 1 year ago

@z3dev I just pushed some more changes which I hope will address your concerns:

Let me know what you think