Alembic Version 1.1

MaterialFlatten.h
Go to the documentation of this file.
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_MaterialFlatten_h
38#define Alembic_AbcMaterial_MaterialFlatten_h
39
40#include <Alembic/Util/Export.h>
41#include <Alembic/AbcMaterial/IMaterial.h>
42
43 namespace Alembic {
44 namespace AbcMaterial {
45 namespace ALEMBIC_VERSION_NS {
46
49 class ALEMBIC_EXPORT MaterialFlatten
50{
51 public:
52
54 MaterialFlatten();
55
57 MaterialFlatten( IMaterialSchema iMaterialSchema );
58
61 MaterialFlatten( IMaterial iMaterialObject );
62
72 MaterialFlatten( Abc::IObject iObject,
73 Abc::IArchive iAlternateSearchArchive=Abc::IArchive() );
74 //TODO: need an append equivalent!
75
77 void append( IMaterialSchema iMaterialSchema );
78
80 void append( IMaterial iMaterialObject );
81
82
84 bool empty();
85
88 void getTargetNames( std::vector<std::string> & oTargetNames );
89
92 void getShaderTypesForTarget( const std::string & iTargetName,
93 std::vector<std::string> & oShaderTypeNames );
94
98 bool getShader( const std::string & iTarget,
99 const std::string & iShaderType,
100 std::string & oResult );
101
102 struct ParameterEntry
103 {
104 ParameterEntry()
105 : header(0)
106 {
107 }
108
109 ParameterEntry( const std::string & iName,
110 Abc::ICompoundProperty iParent,
111 const AbcCoreAbstract::PropertyHeader * iHeader )
112 : name(iName)
113 , parent(iParent)
114 , header(iHeader)
115 {
116 }
117
118 bool operator==( const ParameterEntry &iRhs ) const
119 {
120 return name == iRhs.name &&
121 parent == iRhs.parent &&
122 header == iRhs.header;
123 }
124
125 std::string name;
126 Abc::ICompoundProperty parent;
127 const AbcCoreAbstract::PropertyHeader * header;
128 // header is owned by parent, so it is safe to hold onto the pointer
129 };
130
131 typedef std::vector<ParameterEntry> ParameterEntryVector;
132
137 void getShaderParameters( const std::string & iTarget,
138 const std::string & iShaderType,
139 ParameterEntryVector & oResult );
140
143
144 void getNetworkTerminalTargetNames(std::vector<std::string> & iTargetNames);
145 void getNetworkTerminalShaderTypesForTarget(
146 const std::string & iTargetName,
147 std::vector<std::string> & oShaderTypeNames );
148
149 bool getNetworkTerminal( const std::string & iTarget,
150 const std::string & iShaderType,
151 std::string & oNodeName,
152 std::string & oOutputName );
153
154 typedef std::map<std::string, std::string> StringMap;
155 typedef Alembic::Util::shared_ptr<StringMap> StringMapPtr;
156 typedef std::vector<IMaterialSchema> SchemaVector;
157
158 class ALEMBIC_EXPORT NetworkNode
159 {
160 public:
161
162 NetworkNode();
163
164 bool valid();
165
166 std::string getName();
167 bool getTarget( std::string & oResult );
168 bool getNodeType( std::string & oResult );
169 void getParameters( ParameterEntryVector & oResult );
170
171 struct Connection
172 {
173 Connection( const std::string & iInputName,
174 const std::string & iConnectedNodeName,
175 const std::string & iConnectedOutputName )
176 : inputName( iInputName )
177 , connectedNodeName( iConnectedNodeName )
178 , connectedOutputName( iConnectedOutputName )
179 {
180 }
181
182 bool operator==( const Connection & iRhs ) const
183 {
184 return inputName == iRhs.inputName &&
185 connectedNodeName == iRhs.connectedNodeName &&
186 connectedOutputName == iRhs.connectedOutputName;
187 }
188
189 std::string inputName;
190 std::string connectedNodeName;
191 std::string connectedOutputName;
192 };
193
194 typedef std::vector<Connection> ConnectionVector;
195
196 void getConnections( ConnectionVector & oResult );
197
198 private:
199
200 friend class MaterialFlatten;
201
202 NetworkNode( const std::string & iName,
203 SchemaVector & iSchemas,
204 StringMapPtr iInterfaceMappings );
205
206 std::string m_name;
207 std::vector<IMaterialSchema::NetworkNode> m_nodes;
208 std::vector<Abc::ICompoundProperty> m_networkParameters;
209 StringMapPtr m_interfaceMappings;
210 };
211
212 size_t getNumNetworkNodes();
213 NetworkNode getNetworkNode( size_t iIndex );
214 NetworkNode getNetworkNode( const std::string & iNodeName );
215
216 // TODO: no method to get the node names?
217
218 private:
219
220 SchemaVector m_schemas;
221
222 void flattenNetwork();
223
224 bool m_networkFlattened;
225
226 std::vector<std::string> m_nodeNames;
227 typedef std::map<std::string, StringMapPtr> StringMapMap;
228 StringMapMap m_nodesToInterfaceMappings;
229
230};
231
232}
233
234 using namespace ALEMBIC_VERSION_NS;
235
236}
237}
238
239#endif
Export.h
ALEMBIC_EXPORT
#define ALEMBIC_EXPORT
Definition: Export.h:51
IMaterial.h
ALEMBIC_VERSION_NS
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::PropertyHeader
Definition: PropertyHeader.h:79
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::IMaterialSchema
Definition: IMaterial.h:54
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode
Definition: MaterialFlatten.h:159
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::valid
bool valid()
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::getNodeType
bool getNodeType(std::string &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::getConnections
void getConnections(ConnectionVector &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::getName
std::string getName()
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::NetworkNode
NetworkNode()
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::getTarget
bool getTarget(std::string &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::getParameters
void getParameters(ParameterEntryVector &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::ConnectionVector
std::vector< Connection > ConnectionVector
Definition: MaterialFlatten.h:194
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten
Definition: MaterialFlatten.h:50
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNetworkTerminal
bool getNetworkTerminal(const std::string &iTarget, const std::string &iShaderType, std::string &oNodeName, std::string &oOutputName)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::empty
bool empty()
Returns true is there are no schema in the inheritance path.
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::StringMapPtr
Alembic::Util::shared_ptr< StringMap > StringMapPtr
Definition: MaterialFlatten.h:155
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::append
void append(IMaterial iMaterialObject)
Append the schemas of matching parent material objects.
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNetworkTerminalShaderTypesForTarget
void getNetworkTerminalShaderTypesForTarget(const std::string &iTargetName, std::vector< std::string > &oShaderTypeNames)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getShader
bool getShader(const std::string &iTarget, const std::string &iShaderType, std::string &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::MaterialFlatten
MaterialFlatten()
Create empty. Use append to add material schema manually.
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNetworkNode
NetworkNode getNetworkNode(const std::string &iNodeName)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::append
void append(IMaterialSchema iMaterialSchema)
Manually append a schema to the inheritance hierarchy.
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getShaderParameters
void getShaderParameters(const std::string &iTarget, const std::string &iShaderType, ParameterEntryVector &oResult)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::MaterialFlatten
MaterialFlatten(IMaterial iMaterialObject)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::StringMap
std::map< std::string, std::string > StringMap
Definition: MaterialFlatten.h:154
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getShaderTypesForTarget
void getShaderTypesForTarget(const std::string &iTargetName, std::vector< std::string > &oShaderTypeNames)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::MaterialFlatten
MaterialFlatten(IMaterialSchema iMaterialSchema)
Create with a single materialSchema.
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getTargetNames
void getTargetNames(std::vector< std::string > &oTargetNames)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::MaterialFlatten
MaterialFlatten(Abc::IObject iObject, Abc::IArchive iAlternateSearchArchive=Abc::IArchive())
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNetworkNode
NetworkNode getNetworkNode(size_t iIndex)
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNetworkTerminalTargetNames
void getNetworkTerminalTargetNames(std::vector< std::string > &iTargetNames)
network stuff
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntryVector
std::vector< ParameterEntry > ParameterEntryVector
Definition: MaterialFlatten.h:131
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::getNumNetworkNodes
size_t getNumNetworkNodes()
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::SchemaVector
std::vector< IMaterialSchema > SchemaVector
Definition: MaterialFlatten.h:156
Alembic::Abc::ALEMBIC_VERSION_NS::IArchive
Definition: IArchive.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::ICompoundProperty
Definition: ICompoundProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::IObject
Definition: IObject.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject
Definition: ISchemaObject.h:56
Alembic
Alembic namespace ...
Definition: ArchiveInfo.h:46
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection
Definition: MaterialFlatten.h:172
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection::connectedOutputName
std::string connectedOutputName
Definition: MaterialFlatten.h:191
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection::Connection
Connection(const std::string &iInputName, const std::string &iConnectedNodeName, const std::string &iConnectedOutputName)
Definition: MaterialFlatten.h:173
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection::operator==
bool operator==(const Connection &iRhs) const
Definition: MaterialFlatten.h:182
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection::connectedNodeName
std::string connectedNodeName
Definition: MaterialFlatten.h:190
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::NetworkNode::Connection::inputName
std::string inputName
Definition: MaterialFlatten.h:189
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry
Definition: MaterialFlatten.h:103
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::name
std::string name
Definition: MaterialFlatten.h:125
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::header
const AbcCoreAbstract::PropertyHeader * header
Definition: MaterialFlatten.h:127
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::ParameterEntry
ParameterEntry(const std::string &iName, Abc::ICompoundProperty iParent, const AbcCoreAbstract::PropertyHeader *iHeader)
Definition: MaterialFlatten.h:109
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::parent
Abc::ICompoundProperty parent
Definition: MaterialFlatten.h:126
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::ParameterEntry
ParameterEntry()
Definition: MaterialFlatten.h:104
Alembic::AbcMaterial::ALEMBIC_VERSION_NS::MaterialFlatten::ParameterEntry::operator==
bool operator==(const ParameterEntry &iRhs) const
Definition: MaterialFlatten.h:118