Commit 29f591f3 authored by hybrid's avatar hybrid

Add support for relative texture names in atrributes

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3710 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 07de4257
......@@ -24,6 +24,7 @@
#include "irrArray.h"
#include "IXMLReader.h"
#include "EAttributes.h"
#include "path.h"
namespace irr
{
......@@ -636,10 +637,10 @@ public:
*/
//! Adds an attribute as texture reference
virtual void addTexture(const c8* attributeName, video::ITexture* texture) = 0;
virtual void addTexture(const c8* attributeName, video::ITexture* texture, const io::path& filename = "") = 0;
//! Sets an attribute as texture reference
virtual void setAttribute(const c8* attributeName, video::ITexture* texture ) = 0;
virtual void setAttribute(const c8* attributeName, video::ITexture* texture, const io::path& filename = "") = 0;
//! Gets an attribute as texture reference
//! \param attributeName: Name of the attribute to get.
......@@ -650,7 +651,7 @@ public:
virtual video::ITexture* getAttributeAsTexture(s32 index) = 0;
//! Sets an attribute as texture reference
virtual void setAttribute(s32 index, video::ITexture* texture) = 0;
virtual void setAttribute(s32 index, video::ITexture* texture, const io::path& filename = "") = 0;
/*
......
......@@ -25,6 +25,7 @@ namespace irr
namespace io
{
class IAttributes;
struct SAttributeReadWriteOptions;
class IReadFile;
class IWriteFile;
} // end namespace io
......@@ -1310,9 +1311,12 @@ namespace video
renderer names from getMaterialRendererName() to write out the
material type name, so they should be set before.
\param material The material to serialize.
\param options Additional options which might influence the
serialization.
\return The io::IAttributes container holding the material
properties. */
virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material) =0;
virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material,
io::SAttributeReadWriteOptions* options=0) =0;
//! Fills an SMaterial structure from attributes.
/** Please note that for setting material types of the
......
......@@ -1797,8 +1797,8 @@ class CTextureAttribute : public IAttribute
{
public:
CTextureAttribute(const char* name, video::ITexture* value, video::IVideoDriver* driver)
: Value(0), Driver(driver)
CTextureAttribute(const char* name, video::ITexture* value, video::IVideoDriver* driver, const io::path& filename)
: Value(0), Driver(driver), OverrideName(filename)
{
if (Driver)
Driver->grab();
......@@ -1828,13 +1828,15 @@ public:
virtual core::stringw getStringW()
{
return core::stringw(Value ? Value->getName().getPath().c_str() : 0);
return core::stringw(OverrideName.size()?OverrideName:
Value ? Value->getName().getPath().c_str() : 0);
}
virtual core::stringc getString()
{
// since texture names can be stringw we are careful with the types
return core::stringc(Value ? Value->getName().getPath().c_str() : 0);
return core::stringc(OverrideName.size()?OverrideName:
Value ? Value->getName().getPath().c_str() : 0);
}
virtual void setString(const char* text)
......@@ -1842,7 +1844,10 @@ public:
if (Driver)
{
if (text && *text)
{
setTexture(Driver->getTexture(text));
OverrideName=text;
}
else
setTexture(0);
}
......@@ -1875,6 +1880,7 @@ public:
video::ITexture* Value;
video::IVideoDriver* Driver;
io::path OverrideName;
};
......
......@@ -509,13 +509,13 @@ void CAttributes::getAttributeEnumerationLiteralsOfEnumeration(const c8* attribu
}
//! Sets an attribute as texture reference
void CAttributes::setAttribute(const c8* attributeName, video::ITexture* value )
void CAttributes::setAttribute(const c8* attributeName, video::ITexture* value, const io::path& filename)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setTexture(value);
att->setTexture(value, filename);
else
Attributes.push_back(new CTextureAttribute(attributeName, value, Driver));
Attributes.push_back(new CTextureAttribute(attributeName, value, Driver, filename));
}
......@@ -818,9 +818,9 @@ void CAttributes::addBinary(const c8* attributeName, void* data, s32 dataSizeInB
}
//! Adds an attribute as texture reference
void CAttributes::addTexture(const c8* attributeName, video::ITexture* texture)
void CAttributes::addTexture(const c8* attributeName, video::ITexture* texture, const io::path& filename)
{
Attributes.push_back(new CTextureAttribute(attributeName, texture, Driver));
Attributes.push_back(new CTextureAttribute(attributeName, texture, Driver, filename));
}
//! Returns if an attribute with a name exists
......@@ -918,10 +918,10 @@ void CAttributes::setAttribute(s32 index, const char* enumValue, const char* con
//! Sets an attribute as texture reference
void CAttributes::setAttribute(s32 index, video::ITexture* texture)
void CAttributes::setAttribute(s32 index, video::ITexture* texture, const io::path& filename)
{
if ((u32)index < Attributes.size())
Attributes[index]->setTexture(texture);
Attributes[index]->setTexture(texture, filename);
}
......
......@@ -602,10 +602,10 @@ public:
*/
//! Adds an attribute as texture reference
virtual void addTexture(const c8* attributeName, video::ITexture* texture);
virtual void addTexture(const c8* attributeName, video::ITexture* texture, const io::path& filename = "");
//! Sets an attribute as texture reference
virtual void setAttribute(const c8* attributeName, video::ITexture* texture );
virtual void setAttribute(const c8* attributeName, video::ITexture* texture, const io::path& filename = "");
//! Gets an attribute as texture reference
//! \param attributeName: Name of the attribute to get.
......@@ -616,7 +616,7 @@ public:
virtual video::ITexture* getAttributeAsTexture(s32 index);
//! Sets an attribute as texture reference
virtual void setAttribute(s32 index, video::ITexture* texture);
virtual void setAttribute(s32 index, video::ITexture* texture, const io::path& filename = "");
......
......@@ -14,6 +14,7 @@
#include "IAnimatedMeshSceneNode.h"
#include "CMeshManipulator.h"
#include "CColorConverter.h"
#include "IAttributeExchangingObject.h"
namespace irr
......@@ -1790,7 +1791,8 @@ void CNullDriver::setMaterialRendererName(s32 idx, const char* name)
//! Creates material attributes list from a material, usable for serialization and more.
io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMaterial& material)
io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMaterial& material,
io::SAttributeReadWriteOptions* options)
{
io::CAttributes* attr = new io::CAttributes(this);
......@@ -1808,7 +1810,16 @@ io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMateria
core::stringc prefix="Texture";
u32 i;
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i));
{
if (options && (options->Flags&io::EARWF_USE_RELATIVE_PATHS) && options->Filename && material.getTexture(i))
{
io::path path = FileSystem->getRelativeFilename(
FileSystem->getAbsolutePath(material.getTexture(i)->getName()), options->Filename);
attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i), path);
}
else
attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i));
}
attr->addBool("Wireframe", material.Wireframe);
attr->addBool("GouraudShading", material.GouraudShading);
......
......@@ -592,7 +592,8 @@ namespace video
virtual void setMaterialRendererName(s32 idx, const char* name);
//! Creates material attributes list from a material, usable for serialization and more.
virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material);
virtual io::IAttributes* createAttributesFromMaterial(const video::SMaterial& material,
io::SAttributeReadWriteOptions* options=0);
//! Fills an SMaterial structure from attributes.
virtual void fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attributes);
......
......@@ -92,7 +92,7 @@ public:
virtual void setUserPointer(void* v) {};
virtual void setEnum(const char* enumValue, const char* const* enumerationLiterals) {};
virtual void setTexture(video::ITexture*) {};
virtual void setTexture(video::ITexture*, const path& filename) {};
core::stringc Name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment