Hello,
Sorry for the delay and for the confusion.
What Replicator is doing behind-the-scenes is setting up an OmniGraph Action Graph that will later execute during simulation.
So, somewhat unintuitively, when you created your cone
object, it has not actually been modified yet during script execution, since the script is executed “all-at-once” and simulation/graph execution takes place after.
A “simple” way to see this is to print the transform of your cone in a second script execution, because in-between script executions, the OmniGraph has had time to execute (automatically) and set a value for your transform -which is what you see happen in the viewport, it just happens fast enough that it seems instant.
If you need to extract information from your replicator-created items within the same script execution, you can add-in a simulation step trigger such as rep.orchestrator.step()
or also through OmniGraph directly via og.Controller.evaluate_sync()
.
Example script:
import numpy as np
import omni.replicator.core as rep
import omni.usd
from omni.usd._impl.utils import get_prim_at_path
from pxr import Sdf
import omni.graph.core as og
with rep.new_layer():
cone = rep.create.cone(position=(1,1,1))
prim_path = "/Replicator/Cone_Xform"
cone_prim = get_prim_at_path(Sdf.Path(prim_path))
transform_matrix = np.array(omni.usd.get_world_transform_matrix(cone_prim)).T
print(transform_matrix) # print 1
with cone:
rep.modify.pose(
position=rep.distribution.uniform((-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)),
rotation=rep.distribution.uniform((0.0, 0.0, 0.0), (100.0, 100.0, 100.0)),
)
transform_matrix = np.array(omni.usd.get_world_transform_matrix(cone_prim)).T
print(transform_matrix) # print 2
og.Controller.evaluate_sync()
print("After Sync") # print 3
transform_matrix = np.array(omni.usd.get_world_transform_matrix(cone_prim)).T
print(transform_matrix)
My output:
# first print
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
# Second print
# In the script, the cone position "seems" like it has been modified, but as you can see it has not
# because the omni graph has not executed a simulation step yet
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
After Sync
[[ 0.92044801 0.3848541 0.06828459 -0.80145752]
[ 0.02861739 0.10787761 -0.99375222 0.25251219]
[-0.38981599 0.91665137 0.08828221 0.61443901]
[ 0. 0. 0. 1. ]]
We know this is a bit unintuitive and cumbersome at the moment, and we are currently working on making API methods in Replicator that will make these types of queries about the state of the simulation easier to access.