HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_SetAttributes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_SetAttributes_h__
19 #define __HUSD_SetAttributes_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_TimeCode.h"
24 #include <UT/UT_StringHolder.h>
25 
26 class UT_Options;
27 class HUSD_FindPrims;
28 
29 enum class HUSD_ArrayEditMode {
30  OVERWRITE,
31  SPARSE,
33 };
34 
36 {
37 public:
40 
41  /// @{ Create an attribute or primvar on a primitive.
42  bool addAttribute(const UT_StringRef &primpath,
43  const UT_StringRef &attrname,
44  const UT_StringRef &type,
45  bool custom = true) const;
46 
47  bool addPrimvar(const UT_StringRef &primpath,
48  const UT_StringRef &primvarname,
49  const UT_StringRef &interpolation,
50  const UT_StringRef &type) const;
51  /// @}
52 
53  /// @{ Set an attribute or primvar value on a primitive.
54  template<typename UtValueType>
55  bool setAttribute(const UT_StringRef &primpath,
56  const UT_StringRef &attrname,
57  const UtValueType &value,
58  const HUSD_TimeCode &timecode,
59  const UT_StringRef &valueType =
61  bool custom = true,
62  bool clear_existing = true) const;
63 
64  template<typename UtValueType>
65  bool setPrimvar(const UT_StringRef &primpath,
66  const UT_StringRef &primvarname,
67  const UT_StringRef &interpolation,
68  const UtValueType &value,
69  const HUSD_TimeCode &timecode,
70  const UT_StringRef &valueType =
72  int elementsize = 1,
73  bool clear_existing = true) const;
74  /// @}
75 
76 
77  /// @{ Set an attribute or primvar value on a primitive,
78  /// but accept the *subclasses* of the UT_Array.
79  template<typename UtValueType>
80  bool setAttributeArray(const UT_StringRef &primpath,
81  const UT_StringRef &attrname,
82  const UT_Array<UtValueType> &value,
83  const HUSD_TimeCode &timecode,
84  const UT_StringRef &valueType =
86  bool custom = true,
87  bool clear_existing = true) const
88  { return setAttribute(primpath, attrname,
89  value, timecode, valueType,
90  custom, clear_existing); }
91 
92  template<typename UtValueType>
93  bool setPrimvarArray(const UT_StringRef &primpath,
94  const UT_StringRef &primvarname,
95  const UT_StringRef &interpolation,
96  const UT_Array<UtValueType> &value,
97  const HUSD_TimeCode &timecode,
98  const UT_StringRef &valueType =
100  int elementsize = 1,
101  bool clear_existing = true) const
102  { return setPrimvar(primpath, primvarname,
103  interpolation, value, timecode,
104  valueType, elementsize, clear_existing); }
105  /// @}
106 
107  /// @{ Set attributes for every entry in a UT_Options object.
108  bool setAttributes(const UT_StringRef &primpath,
109  const UT_Options &options,
110  const HUSD_TimeCode &timecode,
111  const UT_StringRef &attrnamespace =
113  bool clear_existing = true) const;
114  /// @}
115 
116  /// @{ Blocks an attribute or primvar.
117  bool blockAttribute(const UT_StringRef &primpath,
118  const UT_StringRef &attrname) const;
119  bool blockPrimvar(const UT_StringRef &primpath,
120  const UT_StringRef &primvarname) const;
121  bool blockPrimvarIndices(const UT_StringRef &primpath,
122  const UT_StringRef &primvarname) const;
123  /// @}
124 
125  /// @{ Blocks animation on an attribute
126  bool blockAttributeAnimation(const UT_StringRef &primpath,
127  const UT_StringRef &attrname) const;
128  /// @}
129 
130  /// @{ Creates a connection between the given shading (ie, input or output)
131  /// attributes.
132  bool connect(const UT_StringRef &src_primpath,
133  const UT_StringRef &src_attrname,
134  const UT_StringRef &dst_primpath,
135  const UT_StringRef &dst_attrname) const;
136  /// @}
137 
138  /// @{ Disconnects a shading (ie input or output) attribute from its source.
139  bool disconnect(const UT_StringRef &primpath,
140  const UT_StringRef &attrname) const;
141  bool disconnectIfConnected(const UT_StringRef &primpath,
142  const UT_StringRef &attrname) const;
143  bool isConnected(const UT_StringRef &primpath,
144  const UT_StringRef &attrname) const;
145  /// @}
146 
147 
148  /// Sets primvar's indices, making it an indexed primvar.
149  bool setPrimvarIndices( const UT_StringRef &primpath,
150  const UT_StringRef &primvar_name,
151  const UT_ExintArray &indices,
152  const HUSD_TimeCode &timecode,
153  bool clear_existing = true) const;
154 
155  /// @{ Returns effective time code at which the value should be set.
156  /// Eg, if attribute has time samples and the given time code is default,
157  /// it needs to be "promoted" to time code for the specific frame/time.
158  /// Otherwise, setting value at default time will not take effect, if
159  /// there is already a value at that specific frame/time.
160  /// This ensures that getAttribute() returns the same value as set here.
161  HUSD_TimeCode getAttribEffectiveTimeCode(
162  const UT_StringRef &primpath,
163  const UT_StringRef &attribname,
164  const HUSD_TimeCode &timecode) const;
165  HUSD_TimeCode getPrimvarEffectiveTimeCode(
166  const UT_StringRef &primpath,
167  const UT_StringRef &primvarname,
168  const HUSD_TimeCode &timecode) const;
169  HUSD_TimeCode getPrimvarIndicesEffectiveTimeCode(
170  const UT_StringRef &primpath,
171  const UT_StringRef &primvarname,
172  const HUSD_TimeCode &timecode) const;
173  /// @}
174 
175  /// Copies an attribute from one primitive to another. This method will
176  /// copy all values and time samples, ensure matching data types, etc.
177  bool copyProperty(
178  const UT_StringRef &srcprimpath,
179  const UT_StringRef &srcpropertyname,
180  const HUSD_FindPrims &finddestprims,
181  const UT_StringRef &destpropertyname,
182  bool copymetadata,
183  bool blocksource);
184 
185 private:
186  HUSD_AutoWriteLock &myWriteLock;
187 };
188 
189 #endif
bool setAttributeArray(const UT_StringRef &primpath, const UT_StringRef &attrname, const UT_Array< UtValueType > &value, const HUSD_TimeCode &timecode, const UT_StringRef &valueType=UT_StringHolder::theEmptyString, bool custom=true, bool clear_existing=true) const
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define HUSD_API
Definition: HUSD_API.h:31
HUSD_ArrayEditMode
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
static const UT_StringHolder theEmptyString
A map of string to various well defined value types.
Definition: UT_Options.h:87
bool setPrimvarArray(const UT_StringRef &primpath, const UT_StringRef &primvarname, const UT_StringRef &interpolation, const UT_Array< UtValueType > &value, const HUSD_TimeCode &timecode, const UT_StringRef &valueType=UT_StringHolder::theEmptyString, int elementsize=1, bool clear_existing=true) const
UN_API bool isConnected(const UN_GraphData *graph_data, UN_PortID port_id, const UN_ConstPort &src_or_dst_port)