3ds Max USD API Reference
Loading...
Searching...
No Matches
MappedAttributeBuilder.h
1//**************************************************************************/
2// Copyright (c) 1998-2020 Autodesk, Inc.
3// All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license
6// agreement provided at the time of installation or download, or which
7// otherwise accompanies this software in either electronic or hard copy form.
8//**************************************************************************/
9// DESCRIPTION: Mapped Attribute builder.
10// AUTHOR: Autodesk Inc.
11//***************************************************************************/
12
13#pragma once
14
15#pragma warning(push)
16#pragma warning(disable : 4275) // non dll-interface class 'boost::python::api::object' used as base for dll-interface struct 'boost::python::detail::list_base'
17#include <pxr/usd/usdGeom/primvar.h>
18#include <pxr/usd/usdGeom/mesh.h>
19#pragma warning(pop)
20#include <pxr/base/tf/token.h>
21
22#include "MaxUsd/MeshConversion/MeshFacade.h"
23#include "MaxUSDAPI.h"
24#include "MaxUsd.h"
25
26namespace MAXUSD_NS_DEF {
27
29{
30public:
31
32 enum class MaxUSDAPI Type
33 {
34 TexCoord2fArray,
35 TexCoord3fArray,
36 FloatArray,
37 Float2Array,
38 Float3Array,
39 Color3fArray,
40 };
41
42 class Config
43 {
44 private:
45 // An empty primvar name means we will not export the associated channel.
46 pxr::TfToken primvarName;
47 Type primvarType;
48 bool autoExpandType;
49
50 public:
51 MaxUSDAPI Config()
52 : primvarType(), autoExpandType(false)
53 {
54 }
55
56 MaxUSDAPI Config(const pxr::TfToken& primvarName, Type type, bool autoExpandType = false)
57 {
58 this->primvarName = primvarName;
59 this->primvarType = type;
60 this->autoExpandType = autoExpandType;
61 }
62
63 MaxUSDAPI bool operator==(const Config& config)
64 {
65 return primvarName == config.primvarName && primvarType == config.primvarType && autoExpandType == config.autoExpandType;
66 }
67
68 MaxUSDAPI const pxr::TfToken& GetPrimvarName() const
69 {
70 return primvarName;
71 }
72 MaxUSDAPI const Type GetPrimvarType() const
73 {
74 return primvarType;
75 }
76 MaxUSDAPI bool IsAutoExpandType() const
77 {
78 return autoExpandType;
79 }
80
81 };
82
84 {
85 private:
86 const Point3* data;
87 size_t dataCount;
88 const std::shared_ptr<std::vector<int>> faceDataIndices;
89
90 public:
91 MappedData() = delete;
92 MaxUSDAPI explicit MappedData(
93 const Point3* data, size_t dataCount, const std::shared_ptr<std::vector<int>> faceDataIndices)
94 : data(data)
95 , dataCount(dataCount)
96 , faceDataIndices(faceDataIndices)
97 {
98 }
99 MaxUSDAPI const Point3* GetData() const
100 {
101 return data;
102 }
103 MaxUSDAPI const size_t GetDataCount() const
104 {
105 return dataCount;
106 }
107 MaxUSDAPI const std::shared_ptr<std::vector<int>> GetFaceDataIndices() const
108 {
109 return faceDataIndices;
110 }
111 };
112
114 {
115 private:
116 pxr::TfToken interpolation;
117 bool indexed;
118
119 public:
120 DataLayout() = delete;
121 MaxUSDAPI explicit DataLayout(const pxr::TfToken interpolation, bool indexed)
122 : interpolation(interpolation)
123 , indexed(indexed)
124 {
125 }
126 MaxUSDAPI const pxr::TfToken& GetInterpolation() const
127 {
128 return interpolation;
129 }
130 MaxUSDAPI bool IsIndexed() const
131 {
132 return indexed;
133 }
134 };
135
141 MaxUSDAPI MappedAttributeBuilder(MeshFacade& maxMesh, std::shared_ptr<MappedData> data);
145 MaxUSDAPI MappedAttributeBuilder(MeshFacade&& maxMesh, std::shared_ptr<MappedData> data)
146 : MappedAttributeBuilder(maxMesh, data) {}
147
156 MaxUSDAPI bool BuildPrimvar(
157 pxr::UsdGeomMesh& target, const Config& config, const pxr::UsdTimeCode& timeCode, bool animated) const;
158
167 MaxUSDAPI bool PopulateAttribute(pxr::UsdAttribute& attribute, const DataLayout& layout,
168 pxr::UsdGeomPrimvar* primvar, const pxr::UsdTimeCode& timeCode) const;
169
175
181 static MaxUSDAPI pxr::SdfValueTypeName GetValueTypeName(const Type& type);
182
188 static MaxUSDAPI size_t GetTypeDimension(const Type& type);
189
200 static MaxUSDAPI Type GetEquivalentType(const Type& type, int dimension);
201
202private:
203 // Faces indices of the mesh.
204 std::shared_ptr<const std::vector<int>> faceIndices;
205 int vertexCount;
206 std::shared_ptr<MappedData> mappedData;
207};
208}
Definition: MappedAttributeBuilder.h:43
Definition: MappedAttributeBuilder.h:114
Definition: MappedAttributeBuilder.h:84
Definition: MappedAttributeBuilder.h:29
MaxUSDAPI DataLayout InferAttributeDataLayout() const
Infers the data layout i.e. the interpolation scheme and whether it should be indexed or not.
MaxUSDAPI bool PopulateAttribute(pxr::UsdAttribute &attribute, const DataLayout &layout, pxr::UsdGeomPrimvar *primvar, const pxr::UsdTimeCode &timeCode) const
Populates a given attribute with the mapped data.
static MaxUSDAPI size_t GetTypeDimension(const Type &type)
Returns the dimension of the given type.
MaxUSDAPI MappedAttributeBuilder(MeshFacade &maxMesh, std::shared_ptr< MappedData > data)
Constructor.
static MaxUSDAPI pxr::SdfValueTypeName GetValueTypeName(const Type &type)
Returns the SdfValueTypeName associated with this type.
MaxUSDAPI MappedAttributeBuilder(MeshFacade &&maxMesh, std::shared_ptr< MappedData > data)
Constructor. This overload was added to allow passing a temporary MeshFacade as parameter.
Definition: MappedAttributeBuilder.h:145
static MaxUSDAPI Type GetEquivalentType(const Type &type, int dimension)
Returns a type equivalent to the given type for a given dimension. For example the equivalent to texc...
MaxUSDAPI bool BuildPrimvar(pxr::UsdGeomMesh &target, const Config &config, const pxr::UsdTimeCode &timeCode, bool animated) const
Creates a new primvar onto the target USD mesh and populate it with the the mapped data.
A facade to work with the 3dsMax Mesh and MNMesh classes transparently. Does some caching internally ...
Definition: MeshFacade.h:30