int overrideClippingPlane = chi("override_clipping_planes");
vector clipping_planes = chv("clipping_planes");
//float horizontalAperture = usd_attrib(0,@primpath, "horizontalAperture");
float horizontalAperture = 0.305816;
float verticalAperture = usd_attrib(0, @primpath, "verticalAperture");
float focalLength = usd_attrib(0, @primpath, "focalLength");
vector2 clipping= usd_attrib(0, @primpath, "clippingRange");
if (overrideClippingPlane) {
vector clipping2 = chv("clipping_planes");
clipping.x = clipping2.x;
clipping.y = clipping2.y;
//vector2 clipping= usd_attrib(0, @primpath, "clippingRange");
};
float x = ((horizontalAperture/focalLength*clipping.x)/2);
float y = (((verticalAperture*clipping.x)/focalLength)/2);
vector p0 = set(-x,y,-clipping.x+1);//top right
vector p1 = set(x,y,-clipping.x+1);//top left
vector p2 = set(-x,-y,-clipping.x+1);//bottom right
vector p3 = set(x,-y,-clipping.x+1);//bottom left
float x_far = ((horizontalAperture/focalLength*clipping.y)/2);
float y_far = (((verticalAperture/1*clipping.y)/focalLength)/2);
//set far position
vector p4 = set(x_far,y_far,-clipping.y);
vector p5 = set(-x_far,y_far,-clipping.y);
vector p6 = set(x_far,-y_far,-clipping.y);
vector p7 = set(-x_far,-y_far,-clipping.y);
vector points[] = array(
p0,
p1,
p2,
p3,
p4,
p5,
p6,
p7);
string prim_location = concat(@primpath,"/frustum");
usd_addprim(0, prim_location, "Mesh");
usd_setattrib(0, prim_location, "points", points);
int faceVertexCounts[] ={
4,
4,
4,
4,
4,
4,
};
int faceVertexIndicies[] ={
0,
1,
3,
2,
4,
5,
7,
6,
6,
7,
2,
3,
5,
4,
1,
0,
5,
0,
2,
7,
1,
4,
6,
3};
usd_setattrib(0, prim_location, "faceVertexCounts", faceVertexCounts);
usd_setattrib(0, prim_location, "faceVertexIndices", faceVertexIndicies);
usd_setattrib(0, prim_location, "purpose", "guide");
vector displayColor[] = array({0,1,0});
usd_setattrib(0, prim_location, "primvars:displayColor",displayColor );