kopia lustrzana https://github.com/carson-katri/geometry-script
Add curve support
rodzic
7d539baf6a
commit
e7957c75d0
|
@ -6,6 +6,7 @@ import re
|
||||||
from .state import State
|
from .state import State
|
||||||
from .types import *
|
from .types import *
|
||||||
from .static.input_group import InputGroup
|
from .static.input_group import InputGroup
|
||||||
|
from .static.curve import Curve
|
||||||
from ..absolute_path import absolute_path
|
from ..absolute_path import absolute_path
|
||||||
|
|
||||||
class OutputsList(dict):
|
class OutputsList(dict):
|
||||||
|
@ -28,6 +29,13 @@ def build_node(node_type):
|
||||||
argname = prop.identifier.lower().replace(' ', '_')
|
argname = prop.identifier.lower().replace(' ', '_')
|
||||||
if argname in kwargs:
|
if argname in kwargs:
|
||||||
value = kwargs[argname]
|
value = kwargs[argname]
|
||||||
|
if isinstance(value, list) and len(value) > 0 and isinstance(value[0], Curve):
|
||||||
|
for i, curve in enumerate(value):
|
||||||
|
curve.apply(getattr(node, prop.identifier).curves[i])
|
||||||
|
continue
|
||||||
|
if isinstance(value, Curve):
|
||||||
|
value.apply(getattr(node, prop.identifier).curves[0])
|
||||||
|
continue
|
||||||
if isinstance(value, enum.Enum):
|
if isinstance(value, enum.Enum):
|
||||||
value = value.value
|
value = value.value
|
||||||
setattr(node, prop.identifier, value)
|
setattr(node, prop.identifier, value)
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
from typing import List
|
||||||
|
import enum
|
||||||
|
|
||||||
|
class HandleType(enum.Enum):
|
||||||
|
AUTO = 'AUTO'
|
||||||
|
VECTOR = 'VECTOR'
|
||||||
|
AUTO_CLAMPED = 'AUTO_CLAMPED'
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
"""
|
||||||
|
A single point on a curve
|
||||||
|
"""
|
||||||
|
|
||||||
|
x: float
|
||||||
|
y: float
|
||||||
|
handle_type: HandleType
|
||||||
|
|
||||||
|
def __init__(self, x: float, y: float, handle_type: HandleType = HandleType.AUTO):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.handle_type = handle_type
|
||||||
|
|
||||||
|
class Curve:
|
||||||
|
"""
|
||||||
|
A class that represents a curve.
|
||||||
|
|
||||||
|
Create a curve from a set of `Point`s.
|
||||||
|
```python
|
||||||
|
my_curve = Curve(
|
||||||
|
Point(0, 0, Handle.AUTO_CLAMPED),
|
||||||
|
Point(0.2, 0.3, Handle.AUTO),
|
||||||
|
Point(1, 1, Handle.VECTOR)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
points: List[Point]
|
||||||
|
|
||||||
|
def __init__(self, *points: Point):
|
||||||
|
if len(points) == 1 and isinstance(points[0], list):
|
||||||
|
self.points = points[0]
|
||||||
|
else:
|
||||||
|
self.points = list(points)
|
||||||
|
|
||||||
|
def apply(self, curve):
|
||||||
|
"""
|
||||||
|
Apply the points to a curve object.
|
||||||
|
"""
|
||||||
|
for i, point in enumerate(self.points):
|
||||||
|
if len(curve.points) > i:
|
||||||
|
curve.points[i].location = (point.x, point.y)
|
||||||
|
curve.points[i].handle_type = point.handle_type.value
|
||||||
|
else:
|
||||||
|
curve.points.new(point.x, point.y).handle_type = point.handle_type.value
|
|
@ -8,6 +8,7 @@ from .state import State
|
||||||
from .types import *
|
from .types import *
|
||||||
from .node_mapper import *
|
from .node_mapper import *
|
||||||
from .static.attribute import *
|
from .static.attribute import *
|
||||||
|
from .static.curve import *
|
||||||
from .static.expression import *
|
from .static.expression import *
|
||||||
from .static.input_group import *
|
from .static.input_group import *
|
||||||
from .static.sample_mode import *
|
from .static.sample_mode import *
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
- [Input Groups](./api/advanced-scripting/input-groups.md)
|
- [Input Groups](./api/advanced-scripting/input-groups.md)
|
||||||
- [Attributes](./api/advanced-scripting/attributes.md)
|
- [Attributes](./api/advanced-scripting/attributes.md)
|
||||||
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
|
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
|
||||||
|
- [Curves](./api/advanced-scripting/curves.md)
|
||||||
- [Drivers](./api/advanced-scripting/drivers.md)
|
- [Drivers](./api/advanced-scripting/drivers.md)
|
||||||
- [Simulation](./api/advanced-scripting/simulation.md)
|
- [Simulation](./api/advanced-scripting/simulation.md)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Curves
|
||||||
|
|
||||||
|
Some nodes, such as *Float Curve* take a curve as a property. You can create a curve with the `Curve` class.
|
||||||
|
|
||||||
|
```python
|
||||||
|
float_curve(
|
||||||
|
mapping=Curve(
|
||||||
|
Point(0, 0),
|
||||||
|
Point(0.5, 0.25),
|
||||||
|
Point(1, 1, HandleType.VECTOR), # Optionally specify a handle type, such as `AUTO`, `VECTOR`, or `AUTO_CLAMPED`.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You can also pass the points as a list to `Curve`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
points = [Point(0, 0), Point(1, 1)]
|
||||||
|
float_curve(
|
||||||
|
mapping=Curve(points)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
If a node has multiple curve properties, such as the *Vector Curves* node, pass a list of curves to the node.
|
||||||
|
|
||||||
|
```python
|
||||||
|
vector_curves(
|
||||||
|
mapping=[x_curve, y_curve, z_curve]
|
||||||
|
)
|
||||||
|
```
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 36 KiB |
Ładowanie…
Reference in New Issue