/src/alembic/lib/Alembic/AbcMaterial/IMaterial.h
Line | Count | Source (jump to first uncovered line) |
1 | | //-***************************************************************************** |
2 | | // |
3 | | // Copyright (c) 2009-2015, |
4 | | // Sony Pictures Imageworks Inc. and |
5 | | // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. |
6 | | // |
7 | | // All rights reserved. |
8 | | // |
9 | | // Redistribution and use in source and binary forms, with or without |
10 | | // modification, are permitted provided that the following conditions are |
11 | | // met: |
12 | | // * Redistributions of source code must retain the above copyright |
13 | | // notice, this list of conditions and the following disclaimer. |
14 | | // * Redistributions in binary form must reproduce the above |
15 | | // copyright notice, this list of conditions and the following disclaimer |
16 | | // in the documentation and/or other materials provided with the |
17 | | // distribution. |
18 | | // * Neither the name of Sony Pictures Imageworks, nor |
19 | | // Industrial Light & Magic, nor the names of their contributors may be used |
20 | | // to endorse or promote products derived from this software without specific |
21 | | // prior written permission. |
22 | | // |
23 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
26 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
27 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
28 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
29 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
33 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | | // |
35 | | //-***************************************************************************** |
36 | | |
37 | | #ifndef Alembic_AbcMaterial_IMaterial_h |
38 | | #define Alembic_AbcMaterial_IMaterial_h |
39 | | |
40 | | #include <Alembic/Abc/All.h> |
41 | | #include <Alembic/Util/Export.h> |
42 | | #include <Alembic/AbcMaterial/SchemaInfoDeclarations.h> |
43 | | |
44 | | namespace Alembic { |
45 | | namespace AbcMaterial { |
46 | | namespace ALEMBIC_VERSION_NS { |
47 | | |
48 | | //! Schema for reading and querying shader definitions from either an object or |
49 | | //! compound property. |
50 | | //! Only "monolithic" shader definitions (i.e. non network) are presently |
51 | | //! supported in this implementation. |
52 | | class ALEMBIC_EXPORT IMaterialSchema |
53 | | : public Abc::ISchema<MaterialSchemaInfo> |
54 | | { |
55 | | public: |
56 | | |
57 | | //------------------------------------------------------------------------- |
58 | | //BOILERPLATE |
59 | | |
60 | | typedef IMaterialSchema this_type; |
61 | | |
62 | 0 | IMaterialSchema() {} |
63 | | |
64 | | //! This constructor creates a new material reader. |
65 | | //! The first argument is the parent ICompoundProperty, from which the |
66 | | //! error handler policy for is derived. The second argument is the name |
67 | | //! of the ICompoundProperty that contains this schemas properties. The |
68 | | //! remaining optional arguments can be used to override the |
69 | | //! ErrorHandlerPolicy and to specify schema interpretation matching. |
70 | | IMaterialSchema( const ICompoundProperty &iParent, |
71 | | const std::string &iName, |
72 | | const Abc::Argument &iArg0 = Abc::Argument(), |
73 | | const Abc::Argument &iArg1 = Abc::Argument() ) |
74 | | |
75 | 0 | : Abc::ISchema<MaterialSchemaInfo>( iParent, iName, iArg0, iArg1 ) |
76 | 0 | { |
77 | 0 | init(); |
78 | 0 | } |
79 | | |
80 | | //! This constructor wraps an existing ICompoundProperty as the material |
81 | | //! reader, and the error handler policy is derived from it. |
82 | | //! The remaining optional arguments can be used to override the |
83 | | //! ErrorHandlerPolicy and to specify schema interpretation matching. |
84 | | IMaterialSchema( const ICompoundProperty &iProp, |
85 | | const Abc::Argument &iArg0 = Abc::Argument(), |
86 | | const Abc::Argument &iArg1 = Abc::Argument() ) |
87 | | : Abc::ISchema<MaterialSchemaInfo>( iProp, iArg0, iArg1 ) |
88 | 0 | { |
89 | 0 | init(); |
90 | 0 | } |
91 | | |
92 | | //------------------------------------------------------------------------- |
93 | | //ACTUAL STUFF |
94 | | |
95 | | //! Fills a list of target name strings for which either shader or |
96 | | //! parameter definitions are locally present. |
97 | | //! Target name values match an upon convention for a renderer |
98 | | //! or application (i.e. "prman") |
99 | | //! This gets the target names for the monolithic shaders |
100 | | void getTargetNames( std::vector<std::string> & iTargetNames ); |
101 | | |
102 | | //! Fills a list of shader type strings for which either shader or |
103 | | //! parameter definitions are locally present for a given target. |
104 | | //! Shader type names match an agreed upon convention for shader terminals |
105 | | //! such as "surface," "displacement," "light", "coshader_somename." |
106 | | void getShaderTypesForTarget( const std::string & iTargetName, |
107 | | std::vector<std::string> & oShaderTypeNames ); |
108 | | |
109 | | //! Returns true and fills result with the shader name for a given |
110 | | //! target and shaderType if locally defined |
111 | | bool getShader( const std::string & iTarget, |
112 | | const std::string & iShaderType, |
113 | | std::string & oResult ); |
114 | | |
115 | | //! Returns the enclosing compound property for the given target and |
116 | | //! shader type. Call .valid() on the result to determine whether it's |
117 | | //! locally defined or not. |
118 | | Abc::ICompoundProperty getShaderParameters( |
119 | | const std::string & iTarget, const std::string & iShaderType ); |
120 | | |
121 | | //------------------------------------------------------------------------- |
122 | | |
123 | | class ALEMBIC_EXPORT NetworkNode |
124 | | { |
125 | | public: |
126 | | |
127 | | NetworkNode(); |
128 | | NetworkNode( Abc::ICompoundProperty iCompound ); |
129 | | NetworkNode( Abc::ICompoundProperty iParent, |
130 | | const std::string & iNodeName ); |
131 | | |
132 | | bool valid(); |
133 | | |
134 | | std::string getName(); |
135 | | |
136 | | bool getTarget( std::string & oResult ); |
137 | | bool getNodeType( std::string & oResult ); |
138 | | |
139 | | Abc::ICompoundProperty getParameters(); |
140 | | |
141 | | size_t getNumConnections(); |
142 | | bool getConnection( size_t iIndex, |
143 | | std::string & oInputName, |
144 | | std::string & oConnectedNodeName, |
145 | | std::string & oConnectedOutputName ); |
146 | | |
147 | | bool getConnection( const std::string & iInputName, |
148 | | std::string & oConnectedNodeName, |
149 | | std::string & oConnectedOutputName ); |
150 | | |
151 | | private: |
152 | | Abc::ICompoundProperty m_compound; |
153 | | |
154 | | bool m_connectionsChecked; |
155 | | std::vector< std::string > m_connections; |
156 | | std::map< std::string, std::string > m_connectionsMap; |
157 | | |
158 | | void splitConnectionValue( const std::string & v, |
159 | | std::string & a, |
160 | | std::string & b ); |
161 | | }; |
162 | | |
163 | | size_t getNumNetworkNodes(); |
164 | | void getNetworkNodeNames( std::vector<std::string> & oNames ); |
165 | | |
166 | | NetworkNode getNetworkNode( size_t iIndex ); |
167 | | NetworkNode getNetworkNode( const std::string & iNodeName ); |
168 | | |
169 | | void getNetworkTerminalTargetNames( |
170 | | std::vector<std::string> & oTargetNames ); |
171 | | |
172 | | void getNetworkTerminalShaderTypesForTarget( |
173 | | const std::string & iTargetName, |
174 | | std::vector<std::string> & oShaderTypeNames ); |
175 | | |
176 | | bool getNetworkTerminal( const std::string & iTarget, |
177 | | const std::string & iShaderType, |
178 | | std::string & oNodeName, |
179 | | std::string & oOutputName ); |
180 | | |
181 | | size_t getNumNetworkInterfaceParameterMappings(); |
182 | | bool getNetworkInterfaceParameterMapping( size_t iIndex, |
183 | | std::string & oInterfaceParamName, |
184 | | std::string & oMapToNodeName, |
185 | | std::string & oMapToParamName ); |
186 | | |
187 | | void getNetworkInterfaceParameterMappingNames( |
188 | | std::vector<std::string> & oNames ); |
189 | | |
190 | | bool getNetworkInterfaceParameterMapping( |
191 | | const std::string & iInterfaceParamName, |
192 | | std::string & oMapToNodeName, |
193 | | std::string & oMapToParamName ); |
194 | | |
195 | | Abc::ICompoundProperty getNetworkInterfaceParameters(); |
196 | | |
197 | | protected: |
198 | | |
199 | | private: |
200 | | |
201 | | void init(); |
202 | | |
203 | | std::map<std::string, std::string> m_shaderNames; |
204 | | std::map<std::string, std::string> m_terminals; |
205 | | std::map<std::string, std::string> m_interfaceMap; |
206 | | std::vector<std::string> m_interface; |
207 | | |
208 | | Abc::ICompoundProperty m_interfaceParams; |
209 | | Abc::ICompoundProperty m_node; |
210 | | }; |
211 | | |
212 | | //! Object declaration |
213 | | typedef Abc::ISchemaObject<IMaterialSchema> IMaterial; |
214 | | |
215 | | typedef Util::shared_ptr< IMaterial > IMaterialPtr; |
216 | | |
217 | | } // End namespace ALEMBIC_VERSION_NS |
218 | | |
219 | | using namespace ALEMBIC_VERSION_NS; |
220 | | |
221 | | } // End namespace AbcMaterial |
222 | | } // End namespace Alembic |
223 | | |
224 | | #endif |