void UsdImagingPointsAdapter::UpdateForTime(UsdPrim const& prim, SdfPath const& cachePath, UsdTimeCode time, HdDirtyBits requestedBits, HdDirtyBits* resultBits, UsdImagingInstancerContext const* instancerContext) { BaseAdapter::UpdateForTime( prim, cachePath, time, requestedBits, resultBits, instancerContext); UsdImagingValueCache* valueCache = _GetValueCache(); PrimvarInfoVector& primvars = valueCache->GetPrimvars(cachePath); VtValue& pointsValues = valueCache->GetPoints(cachePath); if (requestedBits & HdChangeTracker::DirtyPoints) { _GetPoints(prim, &pointsValues, time); UsdImagingValueCache::PrimvarInfo primvar; primvar.name = HdTokens->points; primvar.interpolation = UsdGeomTokens->vertex; _MergePrimvar(primvar, &primvars); } if (requestedBits & HdChangeTracker::DirtyWidths) { UsdImagingValueCache::PrimvarInfo primvar; UsdGeomPoints points(prim); VtFloatArray widths; primvar.name = UsdGeomTokens->widths; // XXX Add support for real constant interpolation primvar.interpolation = UsdGeomTokens->vertex; // Read the widths, if there is no widths create a buffer // and fill it with default widths of 1.0f if (!points.GetWidthsAttr().Get(&widths, time)) { // Check if we have just updated the points because in that // case we don't need to read the points again if (!(requestedBits & HdChangeTracker::DirtyPoints)) { _GetPoints(prim, &pointsValues, time); } for(size_t i = 0; i < pointsValues.Get<VtVec3fArray>().size() ; i ++) { widths.push_back(1.0f); } } _MergePrimvar(primvar, &primvars); valueCache->GetWidths(cachePath) = VtValue(widths); } }
void UsdImagingCubeAdapter::UpdateForTime(UsdPrim const& prim, SdfPath const& cachePath, UsdTimeCode time, HdDirtyBits requestedBits, HdDirtyBits* resultBits, UsdImagingInstancerContext const* instancerContext) { BaseAdapter::UpdateForTime( prim, cachePath, time, requestedBits, resultBits, instancerContext); UsdImagingValueCache* valueCache = _GetValueCache(); if (requestedBits & HdChangeTracker::DirtyTransform) { // Update the transform with the size authored for the cube. GfMatrix4d& ctm = valueCache->GetTransform(cachePath); GfMatrix4d xf = GetMeshTransform(prim, time); ctm = xf * ctm; } if (requestedBits & HdChangeTracker::DirtyTopology) { valueCache->GetTopology(cachePath) = GetMeshTopology(); } if (requestedBits & HdChangeTracker::DirtyPoints) { valueCache->GetPoints(cachePath)= GetMeshPoints(prim, time); // Expose points as a primvar. UsdImagingValueCache::PrimvarInfo primvar; primvar.name = HdTokens->points; primvar.interpolation = UsdGeomTokens->vertex; PrimvarInfoVector& primvars = valueCache->GetPrimvars(cachePath); _MergePrimvar(primvar, &primvars); } }
void UsdImagingMeshAdapter::UpdateForTime(UsdPrim const& prim, SdfPath const& cachePath, UsdTimeCode time, HdDirtyBits requestedBits, HdDirtyBits* resultBits, UsdImagingInstancerContext const* instancerContext) { BaseAdapter::UpdateForTime( prim, cachePath, time, requestedBits, resultBits, instancerContext); UsdImagingValueCache* valueCache = _GetValueCache(); PrimvarInfoVector& primvars = valueCache->GetPrimvars(cachePath); if (requestedBits & HdChangeTracker::DirtyTopology) { VtValue& topology = valueCache->GetTopology(cachePath); _GetMeshTopology(prim, &topology, time); } if (requestedBits & HdChangeTracker::DirtyPoints) { VtValue& points = valueCache->GetPoints(cachePath); _GetPoints(prim, &points, time); UsdImagingValueCache::PrimvarInfo primvar; primvar.name = HdTokens->points; primvar.interpolation = UsdGeomTokens->vertex; _MergePrimvar(primvar, &primvars); } if (requestedBits & HdChangeTracker::DirtySubdivTags) { SubdivTags& tags = valueCache->GetSubdivTags(cachePath); _GetSubdivTags(prim, &tags, time); } }
// Thread safe. // * Populate dirty bits for the given \p time. void UsdImagingConeAdapter::UpdateForTime(UsdPrim const& prim, SdfPath const& cachePath, UsdTimeCode time, int requestedBits, int* resultBits, UsdImagingInstancerContext const* instancerContext) { BaseAdapter::UpdateForTime( prim, cachePath, time, requestedBits, resultBits, instancerContext); UsdImagingValueCache* valueCache = _GetValueCache(); if (requestedBits & HdChangeTracker::DirtyTopology) { valueCache->GetTopology(cachePath) = GetMeshTopology(); } if (requestedBits & HdChangeTracker::DirtyPoints) { valueCache->GetPoints(cachePath) = GetMeshPoints(prim, time); // Expose points as a primvar. UsdImagingValueCache::PrimvarInfo primvar; primvar.name = HdTokens->points; primvar.interpolation = UsdGeomTokens->vertex; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } }
void UsdImagingGprimAdapter::_DiscoverPrimvars(UsdGeomGprim const& gprim, SdfPath const& cachePath, UsdShadeShader const& shader, UsdTimeCode time, UsdImagingValueCache* valueCache) { // TODO: It might be convenient to implicitly wire up PtexFaceOffset and // PtexFaceIndex primvars. TF_DEBUG(USDIMAGING_SHADERS).Msg("\t Looking for <%s> primvars at <%s>\n", gprim.GetPrim().GetPath().GetText(), shader.GetPrim().GetPath().GetText()); for (UsdShadeParameter const& param : shader.GetParameters()) { UsdShadeShader source; TfToken outputName; if (param.GetConnectedSource(&source, &outputName)) { UsdAttribute attr = source.GetIdAttr(); TfToken id; if (not attr or not attr.Get(&id)) { continue; } TF_DEBUG(USDIMAGING_SHADERS).Msg("\t\t Param <%s> connected <%s>(%s)\n", param.GetAttr().GetName().GetText(), source.GetPath().GetText(), id.GetText()); if (id == UsdHydraTokens->HwPrimvar_1) { TfToken t; VtValue v; UsdGeomPrimvar primvarAttr; if (UsdHydraPrimvar(source).GetVarnameAttr().Get(&t, UsdTimeCode::Default())) { primvarAttr = gprim.GetPrimvar(t); if (primvarAttr.ComputeFlattened(&v, time)) { TF_DEBUG(USDIMAGING_SHADERS).Msg("Found primvar %s\n", t.GetText()); UsdImagingValueCache::PrimvarInfo primvar; primvar.name = t; primvar.interpolation = primvarAttr.GetInterpolation(); valueCache->GetPrimvar(cachePath, t) = v; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } else { TF_DEBUG(USDIMAGING_SHADERS).Msg( "\t\t No primvar on <%s> named %s\n", gprim.GetPath().GetText(), t.GetText()); } } } else { // Recursively look for more primvars _DiscoverPrimvars(gprim, cachePath, source, time, valueCache); } } } }
void UsdImagingGprimAdapter::_DiscoverPrimvarsDeprecated(UsdGeomGprim const& gprim, SdfPath const& cachePath, UsdPrim const& shaderPrim, UsdTimeCode time, UsdImagingValueCache* valueCache) { UsdImagingValueCache::PrimvarInfo primvar; std::vector<UsdProperty> const& props = shaderPrim.GetProperties(); TF_FOR_ALL(propIt, props) { UsdAttribute attr = propIt->As<UsdAttribute>(); if (not attr) { continue; } if (attr.GetPath().IsNamespacedPropertyPath()) { continue; } // Ok this is a parameter, check source input. if (UsdAttribute texAttr = shaderPrim.GetAttribute( TfToken(attr.GetPath().GetName() + ":texture"))) { TfToken t; SdfAssetPath ap; VtValue v; UsdGeomPrimvar primvarAttr; texAttr.Get(&ap, UsdTimeCode::Default()); bool isPtex = GlfPtexTexture::IsPtexTexture(TfToken(ap.GetAssetPath())); if (isPtex) { t = UsdImagingTokens->ptexFaceIndex; // Allow the client to override this name texAttr.GetMetadata(UsdImagingTokens->faceIndexPrimvar, &t); primvarAttr = gprim.GetPrimvar(t); if (primvarAttr) { if (primvarAttr.ComputeFlattened(&v, time)) { primvar.name = t; primvar.interpolation = primvarAttr.GetInterpolation(); valueCache->GetPrimvar(cachePath, t) = v; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } } t = UsdImagingTokens->ptexFaceOffset; // Allow the client to override this name texAttr.GetMetadata(UsdImagingTokens->faceOffsetPrimvar, &t); primvarAttr = gprim.GetPrimvar(t); if (primvarAttr) { primvar.name = t; primvar.interpolation = primvarAttr.GetInterpolation(); if (primvarAttr.ComputeFlattened(&v, time)) { valueCache->GetPrimvar(cachePath, t) = v; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } } } else { texAttr.GetMetadata(UsdImagingTokens->uvPrimvar, &t); primvarAttr = gprim.GetPrimvar(t); if (TF_VERIFY(primvarAttr, "%s\n", t.GetText())) { if (TF_VERIFY(primvarAttr.ComputeFlattened(&v, time))) { primvar.name = t; // does not include primvars: primvar.interpolation = primvarAttr.GetInterpolation(); // Convert double to float, we don't need double precision. if (v.IsHolding<VtVec2dArray>()) { v = VtValue::Cast<VtVec2fArray>(v); } valueCache->GetPrimvar(cachePath, t) = v; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } } } } else if (UsdAttribute pvAttr = shaderPrim.GetAttribute( TfToken(attr.GetPath().GetName() + ":primvar"))) { TfToken t; VtValue v; UsdGeomPrimvar primvarAttr; if (TF_VERIFY(pvAttr.Get(&t, UsdTimeCode::Default()))) { primvarAttr = gprim.GetPrimvar(t); if (TF_VERIFY(primvarAttr.ComputeFlattened(&v, time))) { primvar.name = t; // does not include primvars: primvar.interpolation = primvarAttr.GetInterpolation(); valueCache->GetPrimvar(cachePath, t) = v; _MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath)); } } } }