当前位置: 首页>>代码示例>>C++>>正文


C++ MaterialManager::addMaterial方法代码示例

本文整理汇总了C++中MaterialManager::addMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialManager::addMaterial方法的具体用法?C++ MaterialManager::addMaterial怎么用?C++ MaterialManager::addMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MaterialManager的用法示例。


在下文中一共展示了MaterialManager::addMaterial方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadMTLFile

bool ObjModel::loadMTLFile(const char* fileName)	{
	cout << "Loading material file: " << fileName << endl;

	FILE* fp;
	string* modelPath = getCvarAddress_S("r_modelPath");

	string canonicalPath = *modelPath + "obj/" + fileName;

	cout << "From file path: " << canonicalPath << endl;

	if( !(fp=fopen(canonicalPath.c_str(), "r")) )	{
		error = "OBJ Materials file not found";
		Con_print("Obj: File not found - %s", canonicalPath.c_str());
		return false;
	}

	MaterialManager* tm = getMaterialManager();

	material_t* mat;

	while( !feof(fp) )	{
		char in[MAX_OBJ_LINE_LEN];
		fgets(in, MAX_OBJ_LINE_LEN, fp);
		char incpy[MAX_OBJ_LINE_LEN];
#ifdef OBJMATDEBUG
		cout << "MAT Line: " << in << endl;
#endif
		strcpy(incpy, in);

		// if its a comment or whitespace skip it
		if( in[0] == '#' || in[0] == ' ' || in[0] == '\n' ||
				in[0] == '\r'  || in[0] == '\t')
			continue;
		else	{	// otherwise we need to process some data
			char* token = strtok(in, WHITESPACE);

			if( token == NULL )
				break;

			if( !strcmp(token, "newmtl") )	{
				material_t* newmat = new material_t;
				initializeMaterial(newmat);

				token = strtok(NULL, WHITESPACE);
				if( !tm->hasMaterial(token) )	{
					tm->addMaterial(token, newmat);
					mat = newmat;
#ifdef OBJMATDEBUG
					cout << "New material created: " << token << endl;
#endif
				}
				else	{
#ifdef OBJMATDEBUG
					cout << "MTL Error: Material redefinition: " << token << endl;
#endif
				}
			}
			else if( !strcmp(token, "Ns") )	{
				sscanf(incpy, "Ns %f", &mat->Ns);
			}
			else if( !strcmp(token, "Ka") )	{
				sscanf(incpy, "Ka %f %f %f", &mat->Ka[0], &mat->Ka[1], &mat->Ka[2]);
			}
			else if( !strcmp(token, "Kd") )	{
				sscanf(incpy, "Kd %f %f %f", &mat->Kd[0], &mat->Kd[1], &mat->Kd[2]);
			}
			else if( !strcmp(token, "Ks") )	{
				sscanf(incpy, "Ks %f %f %f", &mat->Ks[0], &mat->Ks[1],& mat->Ks[2]);
			}
			else if( !strcmp(token, "Ni") )	{
				sscanf(incpy, "Ni %f", &mat->Ni);
			}
			else if( !strcmp(token, "d") )	{
				sscanf(incpy, "d %f", &mat->d);
			}
			else if( !strcmp(token, "illum") )	{
				sscanf(incpy, "illum %d", &mat->illum);
			}
			else if( !strcmp(token, "map_Kd") )	{
				token = strtok(NULL, WHITESPACE);
				strcpy(mat->map_Kd, token);
#ifdef OBJMATDEBUG
				cout << "Loading texture: " << mat->map_Kd << endl;
#endif
				getMaterialManager()->loadBitmap(mat->map_Kd);
			}
		}
	}

	fclose(fp);

	return true;
}
开发者ID:nonsensicalthinking,项目名称:rendar,代码行数:93,代码来源:WavefrontObj.cpp

示例2: parseMaterialFile

void WFLoader::parseMaterialFile( const char *line )
{
    /* Variables
     */
    char                tempStr[20] = "\0";
    MaterialManager     *matMngrPtr = NULL;
    MaterialData        matData;
    float               r, g, b;

    /* Code
     */
    matMngrPtr = MaterialManager::getInstance();

    if( strlen( line ) > 0 )
    {
        if( line[ 0 ] == 'n' )
        {
            sscanf( line, "%s", tempStr );
            /* Material name */
            if( strcmp( tempStr, "newmtl" ) == 0 )
            {
                sscanf( line, "%*s %s", m_CurrentMatName );
                matMngrPtr->addMaterial( m_CurrentMatName, matData );
            }
        }
        else if( line[ 0 ] == 'N' )
        {
            switch( line[ 1 ] )
            {
            case 's':
                /* Specular exponent ( shininess ) */
                sscanf( line, "%*s %f", &r );
                /* Even though Color4f is used, only the value of r gets
                   saved into the Material values */
                matMngrPtr->setValue( m_CurrentMatName,
                                      MaterialManager::MAT_SHININESS,
                                      Color4f( r, 0.0, 0.0, 1.0 ) );
                break;
            }
        }
        /* Reflectivity information */
        else if( line[ 0 ] == 'K' )
        {

            switch( line[ 1 ] ) //if( line[ 1 ] == 'a' )
            {
            case 'a':
                /* Ambient */
                sscanf( line, "%*s %f %f %f", &r, &g, &b );
                matMngrPtr->setValue( m_CurrentMatName,
                                      MaterialManager::MAT_AMBIENT,
                                      Color4f( r, g, b, 1.0 ) );
                break;
            case 'd':
                /* Diffuse */
                sscanf( line, "%*s %f %f %f", &r, &g, &b );
                matMngrPtr->setValue( m_CurrentMatName,
                                      MaterialManager::MAT_DIFFUSE,
                                      Color4f( r, g, b, 1.0 ) );
                break;
            case 's':
                /* Specular */
                sscanf( line, "%*s %f %f %f", &r, &g, &b );
                matMngrPtr->setValue( m_CurrentMatName,
                                      MaterialManager::MAT_SPECULAR,
                                      Color4f( r, g, b, 1.0 ) );
                break;
            }
        }
    }
}
开发者ID:kilppari,项目名称:turtleRenderer,代码行数:71,代码来源:wf_loader.cpp


注:本文中的MaterialManager::addMaterial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。