|
1 | 1 | import bpy |
2 | 2 | from bpy.types import NodeSocketStandard |
3 | 3 | import nodeitems_utils |
| 4 | +import enum |
4 | 5 | from .state import State |
| 6 | +from .static.sample_mode import SampleMode |
5 | 7 | import geometry_script |
6 | 8 |
|
7 | 9 | def map_case_name(i): |
@@ -178,6 +180,53 @@ def capture(self, value, **kwargs): |
178 | 180 | def transfer(self, attribute, **kwargs): |
179 | 181 | data_type = socket_type_to_data_type(attribute._socket.type) |
180 | 182 | return self.transfer_attribute(data_type=data_type, attribute=attribute, **kwargs) |
| 183 | + |
| 184 | + def __getitem__(self, subscript): |
| 185 | + if isinstance(subscript, tuple): |
| 186 | + accessor = subscript[0] |
| 187 | + args = subscript[1:] |
| 188 | + else: |
| 189 | + accessor = subscript |
| 190 | + args = [] |
| 191 | + sample_mode = SampleMode.INDEX if len(args) < 1 else args[0] |
| 192 | + domain = 'POINT' if len(args) < 2 else (args[1].value if isinstance(args[1], enum.Enum) else args[1]) |
| 193 | + sample_position = None |
| 194 | + sampling_index = None |
| 195 | + if isinstance(accessor, slice): |
| 196 | + data_type = socket_type_to_data_type(accessor.start._socket.type) |
| 197 | + value = accessor.start |
| 198 | + match sample_mode: |
| 199 | + case SampleMode.INDEX: |
| 200 | + sampling_index = accessor.stop |
| 201 | + case SampleMode.NEAREST_SURFACE: |
| 202 | + sample_position = accessor.stop |
| 203 | + case SampleMode.NEAREST: |
| 204 | + sample_position = accessor.stop |
| 205 | + if accessor.step is not None: |
| 206 | + domain = accessor.step.value if isinstance(accessor.step, enum.Enum) else accessor.step |
| 207 | + else: |
| 208 | + data_type = socket_type_to_data_type(accessor._socket.type) |
| 209 | + value = accessor |
| 210 | + match sample_mode: |
| 211 | + case SampleMode.INDEX: |
| 212 | + return self.sample_index( |
| 213 | + data_type=data_type, |
| 214 | + domain=domain, |
| 215 | + value=value, |
| 216 | + index=sampling_index or geometry_script.index() |
| 217 | + ) |
| 218 | + case SampleMode.NEAREST_SURFACE: |
| 219 | + return self.sample_nearest_surface( |
| 220 | + data_type=data_type, |
| 221 | + value=value, |
| 222 | + sample_position=sample_position or geometry_script.position() |
| 223 | + ) |
| 224 | + case SampleMode.NEAREST: |
| 225 | + return self.sample_index( |
| 226 | + data_type=data_type, |
| 227 | + value=value, |
| 228 | + index=self.sample_nearest(domain=domain, sample_position=sample_position or geometry_script.position()) |
| 229 | + ) |
181 | 230 |
|
182 | 231 | for standard_socket in list(filter(lambda x: 'NodeSocket' in x, dir(bpy.types))): |
183 | 232 | name = standard_socket.replace('NodeSocket', '') |
|
0 commit comments