From b841b810b2bb529030a417b2c59b63165f66c655 Mon Sep 17 00:00:00 2001 From: Pierre Wang Date: Fri, 17 Dec 2021 11:49:09 +0800 Subject: [PATCH] Refactor the code (#90) (cherry picked from commit 076abbae4d2bbed42ab4d465cef925b6aa06c245) --- pxr/imaging/hd/simpleText.cpp | 3 +- pxr/imaging/hd/simpleTextTopology.cpp | 10 +- pxr/imaging/hd/simpleTextTopology.h | 23 +- pxr/imaging/hdSt/shaders/text.glslfx | 34 +- pxr/imaging/hdSt/simpleText.cpp | 36 +- pxr/imaging/hdSt/simpleText.h | 34 +- pxr/imaging/hdSt/simpleTextShaderKey.cpp | 8 +- pxr/imaging/hdSt/simpleTextShaderKey.h | 26 +- pxr/imaging/hdSt/simpleTextTopology.cpp | 10 +- pxr/imaging/hdSt/simpleTextTopology.h | 9 +- pxr/usd/usdGeom/simpleText.cpp | 54 ++- pxr/usd/usdGeom/simpleText.h | 20 +- pxr/usd/usdGeom/tokens.cpp | 8 +- pxr/usd/usdGeom/tokens.h | 14 +- .../usdImaging/simpleTextAdapter.cpp | 406 +++++++----------- pxr/usdImaging/usdImaging/simpleTextAdapter.h | 6 +- 16 files changed, 343 insertions(+), 358 deletions(-) diff --git a/pxr/imaging/hd/simpleText.cpp b/pxr/imaging/hd/simpleText.cpp index 1e88ba2978..4c2401d3db 100644 --- a/pxr/imaging/hd/simpleText.cpp +++ b/pxr/imaging/hd/simpleText.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -24,7 +24,6 @@ #include "pxr/pxr.h" #include "pxr/imaging/hd/simpleText.h" #include "pxr/imaging/hd/tokens.h" -#include "pxr/base/tf/envSetting.h" PXR_NAMESPACE_OPEN_SCOPE diff --git a/pxr/imaging/hd/simpleTextTopology.cpp b/pxr/imaging/hd/simpleTextTopology.cpp index 38e301f345..416d255265 100644 --- a/pxr/imaging/hd/simpleTextTopology.cpp +++ b/pxr/imaging/hd/simpleTextTopology.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -58,14 +58,13 @@ HdSimpleTextTopology::operator==(HdSimpleTextTopology const &other) const { HD_TRACE_FUNCTION(); - // no need to compare _adajency and _quadInfo - return (_pointCount == other._pointCount); + return _pointCount == other._pointCount; } bool HdSimpleTextTopology::operator!=(HdSimpleTextTopology const &other) const { - return !(*this == other); + return _pointCount != other._pointCount; } HdTopology::ID @@ -74,6 +73,7 @@ HdSimpleTextTopology::ComputeHash() const HD_TRACE_FUNCTION(); HdTopology::ID hash = 0; + // We only need to hash the point count. hash = ArchHash64((const char*)&_pointCount, sizeof(int), hash); // Note: We don't hash topological visibility, because it is treated as a @@ -84,7 +84,7 @@ HdSimpleTextTopology::ComputeHash() const std::ostream& operator << (std::ostream &out, HdSimpleTextTopology const &topo) { - out << ""; + out << "(" << topo.GetPointCount() << ")"; return out; } diff --git a/pxr/imaging/hd/simpleTextTopology.h b/pxr/imaging/hd/simpleTextTopology.h index d67a2c1ada..d8acab8429 100644 --- a/pxr/imaging/hd/simpleTextTopology.h +++ b/pxr/imaging/hd/simpleTextTopology.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -25,18 +25,20 @@ #define PXR_IMAGING_HD_SIMPLE_TEXT_TOPOLOGY_H #include "pxr/pxr.h" -#include "pxr/imaging/hd/api.h" -#include "pxr/imaging/hd/version.h" #include "pxr/imaging/hd/topology.h" -#include "pxr/imaging/hd/tokens.h" - -#include "pxr/base/vt/array.h" -#include "pxr/base/vt/value.h" - -#include "pxr/base/tf/token.h" PXR_NAMESPACE_OPEN_SCOPE +/// \class HdSimpleTextTopology +/// +/// Topology data for simpleText. +/// +/// HdSimpleTextTopology holds the raw input topology data for simpleText. +/// +/// The geometries of the text render items are always triangles, and we provide separate position +/// for each point. So the indices are always from zero to the count of points. The topology only +/// diffs by pointCount. +/// class HdSimpleTextTopology : public HdTopology { public: HD_API @@ -52,11 +54,12 @@ class HdSimpleTextTopology : public HdTopology { HD_API virtual ID ComputeHash() const; + /// Returns point count of the text geometry. int GetPointCount() const { return _pointCount; } - /// Equality check between two basisCurves topologies. + /// Equality check between two simpleText topologies. HD_API bool operator==(HdSimpleTextTopology const &other) const; HD_API diff --git a/pxr/imaging/hdSt/shaders/text.glslfx b/pxr/imaging/hdSt/shaders/text.glslfx index 9a4c8959ae..5199270260 100644 --- a/pxr/imaging/hdSt/shaders/text.glslfx +++ b/pxr/imaging/hdSt/shaders/text.glslfx @@ -116,14 +116,16 @@ out VSOutputShaderData { // The vertex position. vec4 Peye; - // The interpolated texture coordinates. - vec2 UV; + + vec2 UV; vec2 TriType; + vec3 TextColor; }outData; // Vertex shader - for shader based text. void main(void) { + // The position in object space. vec4 position = vec4(HdGet_points(), 1.0); // Transform the position from object space to clip space for output. @@ -135,6 +137,12 @@ void main(void) outData.UV = HdGet_textUV(); outData.TriType = HdGet_triType(); + // Pass the text color. + outData.TextColor = vec3(1.0, 0.5, 0.5); +#ifdef HD_HAS_displayColor + outData.TextColor = HdGet_displayColor().rgb; +#endif + gl_Position = vec4(GetProjectionMatrix() * outData.Peye); gl_Position.z -= gl_Position.w* 2.0 * GetDepthPriority(); ApplyClipPlanes(outData.Peye); @@ -148,18 +156,17 @@ in VSOutputShaderData { // The vertex position. vec4 Peye; - // The interpolated texture coordinates. - vec2 UV; + + vec2 UV; vec2 TriType; + vec3 TextColor; }inData; // Pixel shader - for shader based text. void main(void) { float alpha = 1.0; -#ifdef HD_HAS_displayOpacity - alpha = HdGet_displayOpacity().r; -#endif + vec2 uv = inData.UV; vec2 triType = inData.TriType; @@ -207,13 +214,12 @@ void main(void) alpha *= dist < -0.5 ? 1.0 : ( dist < 0.5 ? (0.5 - dist) : 0.0); } - vec3 displayColor = vec3(1.0, 0.5, 0.5); -#ifdef HD_HAS_displayColor - displayColor = HdGet_displayColor().rgb; -#endif - - vec4 finalColor = vec4(displayColor * alpha, alpha); - finalColor = ApplyColorOverrides(finalColor); + // The text primitive have alpha natively. So here we first get the override color, then + // multiply the alpha of the primitive with the override alpha, and finally set the alpha + // to the final color. + vec4 overrideColor = ApplyColorOverrides(vec4(inData.TextColor.rgb, 1.0)); + alpha = alpha * overrideColor.a; + vec4 finalColor = vec4(overrideColor.rgb * alpha, alpha); vec3 Peye = inData.Peye.xyz / inData.Peye.w; RenderOutput(vec4(Peye, 1), vec3(0, 0, 1), finalColor, vec4(1)); diff --git a/pxr/imaging/hdSt/simpleText.cpp b/pxr/imaging/hdSt/simpleText.cpp index 75cbf7aff3..5ef2d0b963 100644 --- a/pxr/imaging/hdSt/simpleText.cpp +++ b/pxr/imaging/hdSt/simpleText.cpp @@ -38,15 +38,9 @@ #include "pxr/base/arch/hash.h" -#include "pxr/base/gf/matrix4d.h" -#include "pxr/base/gf/matrix4f.h" -#include "pxr/base/gf/vec2d.h" -#include "pxr/base/gf/vec2i.h" - #include "pxr/imaging/hd/bufferSource.h" #include "pxr/imaging/hd/computation.h" #include "pxr/imaging/hd/repr.h" -#include "pxr/imaging/hd/vertexAdjacency.h" #include "pxr/imaging/hd/vtBufferSource.h" #include "pxr/base/vt/value.h" @@ -56,6 +50,7 @@ HdStSimpleText::HdStSimpleText(SdfPath const& id) : HdSimpleText(id) , _topology() , _topologyId(0) + , _customDirtyBitsInUse(0) , _refineLevel(0) , _displayOpacity(false) { @@ -197,7 +192,8 @@ HdStSimpleText::_UpdateDrawItem(HdSceneDelegate *sceneDelegate, // XXX: _PopulateTopology should be split into two phase // for scene dirtybits and for repr dirtybits. if (*dirtyBits & (HdChangeTracker::DirtyTopology - | HdChangeTracker::DirtyDisplayStyle)) { + | HdChangeTracker::DirtyDisplayStyle + | DirtyIndices)) { _PopulateTopology( sceneDelegate, renderParam, drawItem, dirtyBits); } @@ -205,11 +201,6 @@ HdStSimpleText::_UpdateDrawItem(HdSceneDelegate *sceneDelegate, /* PRIMVAR */ if ((*dirtyBits & HdChangeTracker::NewRepr) || HdChangeTracker::IsAnyPrimvarDirty(*dirtyBits, id)) { - // XXX: curves don't use refined vertex primvars, however, - // the refined renderpass masks the dirtiness of non-refined vertex - // primvars, so we need to see refined dirty for updating coarse - // vertex primvars if there is only refined reprs being updated. - // we'll fix the change tracking in order to address this craziness. _PopulateVertexPrimvars( sceneDelegate, renderParam, drawItem, dirtyBits); } @@ -220,8 +211,7 @@ HdStSimpleText::_UpdateDrawItem(HdSceneDelegate *sceneDelegate, // work with delegates that don't keep information around once extracted. *dirtyBits &= ~HdChangeTracker::AllSceneDirtyBits; - // Topology and VertexPrimvar may be null, if the curve has zero line - // segments. + // Topology and VertexPrimvar may be null. TF_VERIFY(drawItem->GetConstantPrimvarRange()); } @@ -260,7 +250,7 @@ HdStSimpleText::_PopulateTopology(HdSceneDelegate *sceneDelegate, _topologyId = ArchHash64((const char*)&refined, sizeof(refined), _topologyId); - // ask the registry if there is a sharable basisCurves topology + // ask the registry if there is a sharable simpleText topology HdInstance topologyInstance = resourceRegistry->RegisterSimpleTextTopology(_topologyId); @@ -282,7 +272,9 @@ HdStSimpleText::_PopulateTopology(HdSceneDelegate *sceneDelegate, } } + if ((*dirtyBits & DirtyIndices) == 0) return; TfToken indexToken; + *dirtyBits &= ~DirtyIndices; indexToken = HdTokens->indices; HdInstance rangeInstance = @@ -373,7 +365,7 @@ HdStSimpleText::_PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate, // are points if (!_topology) { if (primvar.name == HdTokens->points) { - TF_CODING_ERROR("No topology set for BasisCurve %s", + TF_CODING_ERROR("No topology set for SimpleText %s", id.GetName().c_str()); break; } @@ -464,12 +456,13 @@ HdStSimpleText::_UpdateRepr(HdSceneDelegate *sceneDelegate, } // Filter custom dirty bits to only those in use. - *dirtyBits &= (HdChangeTracker::AllSceneDirtyBits | + *dirtyBits &= (_customDirtyBitsInUse | + HdChangeTracker::AllSceneDirtyBits | HdChangeTracker::NewRepr); if (TfDebug::IsEnabled(HD_RPRIM_UPDATED)) { TfDebug::Helper().Msg( - "HdStBasisCurves::_UpdateRepr for %s : Repr = %s\n", + "HdStSimpleText::_UpdateRepr for %s : Repr = %s\n", GetId().GetText(), reprToken.GetText()); HdChangeTracker::DumpDirtyBits(*dirtyBits); } @@ -551,6 +544,11 @@ HdStSimpleText::Finalize(HdRenderParam *renderParam) HdDirtyBits HdStSimpleText::_PropagateDirtyBits(HdDirtyBits bits) const { + // propagate scene-based dirtyBits into rprim-custom dirtyBits + if (bits & HdChangeTracker::DirtyTopology) { + bits |= _customDirtyBitsInUse & DirtyIndices; + } + return bits; } @@ -566,6 +564,8 @@ HdStSimpleText::_InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) HdReprSharedPtr &repr = _reprs.back().second; *dirtyBits |= HdChangeTracker::NewRepr; + _customDirtyBitsInUse |= DirtyIndices; + *dirtyBits |= DirtyIndices; HdRepr::DrawItemUniquePtr drawItem = std::make_unique(&_sharedData); diff --git a/pxr/imaging/hdSt/simpleText.h b/pxr/imaging/hdSt/simpleText.h index 71dfbc099f..548e320ff8 100644 --- a/pxr/imaging/hdSt/simpleText.h +++ b/pxr/imaging/hdSt/simpleText.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -28,7 +28,6 @@ #include "pxr/imaging/hdSt/api.h" #include "pxr/imaging/hd/version.h" #include "pxr/imaging/hd/simpleText.h" -#include "pxr/imaging/hd/drawingCoord.h" #include "pxr/imaging/hd/enums.h" #include "pxr/imaging/hd/perfLog.h" @@ -43,31 +42,13 @@ class HdStDrawItem; using HdSt_SimpleTextTopologySharedPtr = std::shared_ptr; -/// \class HdStBasisCurves +/// \class HdStSimpleText /// -/// A collection of curves using a particular basis. +/// A single line single style text. /// -/// Render mode is dependent on both the HdBasisCurvesGeomStyle, refinement -/// level, and the authored primvars. +/// Currently we only support render the text using shader based technique. Next we will support +/// texture based technique. /// -/// If style is set to HdBasisCurvesGeomStyleWire, the curves will always draw -/// as infinitely thin wires. Cubic curves will be refined if complexity is -/// above 0, otherwise they draw the unrefined control points. (This may -/// provide a misleading representation for Catmull-Rom and Bspline curves.) -/// -/// If style is set to HdBasisCurvesGeomStylePatch, the curves will draw as -/// patches ONLY if refinement level is above 0. Otherwise, they draw -/// as the unrefined control points (see notes on HdBasisCurvesGeomStyleWire). -/// -/// Curves rendered as patches may be rendered as ribbons or halftubes. -/// Curves with primvar authored normals will always render as ribbons. -/// Curves without primvar authored normals are assumed to be round and may be -/// rendered in one of three styles: -/// * if complexity is 1, a camera facing normal is used -/// * if complexity is 2, a fake "bumped" round normal is used -/// * if complexity is 3 or above, the patch is displaced into a half tube -/// We plan for future checkins will remove the need for the camera facing normal -/// mode, using the fake "bumped" round normal instead. class HdStSimpleText final: public HdSimpleText { public: @@ -120,6 +101,10 @@ class HdStSimpleText final: public HdSimpleText bool updateGeometricShader); private: + enum DirtyBits : HdDirtyBits { + DirtyIndices = HdChangeTracker::CustomBitsBegin, + }; + void _UpdateDrawItem(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdStDrawItem *drawItem, @@ -127,6 +112,7 @@ class HdStSimpleText final: public HdSimpleText HdSt_SimpleTextTopologySharedPtr _topology; HdTopology::ID _topologyId; + HdDirtyBits _customDirtyBitsInUse; int _refineLevel; // XXX: could be moved into HdBasisCurveTopology. bool _displayOpacity : 1; }; diff --git a/pxr/imaging/hdSt/simpleTextShaderKey.cpp b/pxr/imaging/hdSt/simpleTextShaderKey.cpp index d89a51e9d1..c3d92cdfdb 100644 --- a/pxr/imaging/hdSt/simpleTextShaderKey.cpp +++ b/pxr/imaging/hdSt/simpleTextShaderKey.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -34,10 +34,16 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PRIVATE_TOKENS( _tokens, ((baseGLSLFX, "text.glslfx")) + + // texture based ((vsTextureText, "VSTextureText")) ((psTextureText, "PSTextureText")) + + // shader based ((vsShaderText, "VSShaderText")) ((psShaderText, "PSShaderText")) + + // point id mixins ((pointIdNoneVS, "PointId.Vertex.None")) ((pointIdFallbackFS, "PointId.Fragment.Fallback")) ); diff --git a/pxr/imaging/hdSt/simpleTextShaderKey.h b/pxr/imaging/hdSt/simpleTextShaderKey.h index 2e28cd5f5f..cd3ee94e3a 100644 --- a/pxr/imaging/hdSt/simpleTextShaderKey.h +++ b/pxr/imaging/hdSt/simpleTextShaderKey.h @@ -25,34 +25,16 @@ #define PXR_IMAGING_HD_ST_SIMPLE_TEXT_SHADER_KEY_H #include "pxr/pxr.h" -#include "pxr/imaging/hd/version.h" -#include "pxr/imaging/hd/enums.h" -#include "pxr/imaging/hdSt/geometricShader.h" #include "pxr/imaging/hdSt/shaderKey.h" -#include "pxr/base/tf/token.h" PXR_NAMESPACE_OPEN_SCOPE -/// \class HdSt_BasisCurvesShaderKey +/// \class HdSt_SimpleTextShaderKey /// -/// The draw styles are designed to strike a balance between matching offline -/// renderers like RenderMan and providing high interactive performance. At -/// the time of this writing, RenderMan (as of R22) only provides two curve -/// drawing modes: a round ray oriented half tube (HALFTUBE, ROUND) and a -/// flat primvar oriented ribbon (RIBBON, ORIENTED). +/// Currently simpleText doesn't have draw styles. We only support shader based rendering +/// technique. Next we can draw text using texture based or shader based technique. +/// So currrently there is only one set of shaders. /// -/// We allow all curves to be drawn as wires: for interactive guides which -/// may not have authored width and as a performance optimization. -/// -/// We allow for the combination of (RIBBON, ROUND) as a cheaper code path -/// which fakes a round normal on a flat camera oriented ribbon as an -/// optimization for half tubes. To alleviate aliasing, for very thin curves, -/// we provide a HAIR mode. -/// -/// Not all combinations of DrawStyle and NormalStyle are meaningful. For -/// example ORIENTED only makes sense with RIBBON. In the future, we hope to -/// eliminate NormalStyle, perhaps by merging the (RIBBON, ROUND) mode into a -/// more automatic HALFTUBE and by relying more on materials for HAIR. struct HdSt_SimpleTextShaderKey : public HdSt_ShaderKey { HdSt_SimpleTextShaderKey(); diff --git a/pxr/imaging/hdSt/simpleTextTopology.cpp b/pxr/imaging/hdSt/simpleTextTopology.cpp index baa1c40531..698b1f8154 100644 --- a/pxr/imaging/hdSt/simpleTextTopology.cpp +++ b/pxr/imaging/hdSt/simpleTextTopology.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -23,8 +23,11 @@ // #include "pxr/pxr.h" #include "pxr/imaging/hdSt/simpleTextTopology.h" - #include "pxr/imaging/hd/vtBufferSource.h" +#include "pxr/imaging/hd/tokens.h" + +#include "pxr/base/vt/array.h" +#include "pxr/base/vt/value.h" PXR_NAMESPACE_OPEN_SCOPE @@ -51,6 +54,8 @@ HdSt_SimpleTextTopology::~HdSt_SimpleTextTopology() HdBufferSourceSharedPtr HdSt_SimpleTextTopology::GetPointsIndexBuilderComputation() { + // We already have positions for every point. So here we just provide indices from the first + // point to the last. size_t characterCount = GetPointCount(); VtIntArray finalIndices; for (size_t i = 0; i < characterCount; i++) @@ -58,7 +63,6 @@ HdSt_SimpleTextTopology::GetPointsIndexBuilderComputation() finalIndices.emplace_back(i); } - // Note: The primitive param buffer isn't bound. return HdBufferSourceSharedPtr( new HdVtBufferSource(HdTokens->indices, VtValue(finalIndices))); } diff --git a/pxr/imaging/hdSt/simpleTextTopology.h b/pxr/imaging/hdSt/simpleTextTopology.h index 6f8660946e..f6d3f5bb9f 100644 --- a/pxr/imaging/hdSt/simpleTextTopology.h +++ b/pxr/imaging/hdSt/simpleTextTopology.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -27,8 +27,6 @@ #include "pxr/pxr.h" #include "pxr/imaging/hd/simpleTextTopology.h" -#include - PXR_NAMESPACE_OPEN_SCOPE using HdSt_SimpleTextTopologySharedPtr = @@ -36,10 +34,9 @@ using HdSt_SimpleTextTopologySharedPtr = using HdBufferSourceSharedPtr = std::shared_ptr; - -// HdSt_BasisCurvesTopology +// HdSt_SimpleTextTopology // -// Storm implementation for basisCurves topology. +// Storm implementation for simpleText topology. // class HdSt_SimpleTextTopology final : public HdSimpleTextTopology { public: diff --git a/pxr/usd/usdGeom/simpleText.cpp b/pxr/usd/usdGeom/simpleText.cpp index 384e8de0a3..398bdd7816 100644 --- a/pxr/usd/usdGeom/simpleText.cpp +++ b/pxr/usd/usdGeom/simpleText.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -326,3 +326,55 @@ PXR_NAMESPACE_CLOSE_SCOPE // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. // ===================================================================== // // --(BEGIN CUSTOM CODE)-- +PXR_NAMESPACE_OPEN_SCOPE +UsdAttribute +UsdGeomSimpleText::GetTextUVsAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->textUVs); +} + +UsdAttribute +UsdGeomSimpleText::CreateTextUVsAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->textUVs, + SdfValueTypeNames->Float2Array, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomSimpleText::GetTriTypesAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->triTypes); +} + +UsdAttribute +UsdGeomSimpleText::CreateTriTypesAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->triTypes, + SdfValueTypeNames->Float2Array, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomSimpleText::GetTextGeometryAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->textGeometry); +} + +UsdAttribute +UsdGeomSimpleText::CreateTextGeometryAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->textGeometry, + SdfValueTypeNames->Point3fArray, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdGeom/simpleText.h b/pxr/usd/usdGeom/simpleText.h index 4b1691c66e..7676af0456 100644 --- a/pxr/usd/usdGeom/simpleText.h +++ b/pxr/usd/usdGeom/simpleText.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -397,6 +397,24 @@ class UsdGeomSimpleText : public UsdGeomGprim // - Close the include guard with #endif // ===================================================================== // // --(BEGIN CUSTOM CODE)-- + USDGEOM_API + UsdAttribute GetTextUVsAttr() const; + + USDGEOM_API + UsdAttribute CreateTextUVsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely = false) const; + + USDGEOM_API + UsdAttribute GetTriTypesAttr() const; + + USDGEOM_API + UsdAttribute CreateTriTypesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely = false) const; + + USDGEOM_API + UsdAttribute GetTextGeometryAttr() const; + + USDGEOM_API + UsdAttribute CreateTextGeometryAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely = false) const; + }; PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdGeom/tokens.cpp b/pxr/usd/usdGeom/tokens.cpp index 5e7598bc7f..2794fa8a1d 100644 --- a/pxr/usd/usdGeom/tokens.cpp +++ b/pxr/usd/usdGeom/tokens.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -159,7 +159,9 @@ UsdGeomTokensType::UsdGeomTokensType() : tangents("tangents", TfToken::Immortal), textData("textData", TfToken::Immortal), textEncoding("textEncoding", TfToken::Immortal), + textGeometry("textGeometry", TfToken::Immortal), textHeight("textHeight", TfToken::Immortal), + textUVs("textUVs", TfToken::Immortal), textWidthFactor("textWidthFactor", TfToken::Immortal), triangleSubdivisionRule("triangleSubdivisionRule", TfToken::Immortal), trimCurveCounts("trimCurve:counts", TfToken::Immortal), @@ -168,6 +170,7 @@ UsdGeomTokensType::UsdGeomTokensType() : trimCurvePoints("trimCurve:points", TfToken::Immortal), trimCurveRanges("trimCurve:ranges", TfToken::Immortal), trimCurveVertexCounts("trimCurve:vertexCounts", TfToken::Immortal), + triTypes("triTypes", TfToken::Immortal), type("type", TfToken::Immortal), typeface("typeface", TfToken::Immortal), uForm("uForm", TfToken::Immortal), @@ -335,7 +338,9 @@ UsdGeomTokensType::UsdGeomTokensType() : tangents, textData, textEncoding, + textGeometry, textHeight, + textUVs, textWidthFactor, triangleSubdivisionRule, trimCurveCounts, @@ -344,6 +349,7 @@ UsdGeomTokensType::UsdGeomTokensType() : trimCurvePoints, trimCurveRanges, trimCurveVertexCounts, + triTypes, type, typeface, uForm, diff --git a/pxr/usd/usdGeom/tokens.h b/pxr/usd/usdGeom/tokens.h index 266c951037..53e85e0a45 100644 --- a/pxr/usd/usdGeom/tokens.h +++ b/pxr/usd/usdGeom/tokens.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -594,10 +594,18 @@ struct UsdGeomTokensType { /// /// UsdGeomSimpleText const TfToken textEncoding; + /// \brief "textGeometry" + /// + /// UsdGeomSimpleText + const TfToken textGeometry; /// \brief "textHeight" /// /// UsdGeomSimpleText const TfToken textHeight; + /// \brief "textUVs" + /// + /// UsdGeomSimpleText + const TfToken textUVs; /// \brief "textWidthFactor" /// /// UsdGeomSimpleText @@ -630,6 +638,10 @@ struct UsdGeomTokensType { /// /// UsdGeomNurbsPatch const TfToken trimCurveVertexCounts; + /// \brief "triTypes" + /// + /// UsdGeomSimpleText + const TfToken triTypes; /// \brief "type" /// /// UsdGeomBasisCurves diff --git a/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp b/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp index bb567040e2..802be35c8a 100644 --- a/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp +++ b/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -44,7 +44,7 @@ PXR_NAMESPACE_OPEN_SCOPE - +// Register the adapter. TF_REGISTRY_FUNCTION(TfType) { typedef UsdImagingSimpleTextAdapter Adapter; @@ -82,48 +82,52 @@ UsdImagingSimpleTextAdapter::TrackVariability(UsdPrim const& prim, BaseAdapter::TrackVariability( prim, cachePath, timeVaryingBits, instancerContext); + // The textData, textEncoding, typeface, height, widthFactor, bold and italic will impact the + // topology. if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->textData, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->textEncoding, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->typeface, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->textHeight, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->textWidthFactor, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->italic, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } if ((*timeVaryingBits & HdChangeTracker::DirtyTopology) == 0) { _IsVarying(prim, UsdGeomTokens->bold, HdChangeTracker::DirtyTopology, - UsdImagingTokens->usdVaryingPrimvar, + UsdImagingTokens->usdVaryingTopology, timeVaryingBits, /*inherited*/false); } + // The obliqueAngle, charSpacing and charPos will not impact the topology, but impact the + // position of the points. if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { _IsVarying(prim, UsdGeomTokens->obliqueAngle, HdChangeTracker::DirtyPoints, @@ -147,7 +151,7 @@ UsdImagingSimpleTextAdapter::TrackVariability(UsdPrim const& prim, bool UsdImagingSimpleTextAdapter::_IsBuiltinPrimvar(TfToken const& primvarName) const { - return (primvarName == HdTokens->textUV || primvarName == HdTokens->triType + return (primvarName == HdTokens->textUV || primvarName == HdTokens->triType || BaseAdapter::_IsBuiltinPrimvar(primvarName)); } @@ -179,14 +183,16 @@ UsdImagingSimpleTextAdapter::ProcessPropertyChange(UsdPrim const& prim, SdfPath const& cachePath, TfToken const& propertyName) { - // Even though points is treated as a primvar, it is special and is always - // treated as a vertex primvar. + // The textData, textEncoding, typeface, height, widthFactor, bold and italic will impact the + // topology. if (propertyName == UsdGeomTokens->textData || propertyName == UsdGeomTokens->textEncoding || propertyName == UsdGeomTokens->typeface || propertyName == UsdGeomTokens->bold || propertyName == UsdGeomTokens->italic || propertyName == UsdGeomTokens->textHeight || propertyName == UsdGeomTokens->textWidthFactor) { return HdChangeTracker::DirtyTopology; } + // The obliqueAngle, charSpacing and charPos will not impact the topology, but impact the + // position of the points. else if (propertyName == UsdGeomTokens->obliqueAngle || propertyName == UsdGeomTokens->charSpacing || propertyName == UsdGeomTokens->charPos) return HdChangeTracker::DirtyPoints; @@ -195,43 +201,37 @@ UsdImagingSimpleTextAdapter::ProcessPropertyChange(UsdPrim const& prim, return BaseAdapter::ProcessPropertyChange(prim, cachePath, propertyName); } -/*virtual*/ -VtValue -UsdImagingSimpleTextAdapter::GetTopology(UsdPrim const& prim, - SdfPath const& cachePath, - UsdTimeCode time) const +void GenerateTextGeometries(UsdPrim const& prim, UsdTimeCode time, VtVec3fArray& geometries, + VtVec2fArray& uvs, VtVec2fArray& triTypes) { - TRACE_FUNCTION(); - HF_MALLOC_TAG_FUNCTION(); - UsdGeomSimpleText text(prim); std::string textData; if (!text.GetTextDataAttr().Get(&textData, time)) { - return VtValue(HdSimpleTextTopology()); + return; } TfToken textEncoding; if (!text.GetTextEncodingAttr().Get(&textEncoding, time)) { - return VtValue(HdSimpleTextTopology()); + return; } std::string typeface; if (!text.GetTypefaceAttr().Get(&typeface, time)) { - return VtValue(HdSimpleTextTopology()); + return; } int textHeight; if (!text.GetTextHeightAttr().Get(&textHeight, time)) { - return VtValue(HdSimpleTextTopology()); + return; } float textWidthFactor; if (!text.GetTextWidthFactorAttr().Get(&textWidthFactor, time)) { - return VtValue(HdSimpleTextTopology()); + return; } bool bold; if (!text.GetBoldAttr().Get(&bold, time)) { - return VtValue(HdSimpleTextTopology()); + return; } bool italic; if (!text.GetItalicAttr().Get(&italic, time)) { - return VtValue(HdSimpleTextTopology()); + return; } OGS::Text::TextStyle style; style._typeface = typeface; @@ -249,15 +249,85 @@ UsdImagingSimpleTextAdapter::GetTopology(UsdPrim const& prim, simpleManager.generateCharMetricsAndIndices(textData, layout); simpleManager.generateTextMetrics(layout); - int pointCount = 0; + static const GfVec2f innerTriangle(1.0f, 0.0f), + convexTriangle(0.0f, 1.0f), + concaveTriangle(0.0f, 0.0f); + for (int i = 0; i < layout.countOfRenderableChars(); i++) { OGS::Text::CharMetrics& metrics = layout.characterMetrics(i); OGS::Text::TextTriangles triangles; OGS::Text::Box2 rasBox; simpleManager.generateGlyphGeometry(layout.characterIndices()[i], rasBox, triangles); - pointCount += triangles.size() * 3; + for (auto it = triangles.begin(); it != triangles.end(); ++it) + { + OGS::Text::TextTriangle& triangle = *it; + bool changeOrder = false; + changeOrder = changeOrder ^ (triangle.tflag == OGS::Text::TextTriangle::CONCAVE); + for (int i = 0; i < 3; ++i) + { + int index = changeOrder ? ((3 - i) < 3 ? 3 - i : 0) : i; + geometries.emplace_back(GfVec3f(metrics._startPosition + triangle.ptArray[index]._x, + triangle.ptArray[index]._y, + 0.0f)); + uvs.emplace_back(GfVec2f(0.5f * index, (float)(index / 2))); + switch (triangle.tflag) + { + case OGS::Text::TextTriangle::INNER: + triTypes.emplace_back(innerTriangle); + break; + case OGS::Text::TextTriangle::CONCAVE: + triTypes.emplace_back(concaveTriangle); + break; + case OGS::Text::TextTriangle::CONVEX: + triTypes.emplace_back(convexTriangle); + break; + default: + break; + } + } + } + } +} + +/*virtual*/ +VtValue +UsdImagingSimpleTextAdapter::GetTopology(UsdPrim const& prim, + SdfPath const& cachePath, + UsdTimeCode time) const +{ + TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + // Get the geometry triangles of the text. + UsdGeomSimpleText text(prim); + VtVec3fArray geometries; + if (!text.GetTextGeometryAttr().Get(&geometries, time)) + { + // If the attribute is not valid, generate it. + VtVec2fArray uvs; + VtVec2fArray triTypes; + + GenerateTextGeometries(prim, time, geometries, uvs, triTypes); + if (!text.GetTextGeometryAttr().GetTypeName()) + { + text.CreateTextGeometryAttr(); + } + text.GetTextGeometryAttr().Set(geometries, time); + if (!text.GetTextUVsAttr().GetTypeName()) + { + text.CreateTextUVsAttr(); + } + text.GetTextUVsAttr().Set(uvs, time); + if (!text.GetTriTypesAttr().GetTypeName()) + { + text.CreateTriTypesAttr(); + } + text.GetTriTypesAttr().Set(triTypes, time); + } + // Get the point count from geometries. + int pointCount = geometries.size(); HdSimpleTextTopology topology(pointCount); return VtValue(topology); } @@ -281,154 +351,61 @@ UsdImagingSimpleTextAdapter::Get(UsdPrim const& prim, if (key == HdTokens->points) { VtValue value; - VtVec3fArray points; UsdGeomSimpleText text(prim); - std::string textData; - if (!text.GetTextDataAttr().Get(&textData, time)) { - value = points; - return value; - } - TfToken textEncoding; - if (!text.GetTextEncodingAttr().Get(&textEncoding, time)) { - value = points; - return value; - } - std::string typeface; - if (!text.GetTypefaceAttr().Get(&typeface, time)) { - value = points; - return value; - } - int textHeight; - if (!text.GetTextHeightAttr().Get(&textHeight, time)) { - value = points; - return value; - } - float textWidthFactor; - if (!text.GetTextWidthFactorAttr().Get(&textWidthFactor, time)) { - value = points; - return value; - } - bool bold; - if (!text.GetBoldAttr().Get(&bold, time)) { - value = points; - return value; - } - bool italic; - if (!text.GetItalicAttr().Get(&italic, time)) { - value = points; - return value; - } - OGS::Text::TextStyle style; - style._typeface = typeface; - style._bold = bold; - style._italic = italic; - style._height = textHeight; - style._widthFactor = textWidthFactor; - style._obliqueAngle = 0; - style._characterSpaceFactor = 1; - - OGS::Text::TrueTypeSimpleLayoutManager& simpleManager = - OGS::Text::TextSystem::instance()->getSimpleLayoutManager(style); - - OGS::Text::SimpleLayout layout; - simpleManager.generateCharMetricsAndIndices(textData, layout); - simpleManager.generateTextMetrics(layout); - - for (int i = 0; i < layout.countOfRenderableChars(); i++) + VtVec3fArray geometries; + if (!text.GetTextGeometryAttr().Get(&geometries, time)) { - OGS::Text::CharMetrics& metrics = layout.characterMetrics(i); - OGS::Text::TextTriangles triangles; - OGS::Text::Box2 rasBox; - simpleManager.generateGlyphGeometry(layout.characterIndices()[i], rasBox, triangles); - for (auto it = triangles.begin(); it != triangles.end(); ++it) + VtVec2fArray uvs; + VtVec2fArray triTypes; + + // If the attribute is not valid, generate it. + GenerateTextGeometries(prim, time, geometries, uvs, triTypes); + if (!text.GetTextGeometryAttr().GetTypeName()) { - OGS::Text::TextTriangle& triangle = *it; - bool changeOrder = false; - changeOrder = changeOrder ^ (triangle.tflag == OGS::Text::TextTriangle::CONCAVE); - for (int i = 0; i < 3; ++i) - { - int index = changeOrder ? ((3 - i) < 3 ? 3 - i : 0) : i; - points.emplace_back(GfVec3f(metrics._startPosition + triangle.ptArray[index]._x, - triangle.ptArray[index]._y, - 0.0f)); - } + text.CreateTextGeometryAttr(); } + text.GetTextGeometryAttr().Set(geometries, time); + if (!text.GetTextUVsAttr().GetTypeName()) + { + text.CreateTextUVsAttr(); + } + text.GetTextUVsAttr().Set(uvs, time); + if (!text.GetTriTypesAttr().GetTypeName()) + { + text.CreateTriTypesAttr(); + } + text.GetTriTypesAttr().Set(triTypes, time); } - value = points; + value = geometries; return value; } else if (key == HdTokens->textUV) { VtValue value; - VtVec2fArray uvs; UsdGeomSimpleText text(prim); - std::string textData; - if (!text.GetTextDataAttr().Get(&textData, time)) { - value = uvs; - return value; - } - TfToken textEncoding; - if (!text.GetTextEncodingAttr().Get(&textEncoding, time)) { - value = uvs; - return value; - } - std::string typeface; - if (!text.GetTypefaceAttr().Get(&typeface, time)) { - value = uvs; - return value; - } - int textHeight; - if (!text.GetTextHeightAttr().Get(&textHeight, time)) { - value = uvs; - return value; - } - float textWidthFactor; - if (!text.GetTextWidthFactorAttr().Get(&textWidthFactor, time)) { - value = uvs; - return value; - } - bool bold; - if (!text.GetBoldAttr().Get(&bold, time)) { - value = uvs; - return value; - } - bool italic; - if (!text.GetItalicAttr().Get(&italic, time)) { - value = uvs; - return value; - } - OGS::Text::TextStyle style; - style._typeface = typeface; - style._bold = bold; - style._italic = italic; - style._height = textHeight; - style._widthFactor = textWidthFactor; - style._obliqueAngle = 0; - style._characterSpaceFactor = 1; - - OGS::Text::TrueTypeSimpleLayoutManager& simpleManager = - OGS::Text::TextSystem::instance()->getSimpleLayoutManager(style); - - OGS::Text::SimpleLayout layout; - simpleManager.generateCharMetricsAndIndices(textData, layout); - simpleManager.generateTextMetrics(layout); - - for (int i = 0; i < layout.countOfRenderableChars(); i++) + VtVec2fArray uvs; + if (!text.GetTextUVsAttr().Get(&uvs, time)) { - OGS::Text::CharMetrics& metrics = layout.characterMetrics(i); - OGS::Text::TextTriangles triangles; - OGS::Text::Box2 rasBox; - simpleManager.generateGlyphGeometry(layout.characterIndices()[i], rasBox, triangles); - for (auto it = triangles.begin(); it != triangles.end(); ++it) + VtVec3fArray geometries; + VtVec2fArray triTypes; + + // If the attribute is not valid, generate it. + GenerateTextGeometries(prim, time, geometries, uvs, triTypes); + + if (!text.GetTextGeometryAttr().GetTypeName()) { - OGS::Text::TextTriangle& triangle = *it; - bool changeOrder = false; - changeOrder = changeOrder ^ (triangle.tflag == OGS::Text::TextTriangle::CONCAVE); - for (int i = 0; i < 3; ++i) - { - int index = changeOrder ? ((3 - i) < 3 ? 3 - i : 0) : i; - uvs.emplace_back(GfVec2f(0.5f * index, (float)(index / 2))); - } + text.CreateTextGeometryAttr(); + } + text.GetTextGeometryAttr().Set(geometries, time); + if (!text.GetTextUVsAttr().GetTypeName()) + { + text.CreateTextUVsAttr(); + } + text.GetTextUVsAttr().Set(uvs, time); + if (!text.GetTriTypesAttr().GetTypeName()) + { + text.CreateTriTypesAttr(); } + text.GetTriTypesAttr().Set(triTypes, time); } value = uvs; return value; @@ -437,91 +414,28 @@ UsdImagingSimpleTextAdapter::Get(UsdPrim const& prim, VtValue value; UsdGeomSimpleText text(prim); VtVec2fArray triTypes; - std::string textData; - if (!text.GetTextDataAttr().Get(&textData, time)) { - value = triTypes; - return value; - } - TfToken textEncoding; - if (!text.GetTextEncodingAttr().Get(&textEncoding, time)) { - value = triTypes; - return value; - } - std::string typeface; - if (!text.GetTypefaceAttr().Get(&typeface, time)) { - value = triTypes; - return value; - } - int textHeight; - if (!text.GetTextHeightAttr().Get(&textHeight, time)) { - value = triTypes; - return value; - } - float textWidthFactor; - if (!text.GetTextWidthFactorAttr().Get(&textWidthFactor, time)) { - value = triTypes; - return value; - } - bool bold; - if (!text.GetBoldAttr().Get(&bold, time)) { - value = triTypes; - return value; - } - bool italic; - if (!text.GetItalicAttr().Get(&italic, time)) { - value = triTypes; - return value; - } - OGS::Text::TextStyle style; - style._typeface = typeface; - style._bold = bold; - style._italic = italic; - style._height = textHeight; - style._widthFactor = textWidthFactor; - style._obliqueAngle = 0; - style._characterSpaceFactor = 1; - - OGS::Text::TrueTypeSimpleLayoutManager& simpleManager = - OGS::Text::TextSystem::instance()->getSimpleLayoutManager(style); - - OGS::Text::SimpleLayout layout; - simpleManager.generateCharMetricsAndIndices(textData, layout); - simpleManager.generateTextMetrics(layout); - - static const GfVec2f innerTriangle(1.0f, 0.0f), - convexTriangle(0.0f, 1.0f), - concaveTriangle(0.0f, 0.0f); - - for (int i = 0; i < layout.countOfRenderableChars(); i++) + if (!text.GetTriTypesAttr().Get(&triTypes, time)) { - OGS::Text::CharMetrics& metrics = layout.characterMetrics(i); - OGS::Text::TextTriangles triangles; - OGS::Text::Box2 rasBox; - simpleManager.generateGlyphGeometry(layout.characterIndices()[i], rasBox, triangles); - for (auto it = triangles.begin(); it != triangles.end(); ++it) + VtVec3fArray geometries; + VtVec2fArray uvs; + + // If the attribute is not valid, generate it. + GenerateTextGeometries(prim, time, geometries, uvs, triTypes); + if (!text.GetTextGeometryAttr().GetTypeName()) { - OGS::Text::TextTriangle& triangle = *it; - bool changeOrder = false; - changeOrder = changeOrder ^ (triangle.tflag == OGS::Text::TextTriangle::CONCAVE); - for (int i = 0; i < 3; ++i) - { - int index = changeOrder ? ((3 - i) < 3 ? 3 - i : 0) : i; - switch (triangle.tflag) - { - case OGS::Text::TextTriangle::INNER: - triTypes.emplace_back(innerTriangle); - break; - case OGS::Text::TextTriangle::CONCAVE: - triTypes.emplace_back(concaveTriangle); - break; - case OGS::Text::TextTriangle::CONVEX: - triTypes.emplace_back(convexTriangle); - break; - default: - break; - } - } + text.CreateTextGeometryAttr(); + } + text.GetTextGeometryAttr().Set(geometries, time); + if (!text.GetTextUVsAttr().GetTypeName()) + { + text.CreateTextUVsAttr(); + } + text.GetTextUVsAttr().Set(uvs, time); + if (!text.GetTriTypesAttr().GetTypeName()) + { + text.CreateTriTypesAttr(); } + text.GetTriTypesAttr().Set(triTypes, time); } value = triTypes; return value; diff --git a/pxr/usdImaging/usdImaging/simpleTextAdapter.h b/pxr/usdImaging/usdImaging/simpleTextAdapter.h index 90d2bbe50f..806a00321f 100644 --- a/pxr/usdImaging/usdImaging/simpleTextAdapter.h +++ b/pxr/usdImaging/usdImaging/simpleTextAdapter.h @@ -1,5 +1,5 @@ // -// Copyright 2016 Pixar +// Copyright 2021 Pixar // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in @@ -34,9 +34,9 @@ PXR_NAMESPACE_OPEN_SCOPE -/// \class UsdImagingBasisCurvesAdapter +/// \class UsdImagingSimpleTextAdapter /// -/// Delegate support for UsdGeomBasisCurves. +/// Delegate support for UsdGeomSimpleText. /// class UsdImagingSimpleTextAdapter : public UsdImagingGprimAdapter {