-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transform_layer_writing.py
More file actions
141 lines (117 loc) · 4.96 KB
/
test_transform_layer_writing.py
File metadata and controls
141 lines (117 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
"""
Test script to diagnose Transform Edit layer writing issue.
Directly tests the execution flow to see where prim specs are lost.
"""
from pxr import Usd, UsdGeom, Sdf, Gf
import sys
import os
# Add project to path
sys.path.insert(0, os.path.dirname(__file__))
from usd_ultimate.plugins.executions.transform_edit import TransformEditExecution
def main():
print("=" * 80)
print("TRANSFORM EDIT LAYER WRITING TEST")
print("=" * 80)
# Open the kitchen USD file
usd_file = "/Users/nickgrobler/Projects/USD/Kitchen_set/Kitchen_set.usd"
print(f"\n1. Opening USD file: {usd_file}")
stage = Usd.Stage.Open(usd_file)
if not stage:
print("ERROR: Failed to open USD file!")
return 1
print(f" ✓ Stage opened successfully")
print(f" Root layer: {stage.GetRootLayer().identifier}")
# Create an execution block layer (simulating what SequentialExecPanel does)
print(f"\n2. Creating anonymous execution_block layer...")
execution_layer = Sdf.Layer.CreateAnonymous("execution_block")
print(f" ✓ Layer created: {execution_layer.identifier}")
# Add layer to root layer sublayers (simulating SequentialExecPanel)
print(f"\n3. Adding layer to root layer sublayers...")
root_layer = stage.GetRootLayer()
sublayer_paths = list(root_layer.subLayerPaths)
print(f" Current sublayers: {sublayer_paths}")
sublayer_paths.insert(0, execution_layer.identifier)
root_layer.subLayerPaths = sublayer_paths
print(f" ✓ Layer added to sublayers")
print(f" New sublayers: {list(root_layer.subLayerPaths)}")
# Verify layer is in stage layer stack
print(f"\n4. Verifying layer stack...")
layer_stack = stage.GetLayerStack()
print(f" Stage has {len(layer_stack)} layers:")
for i, layer in enumerate(layer_stack):
print(f" {i}: {layer.identifier}")
# Create Transform Edit execution and run it
print(f"\n5. Creating Transform Edit execution...")
transform_edit = TransformEditExecution()
# Test prim path
prim_path = "/Flat/Kitchen_set/Props_grp/DiningTable_grp/ChairB_2"
print(f" Target prim: {prim_path}")
# Get original transform
print(f"\n6. Getting original transform...")
prim = stage.GetPrimAtPath(prim_path)
if not prim or not prim.IsValid():
print(f"ERROR: Prim not found: {prim_path}")
return 1
xformable = UsdGeom.Xformable(prim)
original_transform = xformable.ComputeLocalToWorldTransform(Usd.TimeCode.Default())
original_position = original_transform.ExtractTranslation()
print(f" Original position: {original_position}")
# Execute transform edit
print(f"\n7. Executing Transform Edit...")
params = {
'prim_path': prim_path,
'mode': 'replace',
'translate': [100.0, 200.0, 0.0],
'rotate': [0.0, 0.0, 0.0],
'scale': [1.0, 1.0, 1.0]
}
print(f" Parameters: {params}")
try:
transform_edit.execute(stage, execution_layer, params)
print(f" ✓ Execute completed successfully")
except Exception as e:
print(f" ✗ Execute failed: {e}")
import traceback
traceback.print_exc()
return 1
# Check layer contents IMMEDIATELY after execution
print(f"\n8. Checking layer contents IMMEDIATELY after execution...")
prim_spec = execution_layer.GetPrimAtPath(prim_path)
if prim_spec:
print(f" ✓ Layer HAS prim spec for {prim_path}")
if prim_spec.properties:
print(f" ✓ Prim spec has {len(prim_spec.properties)} properties:")
for prop_name, prop_spec in prim_spec.properties.items():
print(f" {prop_name} = {prop_spec.default}")
else:
print(f" ✗ PROBLEM: Prim spec exists but has NO PROPERTIES!")
else:
print(f" ✗ PROBLEM: Layer has NO prim spec for {prim_path}!")
# Check if USD composition sees the changes
print(f"\n9. Checking USD composition...")
new_transform = xformable.ComputeLocalToWorldTransform(Usd.TimeCode.Default())
new_position = new_transform.ExtractTranslation()
print(f" New position: {new_position}")
if new_position != original_position:
print(f" ✓ Position changed! USD composition sees the changes.")
else:
print(f" ✗ Position unchanged! USD composition does NOT see the changes.")
# Export layer to file for inspection
print(f"\n10. Exporting layer to file...")
export_path = "/tmp/transform_edit_test_layer.usda"
execution_layer.Export(export_path)
print(f" ✓ Layer exported to: {export_path}")
print(f" You can inspect this file to see what was written.")
# Print layer contents as text
print(f"\n11. Layer contents as text:")
print("-" * 80)
layer_text = execution_layer.ExportToString()
print(layer_text)
print("-" * 80)
print(f"\n" + "=" * 80)
print("TEST COMPLETE")
print("=" * 80)
return 0
if __name__ == "__main__":
sys.exit(main())