How to Disable USD Time Samples in LOP vex

   868   10   1
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
I've developed a camera frustum culling tool in Houdini's Solaris environment using VEX. My tool calculates camera transformations over time to ensure all primitives are accurately included for culling throughout an animation sequence. I retrieve the camera's transformation using usd_attrib and usd_worldtransform with time-sampled values, as shown below:
for(int time = int(start_frame); time <= end_frame; time += int((end_frame - start_frame) / frame_sample)){
    matrix camTransform_anim = usd_attrib("opinput:0", cam_path, "xformOp:transform", time);
}
Although I iterate over the necessary frames to capture every relevant position of the camera, evaluating every frame's transformation is not required beyond this point. Essentially, I wish to consolidate the time-sampled data into a static form after this iteration, as my culling decision doesn't need to be recalculated for every frame thereafter.

Could you advise on how to either prevent the automatic evaluation of attributes at every frame or how to remove/flatten these time samples after they've been calculated? I aim to optimize the tool by avoiding unnecessary recalculations of the camera's position outside the specified frame range.

Thank you
User Avatar
Member
8582 posts
Joined: July 2007
Offline
on your Attrib Wrangle VOP set Sampling Behavior to Sample Frame Range and set it to a single frame range like 1,1,1
or whichever single frame you want to have your timesample on, like 1001, 1001, 1

this way it will author your property only on that frame running the computation once
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
tamte
on your Attrib Wrangle VOP set Sampling Behavior to Sample Frame Range and set it to a single frame range like 1,1,1
or whichever single frame you want to have your timesample on, like 1001, 1001, 1

this way it will author your property only on that frame running the computation once


thank you for reply
but I am using houdini 19.5, there's no Sampling Behavior options.
is there any other way?
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
there's another test, I am using houdini20,
I set the timesample to 1,1,1
and use this code to store all camera transform array.

string cam_path = chs("cam_path");
matrix camTransform[];
usd_addattrib(0,cam_path,"cam_trans","matrix4d[]");
for(int time=0;time<100;time++){
    camTransform[time] = usd_worldtransform("opinput:0", cam_path,time);
}
usd_setattrib(0,cam_path,"cam_trans",camTransform);
but the param seems also green, it's still timesample base.

Attachments:
solaris_time_sample_issue.png (243.2 KB)

User Avatar
Member
8582 posts
Joined: July 2007
Offline
dishuman
but the param seems also green, it's still timesample base.
Yes, it should have exactly 1 timesample, it shouldn't execute your code more than once

I personally dont know another way that wouldn't recompute when you change frame
Edited by tamte - March 19, 2024 22:30:37
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
tamte
dishuman
but the param seems also green, it's still timesample base.
Yes, it should have exactly 1 timesample, it shouldn't execute your code more than once

I personally dont know another way that wouldn't recompute when you change frame

Thank you for your reply again
I think it's related to the build in function 'usd_attrib' if use a specific time number, should return non-time sample result.
User Avatar
Staff
451 posts
Joined: June 2020
Offline
Thanks for flagging this, we're investigating it as a bug.
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
robp_sidefx
Thanks for flagging this, we're investigating it as a bug.
OK, Thank you
Is there any way to remove the attribute timesample for now?
User Avatar
Staff
451 posts
Joined: June 2020
Offline
dishuman
Is there any way to remove the attribute timesample for now?

You'd probably need to dip into the USD Python API to do this. For example:
prim = stage.GetPrimAtPath('/cameras/camera1')
attr = prim.GetAttribute('cam_trans')
val = attr.Get(0)  # query a time-sample value
attr.Clear()       # remove all the time-samples
attr.Set(val)      # set a default (non-time-sample) value

At this point you might consider just doing the whole process in Python instead:
node = hou.pwd()
stage = node.editableStage()

from pxr import Sdf, UsdGeom

primpath = '/cameras/camera1'
fstart = 1
fend = 100

prim = stage.GetPrimAtPath(primpath)
cam = UsdGeom.Camera(prim)
cam_trans = [cam.ComputeLocalToWorldTransform(f) for f in range(fstart, fend+1)]
attr = prim.CreateAttribute('cam_trans', Sdf.ValueTypeNames.Matrix4dArray)
attr.Set(cam_trans)
Edited by robp_sidefx - March 21, 2024 05:58:35
User Avatar
Member
6 posts
Joined: Nov. 2014
Offline
OK,
Seems use python to get transform array no need clear time sample.

Thank you, Problem solved.
User Avatar
Staff
451 posts
Joined: June 2020
Offline
dishuman
Thank you, Problem solved.

Great! Sorry for the trouble and thank you again for flagging this issue to us.
  • Quick Links