本文整理汇总了C++中UsdGeomPrimvar::GetUnauthoredValuesIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ UsdGeomPrimvar::GetUnauthoredValuesIndex方法的具体用法?C++ UsdGeomPrimvar::GetUnauthoredValuesIndex怎么用?C++ UsdGeomPrimvar::GetUnauthoredValuesIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UsdGeomPrimvar
的用法示例。
在下文中一共展示了UsdGeomPrimvar::GetUnauthoredValuesIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _createUVPrimVar
bool MayaMeshWriter::_createUVPrimVar(
UsdGeomGprim &primSchema,
const TfToken& name,
const VtArray<GfVec2f>& data,
const TfToken& interpolation,
const VtArray<int>& assignmentIndices,
const int unassignedValueIndex)
{
unsigned int numValues = data.size();
if (numValues == 0) {
return false;
}
TfToken interp = interpolation;
if (numValues == 1 && interp == UsdGeomTokens->constant) {
interp = TfToken();
}
UsdGeomPrimvar primVar =
primSchema.CreatePrimvar(name,
SdfValueTypeNames->Float2Array,
interp);
primVar.Set(data);
if (!assignmentIndices.empty()) {
primVar.SetIndices(assignmentIndices);
if (unassignedValueIndex != primVar.GetUnauthoredValuesIndex()) {
primVar.SetUnauthoredValuesIndex(unassignedValueIndex);
}
}
return true;
}
示例2: _createRGBAPrimVar
bool MayaMeshWriter::_createRGBAPrimVar(
UsdGeomGprim &primSchema,
const TfToken& name,
const VtArray<GfVec3f>& rgbData,
const VtArray<float>& alphaData,
const TfToken& interpolation,
const VtArray<int>& assignmentIndices,
const int unassignedValueIndex,
bool clamped)
{
unsigned int numValues = rgbData.size();
if (numValues == 0 || numValues != alphaData.size()) {
return false;
}
TfToken interp = interpolation;
if (numValues == 1 && interp == UsdGeomTokens->constant) {
interp = TfToken();
}
UsdGeomPrimvar primVar =
primSchema.CreatePrimvar(name,
SdfValueTypeNames->Color4fArray,
interp);
VtArray<GfVec4f> rgbaData(numValues);
for (size_t i = 0; i < rgbaData.size(); ++i) {
rgbaData[i] = GfVec4f(rgbData[i][0], rgbData[i][1], rgbData[i][2],
alphaData[i]);
}
primVar.Set(rgbaData);
if (!assignmentIndices.empty()) {
primVar.SetIndices(assignmentIndices);
if (unassignedValueIndex != primVar.GetUnauthoredValuesIndex()) {
primVar.SetUnauthoredValuesIndex(unassignedValueIndex);
}
}
if (clamped) {
PxrUsdMayaRoundTripUtil::MarkPrimvarAsClamped(primVar);
}
return true;
}
示例3: _createRGBPrimVar
bool MayaMeshWriter::_createRGBPrimVar(
UsdGeomGprim &primSchema,
const TfToken& name,
const VtArray<GfVec3f>& data,
const TfToken& interpolation,
const VtArray<int>& assignmentIndices,
const int unassignedValueIndex,
bool clamped)
{
unsigned int numValues = data.size();
if (numValues == 0) {
return false;
}
TfToken interp = interpolation;
if (numValues == 1 && interp == UsdGeomTokens->constant) {
interp = TfToken();
}
UsdGeomPrimvar primVar =
primSchema.CreatePrimvar(name,
SdfValueTypeNames->Color3fArray,
interp);
primVar.Set(data);
if (!assignmentIndices.empty()) {
primVar.SetIndices(assignmentIndices);
if (unassignedValueIndex != primVar.GetUnauthoredValuesIndex()) {
primVar.SetUnauthoredValuesIndex(unassignedValueIndex);
}
}
if (clamped) {
PxrUsdMayaRoundTripUtil::MarkPrimvarAsClamped(primVar);
}
return true;
}
示例4: colorSetName
/* static */
bool
UsdMayaTranslatorMesh::_AssignColorSetPrimvarToMesh(
const UsdGeomMesh& primSchema,
const UsdGeomPrimvar& primvar,
MFnMesh& meshFn)
{
const TfToken& primvarName = primvar.GetPrimvarName();
const SdfValueTypeName& typeName = primvar.GetTypeName();
MString colorSetName(primvarName.GetText());
// If the primvar is displayOpacity and it is a FloatArray, check if
// displayColor is authored. If not, we'll import this 'displayOpacity'
// primvar as a 'displayColor' color set. This supports cases where the
// user created a single channel value for displayColor.
// Note that if BOTH displayColor and displayOpacity are authored, they will
// be imported as separate color sets. We do not attempt to combine them
// into a single color set.
if (primvarName == UsdMayaMeshColorSetTokens->DisplayOpacityColorSetName &&
typeName == SdfValueTypeNames->FloatArray) {
if (!UsdMayaRoundTripUtil::IsAttributeUserAuthored(primSchema.GetDisplayColorPrimvar())) {
colorSetName = UsdMayaMeshColorSetTokens->DisplayColorColorSetName.GetText();
}
}
// We'll need to convert colors from linear to display if this color set is
// for display colors.
const bool isDisplayColor =
(colorSetName == UsdMayaMeshColorSetTokens->DisplayColorColorSetName.GetText());
// Get the raw data before applying any indexing. We'll only populate one
// of these arrays based on the primvar's typeName, and we'll also set the
// color representation so we know which array to use later.
VtFloatArray alphaArray;
VtVec3fArray rgbArray;
VtVec4fArray rgbaArray;
MFnMesh::MColorRepresentation colorRep;
size_t numValues = 0;
MStatus status = MS::kSuccess;
if (typeName == SdfValueTypeNames->FloatArray) {
colorRep = MFnMesh::kAlpha;
if (!primvar.Get(&alphaArray) || alphaArray.empty()) {
status = MS::kFailure;
} else {
numValues = alphaArray.size();
}
} else if (typeName == SdfValueTypeNames->Float3Array ||
typeName == SdfValueTypeNames->Color3fArray) {
colorRep = MFnMesh::kRGB;
if (!primvar.Get(&rgbArray) || rgbArray.empty()) {
status = MS::kFailure;
} else {
numValues = rgbArray.size();
}
} else if (typeName == SdfValueTypeNames->Float4Array ||
typeName == SdfValueTypeNames->Color4fArray) {
colorRep = MFnMesh::kRGBA;
if (!primvar.Get(&rgbaArray) || rgbaArray.empty()) {
status = MS::kFailure;
} else {
numValues = rgbaArray.size();
}
} else {
TF_WARN("Unsupported color set primvar type '%s' for primvar '%s' on "
"mesh: %s",
typeName.GetAsToken().GetText(),
primvarName.GetText(),
primvar.GetAttr().GetPrimPath().GetText());
return false;
}
if (status != MS::kSuccess || numValues == 0) {
TF_WARN("Could not read color set values from primvar '%s' on mesh: %s",
primvarName.GetText(),
primvar.GetAttr().GetPrimPath().GetText());
return false;
}
VtIntArray assignmentIndices;
int unauthoredValuesIndex = -1;
if (primvar.GetIndices(&assignmentIndices)) {
// The primvar IS indexed, so the indices array is what determines the
// number of color values.
numValues = assignmentIndices.size();
unauthoredValuesIndex = primvar.GetUnauthoredValuesIndex();
}
// Go through the color data and translate the values into MColors in the
// colorArray, taking into consideration that indexed data may have been
// authored sparsely. If the assignmentIndices array is empty then the data
// is NOT indexed.
// Note that with indexed data, the data is added to the arrays in ascending
// component ID order according to the primvar's interpolation (ascending
// face ID for uniform interpolation, ascending vertex ID for vertex
// interpolation, etc.). This ordering may be different from the way the
// values are ordered in the primvar. Because of this, we recycle the
// assignmentIndices array as we go to store the new mapping from component
//.........这里部分代码省略.........
示例5: uvSetName
/* static */
bool
UsdMayaTranslatorMesh::_AssignUVSetPrimvarToMesh(
const UsdGeomPrimvar& primvar,
MFnMesh& meshFn)
{
const TfToken& primvarName = primvar.GetPrimvarName();
// Get the raw data before applying any indexing.
VtVec2fArray uvValues;
if (!primvar.Get(&uvValues) || uvValues.empty()) {
TF_WARN("Could not read UV values from primvar '%s' on mesh: %s",
primvarName.GetText(),
primvar.GetAttr().GetPrimPath().GetText());
return false;
}
// This is the number of UV values assuming the primvar is NOT indexed.
VtIntArray assignmentIndices;
if (primvar.GetIndices(&assignmentIndices)) {
// The primvar IS indexed, so the indices array is what determines the
// number of UV values.
int unauthoredValuesIndex = primvar.GetUnauthoredValuesIndex();
// Replace any index equal to unauthoredValuesIndex with -1.
if (unauthoredValuesIndex != -1) {
for (int& index : assignmentIndices) {
if (index == unauthoredValuesIndex) {
index = -1;
}
}
}
// Furthermore, if unauthoredValuesIndex is valid for uvValues, then
// remove it from uvValues and shift the indices (we don't want to
// import the unauthored value into Maya, where it has no meaning).
if (unauthoredValuesIndex >= 0 &&
static_cast<size_t>(unauthoredValuesIndex) < uvValues.size()) {
// This moves [unauthoredValuesIndex + 1, end) to
// [unauthoredValuesIndex, end - 1), erasing the
// unauthoredValuesIndex.
std::move(
uvValues.begin() + unauthoredValuesIndex + 1,
uvValues.end(),
uvValues.begin() + unauthoredValuesIndex);
uvValues.pop_back();
for (int& index : assignmentIndices) {
if (index > unauthoredValuesIndex) {
index = index - 1;
}
}
}
}
// Go through the UV data and add the U and V values to separate
// MFloatArrays.
MFloatArray uCoords;
MFloatArray vCoords;
for (const GfVec2f& v : uvValues) {
uCoords.append(v[0]);
vCoords.append(v[1]);
}
MStatus status;
MString uvSetName(primvarName.GetText());
if (primvarName == UsdUtilsGetPrimaryUVSetName()) {
// We assume that the primary USD UV set maps to Maya's default 'map1'
// set which always exists, so we shouldn't try to create it.
uvSetName = "map1";
} else {
status = meshFn.createUVSet(uvSetName);
if (status != MS::kSuccess) {
TF_WARN("Unable to create UV set '%s' for mesh: %s",
uvSetName.asChar(),
meshFn.fullPathName().asChar());
return false;
}
}
// The following two lines should have no effect on user-visible state but
// prevent a Maya crash in MFnMesh.setUVs after creating a crease set.
// XXX this workaround is needed pending a fix by Autodesk.
MString currentSet = meshFn.currentUVSetName();
meshFn.setCurrentUVSetName(currentSet);
// Create UVs on the mesh from the values we collected out of the primvar.
// We'll assign mesh components to these values below.
status = meshFn.setUVs(uCoords, vCoords, &uvSetName);
if (status != MS::kSuccess) {
TF_WARN("Unable to set UV data on UV set '%s' for mesh: %s",
uvSetName.asChar(),
meshFn.fullPathName().asChar());
return false;
}
const TfToken& interpolation = primvar.GetInterpolation();
// Build an array of value assignments for each face vertex in the mesh.
// Any assignments left as -1 will not be assigned a value.
//.........这里部分代码省略.........
示例6: _addDisplayPrimvars
bool MayaMeshWriter::_addDisplayPrimvars(
UsdGeomGprim &primSchema,
const MFnMesh::MColorRepresentation colorRep,
const VtArray<GfVec3f>& RGBData,
const VtArray<float>& AlphaData,
const TfToken& interpolation,
const VtArray<int>& assignmentIndices,
const int unassignedValueIndex,
const bool clamped,
const bool authored)
{
// If we already have an authored value, don't try to write a new one.
UsdAttribute colorAttr = primSchema.GetDisplayColorAttr();
if (!colorAttr.HasAuthoredValueOpinion() && !RGBData.empty()) {
UsdGeomPrimvar displayColor = primSchema.CreateDisplayColorPrimvar();
if (interpolation != displayColor.GetInterpolation()) {
displayColor.SetInterpolation(interpolation);
}
displayColor.Set(RGBData);
if (!assignmentIndices.empty()) {
displayColor.SetIndices(assignmentIndices);
if (unassignedValueIndex != displayColor.GetUnauthoredValuesIndex()) {
displayColor.SetUnauthoredValuesIndex(unassignedValueIndex);
}
}
bool authRGB = authored;
if (colorRep == MFnMesh::kAlpha) {
authRGB = false;
}
if (authRGB) {
if (clamped) {
PxrUsdMayaRoundTripUtil::MarkPrimvarAsClamped(displayColor);
}
}
else {
PxrUsdMayaRoundTripUtil::MarkAttributeAsMayaGenerated(colorAttr);
}
}
UsdAttribute alphaAttr = primSchema.GetDisplayOpacityAttr();
if (!alphaAttr.HasAuthoredValueOpinion() && !AlphaData.empty()) {
// we consider a single alpha value that is 1.0 to be the "default"
// value. We only want to write values that are not the "default".
bool hasDefaultAlpha = AlphaData.size() == 1 && GfIsClose(AlphaData[0], 1.0, 1e-9);
if (!hasDefaultAlpha) {
UsdGeomPrimvar displayOpacity = primSchema.CreateDisplayOpacityPrimvar();
if (interpolation != displayOpacity.GetInterpolation()) {
displayOpacity.SetInterpolation(interpolation);
}
displayOpacity.Set(AlphaData);
if (!assignmentIndices.empty()) {
displayOpacity.SetIndices(assignmentIndices);
if (unassignedValueIndex != displayOpacity.GetUnauthoredValuesIndex()) {
displayOpacity.SetUnauthoredValuesIndex(unassignedValueIndex);
}
}
bool authAlpha = authored;
if (colorRep == MFnMesh::kRGB) {
authAlpha = false;
}
if (authAlpha) {
if (clamped) {
PxrUsdMayaRoundTripUtil::MarkPrimvarAsClamped(displayOpacity);
}
}
else {
PxrUsdMayaRoundTripUtil::MarkAttributeAsMayaGenerated(alphaAttr);
}
}
}
return true;
}