1 // 2 // Copyright 2016 Pixar 3 // 4 // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 // with the following modification; you may not use this file except in 6 // compliance with the Apache License and the following modification to it: 7 // Section 6. Trademarks. is deleted and replaced with: 8 // 9 // 6. Trademarks. This License does not grant permission to use the trade 10 // names, trademarks, service marks, or product names of the Licensor 11 // and its affiliates, except as required to comply with Section 4(c) of 12 // the License and to reproduce the content of the NOTICE file. 13 // 14 // You may obtain a copy of the Apache License at 15 // 16 // http://www.apache.org/licenses/LICENSE-2.0 17 // 18 // Unless required by applicable law or agreed to in writing, software 19 // distributed under the Apache License with the above modification is 20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 // KIND, either express or implied. See the Apache License for the specific 22 // language governing permissions and limitations under the Apache License. 23 // 24 #ifndef USDGEOM_GENERATED_HERMITECURVES_H 25 #define USDGEOM_GENERATED_HERMITECURVES_H 26 27 /// \file usdGeom/hermiteCurves.h 28 29 #include "pxr/pxr.h" 30 #include "pxr/usd/usdGeom/api.h" 31 #include "pxr/usd/usdGeom/curves.h" 32 #include "pxr/usd/usd/prim.h" 33 #include "pxr/usd/usd/stage.h" 34 #include "pxr/usd/usdGeom/tokens.h" 35 36 #include "pxr/base/vt/value.h" 37 38 #include "pxr/base/gf/vec3d.h" 39 #include "pxr/base/gf/vec3f.h" 40 #include "pxr/base/gf/matrix4d.h" 41 42 #include "pxr/base/tf/token.h" 43 #include "pxr/base/tf/type.h" 44 45 PXR_NAMESPACE_OPEN_SCOPE 46 47 class SdfAssetPath; 48 49 // -------------------------------------------------------------------------- // 50 // HERMITECURVES // 51 // -------------------------------------------------------------------------- // 52 53 /// \class UsdGeomHermiteCurves 54 /// 55 /// This schema specifies a cubic hermite interpolated curve batch as 56 /// sometimes used for defining guides for animation. While hermite curves can 57 /// be useful because they interpolate through their control points, they are 58 /// not well supported by high-end renderers for imaging. Therefore, while we 59 /// include this schema for interchange, we strongly recommend the use of 60 /// UsdGeomBasisCurves as the representation of curves intended to be rendered 61 /// (ie. hair or grass). Hermite curves can be converted to a Bezier 62 /// representation (though not from Bezier back to Hermite in general). 63 /// 64 /// \section UsdGeomHermiteCurves_Interpolation Point Interpolation 65 /// 66 /// The initial cubic curve segment is defined by the first two points and 67 /// first two tangents. Additional segments are defined by additional 68 /// point / tangent pairs. The number of segments for each non-batched hermite 69 /// curve would be len(curve.points) - 1. The total number of segments 70 /// for the batched UsdGeomHermiteCurves representation is 71 /// len(points) - len(curveVertexCounts). 72 /// 73 /// \section UsdGeomHermiteCurves_Primvars Primvar, Width, and Normal Interpolation 74 /// 75 /// Primvar interpolation is not well specified for this type as it is not 76 /// intended as a rendering representation. We suggest that per point 77 /// primvars would be linearly interpolated across each segment and should 78 /// be tagged as 'varying'. 79 /// 80 /// It is not immediately clear how to specify cubic or 'vertex' interpolation 81 /// for this type, as we lack a specification for primvar tangents. This 82 /// also means that width and normal interpolation should be restricted to 83 /// varying (linear), uniform (per curve element), or constant (per prim). 84 /// 85 /// 86 class UsdGeomHermiteCurves : public UsdGeomCurves 87 { 88 public: 89 /// Compile time constant representing what kind of schema this class is. 90 /// 91 /// \sa UsdSchemaKind 92 static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; 93 94 /// Construct a UsdGeomHermiteCurves on UsdPrim \p prim . 95 /// Equivalent to UsdGeomHermiteCurves::Get(prim.GetStage(), prim.GetPath()) 96 /// for a \em valid \p prim, but will not immediately throw an error for 97 /// an invalid \p prim 98 explicit UsdGeomHermiteCurves(const UsdPrim& prim=UsdPrim()) UsdGeomCurves(prim)99 : UsdGeomCurves(prim) 100 { 101 } 102 103 /// Construct a UsdGeomHermiteCurves on the prim held by \p schemaObj . 104 /// Should be preferred over UsdGeomHermiteCurves(schemaObj.GetPrim()), 105 /// as it preserves SchemaBase state. UsdGeomHermiteCurves(const UsdSchemaBase & schemaObj)106 explicit UsdGeomHermiteCurves(const UsdSchemaBase& schemaObj) 107 : UsdGeomCurves(schemaObj) 108 { 109 } 110 111 /// Destructor. 112 USDGEOM_API 113 virtual ~UsdGeomHermiteCurves(); 114 115 /// Return a vector of names of all pre-declared attributes for this schema 116 /// class and all its ancestor classes. Does not include attributes that 117 /// may be authored by custom/extended methods of the schemas involved. 118 USDGEOM_API 119 static const TfTokenVector & 120 GetSchemaAttributeNames(bool includeInherited=true); 121 122 /// Return a UsdGeomHermiteCurves holding the prim adhering to this 123 /// schema at \p path on \p stage. If no prim exists at \p path on 124 /// \p stage, or if the prim at that path does not adhere to this schema, 125 /// return an invalid schema object. This is shorthand for the following: 126 /// 127 /// \code 128 /// UsdGeomHermiteCurves(stage->GetPrimAtPath(path)); 129 /// \endcode 130 /// 131 USDGEOM_API 132 static UsdGeomHermiteCurves 133 Get(const UsdStagePtr &stage, const SdfPath &path); 134 135 /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path 136 /// is defined (according to UsdPrim::IsDefined()) on this stage. 137 /// 138 /// If a prim adhering to this schema at \p path is already defined on this 139 /// stage, return that prim. Otherwise author an \a SdfPrimSpec with 140 /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for 141 /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s 142 /// with \p specifier == \a SdfSpecifierDef and empty typeName at the 143 /// current EditTarget for any nonexistent, or existing but not \a Defined 144 /// ancestors. 145 /// 146 /// The given \a path must be an absolute prim path that does not contain 147 /// any variant selections. 148 /// 149 /// If it is impossible to author any of the necessary PrimSpecs, (for 150 /// example, in case \a path cannot map to the current UsdEditTarget's 151 /// namespace) issue an error and return an invalid \a UsdPrim. 152 /// 153 /// Note that this method may return a defined prim whose typeName does not 154 /// specify this schema class, in case a stronger typeName opinion overrides 155 /// the opinion at the current EditTarget. 156 /// 157 USDGEOM_API 158 static UsdGeomHermiteCurves 159 Define(const UsdStagePtr &stage, const SdfPath &path); 160 161 protected: 162 /// Returns the kind of schema this class belongs to. 163 /// 164 /// \sa UsdSchemaKind 165 USDGEOM_API 166 UsdSchemaKind _GetSchemaKind() const override; 167 168 private: 169 // needs to invoke _GetStaticTfType. 170 friend class UsdSchemaRegistry; 171 USDGEOM_API 172 static const TfType &_GetStaticTfType(); 173 174 static bool _IsTypedSchema(); 175 176 // override SchemaBase virtuals. 177 USDGEOM_API 178 const TfType &_GetTfType() const override; 179 180 public: 181 // --------------------------------------------------------------------- // 182 // TANGENTS 183 // --------------------------------------------------------------------- // 184 /// Defines the outgoing trajectory tangent for each point. 185 /// Tangents should be the same size as the points attribute. 186 /// 187 /// | || 188 /// | -- | -- | 189 /// | Declaration | `vector3f[] tangents = []` | 190 /// | C++ Type | VtArray<GfVec3f> | 191 /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray | 192 USDGEOM_API 193 UsdAttribute GetTangentsAttr() const; 194 195 /// See GetTangentsAttr(), and also 196 /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. 197 /// If specified, author \p defaultValue as the attribute's default, 198 /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - 199 /// the default for \p writeSparsely is \c false. 200 USDGEOM_API 201 UsdAttribute CreateTangentsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; 202 203 public: 204 // ===================================================================== // 205 // Feel free to add custom code below this line, it will be preserved by 206 // the code generator. 207 // 208 // Just remember to: 209 // - Close the class declaration with }; 210 // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE 211 // - Close the include guard with #endif 212 // ===================================================================== // 213 // --(BEGIN CUSTOM CODE)-- 214 215 /// Represents points and tangents of the same size. 216 /// 217 /// Utility to interleave point and tangent data. This class is immutable. 218 class PointAndTangentArrays { 219 VtArray<GfVec3f> _points; 220 VtArray<GfVec3f> _tangents; 221 222 explicit PointAndTangentArrays(const VtVec3fArray& interleaved); 223 224 public: 225 226 /// Construct empty points and tangents arrays 227 PointAndTangentArrays() = default; 228 PointAndTangentArrays(const PointAndTangentArrays&) = default; 229 PointAndTangentArrays(PointAndTangentArrays&&) = default; 230 PointAndTangentArrays& operator=(const PointAndTangentArrays&) = 231 default; 232 PointAndTangentArrays& operator=(PointAndTangentArrays&&) = default; 233 234 /// Initializes \p points and \p tangents if they are the same size. 235 /// 236 /// If points and tangents are not the same size, an empty container 237 /// is created. PointAndTangentArrays(const VtVec3fArray & points,const VtVec3fArray & tangents)238 PointAndTangentArrays(const VtVec3fArray& points, 239 const VtVec3fArray& tangents) 240 : _points(points), _tangents(tangents) { 241 if (_points.size() != _tangents.size()) { 242 TF_RUNTIME_ERROR("Points and tangents must be the same size."); 243 _points.clear(); 244 _tangents.clear(); 245 } 246 } 247 248 /// Given an \p interleaved points and tangents arrays (P0, T0, ..., Pn, 249 /// Tn), separates them into two arrays (P0, ..., PN) and (T0, ..., Tn). Separate(const VtVec3fArray & interleaved)250 USDGEOM_API static PointAndTangentArrays Separate(const VtVec3fArray& interleaved) { 251 return PointAndTangentArrays(interleaved); 252 } 253 254 /// Interleaves points (P0, ..., Pn) and tangents (T0, ..., Tn) into 255 /// one array (P0, T0, ..., Pn, Tn). 256 USDGEOM_API VtVec3fArray Interleave() const; 257 258 /// Returns true if the containers are empty IsEmpty()259 bool IsEmpty() const { 260 // we only need to check the points, as we've verified on 261 // construction that _points and _tangents have the same size 262 return _points.empty(); 263 } 264 265 /// Returns true if there are values 266 explicit operator bool() const { return !IsEmpty(); } 267 268 /// Get separated points array GetPoints()269 const VtVec3fArray& GetPoints() const { return _points; } 270 271 /// Get separated tangents array GetTangents()272 const VtVec3fArray& GetTangents() const { return _tangents; } 273 274 bool operator==(const PointAndTangentArrays& other) { 275 return (GetPoints() == other.GetPoints()) && 276 (GetTangents() == other.GetTangents()); 277 } 278 bool operator!=(const PointAndTangentArrays& other) { 279 return !((*this) == other); 280 } 281 }; 282 }; 283 284 PXR_NAMESPACE_CLOSE_SCOPE 285 286 #endif 287