Update examples to use generated enums

This commit is contained in:
Carson Katri 2022-11-17 13:18:08 -05:00
commit e7bae54662
6 changed files with 38 additions and 35 deletions

View file

@ -26,8 +26,8 @@ Many nodes have enum properties. For example, the math node lets you choose whic
```python
# Access it by Node.Enum Name.Case
math(operation=Math.Operation.Add)
math(operation=Math.Operation.Subtract)
math(operation=Math.Operation.ADD)
math(operation=Math.Operation.SUBTRACT)
math(operation='MULTIPLY') # Or manually pass a string
```
@ -37,9 +37,9 @@ Internally, this type is generated as:
import enum
class Math:
class Operation(enum.Enum):
Add = 'ADD'
Subtract = 'SUBTRACT'
Multiply = 'MULTIPLY'
ADD = 'ADD'
SUBTRACT = 'SUBTRACT'
MULTIPLY = 'MULTIPLY'
...
...
```
@ -51,9 +51,9 @@ The cases will appear in code completion if you setup an [external editor](../..
Some nodes use the same input name multiple times. For example, the *Math* node has three inputs named `value`. To specify each value, pass a tuple for the input:
```python
math(operation=Math.Operation.Wrap, value=(0.5, 1, 0)) # Pass all 3
math(operation=Math.Operation.Wrap, value=(0.5, 1)) # Only pass 2/3
math(operation=Math.Operation.Wrap, value=0.5) # Only pass 1/3
math(operation=Math.Operation.WRAP, value=(0.5, 1, 0)) # Pass all 3
math(operation=Math.Operation.WRAP, value=(0.5, 1)) # Only pass 2/3
math(operation=Math.Operation.WRAP, value=0.5) # Only pass 1/3
```
![](./math_wrap.png)
@ -122,7 +122,7 @@ size.cube(...)
The node can now be used as a function:
```python
result = capture_attribute(data_type=CaptureAttribute.DataType.Boolean, geometry=cube_geo) # Specify a property and an input
result = capture_attribute(data_type=CaptureAttribute.DataType.BOOLEAN, geometry=cube_geo) # Specify a property and an input
result.geometry # Access the geometry
result.attribute # Access the attribute
```

View file

@ -44,7 +44,7 @@ def city_builder(...):
...
return building_points.instance_on_points(
instance=cube().transform(translation=(0, 0, 0.5)),
scale=random_value(data_type='FLOAT_VECTOR', min=building_size_min, max=building_size_max, seed=seed),
scale=random_value(data_type=RandomValue.DataType.FLOAT_VECTOR, min=building_size_min, max=building_size_max, seed=seed),
)
```
@ -67,10 +67,10 @@ But now the buildings are overlapping the road. We need to remove any point that
def city_builder(...):
...
building_points = ...
road_points = geometry.curve_to_points(mode='EVALUATED').points
road_points = geometry.curve_to_points(mode=CurveToPoints.Mode.EVALUATED).points
building_points = building_points.delete_geometry(
domain='POINT',
selection=geometry_proximity(target_element='POINTS', target=road_points, source_position=position()).distance < road_width
domain=DeleteGeometry.Domain.POINT,
selection=geometry_proximity(target_element=GeometryProximity.TargetElement.POINTS, target=road_points, source_position=position()).distance < road_width
)
...
```
@ -101,16 +101,16 @@ def city_builder(
))
# Building points
building_points = grid(size_x=size_x, size_y=size_y).distribute_points_on_faces(density=density, seed=seed).points
road_points = geometry.curve_to_points(mode='EVALUATED').points
road_points = geometry.curve_to_points(mode=CurveToPoints.Mode.EVALUATED).points
# Delete points within the curve
building_points = building_points.delete_geometry(
domain='POINT',
selection=geometry_proximity(target_element='POINTS', target=road_points, source_position=position()).distance < road_width
domain=DeleteGeometry.Domain.POINT,
selection=geometry_proximity(target_element=GeometryProximity.TargetElement.POINTS, target=road_points, source_position=position()).distance < road_width
)
# Building instances
yield building_points.instance_on_points(
instance=cube().transform(translation=(0, 0, 0.5)),
scale=random_value(data_type='FLOAT_VECTOR', min=building_size_min, max=building_size_max, seed=seed),
scale=random_value(data_type=RandomValue.DataType.FLOAT_VECTOR, min=building_size_min, max=building_size_max, seed=seed),
)
```

View file

@ -57,7 +57,7 @@ def voxelize(geometry: Geometry, resolution: Float = 0.2):
interior_band_width=resolution,
fill_volume=False
).distribute_points_in_volume( # Uniform grid distribution
mode='DENSITY_GRID',
mode=DistributePointsInVolume.Mode.DENSITY_GRID,
spacing=resolution
)
```
@ -73,7 +73,7 @@ def voxelize(geometry: Geometry, resolution: Float = 0.2):
interior_band_width=resolution,
fill_volume=False
).distribute_points_in_volume(
mode='DENSITY_GRID',
mode=DistributePointsInVolume.Mode.DENSITY_GRID,
spacing=resolution
).instance_on_points( # Cube instancing
instance=cube(size=resolution)
@ -97,7 +97,7 @@ def voxelize(geometry: Geometry, resolution: Float = 0.2):
interior_band_width=resolution,
fill_volume=False
).distribute_points_in_volume(
mode='DENSITY_GRID',
mode=DistributePointsInVolume.Mode.DENSITY_GRID,
spacing=resolution
).instance_on_points(
instance=cube(size=resolution)