本文整理汇总了C++中UsdGeomPrimvar::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ UsdGeomPrimvar::Set方法的具体用法?C++ UsdGeomPrimvar::Set怎么用?C++ UsdGeomPrimvar::Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UsdGeomPrimvar
的用法示例。
在下文中一共展示了UsdGeomPrimvar::Set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _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;
}
示例5: writeMeshAttrs
// virtual
bool MayaMeshWriter::writeMeshAttrs(const UsdTimeCode &usdTime, UsdGeomMesh &primSchema)
{
MStatus status = MS::kSuccess;
// Write parent class attrs
writeTransformAttrs(usdTime, primSchema);
// Return if usdTime does not match if shape is animated
if (usdTime.IsDefault() == isShapeAnimated() ) {
// skip shape as the usdTime does not match if shape isAnimated value
return true;
}
MFnMesh lMesh( getDagPath(), &status );
if ( !status )
{
MGlobal::displayError( "MFnMesh() failed for MayaMeshWriter" );
return false;
}
unsigned int numVertices = lMesh.numVertices();
unsigned int numPolygons = lMesh.numPolygons();
// Set mesh attrs ==========
// Get points
// TODO: Use memcpy()
const float* mayaRawPoints = lMesh.getRawPoints(&status);
VtArray<GfVec3f> points(numVertices);
for (unsigned int i = 0; i < numVertices; i++) {
unsigned int floatIndex = i*3;
points[i].Set(mayaRawPoints[floatIndex],
mayaRawPoints[floatIndex+1],
mayaRawPoints[floatIndex+2]);
}
primSchema.GetPointsAttr().Set(points, usdTime); // ANIMATED
// Compute the extent using the raw points
VtArray<GfVec3f> extent(2);
UsdGeomPointBased::ComputeExtent(points, &extent);
primSchema.CreateExtentAttr().Set(extent, usdTime);
// Get faceVertexIndices
unsigned int numFaceVertices = lMesh.numFaceVertices(&status);
VtArray<int> faceVertexCounts(numPolygons);
VtArray<int> faceVertexIndices(numFaceVertices);
MIntArray mayaFaceVertexIndices; // used in loop below
unsigned int curFaceVertexIndex = 0;
for (unsigned int i = 0; i < numPolygons; i++) {
lMesh.getPolygonVertices(i, mayaFaceVertexIndices);
faceVertexCounts[i] = mayaFaceVertexIndices.length();
for (unsigned int j=0; j < mayaFaceVertexIndices.length(); j++) {
faceVertexIndices[ curFaceVertexIndex ] = mayaFaceVertexIndices[j]; // push_back
curFaceVertexIndex++;
}
}
primSchema.GetFaceVertexCountsAttr().Set(faceVertexCounts); // not animatable
primSchema.GetFaceVertexIndicesAttr().Set(faceVertexIndices); // not animatable
// Read usdSdScheme attribute. If not set, we default to defaultMeshScheme
// flag that can be user defined and initialized to catmullClark
TfToken sdScheme = PxrUsdMayaMeshUtil::getSubdivScheme(lMesh, getArgs().defaultMeshScheme);
primSchema.CreateSubdivisionSchemeAttr(VtValue(sdScheme), true);
// Polygonal Mesh Case
if (sdScheme==UsdGeomTokens->none) {
// Support for standard USD bool and with Mojito bool tag
TfToken normalInterp=PxrUsdMayaMeshUtil::getEmitNormals(lMesh, UsdGeomTokens->none);
if (normalInterp==UsdGeomTokens->faceVarying) {
// Get References to members of meshData object
MFloatVectorArray normalArray;
MFloatVectorArray vertexNormalArray;
lMesh.getNormals(normalArray, MSpace::kObject);
// Iterate through each face in the mesh.
vertexNormalArray.setLength(lMesh.numFaceVertices());
VtArray<GfVec3f> meshNormals(lMesh.numFaceVertices());
size_t faceVertIdx = 0;
for (MItMeshPolygon faceIter(getDagPath()); !faceIter.isDone(); faceIter.next()) {
// Iterate through each face-vertex.
for (size_t locVertIdx = 0; locVertIdx < faceIter.polygonVertexCount();
++locVertIdx, ++faceVertIdx) {
int index=faceIter.normalIndex(locVertIdx);
for (int j=0;j<3;j++) {
meshNormals[faceVertIdx][j]=normalArray[index][j];
}
}
}
primSchema.GetNormalsAttr().Set(meshNormals, usdTime);
primSchema.SetNormalsInterpolation(normalInterp);
}
} else {
TfToken sdInterpBound = PxrUsdMayaMeshUtil::getSubdivInterpBoundary(
lMesh, UsdGeomTokens->edgeAndCorner);
primSchema.CreateInterpolateBoundaryAttr(VtValue(sdInterpBound), true);
TfToken sdFVInterpBound = PxrUsdMayaMeshUtil::getSubdivFVInterpBoundary(
//.........这里部分代码省略.........