6#ifndef MATERIALX_TEXTUREBAKER
7#define MATERIALX_TEXTUREBAKER
39 static TextureBakerPtr create(
unsigned int width = 1024,
unsigned int height = 1024, Image::BaseType baseType = Image::BaseType::UINT8)
47 _extension = extension;
64 _colorSpace = colorSpace;
76 _distanceUnit = unitSpace;
88 _averageImages = enable;
94 return _averageImages;
100 _optimizeConstants = enable;
106 return _optimizeConstants;
113 _outputImagePath = outputImagePath;
119 return _outputImagePath;
125 _bakedGraphName= name;
131 return _bakedGraphName;
137 _bakedGeomInfoName = name;
143 return _bakedGeomInfoName;
149 return _textureFilenameTemplate;
155 _textureFilenameTemplate = (filenameTemplate.find(
"$EXTENSION") == string::npos) ?
156 filenameTemplate +
".$EXTENSION" : filenameTemplate;
162 if (_permittedOverrides.count(key))
164 _texTemplateOverrides[key] = value;
171 _outputStream = outputStream;
177 return _outputStream;
185 _hashImageNames = enable;
191 return _hashImageNames;
204 void optimizeBakedTextures(
NodePtr shader);
222 bool isUniform =
false;
228 bool isDefault =
false;
230 using BakedImageVec = vector<BakedImage>;
231 using BakedImageMap = std::unordered_map<OutputPtr, BakedImageVec>;
232 using BakedConstantMap = std::unordered_map<OutputPtr, BakedConstant>;
235 TextureBaker(
unsigned int width,
unsigned int height, Image::BaseType baseType);
241 size_t findVarInTemplate(
const string& filename,
const string& var,
size_t start = 0);
252 string _distanceUnit;
254 bool _optimizeConstants;
256 string _bakedGraphName;
257 string _bakedGeomInfoName;
258 string _textureFilenameTemplate;
259 std::ostream* _outputStream;
260 bool _hashImageNames;
265 BakedImageMap _bakedImageMap;
266 BakedConstantMap _bakedConstantMap;
271 std::unordered_map<string, NodePtr> _worldSpaceNodes;
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:23
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:24
shared_ptr< Input > InputPtr
A shared pointer to an Input.
Definition: Interface.h:32
shared_ptr< Output > OutputPtr
A shared pointer to an Output.
Definition: Interface.h:37
std::set< string > StringSet
A set of strings.
Definition: Library.h:60
vector< string > StringVec
A vector of strings.
Definition: Library.h:56
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:58
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition: Library.h:38
Macros for declaring imported and exported symbols.
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition: Node.h:27
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:25
shared_ptr< class TextureBaker > TextureBakerPtr
A shared pointer to a TextureBaker.
Definition: TextureBaker.h:27
std::vector< std::pair< std::string, DocumentPtr > > BakedDocumentVec
A vector of baked documents with their associated names.
Definition: TextureBaker.h:30
A four-component color value.
Definition: Types.h:389
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:28
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition: File.h:213
A context class for shader generation.
Definition: GenContext.h:27
Helper class for rendering generated GLSL code to produce images.
Definition: GlslRenderer.h:43
Definition: TextureBaker.h:225
Definition: TextureBaker.h:218
A helper class for baking procedural material content to textures.
Definition: TextureBaker.h:37
void setBakedGeomInfoName(const string &name)
Set the name of the baked geometry info element.
Definition: TextureBaker.h:135
void setBakedGraphName(const string &name)
Set the name of the baked graph element.
Definition: TextureBaker.h:123
void setFilenameTemplateVarOverride(const string &key, const string &value)
Set texFilenameOverrides if template variable exists.
Definition: TextureBaker.h:160
const FilePath & getOutputImagePath()
Get the current output location for baked texture images.
Definition: TextureBaker.h:117
std::ostream * getOutputStream() const
Return the output stream for reporting progress and warnings.
Definition: TextureBaker.h:175
bool getAverageImages() const
Return whether images should be averaged to generate constants.
Definition: TextureBaker.h:92
bool getHashImageNames() const
Return whether automatic baked texture resolution is set.
Definition: TextureBaker.h:189
void setDistanceUnit(const string &unitSpace)
Set the distance unit to which textures are baked. Defaults to meters.
Definition: TextureBaker.h:74
const string & getBakedGraphName() const
Return the name of the baked graph element.
Definition: TextureBaker.h:129
const string & getColorSpace() const
Return the color space in which color textures are encoded.
Definition: TextureBaker.h:68
void setColorSpace(const string &colorSpace)
Set the color space in which color textures are encoded.
Definition: TextureBaker.h:62
void setOutputStream(std::ostream *outputStream)
Set the output stream for reporting progress and warnings. Defaults to std::cout.
Definition: TextureBaker.h:169
void setOutputImagePath(const FilePath &outputImagePath)
Set the output location for baked texture images.
Definition: TextureBaker.h:111
void setAverageImages(bool enable)
Set whether images should be averaged to generate constants. Defaults to false.
Definition: TextureBaker.h:86
void setOptimizeConstants(bool enable)
Set whether uniform textures should be stored as constants. Defaults to true.
Definition: TextureBaker.h:98
void setExtension(const string &extension)
Set the file extension for baked textures.
Definition: TextureBaker.h:45
void setHashImageNames(bool enable)
Set whether to create a short name for baked images by hashing the baked image filenames This is usef...
Definition: TextureBaker.h:183
bool getOptimizeConstants() const
Return whether uniform textures should be stored as constants.
Definition: TextureBaker.h:104
const string & getDistanceUnit() const
Return the distance unit to which textures are baked.
Definition: TextureBaker.h:80
const string & getBakedGeomInfoName() const
Return the name of the baked geometry info element.
Definition: TextureBaker.h:141
const string & getTextureFilenameTemplate() const
Get the texture filename template.
Definition: TextureBaker.h:147
const string & getExtension() const
Return the file extension for baked textures.
Definition: TextureBaker.h:51
void setTextureFilenameTemplate(const string &filenameTemplate)
Set the texture filename template.
Definition: TextureBaker.h:153