HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_CreateMaterial.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_CreateMaterial_h__
19 #define __HUSD_CreateMaterial_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Overrides.h"
24 #include "HUSD_TimeCode.h"
25 #include <UT/UT_IntArray.h>
26 
27 
28 class VOP_Node;
29 class OP_Node;
30 class UT_Options;
31 
33 {
34 public:
35  /// Standard c-tor.
37  const HUSD_OverridesPtr &overrides = HUSD_OverridesPtr()
38  );
39 
40  /// Defines a USD material primitive at a given @p usd_mat_path
41  /// based on given @p material_vop material node.
42  /// @param auto_create_preview_shader If true, an attempt is made
43  /// to ensure the created material has a preview shader
44  /// (for the universal render context). Ie, if the material node
45  /// does not contain any explicit preview shader node to translate,
46  /// then an ad-hoc preview shader USD primitive will be generated.
47  bool createMaterial( VOP_Node &material_vop,
48  const UT_StringRef &usd_mat_path,
49  bool auto_create_preview_shader ) const;
50 
51  /// Re-translates the shader parameters given the shader VOP node.
52  bool updateShaderParameters( VOP_Node &shader_vop,
53  const UT_StringArray &parameter_names,
54  const UT_StringRef &usd_shader_path ) const;
55 
56  /// Creates a new USD material primitive at @p usd_mat_path, which inherits
57  /// from the material given by @p base_material_path, and sets
58  /// the parameter override values on the created material.
59  /// The @material_parameters keys are used for Material input attribute
60  /// name (eg, "diffuseColor"), but they can also have a shader primitive
61  /// path prefix (eg, "preview_surface/diffuseColor"), in which case
62  /// the override value for "diffuseColor" will be authored on the
63  /// "preview_surface" Shader primitive inside the @p usd_mat_path Material.
64  bool createDerivedMaterial(
65  const UT_StringRef &base_material_path,
66  const UT_Options &material_parameters,
67  const UT_StringRef &usd_mat_path) const;
68 
69  /// Creates a new USD light filter primitive at @p usd_light_filter_path,
70  /// from the filter node given by @light_filter_vop.
71  bool createLightFilter( VOP_Node &light_filter_vop,
72  const UT_StringRef &usd_light_filter_path ) const;
73 
74  /// Creates a new standard USD preview shader primitive
75  /// based on the given render-specific shader USD primitive.
76  bool createPreviewShader(
77  const UT_StringRef &main_shader_path ) const;
78 
79  /// Destroys auto-created preview shader, that was created based on
80  /// the given render-specific shader.
81  bool deletePreviewShader(
82  const UT_StringRef &main_shader_path ) const;
83 
84  /// Returns ture if the given shader has a corresponding preview shader,
85  /// auto-created based on its input attributes.
86  bool hasPreviewShader( const UT_StringRef &main_shader_path );
87 
88  /// Clears the auto-created metadata flag on the preview shader primitive.
89  bool clearAutoCreateFlag( const UT_StringRef &preview_shader_path );
90 
91  /// Sets the time code at which shader parameters are evaluated.
92  void setTimeCode( const HUSD_TimeCode &time_code )
93  { myTimeCode = time_code; }
94 
95  /// Sets the primitive type that should be used when creating parents
96  /// that don't exist yet in the USD hierarchy.
98  { myParentType = type; }
99 
100  /// Adds the given node as a potential dependent on the shader nodes
101  /// being translated.
102  void addDependent( OP_Node *node );
103 
104  /// Configures the material creator to reference any Render Vars scope
105  /// created by shader translator into the global /Render/Products.
106  /// This will allow Karma to readily render these AOVs/RenderVars.
108  { myShouldReferenceRenderVars = flag; }
109 
110 private:
111  HUSD_AutoWriteLock &myWriteLock;
112  UT_StringHolder myParentType; // Type of intermediate ancestors.
113  HUSD_TimeCode myTimeCode; // Time at which to eval shader parms.
114  UT_IntArray myDependentIDs;// Node IDs of dependants.
115  HUSD_OverridesPtr myOverrides; // Viewport override layer.
116  bool myShouldReferenceRenderVars = false;
117 };
118 
119 
120 #endif
121 
#define HUSD_API
Definition: HUSD_API.h:32
UT_IntrusivePtr< HUSD_Overrides > HUSD_OverridesPtr
void setParentPrimType(const UT_StringHolder &type)
A map of string to various well defined value types.
Definition: UT_Options.h:84
void setShouldReferenceRenderVars(bool flag)
type
Definition: core.h:1059
void setTimeCode(const HUSD_TimeCode &time_code)
Sets the time code at which shader parameters are evaluated.