Skip to content

Commit

Permalink
[OGSMOD-1904] Integrate multiline multi-style multi-column text into …
Browse files Browse the repository at this point in the history
…USD (PixarAnimationStudios#119)

Description of Change(s)
Integrate multiline multi-style multi-column text into USD

(cherry picked from commit 9dd03cd0893862be6767115efe6cef785277d6d1)
  • Loading branch information
PierreWang committed Jan 17, 2023
1 parent 3da9255 commit 57ebf7f
Show file tree
Hide file tree
Showing 40 changed files with 3,166 additions and 66 deletions.
133 changes: 133 additions & 0 deletions extras/usd/examples/usdGeomExamples/multilineText.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#usda 1.0

(
upAxis = "Y"
doc = """This layer represents the various geometric forms that curves
may be used to represent."""
)


def Xform "Linear" {
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (0, 9, 0)
def Scope "Tubes"{
def BasisCurves "ConstantWidth1" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(0, 0, 0), (0, -170, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth2" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(0, -170, 0), (150, -170, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth3" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(150, -170, 0), (150, 0, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth4" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(150, 0, 0), (0, 0, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}

def BasisCurves "ConstantWidth5" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(160, 0, 0), (160, -170, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth6" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(160, -170, 0), (360, -170, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth7" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(360, -170, 0), (360, 0, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
def BasisCurves "ConstantWidth8" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

uniform token type = "linear"
int[] curveVertexCounts = [2]
point3f[] points = [(360, 0, 0), (160, 0, 0)]
float[] widths = [.5] (interpolation = "constant")
color3f[] primvars:displayColor = [(1, 0, 0)]
}
}
}

def Xform "Text1" {
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (0, 9, 0)
def Scope "Text11"{
def GenericText "TextA" (){
uniform token[] xformOpOrder = ["xformOp:translate"]
float3 xformOp:translate = (3, 0, 0)

string markupString = "\\fArial|b0|i1|p34|c0;\\H30;\\c65300;The quick bro\\H20;\\c0;wn fox jumps over \\H30;\\c42137;the lazy dog. \\c12255232;The quick brown fox \\fConsolas|b1|i0|p34|c0;\\c100;jumps over the lazy dog."
uniform token markupLanguage = "mtext"
color3f[] primvars:displayColor = [(0, 1, 1)]
rel textStyle:binding = </StyleA>
rel columnStyle:binding = [
</columnA>,
</columnB>,
]
}
}
}

def TextStyle "StyleA" {
string typeface = "Times New Roman"
int textHeight = 20
}

def ColumnStyle "columnA" {
float columnWidth = 150
float columnHeight = 170
float2 offset = (0.0, 0.0)
}

def ColumnStyle "columnB" {
float columnWidth = 200
float columnHeight = 170
float2 offset = (160.0, 0.0)
}
4 changes: 4 additions & 0 deletions pxr/imaging/hd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if (PXR_ENABLE_TEXT_SUPPORT)
simpleTextTopology
simpleTextSchema
simpleTextTopologySchema
genericText
genericTextTopology
genericTextSchema
genericTextTopologySchema
)
endif()

Expand Down
198 changes: 198 additions & 0 deletions pxr/imaging/hd/dataSourceLegacyPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#include "pxr/imaging/hd/displayFilterSchema.h"
#include "pxr/imaging/hd/simpleTextSchema.h"
#include "pxr/imaging/hd/simpleTextTopologySchema.h"
#include "pxr/imaging/hd/genericTextSchema.h"
#include "pxr/imaging/hd/genericTextTopologySchema.h"
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
#include "pxr/imaging/hd/visibilitySchema.h"
#include "pxr/imaging/hd/volumeFieldBindingSchema.h"
Expand Down Expand Up @@ -1248,6 +1250,194 @@ class Hd_DataSourceSimpleText : public HdContainerDataSource

};

using Hd_GenericTextTopologyStoreSharedPtr =
std::shared_ptr<class Hd_GenericTextTopologyStore>;
using HdGenericTextTopologySharedPtr = std::shared_ptr<HdGenericTextTopology>;

class Hd_GenericTextTopologyStore
{
public:
Hd_GenericTextTopologyStore(
const SdfPath &id, HdSceneDelegate *sceneDelegate)
: _id(id)
, _sceneDelegate(sceneDelegate)
{
}

HdGenericTextTopologySharedPtr Get()
{
HdGenericTextTopologySharedPtr stt = std::atomic_load(
&_genericTextTopology);
if (stt) {
return stt;
}

stt = std::make_shared<HdGenericTextTopology>(
_sceneDelegate->GetGenericTextTopology(_id));
std::atomic_store(&_genericTextTopology, stt);
return stt;
}

void Invalidate()
{
HdGenericTextTopologySharedPtr nullstt;
std::atomic_store(&_genericTextTopology, nullstt);
}

template <typename T>
class MemberDataSource : public HdTypedSampledDataSource<T>
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(MemberDataSource<T>);

T GetTypedValue(HdSampledDataSource::Time shutterOffset) override = 0;

VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
{
return VtValue(GetTypedValue(shutterOffset));
}

bool GetContributingSampleTimesForInterval(
HdSampledDataSource::Time startTime,
HdSampledDataSource::Time endTime,
std::vector<HdSampledDataSource::Time> * outSampleTimes)
override
{
return false;
}

MemberDataSource(const Hd_GenericTextTopologyStoreSharedPtr &stts)
: _stts(stts)
{
}

protected:
Hd_GenericTextTopologyStoreSharedPtr _stts;
};

#define DEFINE_GENERICTEXT_TOPOLOGY_ACCESSOR_DATASOURCE(N, T, A) \
class N : public MemberDataSource<T> \
{ \
public: \
HD_DECLARE_DATASOURCE(N); \
\
N(const Hd_GenericTextTopologyStoreSharedPtr &stts) \
: MemberDataSource(stts) {} \
\
T GetTypedValue(HdSampledDataSource::Time shutterOffset) override \
{ \
return _stts->Get()->A(); \
} \
};

DEFINE_GENERICTEXT_TOPOLOGY_ACCESSOR_DATASOURCE(
PointCountDataSource, int, GetPointCount);

private:
SdfPath _id;
HdSceneDelegate *_sceneDelegate;
HdGenericTextTopologySharedPtr _genericTextTopology;
};



class Hd_DataSourceGenericTextTopology : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(Hd_DataSourceGenericTextTopology);
Hd_DataSourceGenericTextTopology(const Hd_GenericTextTopologyStoreSharedPtr &stts)
: _stts(stts)
{
}

bool Has(const TfToken &name) override
{
if (name == HdGenericTextTopologySchemaTokens->pointCount) {
return true;
}
return false;
}

TfTokenVector GetNames() override
{
return{
HdGenericTextTopologySchemaTokens->pointCount,
};
}

HdDataSourceBaseHandle Get(const TfToken &name) override
{
if (name == HdGenericTextTopologySchemaTokens->pointCount) {
return Hd_GenericTextTopologyStore::
PointCountDataSource::New(_stts);
}
return nullptr;
}

private:
Hd_GenericTextTopologyStoreSharedPtr _stts;
};

class Hd_DataSourceGenericText : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(Hd_DataSourceGenericText);

Hd_DataSourceGenericText(const SdfPath &id, HdSceneDelegate *sceneDelegate)
: _id(id)
, _sceneDelegate(sceneDelegate)
{
}


bool Has(const TfToken &name) override
{
if (name == HdGenericTextSchemaTokens->topology) {
return true;
}

return false;
}

TfTokenVector GetNames() override
{
return{
HdGenericTextSchemaTokens->topology,

};
}

HdDataSourceBaseHandle Get(const TfToken &name) override
{
if (name == HdGenericTextSchemaTokens->topology) {
return Hd_DataSourceGenericTextTopology::New(
_GetGenericTextTopologyStore());
}

return nullptr;
}
private:

Hd_GenericTextTopologyStoreSharedPtr _GetGenericTextTopologyStore()
{
Hd_GenericTextTopologyStoreSharedPtr stts =
std::atomic_load(&_genericTextTopologyStore);
if (stts) {
return stts;
}

stts =
std::make_shared<Hd_GenericTextTopologyStore>(_id, _sceneDelegate);
std::atomic_store(&_genericTextTopologyStore, stts);

return stts;
}

SdfPath _id;
HdSceneDelegate *_sceneDelegate;
Hd_GenericTextTopologyStoreSharedPtr _genericTextTopologyStore;

};
// ----------------------------------------------------------------------------

template <typename T>
Expand Down Expand Up @@ -2414,6 +2604,10 @@ HdDataSourceLegacyPrim::GetNames()
// custom types.
result.push_back(HdPrimvarsSchemaTokens->primvars);

if (_type == HdPrimTypeTokens->genericText) {
result.push_back(HdGenericTextSchemaTokens->genericText);
}

if (HdPrimTypeIsGprim(_type)) {
result.push_back(HdExtComputationPrimvarsSchemaTokens->extComputationPrimvars);
result.push_back(HdMaterialBindingSchemaTokens->materialBinding);
Expand Down Expand Up @@ -3033,6 +3227,10 @@ HdDataSourceLegacyPrim::Get(const TfToken &name)
if (_type == HdPrimTypeTokens->simpleText) {
return Hd_DataSourceSimpleText::New(_id, _sceneDelegate);
}
} else if (name == HdGenericTextSchemaTokens->genericText) {
if (_type == HdPrimTypeTokens->genericText) {
return Hd_DataSourceGenericText::New(_id, _sceneDelegate);
}
} else if (name == HdPrimvarsSchemaTokens->primvars) {
return _GetPrimvarsDataSource();
} else if (
Expand Down
Loading

0 comments on commit 57ebf7f

Please sign in to comment.