本文整理汇总了C++中MaterialManager::hasMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialManager::hasMaterial方法的具体用法?C++ MaterialManager::hasMaterial怎么用?C++ MaterialManager::hasMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaterialManager
的用法示例。
在下文中一共展示了MaterialManager::hasMaterial方法的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;
}
示例2: v
//Loads the MD2 model
MD2Model* MD2Model::load(const char* filename) {
Vec3f xyzMin;
Vec3f xyzMax;
ifstream input;
input.open(filename, istream::binary);
Con_print("****MD2LOAD:START****");
char buffer[64];
input.read(buffer, 4); //Should be "IPD2", if this is an MD2 file
if (buffer[0] != 'I' || buffer[1] != 'D' ||
buffer[2] != 'P' || buffer[3] != '2') {
Con_print("MD2 Error: Wrong MD2 Version Found!");
return NULL;
}
if (readInt(input) != 8) { //The version number
Con_print("MD2 Error: Wrong MD2 Version Number Found!");
return NULL;
}
int textureWidth = readInt(input); //The width of the textures
int textureHeight = readInt(input); //The height of the textures
readInt(input); //The number of bytes per frame
int numTextures = readInt(input); //The number of textures
if (numTextures != 1) {
Con_print("MD2 Error: No Textures Found!");
return NULL;
}
int numVertices = readInt(input); //The number of vertices
int numTexCoords = readInt(input); //The number of texture coordinates
int numTriangles = readInt(input); //The number of triangles
readInt(input); //The number of OpenGL commands
int numFrames = readInt(input); //The number of frames
//Offsets (number of bytes after the beginning of the file to the beginning
//of where certain data appear)
int textureOffset = readInt(input); //The offset to the textures
int texCoordOffset = readInt(input); //The offset to the texture coordinates
int triangleOffset = readInt(input); //The offset to the triangles
int frameOffset = readInt(input); //The offset to the frames
readInt(input); //The offset to the OpenGL commands
readInt(input); //The offset to the end of the file
MD2Model* model = new MD2Model();
MaterialManager* matsMgr = getMaterialManager();
//Load the texture
input.seekg(textureOffset, ios_base::beg);
input.read(buffer, 64);
// FIXME
// Hack to get the md2 models with pcx textures to load bmp version instead
string s = buffer;
s = s.substr(0, s.find_last_of("."));
s = s + ".bmp";
strcpy(buffer, s.c_str());
// END FIXME
////////////////////////
if (strlen(buffer) < 5 || strcmp(buffer + strlen(buffer) - 4, ".bmp") != 0 ) {
Con_print("MD2 Error: Couldn't parse texture name: %s", buffer);
// Set texture not found because we can't load the texture that was set
model->textureId = matsMgr->getGLTexID("not-found.bmp");
}
else {
if( !matsMgr->hasMaterial(buffer) )
matsMgr->loadBitmap(buffer);
model->textureId = matsMgr->getGLTexID(buffer);
}
//Load the texture coordinates
input.seekg(texCoordOffset, ios_base::beg);
model->texCoords = new MD2TexCoord[numTexCoords];
for(int i = 0; i < numTexCoords; i++) {
MD2TexCoord* texCoord = model->texCoords + i;
texCoord->texCoordX = (float)readShort(input) / textureWidth;
texCoord->texCoordY = 1 - (float)readShort(input) / textureHeight;
}
//Load the triangles
input.seekg(triangleOffset, ios_base::beg);
model->triangles = new MD2Triangle[numTriangles];
model->numTriangles = numTriangles;
for(int i = 0; i < numTriangles; i++) {
MD2Triangle* triangle = model->triangles + i;
for(int j = 0; j < 3; j++) {
triangle->vertices[j] = readUShort(input);
}
for(int j = 0; j < 3; j++) {
triangle->texCoords[j] = readUShort(input);
}
}
//.........这里部分代码省略.........