PXR_NAMESPACE_OPEN_SCOPE static void _ClearBuffer(GLenum buffer, GLint drawBuffer, const VtValue &value) { // XXX: There has to be a better way to handle the different formats. if (value.IsHolding<int>()) { glClearBufferiv(buffer, drawBuffer, &value.UncheckedGet<int>()); } else if (value.IsHolding<GfVec2i>()) { glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec2i>().GetArray()); } else if (value.IsHolding<GfVec3i>()) { glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec3i>().GetArray()); } else if (value.IsHolding<GfVec4i>()) { glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec4i>().GetArray()); } else if (value.IsHolding<float>()) { glClearBufferfv(buffer, drawBuffer, &value.UncheckedGet<float>()); } else if (value.IsHolding<GfVec2f>()) { glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec2f>().GetArray()); } else if (value.IsHolding<GfVec3f>()) { glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec3f>().GetArray()); } else if (value.IsHolding<GfVec4f>()) { glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec4f>().GetArray()); } else { TF_CODING_ERROR("Unsupported clear value type: %s", value.GetTypeName().c_str()); } }
bool UsdGeomPrimvar::ComputeFlattened(VtValue *value, UsdTimeCode time) const { VtValue attrVal; if (!Get(&attrVal, time)) { return false; } // If the primvar attr value is not an array or if the primvar isn't // indexed, simply return the attribute value. if (!attrVal.IsArrayValued() || !IsIndexed()) { *value = VtValue::Take(attrVal); return true; } VtIntArray indices; if (!GetIndices(&indices, time)) { TF_CODING_ERROR("No indices authored for indexed primvar <%s>.", _attr.GetPath().GetText()); return false; } // Handle all known supported array value types. bool foundSupportedType = _ComputeFlattenedArray<VtVec2fArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec2dArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec2iArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec2hArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec3fArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec3dArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec3iArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec3hArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec4fArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec4dArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec4iArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtVec4hArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtMatrix3dArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtMatrix4dArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtStringArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtDoubleArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtIntArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtFloatArray>(attrVal, indices, value) || _ComputeFlattenedArray<VtHalfArray>(attrVal, indices, value); if (!foundSupportedType) { TF_WARN("Unsupported indexed primvar value type %s.", attrVal.GetTypeName().c_str()); } return !value->IsEmpty(); }
bool UsdMayaAdaptor::SetMetadata( const TfToken& key, const VtValue& value, MDGModifier& modifier) { if (!*this) { TF_CODING_ERROR("Adaptor is not valid"); return false; } VtValue fallback; if (!SdfSchema::GetInstance().IsRegistered(key, &fallback)) { TF_CODING_ERROR("Metadata key '%s' is not registered", key.GetText()); return false; } if (fallback.IsEmpty()) { return false; } VtValue castValue = VtValue::CastToTypeOf(value, fallback); if (castValue.IsEmpty()) { TF_CODING_ERROR("Can't cast value to type '%s'", fallback.GetTypeName().c_str()); return false; } std::string mayaAttrName = _GetMayaAttrNameForMetadataKey(key); std::string mayaNiceAttrName = key.GetText(); MFnDependencyNode node(_handle.object()); TfType ty = fallback.GetType(); MObject attrObj = UsdMayaReadUtil::FindOrCreateMayaAttr( ty, TfToken(), SdfVariabilityUniform, node, mayaAttrName, mayaNiceAttrName, modifier); if (attrObj.isNull()) { return false; } MPlug plug = node.findPlug(attrObj); if (!UsdMayaReadUtil::SetMayaAttr(plug, castValue, modifier)) { return false; } return true; }