Exemple #1
0
static void setTexture( const String &resolvedPath, const aiString &texPath, CPPCore::TArray<Texture*> &textures ) {
    Texture *tex = new Texture;
    textures.add( tex );
    String texname;
    texname += "file://";
    texname += resolvedPath;
    String temp( texPath.C_Str() ), temp1;
    IO::Uri::normalizePath( temp, '\\', temp1 );
    texname += temp1;

    tex->m_loc = IO::Uri( texname );
    String::size_type pos = texname.rfind( "/" );
    if ( pos != String::npos ) {
        texname = texname.substr( pos, texname.size() - pos );
    }
    if (IO::IOService::getInstance()->fileExists(tex->m_loc)) {
        IO::AbstractFileSystem *fs = IO::IOService::getInstance()->getFileSystem("file");
        IO::Stream *file = fs->open(tex->m_loc, IO::Stream::AccessMode::ReadAccess);
        tex->m_size = file->getSize();
        file->read(tex->m_data, tex->m_size);
        fs->close(&file);
    }
        
    tex->m_textureName = texname;
    tex->m_width = 0;
    tex->m_height = 0;
    tex->m_channels = 0;
    tex->m_data = nullptr;
    tex->m_size = 0;
}
Exemple #2
0
// ------------------------------------------------------------------------------------------------
// Helper function to build a list of all file extensions supported by ASSIMP
void Importer::GetExtensionList(aiString& szOut) const
{
    ASSIMP_BEGIN_EXCEPTION_REGION();
    std::set<std::string> str;
    for (std::vector<BaseImporter*>::const_iterator i =  pimpl->mImporter.begin();i != pimpl->mImporter.end();++i)  {
        (*i)->GetExtensionList(str);
    }

    for (std::set<std::string>::const_iterator it = str.begin();; ) {
        szOut.Append("*.");
        szOut.Append((*it).c_str());

        if (++it == str.end()) {
            break;
        }
        szOut.Append(";");
    }
    ASSIMP_END_EXCEPTION_REGION(void);
}
Exemple #3
0
std::string XFileExporter::toXFileString(aiString &name)
{
	std::string str = std::string(name.C_Str());
	std::replace(str.begin(), str.end(), '<', '_');
	std::replace(str.begin(), str.end(), '>', '_');
	std::replace(str.begin(), str.end(), '{', '_');
	std::replace(str.begin(), str.end(), '}', '_');
	std::replace(str.begin(), str.end(), '$', '_');
	return str;
}
void Material::addTexture(aiString FILEPATH)
{
	int width, height;

	unsigned char* image = SOIL_load_image(FILEPATH.C_Str(), &width, &height, 0, SOIL_LOAD_RGBA);

	p_images.push_back(image);
	p_width.push_back(width);
	p_height.push_back(height);
}
Exemple #5
0
// -----------------------------------------------------------------------------------
// Convert a name to standard XML format
void ConvertName(aiString& out, const aiString& in)
{
	out.length = 0;
	for (unsigned int i = 0; i < in.length; ++i)  {
		switch (in.data[i]) {
			case '<':
				out.Append("&lt;");break;
			case '>':
				out.Append("&gt;");break;
			case '&':
				out.Append("&amp;");break;
			case '\"':
				out.Append("&quot;");break;
			case '\'':
				out.Append("&apos;");break;
			default:
				out.data[out.length++] = in.data[i];
		}
	}
	out.data[out.length] = 0;
}
String^ aiStringToString(aiString str)
{
	// Assimp aiString underlying encoding is UTF-8
	// Windows String underlying encoding is UTF-16
	Encoding^ srcEncoding = Encoding::UTF8;

	const char* pAiData = str.C_Str(); // pointer to the underlying data of he aiString
	array<unsigned char>^ buffer = gcnew array<unsigned char>(str.length);
	for(unsigned int i=0; i<str.length; ++i)
		buffer[i] = pAiData[i];

	return srcEncoding->GetString(buffer);
}
Exemple #7
0
void XFileExporter::writePath(aiString path)
{
	std::string str = std::string(path.C_Str());
	BaseImporter::ConvertUTF8toISO8859_1(str);

	while( str.find( "\\\\") != std::string::npos)
		str.replace( str.find( "\\\\"), 2, "\\");

	while( str.find( "\\") != std::string::npos)
		str.replace( str.find( "\\"), 1, "/");

	mOutput << str;
			
}
Exemple #8
0
std::string XFileExporter::toXFileString(aiString &name)
{
    std::string pref = ""; // node name prefix to prevent unexpected start of string
    std::string str = pref + std::string(name.C_Str());
    for (int i=0; i < (int) str.length(); ++i)
    {
        if ((str[i] >= '0' && str[i] <= '9') || // 0-9
            (str[i] >= 'A' && str[i] <= 'Z') || // A-Z
            (str[i] >= 'a' && str[i] <= 'z')) // a-z
            continue;
        str[i] = '_';
    }
    return str;
}
bool formatTexPath(const aiString& texName, Path& texPath)
{
	if (texName.length == 0)
		return false;

	string name = texName.C_Str();
	name = name.substr(0, name.find_last_of('.')).append(".image");

	std::cout << name << std::endl;

	texPath.composePath(name);

	return true;
}
Exemple #10
0
// TEXTURE2D
vgd::Shp< vgd::node::Texture2D > createTexture2D(	const vgio::Media & media, const boost::filesystem::path pathFilename, const int index, const aiString aiImagePath,
													const aiTextureMapMode mapU, const aiTextureMapMode mapV )
{
	// Compute image path
	std::string imagePathFilenameStr;

	namespace bfs = boost::filesystem;
	const bfs::path imagePathFilename = aiImagePath.C_Str();

	if ( imagePathFilename.is_absolute() )
	{
		imagePathFilenameStr = imagePathFilename.string();
	}
	else // relative path
	{
		const bfs::path rootPath = pathFilename.parent_path();

		imagePathFilenameStr = (rootPath / imagePathFilename).string();
	}

	// Texture node
	using vgd::node::Texture2D;
	vgd::Shp< Texture2D > texture = Texture2D::create( imagePathFilename.filename().string(), (int8)index );

	// IMAGE
	// Gathers the image from the cache.
	vgd::Shp< vgd::basic::IImage > image;
	image = vgio::ImageCache::load( media, imagePathFilenameStr );
	texture->setImage( image );

	// Default values
	texture->setMipmap( true );
	texture->setMinFilter( Texture2D::LINEAR_MIPMAP_LINEAR );
	texture->setMagFilter( Texture2D::LINEAR );

	// WRAPPING
	texture->setWrapS( toEnum(mapU) );
	texture->setWrapT( toEnum(mapV) );

	// FUNCTION
	texture->sethFunction( vgd::node::Texture2D::FUN_MODULATE ); // @todo
	return texture;
}
Exemple #11
0
	bool operator()(const aiString& aiA, const aiString& aiB)const
	{
		std::string a = aiA.C_Str();
		std::string b = aiB.C_Str();
		return a < b;
	}
string toString(const aiString& s) { return s.C_Str(); }
inline std::string assimpToCore( const aiString& string ) {
    return std::string( string.C_Str() );
}