set operation

Synopsis

  • set(attribute, value)

Parameters

  1. attributestring
    Name of shape attribute to set.
  2. value—{ bool | float | string }
    Value to assign to shape attribute. Note that not all shape attributes are writable.

Description

The set operation assigns a value to a shape attribute of the current shape. There are two kinds of shape attributes: builtin attributes such as material.color or scope.tx and generic attributes, which are declared as rule attributes (see Attributes).

Related

Examples

Builtin shape attributes

  • Enable horizontal trim planes
  • Set x-translation of scope 0
  • Set the material color's red component to 0.5
  • Assign the built-in test texture to the colormap channel
  • set(trim.horizontal, true)
  • set(scope.tx, 0)
  • set(material.color.r, 0.5)
  • set(material.colormap, "builtin:uvtest.png")

Generic shape attributes

Store floor index in a generic attribute, floorHeight. The attribute is then used to color the windows on every 3rd floor is pink.

attr floorNumber = -1

const floorHeight = 4

Init-->
   extrude(30)
   comp(f) {side : Side }
   
Side-->
   split(y) { ~floorHeight: Floor }*
   
Floor-->
   set(floorNumber, split.index)
   split(x) { ~1   : Wall 
            | {~3  : Tile }* 
            | ~1   : Wall } 
Tile-->
   split(x) { 0.5  : Wall 
            | ~1   : MidTile 
            | 0.5  : Wall }
MidTile-->
   split(y) { 0.5  : Wall 
            | ~1   : Window 
            | 0.5  : Wall }
			
Window-->
   case floorNumber % 3 == 0:
        color(1.0, 0.0, 1.0)
        X
   else:
        X
Store floor index with floorHeight attribute

In this topic