Skip to content

Commit

Permalink
[OGSMOD-1904] Add GenericText and ColumnStyle schema (PixarAnimationS…
Browse files Browse the repository at this point in the history
…tudios#118)

Add GenericText and ColumnStyle schema

(cherry picked from commit 7431e27036d138be607c5105f2de3534692b59a9)
  • Loading branch information
PierreWang committed Jan 17, 2023
1 parent aa998e1 commit 3da9255
Show file tree
Hide file tree
Showing 23 changed files with 2,472 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pxr/usd/usdGeom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(PXR_PACKAGE usdGeom)

set(optionalPublicClasses "")
if (PXR_ENABLE_TEXT_SUPPORT)
list(APPEND optionalPublicClasses simpleText)
list(APPEND optionalPublicClasses simpleText genericText)
endif()

pxr_library(usdGeom
Expand Down Expand Up @@ -109,6 +109,8 @@ pxr_library(usdGeom
wrapXformable.cpp
wrapXformOp.cpp
wrapXformCommonAPI.cpp
wrapSimpleText.cpp
wrapGenericText.cpp

PYMODULE_FILES
__init__.py
Expand Down
120 changes: 120 additions & 0 deletions pxr/usd/usdGeom/generatedSchema.usda
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,126 @@ class SimpleText "SimpleText" (
)
}

class GenericText "GenericText" (
doc = "Class for multiple lines or multiple styles text."
)
{
uniform bool doubleSided = 0 (
doc = """Although some renderers treat all parametric or polygonal
surfaces as if they were effectively laminae with outward-facing
normals on both sides, some renderers derive significant optimizations
by considering these surfaces to have only a single outward side,
typically determined by control-point winding order and/or
orientation. By doing so they can perform \"backface culling\" to
avoid drawing the many polygons of most closed surfaces that face away
from the viewer.

However, it is often advantageous to model thin objects such as paper
and cloth as single, open surfaces that must be viewable from both
sides, always. Setting a gprim's doubleSided attribute to
\\c true instructs all renderers to disable optimizations such as
backface culling for the gprim, and attempt (not all renderers are able
to do so, but the USD reference GL renderer always will) to provide
forward-facing normals on each side of the surface for lighting
calculations."""
)
float3[] extent (
doc = """Extent is a three dimensional range measuring the geometric
extent of the authored gprim in its own local space (i.e. its own
transform not applied), without accounting for any shader-induced
displacement. Whenever any geometry-affecting attribute is authored
for any gprim in a layer, extent must also be authored at the same
timesample; failure to do so will result in incorrect bounds-computation.
\\sa \\ref UsdGeom_Boundable_Extent.

An authored extent on a prim which has children is expected to include
the extent of all children, as they will be pruned from BBox computation
during traversal."""
)
uniform token markupLanguage = "nomarkup" (
allowedTokens = ["nomarkup", "mtext"]
doc = "The markup language."
)
string markupString (
doc = "The markup string data."
)
uniform token orientation = "rightHanded" (
allowedTokens = ["rightHanded", "leftHanded"]
doc = """Orientation specifies whether the gprim's surface normal
should be computed using the right hand rule, or the left hand rule.
Please see for a deeper explanation and
generalization of orientation to composed scenes with transformation
hierarchies."""
)
color3f[] primvars:backgroundColor (
doc = "Background color for the text."
)
color3f[] primvars:displayColor (
doc = '''It is useful to have an "official" colorSet that can be used
as a display or modeling color, even in the absence of any specified
shader for a gprim. DisplayColor serves this role; because it is a
UsdGeomPrimvar, it can also be used as a gprim override for any shader
that consumes a displayColor parameter.'''
)
float[] primvars:displayOpacity (
doc = """Companion to displayColor that specifies opacity, broken
out as an independent attribute rather than an rgba color, both so that
each can be independently overridden, and because shaders rarely consume
rgba parameters."""
)
rel proxyPrim (
doc = '''The proxyPrim relationship allows us to link a
prim whose purpose is "render" to its (single target)
purpose="proxy" prim. This is entirely optional, but can be
useful in several scenarios:

- In a pipeline that does pruning (for complexity management)
by deactivating prims composed from asset references, when we
deactivate a purpose="render" prim, we will be able to discover
and additionally deactivate its associated purpose="proxy" prim,
so that preview renders reflect the pruning accurately.

- DCC importers may be able to make more aggressive optimizations
for interactive processing and display if they can discover the proxy
for a given render prim.

- With a little more work, a Hydra-based application will be able
to map a picked proxy prim back to its render geometry for selection.

\\note It is only valid to author the proxyPrim relationship on
prims whose purpose is "render".'''
)
uniform token purpose = "default" (
allowedTokens = ["default", "render", "proxy", "guide"]
doc = """Purpose is a classification of geometry into categories that
can each be independently included or excluded from traversals of prims
on a stage, such as rendering or bounding-box computation traversals.

See for more detail about how
purpose is computed and used."""
)
token visibility = "inherited" (
allowedTokens = ["inherited", "invisible"]
doc = '''Visibility is meant to be the simplest form of "pruning"
visibility that is supported by most DCC apps. Visibility is
animatable, allowing a sub-tree of geometry to be present for some
segment of a shot, and absent from others; unlike the action of
deactivating geometry prims, invisible geometry is still
available for inspection, for positioning, for defining volumes, etc.'''
)
uniform token[] xformOpOrder (
doc = """Encodes the sequence of transformation operations in the
order in which they should be pushed onto a transform stack while
visiting a UsdStage's prims in a graph traversal that will effect
the desired positioning for this prim and its descendant prims.

You should rarely, if ever, need to manipulate this attribute directly.
It is managed by the AddXformOp(), SetResetXformStack(), and
SetXformOpOrder(), and consulted by GetOrderedXformOps() and
GetLocalTransformation()."""
)
}

class "PointBased" (
doc = """Base class for all UsdGeomGprims that possess points,
providing common attributes such as normals and velocities."""
Expand Down
198 changes: 198 additions & 0 deletions pxr/usd/usdGeom/genericText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#include "pxr/usd/usdGeom/genericText.h"
#include "pxr/usd/usd/schemaRegistry.h"
#include "pxr/usd/usd/typed.h"

#include "pxr/usd/sdf/types.h"
#include "pxr/usd/sdf/assetPath.h"

PXR_NAMESPACE_OPEN_SCOPE

// Register the schema with the TfType system.
TF_REGISTRY_FUNCTION(TfType)
{
TfType::Define<UsdGeomGenericText,
TfType::Bases< UsdGeomGprim > >();

// Register the usd prim typename as an alias under UsdSchemaBase. This
// enables one to call
// TfType::Find<UsdSchemaBase>().FindDerivedByName("GenericText")
// to find TfType<UsdGeomGenericText>, which is how IsA queries are
// answered.
TfType::AddAlias<UsdSchemaBase, UsdGeomGenericText>("GenericText");
}

/* virtual */
UsdGeomGenericText::~UsdGeomGenericText()
{
}

/* static */
UsdGeomGenericText
UsdGeomGenericText::Get(const UsdStagePtr &stage, const SdfPath &path)
{
if (!stage) {
TF_CODING_ERROR("Invalid stage");
return UsdGeomGenericText();
}
return UsdGeomGenericText(stage->GetPrimAtPath(path));
}

/* static */
UsdGeomGenericText
UsdGeomGenericText::Define(
const UsdStagePtr &stage, const SdfPath &path)
{
static TfToken usdPrimTypeName("GenericText");
if (!stage) {
TF_CODING_ERROR("Invalid stage");
return UsdGeomGenericText();
}
return UsdGeomGenericText(
stage->DefinePrim(path, usdPrimTypeName));
}

/* virtual */
UsdSchemaKind UsdGeomGenericText::_GetSchemaKind() const
{
return UsdGeomGenericText::schemaKind;
}

/* static */
const TfType &
UsdGeomGenericText::_GetStaticTfType()
{
static TfType tfType = TfType::Find<UsdGeomGenericText>();
return tfType;
}

/* static */
bool
UsdGeomGenericText::_IsTypedSchema()
{
static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
return isTyped;
}

/* virtual */
const TfType &
UsdGeomGenericText::_GetTfType() const
{
return _GetStaticTfType();
}

UsdAttribute
UsdGeomGenericText::GetMarkupStringAttr() const
{
return GetPrim().GetAttribute(UsdGeomTokens->markupString);
}

UsdAttribute
UsdGeomGenericText::CreateMarkupStringAttr(VtValue const &defaultValue, bool writeSparsely) const
{
return UsdSchemaBase::_CreateAttr(UsdGeomTokens->markupString,
SdfValueTypeNames->String,
/* custom = */ false,
SdfVariabilityVarying,
defaultValue,
writeSparsely);
}

UsdAttribute
UsdGeomGenericText::GetMarkupLanguageAttr() const
{
return GetPrim().GetAttribute(UsdGeomTokens->markupLanguage);
}

UsdAttribute
UsdGeomGenericText::CreateMarkupLanguageAttr(VtValue const &defaultValue, bool writeSparsely) const
{
return UsdSchemaBase::_CreateAttr(UsdGeomTokens->markupLanguage,
SdfValueTypeNames->Token,
/* custom = */ false,
SdfVariabilityUniform,
defaultValue,
writeSparsely);
}

UsdAttribute
UsdGeomGenericText::GetBackgroundColorAttr() const
{
return GetPrim().GetAttribute(UsdGeomTokens->primvarsBackgroundColor);
}

UsdAttribute
UsdGeomGenericText::CreateBackgroundColorAttr(VtValue const &defaultValue, bool writeSparsely) const
{
return UsdSchemaBase::_CreateAttr(UsdGeomTokens->primvarsBackgroundColor,
SdfValueTypeNames->Color3fArray,
/* custom = */ false,
SdfVariabilityVarying,
defaultValue,
writeSparsely);
}

namespace {
static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
{
TfTokenVector result;
result.reserve(left.size() + right.size());
result.insert(result.end(), left.begin(), left.end());
result.insert(result.end(), right.begin(), right.end());
return result;
}
}

/*static*/
const TfTokenVector&
UsdGeomGenericText::GetSchemaAttributeNames(bool includeInherited)
{
static TfTokenVector localNames = {
UsdGeomTokens->markupString,
UsdGeomTokens->markupLanguage,
UsdGeomTokens->primvarsBackgroundColor,
};
static TfTokenVector allNames =
_ConcatenateAttributeNames(
UsdGeomGprim::GetSchemaAttributeNames(true),
localNames);

if (includeInherited)
return allNames;
else
return localNames;
}

PXR_NAMESPACE_CLOSE_SCOPE

// ===================================================================== //
// Feel free to add custom code below this line. It will be preserved by
// the code generator.
//
// Just remember to wrap code in the appropriate delimiters:
// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'.
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
Loading

0 comments on commit 3da9255

Please sign in to comment.