Skip to content

Commit 7b08b48

Browse files
authored
Merge pull request #671 from threedworld-mit/wireframe_shader
Wireframe shader
2 parents a84c26b + faa4a07 commit 7b08b48

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

Documentation/Changelog.md

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
To upgrade from TDW v1.11 to v1.12, read [this guide](upgrade_guides/v1.11_to_v1.12.md).
66

7+
## v1.12.21
8+
9+
### Command API
10+
11+
#### New Commands
12+
13+
| Command | Description |
14+
| ----------------- | --------------------------------------------- |
15+
| `set_wireframe_material` | Set the visual material of an object or one of its sub-objects to wireframe. |
16+
17+
### `tdw` module
18+
19+
- Added: `TDWUtils.set_wireframe_material(substructure, object_id, color, thickness)`.
20+
21+
### Example Controllers
22+
23+
- Added: `scene_setup_low_level/set_wireframe_material.py`
24+
725
## v1.12.20
826

927
### Command API

Documentation/api/command_api.md

+25
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@
548548
| [`set_texture_scale`](#set_texture_scale) | Set the scale of the tiling of the material's main texture. |
549549
| [`set_visual_material`](#set_visual_material) | Set a visual material of an object or one of its sub-objects. |
550550
| [`set_visual_material_smoothness`](#set_visual_material_smoothness) | Set the smoothness (glossiness) of an object's visual material. |
551+
| [`set_wireframe_material`](#set_wireframe_material) | Set the visual material of an object or one of its sub-objects to wireframe. |
551552

552553
**Wheelchair Replicant Command**
553554

@@ -7227,6 +7228,30 @@ Set the smoothness (glossiness) of an object's visual material.
72277228
| `"object_name"` | string | The name of the sub-object. | |
72287229
| `"id"` | int | The unique object ID. | |
72297230

7231+
***
7232+
7233+
## **`set_wireframe_material`**
7234+
7235+
Set the visual material of an object or one of its sub-objects to wireframe.
7236+
7237+
- <font style="color:darkslategray">**Requires a material asset bundle**: To use this command, you must first download an load a material. Send the [add_material](#add_material) command first.</font>
7238+
7239+
```python
7240+
{"$type": "set_wireframe_material", "material_index": 1, "color": {"r": 0.219607845, "g": 0.0156862754, "b": 0.6901961, "a": 1.0}, "object_name": "string", "id": 1}
7241+
```
7242+
7243+
```python
7244+
{"$type": "set_wireframe_material", "material_index": 1, "color": {"r": 0.219607845, "g": 0.0156862754, "b": 0.6901961, "a": 1.0}, "object_name": "string", "id": 1, "thickness": 0.02}
7245+
```
7246+
7247+
| Parameter | Type | Description | Default |
7248+
| --- | --- | --- | --- |
7249+
| `"material_index"` | int | The index of the material in the sub-object's list of materials. | |
7250+
| `"thickness"` | float | The thickness of the wireframe lines. | 0.02 |
7251+
| `"color"` | Color | The new RGBA color of the wireframe. | |
7252+
| `"object_name"` | string | The name of the sub-object. | |
7253+
| `"id"` | int | The unique object ID. | |
7254+
72307255
# WheelchairReplicantCommand
72317256

72327257
These commands affect a WheelchairReplicant currently in the scene.

Documentation/python/tdw_utils.md

+18
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,24 @@ _(Static)_
405405

406406
_Returns:_ A list of commands to set ALL visual materials on an object to a single material.
407407

408+
#### set_wireframe_material
409+
410+
**`TDWUtils.set_wireframe_material(substructure, object_id, color)`**
411+
412+
**`TDWUtils.set_wireframe_material(substructure, object_id, color, thickness=0.02)`**
413+
414+
_(Static)_
415+
416+
417+
| Parameter | Type | Default | Description |
418+
| --- | --- | --- | --- |
419+
| substructure | List[dict] | | The metadata substructure of the object. |
420+
| object_id | int | | The ID of the object in the scene. |
421+
| color | Dict[str, float] | | The color to make the wireframe. |
422+
| thickness | float | 0.02 | The thickness of the wireframe lines. |
423+
424+
_Returns:_ A list of commands to set ALL visual materials on an object to a single wireframe material.
425+
408426
#### get_depth_values
409427

410428
**`TDWUtils.get_depth_values(image)`**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from tdw.controller import Controller
2+
from tdw.tdw_utils import TDWUtils
3+
from tdw.add_ons.third_person_camera import ThirdPersonCamera
4+
from tdw.add_ons.image_capture import ImageCapture
5+
from tdw.librarian import ModelLibrarian
6+
from tdw.backend.paths import EXAMPLE_CONTROLLER_OUTPUT_PATH
7+
8+
"""
9+
Set an object's material to wireframe.
10+
"""
11+
12+
c = Controller()
13+
object_id_1 = c.get_unique_id()
14+
object_id_2 = c.get_unique_id()
15+
16+
lib = ModelLibrarian()
17+
model_record_1 = lib.get_record("white_lounger_chair")
18+
model_record_2 = lib.get_record("chair_billiani_doll")
19+
cam = ThirdPersonCamera(position={"x": 3.6, "y": 1.6, "z": -0.6},
20+
look_at=object_id_1)
21+
path = EXAMPLE_CONTROLLER_OUTPUT_PATH.joinpath("set_wireframe_material")
22+
print(f"Images will be saved to: {path}")
23+
cap = ImageCapture(avatar_ids=[cam.avatar_id], pass_masks=["_img"], path=path)
24+
c.add_ons.extend([cam, cap])
25+
26+
commands = [TDWUtils.create_empty_room(12, 12),
27+
c.get_add_object(model_name=model_record_1.name,
28+
object_id=object_id_1),
29+
c.get_add_object(model_name=model_record_2.name,
30+
object_id=object_id_2,
31+
position={"x": 2, "y": 0, "z": 0})]
32+
commands.extend(TDWUtils.set_wireframe_material(substructure=model_record_1.substructure, object_id=object_id_1, color={"r": 1.0, "g": 0, "b": 0, "a": 1.0}, thickness=0.05))
33+
commands.extend(TDWUtils.set_wireframe_material(substructure=model_record_2.substructure, object_id=object_id_2, color={"r": 0, "g": 0, "b": 1.0, "a": 1.0}, thickness=0.035))
34+
c.communicate(commands)
35+
c.communicate({"$type": "terminate"})

Python/tdw/tdw_utils.py

+22
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,28 @@ def set_visual_material(c: Controller, substructure: List[dict], object_id: int,
443443
"material_index": i}])
444444
return commands
445445

446+
@staticmethod
447+
def set_wireframe_material(substructure: List[dict], object_id: int, color: Dict[str, float], thickness: float = 0.02) -> List[dict]:
448+
"""
449+
:param substructure: The metadata substructure of the object.
450+
:param object_id: The ID of the object in the scene.
451+
:param color: The color to make the wireframe.
452+
:param thickness: The thickness of the wireframe lines.
453+
454+
:return A list of commands to set ALL visual materials on an object to a single wireframe material.
455+
"""
456+
457+
commands = []
458+
for sub_object in substructure:
459+
for i in range(len(sub_object["materials"])):
460+
commands.extend([{"$type": "set_wireframe_material",
461+
"id": object_id,
462+
"color": color,
463+
"thickness": thickness,
464+
"object_name": sub_object["name"],
465+
"material_index": i}])
466+
return commands
467+
446468
@staticmethod
447469
def get_depth_values(image: np.ndarray, depth_pass: str = "_depth", width: int = 256, height: int = 256, near_plane: float = 0.1, far_plane: float = 100) -> np.ndarray:
448470
"""

Python/tdw/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.12.20.0"
1+
__version__ = "1.12.21.0"

0 commit comments

Comments
 (0)