-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/additional scatter plugins (#10)
* Add simulated scatter * Add crop plugin * Fix wrong link to crop plugin * Add new plugins to docs * Add crop to example plugin * Handle modifiers that cant be applied * Update test_job.syclops.yaml file with new plugins and configurations * Shorten simulation steps
- Loading branch information
Showing
13 changed files
with
703 additions
and
27 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
docs/docs/usage/job_description/config_descriptions/crop.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Crop Plugin Documentation | ||
|
||
The Crop Plugin scatters 3D models on a floor object in a grid pattern to simulate crop rows. | ||
|
||
## Configuration Parameters | ||
|
||
The following table describes each configuration parameter for the Crop Plugin: | ||
|
||
| Parameter | Type | Description | Requirement | | ||
|-----------|------|-------------|-------------| | ||
| `name` | string | Unique identifier of the plugin | **Required** | | ||
| `models` | array or single item | 3D assets to scatter. | **Required** | | ||
| `floor_object` | string | Name of the floor object to scatter on. | **Required** | | ||
| `max_texture_size` | integer | Maximum texture size in pixel. Will reduce the texture to save GPU RAM. | Optional | | ||
| `density_map` | image/texture evaluation | Texture that alters the density. It is normalized to 0-1. | Optional | | ||
| `decimate_mesh_factor` | number (0-1) | Factor between 0-1 that decimates the number of vertices of the mesh. Lower means less vertices. | Optional | | ||
| `scale_standard_deviation` | number evaluation | Scale variance of the scattered objects. | **Required** | | ||
| `class_id` | integer | Class ID for ground truth output. | **Required** | | ||
| `crop_angle` | number evaluation | Global orientation of the row direction in degrees. | **Required** | | ||
| `row_distance` | number evaluation | Distance between rows in meters. | **Required** | | ||
| `row_standard_deviation` | number evaluation | Standard deviation of the row distance in meters. | **Required** | | ||
| `plant_distance` | number evaluation | Intra row distance between plants in meters. | **Required** | | ||
| `plant_standard_deviation` | number evaluation | Standard deviation of the intra row distance in meters. | **Required** | | ||
|
||
### Dynamic Evaluators | ||
|
||
Most parameters, like `scale_standard_deviation`, `crop_angle` etc., can be dynamically evaluated. This means that their values can be altered for each new frame. For more insights on dynamic evaluators and how to use them, kindly refer to [Dynamic Evaluators](../dynamic_evaluators.md). | ||
|
||
## Example Configuration | ||
|
||
```yaml | ||
scene: | ||
syclops_plugin_crop: | ||
- name: "Corn Crop" | ||
models: Example Assets/Corn | ||
floor_object: "Ground" | ||
max_texture_size: 2048 | ||
scale_standard_deviation: 0.1 | ||
class_id: 2 | ||
crop_angle: 45 | ||
row_distance: 1 | ||
row_standard_deviation: 0.1 | ||
plant_distance: 0.3 | ||
plant_standard_deviation: 0.05 | ||
``` | ||
The above configuration will scatter corn models across the ground surface in a grid pattern resembling crop rows. The rows will be oriented at a 45 degree angle, with 1 meter spacing between rows and 30 cm spacing between plants. The row and plant spacings will vary according to the specified standard deviations. | ||
41 changes: 41 additions & 0 deletions
41
docs/docs/usage/job_description/config_descriptions/simulated_scatter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Simulated Scatter Plugin Documentation | ||
|
||
The Simulated Scatter Plugin scatters 3D assets on a floor object and simulates physics to drop them realistically on the surface. | ||
|
||
## Configuration Parameters | ||
|
||
The following table describes each configuration parameter for the Simulated Scatter Plugin: | ||
|
||
| Parameter | Type | Description | Requirement | | ||
|-----------|------|-------------|-------------| | ||
| `name` | string | Unique identifier of the plugin | **Required** | | ||
| `models` | array or single item | 3D assets to scatter. | **Required** | | ||
| `floor_object` | string | Name of the floor object to scatter on. | **Required** | | ||
| `max_texture_size` | integer | Maximum texture size in pixels. Will reduce the texture to save GPU RAM. | Optional | | ||
| `decimate_mesh_factor` | number (0-1) | Factor between 0-1 that decimates the number of vertices of the mesh. Lower means less vertices. | Optional | | ||
| `density` | number | Density of objects per square meter. | **Required** | | ||
| `density_texture` | image/texture evaluation | Texture that alters the density per pixel. Needs to be a single channel image that is normalized to 0-1. | Optional | | ||
| `scale_std` | number | Standard deviation of the scale randomization. | **Required** | | ||
| `convex_decomposition_quality` | integer (1-100) | Quality setting for the convex decomposition. Higher means more accurate but slower. | **Required** | | ||
| `simulation_steps` | integer | Number of simulation steps to run. | **Required** | | ||
|
||
### Dynamic Evaluators | ||
|
||
Parameters like `density_texture` and `scale_std` can be dynamically evaluated. This means that their values can be altered for each new frame. For more insights on dynamic evaluators and how to use them, kindly refer to [Dynamic Evaluators](../dynamic_evaluators.md). | ||
|
||
## Example Configuration | ||
|
||
```yaml | ||
scene: | ||
syclops_plugin_simulated_scatter: | ||
- name: "Rock Scatter" | ||
models: Example Assets/Rocks | ||
floor_object: "Ground" | ||
max_texture_size: 2048 | ||
density: 5 | ||
scale_std: 0.3 | ||
convex_decomposition_quality: 90 | ||
simulation_steps: 100 | ||
``` | ||
The above configuration will scatter rock models across the ground surface. The rocks will be dropped from above and settle into physically realistic positions using a convex decomposition simulation. The simulation will run for 100 steps to allow the rocks to come to rest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""This module contains the Crop plugin for Syclops. | ||
It is used to place objects in a row like fashion to simulate crop. | ||
""" | ||
|
||
import logging | ||
|
||
import bpy | ||
from syclops import utility | ||
from syclops.blender.plugins.plugin_interface import PluginInterface | ||
|
||
|
||
class Crop(PluginInterface): | ||
"""Plugin scatters objects in a row like fashion to simulate crop.""" | ||
|
||
crop: utility.ObjPointer | ||
|
||
def load(self): | ||
"""Load everything into the scene but does not configure it.""" | ||
self.create_base_object() | ||
self.load_instance_objects() | ||
self.load_geometry_nodes() | ||
logging.info("Crop: {0} loaded".format(self.config["name"])) | ||
|
||
def load_geometry_nodes(self): | ||
"""Load geometry nodes from .blend file and assigns them to the crop.""" | ||
# Add crop node group to the scene | ||
node_group_name = "Crop" | ||
blend_path = utility.abs_path("./plugin_data/crop.blend") | ||
|
||
crop_nodes = utility.load_from_blend( | ||
blend_path, | ||
"node_groups", | ||
node_group_name, | ||
)[0] | ||
|
||
# Create GeoNode Modifier | ||
self.geo_node_modifier = self.crop.get().modifiers.new( | ||
self.config["name"], | ||
"NODES", | ||
) | ||
self.geo_node_modifier.show_viewport = False | ||
self.geo_node_modifier.node_group = crop_nodes | ||
|
||
def load_instance_objects(self): | ||
"""Load crop geometry.""" | ||
# Create new collection and assign a pointer | ||
self.instance_objects = utility.ObjPointer( | ||
utility.create_collection("{0}_Objs".format(self.config["name"])), | ||
) | ||
utility.set_active_collection(self.instance_objects.get()) | ||
|
||
# Import the geometry | ||
loaded_objs = utility.import_assets(self.config["models"]) | ||
for obj in loaded_objs: | ||
self.reduce_size(obj) | ||
obj.hide_set(True) | ||
self.write_config(obj) | ||
self.instance_objects.get().hide_render = True | ||
|
||
def create_base_object(self): | ||
"""Add placeholder object to assign GeoNode Modifier to.""" | ||
# Setup a blender collection | ||
collection = utility.create_collection(self.config["name"]) | ||
utility.set_active_collection(collection) | ||
|
||
# Setup GeoNodes | ||
bpy.ops.mesh.primitive_plane_add() | ||
bpy.context.active_object.name = self.config["name"] | ||
self.crop = utility.ObjPointer(bpy.context.active_object) | ||
|
||
def configure(self): | ||
"""Apply configuration for current frame.""" | ||
# Refresh References | ||
self.geo_node_modifier = self.crop.get().modifiers[self.config["name"]] | ||
# Configure settings from config | ||
self.configure_settings() | ||
for obj in self.instance_objects.get().objects: | ||
utility.add_volume_attribute(obj) | ||
logging.info("Crop: {0} configured".format(self.config["name"])) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
description: Scatters 3D models on a floor object in a grid pattern. | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
name: | ||
description: Unique identifier of the plugin | ||
type: string | ||
models: | ||
description: 3D assets to scatter. | ||
oneOf: | ||
- type: array | ||
items: | ||
$ref: "#/definitions/asset_models" | ||
- $ref: "#/definitions/asset_models" | ||
floor_object: | ||
description: Name of the floor object to scatter on. | ||
type: string | ||
max_texture_size: | ||
description: Maximum texture size in pixel. Will reduce the texture to save GPU RAM. | ||
type: integer | ||
density_map: | ||
description: Texture that alters the density. It is normalized to 0-1. | ||
$ref: "#/definitions/image_texture_evaluation" | ||
decimate_mesh_factor: | ||
description: Factor between 0-1 that decimates the number of vertices of the mesh. Lower means less vertices. | ||
type: number | ||
scale_standard_deviation: | ||
description: Scale variance of the scattered objects. | ||
$ref: "#/definitions/number_evaluation" | ||
class_id: | ||
description: Class ID for ground truth output. | ||
type: integer | ||
class_id_offset: | ||
description: Class ID offset for ground truth output. The keys are the name of the material and the values are the offsets. | ||
type: object | ||
additionalProperties: | ||
type: integer | ||
crop_angle: | ||
description: Global orientation of the row direction in degrees. | ||
$ref: "#/definitions/number_evaluation" | ||
row_distance: | ||
description: Distance between rows in meters. | ||
$ref: "#/definitions/number_evaluation" | ||
row_standard_deviation: | ||
description: Standard deviation of the row distance in meters. | ||
$ref: "#/definitions/number_evaluation" | ||
plant_distance: | ||
description: Intra row distance between plants in meters. | ||
$ref: "#/definitions/number_evaluation" | ||
plant_standard_deviation: | ||
description: Standard deviation of the intra row distance in meters. | ||
$ref: "#/definitions/number_evaluation" | ||
|
||
required: | ||
[ | ||
name, | ||
models, | ||
floor_object, | ||
scale_standard_deviation, | ||
row_distance, | ||
plant_distance, | ||
crop_angle, | ||
row_standard_deviation, | ||
plant_standard_deviation, | ||
] |
Oops, something went wrong.