kopia lustrzana https://github.com/carson-katri/geometry-script
Update examples to use generated enums
rodzic
828fb8b6da
commit
e7bae54662
|
@ -4,13 +4,7 @@ import nodeitems_utils
|
|||
from .state import State
|
||||
|
||||
def map_case_name(i):
|
||||
r = i.identifier.replace('_', ' ').title().replace(' ', '')
|
||||
if r == 'None':
|
||||
return 'NONE'
|
||||
elif not r[0].isalpha():
|
||||
return f'_{r}'
|
||||
else:
|
||||
return r
|
||||
return i.identifier.replace(' ', '_').upper()
|
||||
|
||||
# The base class all exposed socket types conform to.
|
||||
class Type:
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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),
|
||||
)
|
||||
```
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -4,7 +4,16 @@
|
|||
from geometry_script import *
|
||||
|
||||
@tree("City Builder")
|
||||
def city_builder(geometry: Geometry, building_size_min: Vector = (0.1, 0.1, 0.2), building_size_max: Vector = (0.3, 0.3, 1), size_x: Float = 5.0, size_y: Float = 5.0, road_width: Float = 0.25, seed: Int = 0, resolution: Int = 60):
|
||||
def city_builder(
|
||||
geometry: Geometry,
|
||||
building_size_min: Vector = (0.1, 0.1, 0.2),
|
||||
building_size_max: Vector = (0.3, 0.3, 1),
|
||||
size_x: Float = 5.0,
|
||||
size_y: Float = 5.0,
|
||||
road_width: Float = 0.25,
|
||||
seed: Int = 0,
|
||||
resolution: Int = 60
|
||||
):
|
||||
# Road geometry from input curves
|
||||
road_points = geometry.curve_to_points().points
|
||||
yield geometry.curve_to_mesh(
|
||||
|
@ -22,10 +31,10 @@ def city_builder(geometry: Geometry, building_size_min: Vector = (0.1, 0.1, 0.2)
|
|||
seed=seed
|
||||
# Delete invalid building points based on proximity to a road
|
||||
).points.delete_geometry(
|
||||
domain='POINT',
|
||||
selection=road_points.geometry_proximity(target_element='POINTS', source_position=position()).distance < road_width * 2
|
||||
domain=DeleteGeometry.Domain.POINT,
|
||||
selection=road_points.geometry_proximity(target_element=GeometryProximity.TargetElement.POINTS, source_position=position()).distance < road_width * 2
|
||||
)
|
||||
random_scale = random_value(data_type='FLOAT_VECTOR', min=building_size_min, max=building_size_max, seed=seed + id())
|
||||
random_scale = random_value(data_type=RandomValue.DataType.FLOAT_VECTOR, min=building_size_min, max=building_size_max, seed=seed + id())
|
||||
yield building_points.instance_on_points(
|
||||
instance=cube(size=(1, 1, 1)).transform(translation=(0, 0, 0.5)),
|
||||
scale=random_scale
|
||||
|
|
|
@ -5,12 +5,12 @@ from geometry_script import *
|
|||
@tree("LEGO")
|
||||
def lego(size: Vector, stud_radius: Float, stud_depth: Float, count_x: Int, count_y: Int):
|
||||
base = cube(size=size)
|
||||
stud_shape = cylinder(fill_type='NGON', radius=stud_radius, depth=stud_depth, vertices=8).mesh
|
||||
stud_shape = cylinder(fill_type=Cylinder.FillType.NGON, radius=stud_radius, depth=stud_depth, vertices=8).mesh
|
||||
stud = stud_shape.transform(translation=combine_xyz(z=(stud_depth / 2) + (size.z / 2)))
|
||||
hole = stud_shape.transform(translation=combine_xyz(z=(stud_depth / 2) - (size.z / 2)))
|
||||
segment = mesh_boolean(
|
||||
operation='DIFFERENCE',
|
||||
mesh_1=mesh_boolean(operation='UNION', mesh_2=[base, stud]).mesh,
|
||||
operation=MeshBoolean.Operation.DIFFERENCE,
|
||||
mesh_1=mesh_boolean(operation=MeshBoolean.Operation.UNION, mesh_2=[base, stud]).mesh,
|
||||
mesh_2=hole
|
||||
).mesh
|
||||
return mesh_line(count=count_x, offset=(1, 0, 0)).instance_on_points(
|
||||
|
@ -20,7 +20,7 @@ def lego(size: Vector, stud_radius: Float, stud_depth: Float, count_x: Int, coun
|
|||
@tree("Mesh to LEGO")
|
||||
def mesh_to_lego(geometry: Geometry, resolution: Float=0.2):
|
||||
return geometry.mesh_to_volume(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=lego(size=resolution, stud_radius=resolution / 3, stud_depth=resolution / 8, count_x=1, count_y=1)
|
||||
|
|
Ładowanie…
Reference in New Issue