Files
modeling-app/docs/kcl/appearance.md
Jess Frazelle 53d40301dc start of Appearance function (#4743)
* initial commit

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add more samples

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updatres

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* regenerate docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* patterns and appearance samples

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fmt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-12-11 01:51:51 +00:00

642 KiB

title, excerpt, layout
title excerpt layout
appearance Set the appearance of a solid. This only works on solids, not sketches or individual paths. manual

Set the appearance of a solid. This only works on solids, not sketches or individual paths.

This will work on any solid, including extruded solids, revolved solids, and shelled solids.

appearance(data: AppearanceData, solid_set: SolidSet) -> SolidSet

Arguments

Name Type Description Required
data AppearanceData Data for appearance. Yes
solid_set SolidSet A solid or a group of solids. Yes

Returns

SolidSet - A solid or a group of solids.

Examples

// / Add color to an extruded solid.
exampleSketch = startSketchOn("XZ")
  |> startProfileAt([0, 0], %)
  |> lineTo([10, 0], %)
  |> lineTo([0, 10], %)
  |> lineTo([-10, 0], %)
  |> close(%)

example = extrude(5, exampleSketch)
  |> appearance({
       color = '#ff0000',
       metalness = 50,
       roughness = 50
     }, %)

Rendered example of appearance 0

// / Add color to a revolved solid.
sketch001 = startSketchOn('XY')
  |> circle({ center = [15, 0], radius = 5 }, %)
  |> revolve({ angle = 360, axis = 'y' }, %)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)

Rendered example of appearance 1

// / Add color to different solids.
fn cube(center) {
  return startSketchOn('XY')
    |> startProfileAt([center[0] - 10, center[1] - 10], %)
    |> lineTo([center[0] + 10, center[1] - 10], %)
    |> lineTo([center[0] + 10, center[1] + 10], %)
    |> lineTo([center[0] - 10, center[1] + 10], %)
    |> close(%)
    |> extrude(10, %)
}

example0 = cube([0, 0])
example1 = cube([20, 0])
example2 = cube([40, 0])

appearance({
  color = '#ff0000',
  metalness = 50,
  roughness = 50
}, [example0, example1])
appearance({
  color = '#00ff00',
  metalness = 50,
  roughness = 50
}, example2)

Rendered example of appearance 2

// / You can set the appearance before or after you shell it will yield the same result.
// / This example shows setting the appearance _after_ the shell.
firstSketch = startSketchOn('XY')
  |> startProfileAt([-12, 12], %)
  |> line([24, 0], %)
  |> line([0, -24], %)
  |> line([-24, 0], %)
  |> close(%)
  |> extrude(6, %)

shell({ faces = ['end'], thickness = 0.25 }, firstSketch)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)

Rendered example of appearance 3

// / You can set the appearance before or after you shell it will yield the same result.
// / This example shows setting the appearance _before_ the shell.
firstSketch = startSketchOn('XY')
  |> startProfileAt([-12, 12], %)
  |> line([24, 0], %)
  |> line([0, -24], %)
  |> line([-24, 0], %)
  |> close(%)
  |> extrude(6, %)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)

shell({ faces = ['end'], thickness = 0.25 }, firstSketch)

Rendered example of appearance 4

// / Setting the appearance of a 3D pattern can be done _before_ or _after_ the pattern.
// / This example shows _before_ the pattern.
exampleSketch = startSketchOn('XZ')
  |> startProfileAt([0, 0], %)
  |> line([0, 2], %)
  |> line([3, 1], %)
  |> line([0, -4], %)
  |> close(%)

example = extrude(1, exampleSketch)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)
  |> patternLinear3d({
       axis = [1, 0, 1],
       instances = 7,
       distance = 6
     }, %)

Rendered example of appearance 5

// / Setting the appearance of a 3D pattern can be done _before_ or _after_ the pattern.
// / This example shows _after_ the pattern.
exampleSketch = startSketchOn('XZ')
  |> startProfileAt([0, 0], %)
  |> line([0, 2], %)
  |> line([3, 1], %)
  |> line([0, -4], %)
  |> close(%)

example = extrude(1, exampleSketch)
  |> patternLinear3d({
       axis = [1, 0, 1],
       instances = 7,
       distance = 6
     }, %)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)

Rendered example of appearance 6

// / Color the result of a 2D pattern that was extruded.
exampleSketch = startSketchOn('XZ')
  |> startProfileAt([.5, 25], %)
  |> line([0, 5], %)
  |> line([-1, 0], %)
  |> line([0, -5], %)
  |> close(%)
  |> patternCircular2d({
       center = [0, 0],
       instances = 13,
       arcDegrees = 360,
       rotateDuplicates = true
     }, %)

example = extrude(1, exampleSketch)
  |> appearance({
       color = '#ff0000',
       metalness = 90,
       roughness = 90
     }, %)

Rendered example of appearance 7