void GLRenderer::render(const Camera view) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Matrix<4, float> p_matrix = view.getProjectionMatrix(); Matrix<4, float> v_matrix = view.getViewMatrix(); while (!m_jobQueue.empty()) { RenderObject job(m_jobQueue.front()); int modelName(job.getModelID()); string shaderName(job.getShaderName()); enableShaderProgram(shaderName); string textureName(job.getTextureName()); if (textureName.length() > 0) { enableTexture(textureName); } Matrix<4, float> m_matrix = job.getModelMatrix(); setUniform<Matrix<4, float>>(shaderName, "m_matrix", m_matrix); setUniform<Matrix<4, float>>(shaderName, "v_matrix", v_matrix); setUniform<Matrix<4, float>>(shaderName, "p_matrix", p_matrix); setUniform<Vector<3, float>>(shaderName, "ambientLightColour", m_ambientLightSource.getColour()); setUniform<Vector<3, float>>(shaderName, "directionalLightColour", m_directionalLightSource.getColour()); setUniform<Vector<3, float>>(shaderName, "directionalLightDirection", m_directionalLightSource.getDirection()); if (m_staticMeshes[modelName] == nullptr) { throw std::out_of_range("Error: Cannot draw the model with that handle as it does not exist."); } else { m_staticMeshes[modelName]->draw(); } m_jobQueue.pop(); } }
/** * Sets a letter for the header texture */ void LetterCube::setLetter(char letter){ this->letter = letter; std::string textureName(""); textureName = this->letter; this->setTopTexture(textureName); std::string standardTexture("tile"); this->setBottomTexture(standardTexture); this->setFrontTexture(standardTexture); this->setBackTexture(standardTexture); this->setLeftTexture(standardTexture); this->setRightTexture(standardTexture); }
static boost::shared_ptr<Font> CreateFont(const char* const filename) { boost::shared_ptr<Font> font(new Font()); std::vector<char> textureName(strlen(filename) + sizeof(".dds")); sprintf(textureName.data(), "%s.dds", filename); font->texture.Load(textureName.data(), GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA); std::vector<char> metadataFilename(strlen(filename) + sizeof(".dat")); sprintf(metadataFilename.data(), "%s.dat", filename); FILE* file(fopen(metadataFilename.data(), "rb")); size_t glyphCount; fread(&glyphCount, sizeof(glyphCount), 1, file); font->glyphs.resize(glyphCount); fread(&font->spaceAdvance, sizeof(font->spaceAdvance), 1, file); for (size_t i = 0; i < glyphCount; ++i) { GlyphMetaData metadata; #define LOAD_GLYPH_DATA(file, member) fread(&member, sizeof(member), 1, file); LOAD_GLYPH_DATA(file, metadata.code); LOAD_GLYPH_DATA(file, metadata.bearing.x); LOAD_GLYPH_DATA(file, metadata.bearing.y); LOAD_GLYPH_DATA(file, metadata.size.y); LOAD_GLYPH_DATA(file, metadata.size.y); LOAD_GLYPH_DATA(file, metadata.penAdvance); LOAD_GLYPH_DATA(file, metadata.textureLeftEdge); LOAD_GLYPH_DATA(file, metadata.textureSize.x); LOAD_GLYPH_DATA(file, metadata.textureSize.y); font->glyphs[i].bearing = metadata.bearing; font->glyphs[i].penAdvance = metadata.penAdvance; font->glyphs[i].size = metadata.size; font->glyphs[i].textureLeftEdge = metadata.textureLeftEdge; font->glyphs[i].textureSize = metadata.textureSize; font->glyphMap[metadata.code] = &font->glyphs[i]; } fclose(file); return font; }
void MainWindow::Export() { stringstream defaultlocation; QString defaultname = QString(lastLSTFile.c_str()).split(".").first(); defaultlocation << "./ExportedModels/" <<defaultname.toStdString(); QString path = QFileDialog::getSaveFileName( this, "Enter A model Name. A directory is created with this name and the models and textures exported into it", defaultlocation.str().c_str(), ""); path = path.split(".").first(); QString ModelName, modelDirectory; ModelName = path.split("/").last(); modelDirectory = path; modelDirectory.chop(modelDirectory.length()-modelDirectory.lastIndexOf("/")-1); QDir().mkdir(QString("ExportedModels/") + ModelName); QDir().mkdir(QString("ExportedModels/") + ModelName + "/textures"); // QDir(QString("ExportedModels")).mkdir(name); // copy bark QString textureName(displayWidget->currentBarkFilePath.c_str()) ; textureName = textureName.split("/").last(); QFile().copy(QString(displayWidget->currentBarkFilePath.c_str()), path + "/textures/" + textureName); // export the mesh if(displaySubdivisionSurface->isChecked() == false) displayWidget->exportCylinderModelToObj((path + "/"+ModelName +"_trunk.obj").toStdString()); else displayWidget->exportMeshToObj((path + "/"+ ModelName +"_trunk.obj").toStdString()); // export the foliage foliageParameters->exportFoliage(modelDirectory, ModelName); }
bool ModelMd2::load(const char* filename, TextureDirectory& textureDirectory, const bool justData) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (file.fail()) { return false; } int fileSize; file.seekg(0, std::ios::end); fileSize = file.tellg(); file.seekg(0, std::ios::beg); char* buffer = new char[fileSize]; file.read((char*) buffer, fileSize); file.close(); // header Header* header = reinterpret_cast<Header*>(buffer); if ((header->magic != MD2_MAGIC_NUM) && (header->version != 8)) { file.close(); return false; } m_numTexCoords = header->numTexCoords; m_numVertices = header->numVertices; m_numTriangles = header->numTriangles; int numFrames = header->numFrames; // texcoords TexcoordMd2* tmptex = new TexcoordMd2[m_numTexCoords]; memcpy(tmptex, &buffer[header->offsetTexCoords], m_numTexCoords * sizeof(TexcoordMd2)); m_pTexcoords = new texCoord[m_numTexCoords]; for (int i = 0; i < m_numTexCoords; i++) { m_pTexcoords[i].u = (float) tmptex[i].s / header->skinWidth; m_pTexcoords[i].v = -(float) tmptex[i].t / header->skinHeight; } delete[] tmptex; m_pTexcoordArray = new texCoord[m_numTriangles * 3]; // one vertex can have more texture coordinates (eg. a corner of a cube) // triangles m_pTriangles = new TriangleMd2[m_numTriangles]; memcpy(m_pTriangles, &buffer[header->offsetTriangles], m_numTriangles * sizeof(TriangleMd2)); // vertices m_pVertices = new vec3[numFrames * m_numVertices]; m_pVertexArray = new vec3[m_numTriangles * 3]; // normal vectors m_pNormals = new vec3[numFrames * m_numVertices]; m_pNormalArray = new vec3[m_numTriangles * 3]; // tangent vectors m_pTangents = new vec3[numFrames * m_numVertices]; m_pTangentArray = new vec3[m_numTriangles * 3]; // precalculated normal vectors float anorms[162][3] = { #include "anorms.h" }; FrameMd2* frame; std::string lastname; std::string filteredLastname; // animációk, vertexek kiolvasása, beállítása for (int i = 0; i < numFrames; i++) { frame = (FrameMd2*) &buffer[ header->offsetFrames + i * header->frameSize ]; // az azonos nevű frameket egy animációba pakoljuk (pl. stand_1, stand_2 ...) if (lastname == "" || strncmp(lastname.c_str(), frame->name, lastname.size()) > 0) { lastname = frame->name; if (lastname[lastname.size() - 2] == '0') // eg. stand01 { lastname.resize(lastname.size() - 2); } else { lastname.resize(lastname.size() - 1); } filteredLastname = lastname; filteredLastname.resize( std::remove_if(filteredLastname.begin(), filteredLastname.end(), filter) - filteredLastname.begin() ); m_numAnims++; m_animations[filteredLastname].start = i; m_animations[filteredLastname].end = -1; } m_animations[filteredLastname].end++; for (int j = 0; j < m_numVertices; j++) { m_pVertices[ i * m_numVertices + j ].x = (frame->verts[j].v[0] * frame->scale[0]) + frame->translate[0]; m_pVertices[ i * m_numVertices + j ].y = (frame->verts[j].v[1] * frame->scale[1]) + frame->translate[1]; m_pVertices[ i * m_numVertices + j ].z = (frame->verts[j].v[2] * frame->scale[2]) + frame->translate[2]; m_pVertices[ i * m_numVertices + j ] = transformVector(m_pVertices[ i * m_numVertices + j ], vec3(0.0f), vec3(90, 90, 0)); const float* normals = anorms[frame->verts[j].normalIndex]; m_pNormals[ i * m_numVertices + j ] = vec3(normals[0], normals[1], normals[2]); } // calculate tangent vectors vec3 tangent, bitangent; for (int j = 0; j < m_numTriangles; j++) { calculateTangent(m_pVertices[ i * m_numVertices + m_pTriangles[j].vertIdx[2] ], m_pVertices[ i * m_numVertices + m_pTriangles[j].vertIdx[1] ], m_pVertices[ i * m_numVertices + m_pTriangles[j].vertIdx[0] ], m_pTexcoords[ m_pTriangles[j].texIdx[2] ], m_pTexcoords[ m_pTriangles[j].texIdx[1] ], m_pTexcoords[ m_pTriangles[j].texIdx[0] ], tangent, bitangent); m_pTangents[ i * m_numVertices + m_pTriangles[j].vertIdx[0] ] = m_pTangents[ i * m_numVertices + m_pTriangles[j].vertIdx[1] ] = m_pTangents[ i * m_numVertices + m_pTriangles[j].vertIdx[2] ] = tangent; } } int v_i = 0; for (int j = 0; j < m_numTriangles; j++) { m_pNormalArray[v_i] = m_pNormals[ m_pTriangles[j].vertIdx[2] ]; m_pNormalArray[v_i + 1] = m_pNormals[ m_pTriangles[j].vertIdx[1] ]; m_pNormalArray[v_i + 2] = m_pNormals[ m_pTriangles[j].vertIdx[0] ]; m_pTexcoordArray[v_i] = m_pTexcoords[ m_pTriangles[j].texIdx[2] ]; m_pTexcoordArray[v_i + 1] = m_pTexcoords[ m_pTriangles[j].texIdx[1] ]; m_pTexcoordArray[v_i + 2] = m_pTexcoords[ m_pTriangles[j].texIdx[0] ]; v_i += 3; } // load textures if (!justData) { // the name of the texture is usually not stored n the file char textureNameTmp[64]; memcpy(textureNameTmp, &buffer[header->offsetSkins], 64 * sizeof(char)); std::string locationtemp = utils::file::getDir(std::string(filename)); std::string textureName(textureNameTmp); utils::toLowerCase(textureName); std::string textemp = locationtemp + textureName; if (textemp.length() > locationtemp.length()) { // texture map loadTexture((char*) textemp.c_str(), m_decalMap, textureDirectory); // normalheight map std::string nhtemp = locationtemp + utils::file::getFileName(textemp) + "_nh.png"; if (!loadTexture((char*) nhtemp.c_str(), m_normalHeightMap, textureDirectory)) { // no nh texture -> use the blank texture m_normalHeightMap = 0; } } } delete[] buffer; return true; }
CRosRttTexture::CRosRttTexture(unsigned width, unsigned height, Ogre::Camera * camera, bool isDepth /*= false*/ ) : m_materialName("MyRttMaterial") , width_(width) , height_(height) , frame_("/map") , m_bIsDepth( isDepth ) { assert( height > 0 && width > 0 ); { // Set encoding current_image_.encoding = ROS_IMAGE_FORMAT; // Set image size current_image_.width = width; current_image_.height = height; // Set image row length in bytes (row length * 3 bytes for a color) current_image_.step = width * BPP; #if OGRE_ENDIAN == ENDIAN_BIG current_image_.is_bigendian = true; #else current_image_.is_bigendian = false; #endif // Resize data current_image_.data.resize( width_ * height_ * BPP); } Ogre::TextureManager & lTextureManager( Ogre::TextureManager::getSingleton() ); Ogre::String textureName("RVIZ_CamCast_Texture"); bool lGammaCorrection( false ); unsigned int lAntiAliasing( 0 ); unsigned int lNumMipmaps( 0 ); if( isDepth ) { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_DEPTH_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } else { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } // Create render target Ogre::RenderTexture* lRenderTarget = NULL; Ogre::HardwarePixelBufferSharedPtr lRttBuffer = texture_->getBuffer(); lRenderTarget = lRttBuffer->getRenderTarget(); lRenderTarget->setAutoUpdated(true); // Create and attach viewport Ogre::Viewport* lRttViewport1 = lRenderTarget->addViewport(camera, 50, 0.00f, 0.00f, 1.0f, 1.0f); lRttViewport1->setAutoUpdated(true); Ogre::ColourValue lBgColor1(0.0,0.0,0.0,1.0); lRttViewport1->setBackgroundColour(lBgColor1); // create a material using this texture. //Get a reference on the material manager, which is a singleton. Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton(); Ogre::MaterialPtr lMaterial = lMaterialManager.create(m_materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique * lTechnique = lMaterial->getTechnique(0); Ogre::Pass* lPass = lTechnique->getPass(0); if( isDepth ) { lPass->setLightingEnabled(false); } Ogre::TextureUnitState* lTextureUnit = lPass->createTextureUnitState(); lTextureUnit->setTextureName(textureName); lTextureUnit->setNumMipmaps(0); lTextureUnit->setTextureFiltering(Ogre::TFO_BILINEAR); update(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexture* MLRTexturePool::Add(const char *tn, int instance) { MString textureName(tn); int i, j, textureNameHashValue = textureName.GetHashValue(); for(i=0;i<lastHandle;i++) { int first = i<<instanceDepth; bool yo = false; for(j=first;j<first+instanceMax;j++) { if( textureArray[j] && textureArray[j]->textureNameHashValue == textureNameHashValue ) { yo = 1; } } if(yo == false) { continue; } for(j=first;j<first+instanceMax;j++) { if( textureArray[j] && textureArray[j]->instance == instance) { return textureArray[j]; } } for(j=first;j<first+instanceMax;j++) { if(!textureArray[j]) { gos_PushCurrentHeap(Heap); textureArray[j] = new MLRTexture( this, textureName, instance, j+1 ); Register_Object(textureArray[j]); gos_PopCurrentHeap(); storedTextures++; unLoadedImages = true; return textureArray[j]; } } STOP(("Asked for too much image instances !")); } int newHandle; gos_PushCurrentHeap(Heap); if(firstFreeHandle < lastFreeHandle) { newHandle = (freeHandle[firstFreeHandle&(handleMax-1)])<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, textureName, instance, newHandle+1 ); storedTextures++; firstFreeHandle++; } else { Verify( ((lastHandle<<instanceDepth)+1) < MLRState::TextureMask ); newHandle = lastHandle<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, textureName, instance, newHandle+1 ); storedTextures++; lastHandle++; } Register_Object(textureArray[newHandle]); gos_PopCurrentHeap(); unLoadedImages = true; return textureArray[newHandle]; }
Resource* WoWImporter::Import( const String& pFilename, const String& /*pParams*/ ) { WoW::ADTFile adtFile; WoW::ADTFileReader adtFileReader( adtFile ); adtFileReader.Read( pFilename ); WorldTile* worldTile = GD_NEW(WorldTile, this, "WoW::WorldTile"); worldTile->GetTerrainChunks().resize( 256 ); worldTile->GetVertexList().Allocate( 16*16 * (9*9 + 8*8), (VertexFormat::Component) (VertexFormat::Position3 | VertexFormat::TexCoord2 | VertexFormat::TexCoord2_2 | VertexFormat::Normal3) ); Vector3f* ptrPosition = worldTile->GetVertexList().GetPositions(); Vector3f* ptrNormal = worldTile->GetVertexList().GetNormals(); Vector2f* ptrTexCoord = worldTile->GetVertexList().GetTextureCoords(); Vector2f* ptrTexCoordAlpha = worldTile->GetVertexList().GetTextureCoords_2(); UInt32 verticesOffset = 0; Vector3f firstChunkPos(0,0,0);//-1.0f*adtFile.mMapChunks[0].mHeader.mPosition.y, adtFile.mMapChunks[0].mHeader.mPosition.z, -1.0f*adtFile.mMapChunks[0].mHeader.mPosition.x ); for( UInt32 iChunk = 0; iChunk < 256; iChunk++ ) { WoW::ADTFile::MapChunk* mapChunk = &adtFile.mMapChunks[iChunk]; // Append vertex data to vertex buffer Float* ptrDataHeight = mapChunk->mHeightMap; Char* ptrDataNormals = mapChunk->mHeightMapNormals[0]; Vector3f chunkPos( -1.0f*mapChunk->mHeader.mPosition.y, mapChunk->mHeader.mPosition.z, -1.0f*mapChunk->mHeader.mPosition.x ); Float posX = chunkPos.x - firstChunkPos.x; Float posZ = chunkPos.z - firstChunkPos.z; for( UInt32 z = 0; z < 9; z++ ) { // Normal row posX = chunkPos.x - firstChunkPos.x; for( UInt32 x = 0; x < 9; x++ ) { ptrPosition->x = posX; ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y; ptrPosition->z = posZ; (*ptrPosition) *= 0.1f; ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f; ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f; ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f; ptrTexCoord->x = x / 8.0f; ptrTexCoord->y = z / 8.0f; ptrTexCoordAlpha->x = (x+0.125f) / 8.25f; ptrTexCoordAlpha->y = (z+0.125f) / 8.25f; ptrDataHeight++; ptrDataNormals += 3; ptrPosition++; ptrNormal++; ptrTexCoord++; ptrTexCoordAlpha++; posX += UNIT_SIZE; } posZ += 0.5f * UNIT_SIZE; if( z == 8 ) break; // Detailed row posX = chunkPos.x + 0.5f * UNIT_SIZE - firstChunkPos.x; for( UInt32 x = 0; x < 8; x++ ) { ptrPosition->x = posX; ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y; ptrPosition->z = posZ; (*ptrPosition) *= 0.1f; ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f; ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f; ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f; ptrTexCoord->x = (x+0.5f) / 8.0f; ptrTexCoord->y = (z+0.5f) / 8.0f; ptrTexCoordAlpha->x = (x+0.5f+0.125f) / 8.25f; ptrTexCoordAlpha->y = (z+0.5f+0.125f) / 8.25f; ptrDataHeight++; ptrDataNormals += 3; ptrPosition++; ptrNormal++; ptrTexCoord++; ptrTexCoordAlpha++; posX += UNIT_SIZE; } posZ += 0.5f * UNIT_SIZE; } WorldTile::TerrainChunk* newChunk = GD_NEW(WorldTile::TerrainChunk, this, "WoW::WorldTile::TerrainChunk"); for( UInt32 iLayer = 0; iLayer < mapChunk->mTextureLayers.size(); iLayer++ ) { String textureName("Data/"); textureName += adtFile.mTextureNames[mapChunk->mTextureLayers[iLayer].mTextureID]; HTexture2D texture(textureName); Texture2D* alpha = NULL; if( iLayer != 0 ) { alpha = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( "AlphaMap" )); alpha->Create( mapChunk->mAlphaMaps[iLayer-1], true ); alpha->Init(); alpha->SetWrapMode( Texture::Wrap_S, Texture::Wrap_Clamp ); alpha->SetWrapMode( Texture::Wrap_T, Texture::Wrap_Clamp ); alpha->SetMinFilter( Texture::MinFilter_Linear ); alpha->SetMagFilter( Texture::MagFilter_Linear ); } newChunk->AddTextureLayer( texture, alpha ); } UInt32 detailedStripSize = (16*18 + 7*2 + 8*2); UInt32 normalStripSize = 158; // Build index buffer newChunk->GetHiResTriangles().Allocate( TriangleBatch::TriangleStrip, detailedStripSize ); newChunk->GetLowResTriangles().Allocate( TriangleBatch::TriangleStrip, normalStripSize ); UInt16* ptrHiIndices = newChunk->GetHiResTriangles().GetIndices(); UInt16* ptrLoIndices = newChunk->GetLowResTriangles().GetIndices(); for( int row = 0; row < 8; row++ ) { UInt32 topRow = verticesOffset + row*(9+8); UInt32 detailrow = verticesOffset + row*(9+8) + 9; UInt32 nextRow = verticesOffset + (row+1)*(9+8); if( row > 0 ) { *ptrHiIndices++ = topRow + 0; // jump end *ptrLoIndices++ = topRow + 0; } for( int col = 0; col < 8; col++ ) { *ptrHiIndices++ = topRow + col; *ptrHiIndices++ = detailrow + col; *ptrLoIndices++ = topRow + col; *ptrLoIndices++ = nextRow + col; } *ptrHiIndices++ = topRow + 8; *ptrHiIndices++ = nextRow + 8; *ptrHiIndices++ = nextRow + 8; // jump start *ptrHiIndices++ = topRow + 0; // jump end *ptrHiIndices++ = topRow + 0; *ptrLoIndices++ = topRow + 8; *ptrLoIndices++ = nextRow + 8; for( int col = 0; col < 8; col++ ) { *ptrHiIndices++ = nextRow + col; *ptrHiIndices++ = detailrow + col; } if( row < 8 ) *ptrHiIndices++ = nextRow + 8; if( row < 7 ) { *ptrHiIndices++ = nextRow + 8; // jump start *ptrLoIndices++ = nextRow + 8; } } verticesOffset += 9*9 + 8*8; worldTile->GetTerrainChunks()[iChunk] = newChunk; } return (Resource*)worldTile; }
static void worldmap_draw (EntComponent comp, EntSpeech speech) { float zNear = video_getZnear () - 0.001; unsigned int width, height; int i = 0, frameMargin = 32, sMargin = 8, sWidth = 55, sHeight = 34, maxWidth, maxHeight, mapSize, mapXMargin, mapYMargin; worldmapData map; const char * type; hexPos position; if (!Worldmap || !input_hasFocus (Worldmap)) return; map = component_getData (entity_getAs (Worldmap, "worldmap")); video_getDimensions (&width, &height); glColor4ub (0xff, 0xff, 0xff, 0xff); glBindTexture (GL_TEXTURE_2D, 0); glBegin (GL_QUADS); i = 0; while (i <= map->worldSpan) { glVertex3f ( video_xMap (width - (frameMargin + sWidth)), video_yMap (i * (sHeight + sMargin) + frameMargin), zNear ); glVertex3f ( video_xMap (width - (frameMargin + sWidth)), video_yMap (i * (sHeight + sMargin) + sHeight + frameMargin), zNear ); glVertex3f ( video_xMap (width - frameMargin), video_yMap (i * (sHeight + sMargin) + sHeight + frameMargin), zNear ); glVertex3f ( video_xMap (width - frameMargin), video_yMap (i * (sHeight + sMargin) + frameMargin), zNear ); i++; } glColor3ub (0xff, 0x00, 0x99); if (map->spanTypeFocus == FOCUS_SPAN) { glVertex3f (video_xMap (width - (frameMargin - 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) + 8), zNear); glVertex3f (video_xMap (width - (frameMargin - 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) - 8), zNear); glVertex3f (video_xMap (width - (frameMargin + 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) - 8), zNear); glVertex3f (video_xMap (width - (frameMargin + 8)), video_yMap ((map->worldSpan - map->spanFocus) * (sHeight + sMargin) + frameMargin + (sHeight / 2.0) + 8), zNear); } else { int fh = fontLineHeight (); glVertex3f (video_xMap (frameMargin - 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) + 8), zNear); glVertex3f (video_xMap (frameMargin + 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) + 8), zNear); glVertex3f (video_xMap (frameMargin + 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) - 8), zNear); glVertex3f (video_xMap (frameMargin - 8), video_yMap (frameMargin + (map->typeFocus + 1) * fh + ((fh - 16) / 2) - 8), zNear); } glEnd (); position = position_get (entity_getByName ("PLAYER")); if (map->types != NULL) { i = 0; fontPrintAlign (ALIGN_LEFT); while ((type = *(const char **)dynarr_at (map->types, i++))) { if (i - 1 == map->typeFocus) glColor4ub (0xff, 0xff, 0xff, 0xff); else glColor4ub (0xaf, 0xaf, 0xaf, 0xff); fontPrint (type, frameMargin, frameMargin + fontLineHeight () * (i - 1)); } } if (map->spanTextures[map->spanFocus] == NULL) { printf ("generating map texture for span %d using pos %p\n", map->spanFocus, position); if (map->types) map->spanTextures[map->spanFocus] = mapGenerateMapTexture (position, map->spanFocus, 0, *(const char **)dynarr_at (map->types, map->typeFocus)); else map->spanTextures[map->spanFocus] = mapGenerateMapTexture (position, map->spanFocus, 0, NULL); } glBindTexture (GL_TEXTURE_2D, textureName (map->spanTextures[map->spanFocus])); glColor4ub (0xff, 0xff, 0xff, 0xff); maxWidth = width - (frameMargin * 2 + sWidth + sMargin); maxHeight = height - (frameMargin * 2); mapSize = maxWidth < maxHeight ? maxWidth : maxHeight; mapXMargin = (width - mapSize) / 2; mapYMargin = (height - mapSize) / 2; glBegin (GL_QUADS); glTexCoord2f (0.00, 0.00); glVertex3f (video_xMap (mapXMargin), video_yMap (mapYMargin), zNear); glTexCoord2f (0.00, 1.00); glVertex3f (video_xMap (mapXMargin), video_yMap (mapYMargin + mapSize), zNear); glTexCoord2f (1.00, 1.00); glVertex3f (video_xMap (mapXMargin + mapSize), video_yMap (mapYMargin + mapSize), zNear); glTexCoord2f (1.00, 0.00); glVertex3f (video_xMap (mapXMargin + mapSize), video_yMap (mapYMargin), zNear); glEnd (); glBindTexture (GL_TEXTURE_2D, 0); }
bool CMayaAsciiWriter::Write() { OBJ_ASSERT(m_pMayaFile); if(!m_pMayaFile) return false; std::string fileName(m_fileName.string()); // Extract native file path string // Verify here that we have something to actually write OBJ_ASSERT(m_pMayaFile->GetMeshVector().size() > 0); // Write Maya Ascii file version 6.0 OBJ_ASSERT(CheckStr(fileName)); if(!CheckStr(fileName)) return false; m_ofs.open(fileName.c_str()); MSG_INFO("Writing Maya Ascii file (.MA) : '" << fileName << "'."); if( !m_ofs.is_open() ) { MSG_ERROR("Couldn't write to Maya file '" << fileName << "'"); return false; } std::string fileNameOnly(fileName); if(m_fileName.has_leaf()) { fileNameOnly = m_fileName.leaf(); } // Write the Maya file header m_ofs << "//Maya ASCII 6.0 scene" << std::endl; m_ofs << "//Name: " << fileNameOnly << std::endl; // Windows System Time // TODO : abstract date&time to have it multiplatform { SYSTEMTIME st; GetSystemTime(&st); m_ofs << "//Last modified: " << st.wMonth << "/" << st.wDay << "/" << st.wYear << " " << st.wHour << ":" << st.wMinute << ":" << st.wSecond << std::endl; } // File information m_ofs << "requires maya \"7.0\";" << std::endl; m_ofs << "currentUnit -l centimeter -a degree -t film;" << std::endl; m_ofs << "fileInfo \"application\" \"ZConverter v1.0\";" << std::endl; m_ofs << "fileInfo \"product\" \"Maya Unlimited 7.0\";" << std::endl; m_ofs << "fileInfo \"version\" \"7.0\";" << std::endl; m_ofs << "fileInfo \"cutIdentifier\" \"200404092210-618567\";" << std::endl; m_ofs << "fileInfo \"osv\" \"Microsoft Windows XP Professional Service Pack 2 (Build 2600)\\n\";" << std::endl; /* // Read the maya_viewport file and write it { std::ifstream ifs("maya_viewport.txt"); if( !ifs ) { MSG_ERROR("Couldn't read the maya_viewport.txt file'"); return false; } const int maxline = 1000; char line[maxline]; while(ifs) { ifs.getline( line, maxline ); // get the curent line pointer m_ofs << line << std::endl; } } */ // Retreive the group vector CMayaFile::MeshVector& meshes = m_pMayaFile->GetMeshVector(); CMayaFile::MeshVector::iterator meshIt; CMayaFile::MeshVector::const_iterator meshEnd = meshes.end(); StringVector validNodeVector; // for every groups for(meshIt = meshes.begin(); meshIt != meshEnd; ++meshIt) // For each Maya mesh { std::string meshName(meshIt->GetMeshName()); // verify that it is a valid node if(meshIt->GetPolyFaceVector().size() <= 0 ) continue; validNodeVector.push_back(meshName); // Create the transform node { m_ofs << "createNode transform -n \"" << meshName << "\";" << std::endl; } // Create the shape node { m_ofs << "createNode mesh -n \"" << meshName << "Shape\" -p \"" << meshName << "\";" << std::endl; m_ofs << "\tsetAttr -k off \".v\";" << std::endl; // what is that ? //m_ofs << "\tsetAttr \".vir\" yes;" << std::endl; //m_ofs << "\tsetAttr \".vif\" yes;" << std::endl; } // Texture coordinates { Vector3DVector& textureCoords = meshIt->GetTextureCoordVector(); Vector3DVector::iterator textureCoordIt; Vector3DVector::const_iterator textureCoordEnd = textureCoords.end(); if(textureCoords.size() > 0) { uint lastFaceIndex = meshIt->GetPolyFaceVector().size() - 1; // Connection on the shading groups : instObjectGroups m_ofs << "\tsetAttr -s 2 \".iog[0].og\";" << std::endl; // I think the 2 is for the initialShadingGroup + assigned shadingGroup m_ofs << "\tsetAttr \".iog[0].og[0].gcl\" -type \"componentList\" 0;" << std::endl; m_ofs << "\tsetAttr \".iog[0].og[1].gcl\" -type \"componentList\" 1 \"f[0:" << lastFaceIndex << "]\";" << std::endl; // Texture coordinates m_ofs << "\tsetAttr \".uvst[0].uvsn\" -type \"string\" \"map1\";" << std::endl; // for a cube : 30 : 60 m_ofs << "\tsetAttr -s " << textureCoords.size() << " \".uvst[0].uvsp[0:" << textureCoords.size()-1 << "]\" -type \"float2\" "; int i = 0; for(textureCoordIt = textureCoords.begin(); textureCoordIt != textureCoordEnd; ++textureCoordIt) // for each UV coord { m_ofs << (*textureCoordIt)[0] << " " << (*textureCoordIt)[1] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; m_ofs << "\tsetAttr \".cuvs\" -type \"string\" \"map1\";" << std::endl; m_ofs << "\tsetAttr \".dcc\" -type \"string\" \"Ambient+Diffuse\";" << std::endl; } } //m_ofs.setf(std::ios::showpoint); //m_ofs.precision(6); // Vertex positions { Vector3DVector& vertices = meshIt->GetVertexPositionVector(); Vector3DVector::iterator vertexIt; Vector3DVector::const_iterator vertexEnd = vertices.end(); OBJ_ASSERT(vertices.size() > 0); if(vertices.size() > 0) // if vertex vector is not empty { m_ofs << "\tsetAttr -s " << vertices.size() << " \".vt[0:" << vertices.size()-1 << "]\" "; int i = 0; for(vertexIt = vertices.begin(); vertexIt != vertexEnd; ++vertexIt) // for each vertex position { m_ofs << (*vertexIt)[0] << " " << (*vertexIt)[1] << " " << (*vertexIt)[2] << " "; if(!(i++%2)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Edges { Vector3DVector& edgeVector = meshIt->GetEdgeVector(); Vector3DVector::iterator edgeIt; Vector3DVector::const_iterator edgeEnd = edgeVector.end(); OBJ_ASSERT(edgeVector.size() > 0); if(edgeVector.size() > 0) // if edge vector is not empty { m_ofs << "\tsetAttr -s " << edgeVector.size() << " \".ed[0:" << edgeVector.size()-1 << "]\" "; int i = 0; for(edgeIt = edgeVector.begin(); edgeIt != edgeEnd; ++edgeIt) // for each edge (2 index to vertex) { m_ofs << (*edgeIt)[0] << " " << (*edgeIt)[1] << " " << (*edgeIt)[2] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Normals (4 per face - 1 per vertex per face) { Vector3DVector& normals = meshIt->GetNormalVector(); Vector3DVector::iterator normalIt; Vector3DVector::const_iterator normalEnd = normals.end(); if(normals.size() > 0) { m_ofs << "\tsetAttr -s " << normals.size() << " \".n[0:" << normals.size()-1 << "]\" -type \"float3\" " << std::endl; int i = 0; for(normalIt = normals.begin(); normalIt != normalEnd; ++normalIt) // for each normal { m_ofs << (*normalIt)[0] << " " << (*normalIt)[1] << " " << (*normalIt)[2] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Faces { CMayaFile::CMesh::PolyFaceVector& polyFaces = meshIt->GetPolyFaceVector(); CMayaFile::CMesh::PolyFaceVector::iterator polyFaceIt; CMayaFile::CMesh::PolyFaceVector::const_iterator polyFaceEnd = polyFaces.end(); OBJ_ASSERT(polyFaces.size() > 0); m_ofs << "\tsetAttr -s " << polyFaces.size() << " \".fc[0:" << polyFaces.size()-1 << "]\" -type \"polyFaces\" " << std::endl; for(polyFaceIt = polyFaces.begin(); polyFaceIt != polyFaceEnd; ++polyFaceIt) // for each face { CMayaFile::CMesh::CPolyFace::CFace face = polyFaceIt->GetFace(); CMayaFile::CMesh::CPolyFace::CMu mu = polyFaceIt->GetMu(); uint edgeCount = face.EdgeCount(); uint uvCount = mu.UvCount(); // Face std::vector<int>& edgeVector = face.GetEdgeVector(); std::vector<int>::iterator edgeIt; std::vector<int>::const_iterator edgeEnd = edgeVector.end(); // Mu std::vector<uint>& uvVector = mu.GetUvVector(); std::vector<uint>::iterator uvIt; std::vector<uint>::const_iterator uvEnd = uvVector.end(); // if edge vector not empty if(edgeVector.size() > 0) { m_ofs << "\t\tf " << edgeCount; for(edgeIt = edgeVector.begin(); edgeIt != edgeEnd; ++edgeIt ) // for each indexed edge { m_ofs << " " << (*edgeIt); } if(polyFaceIt+1 == polyFaceEnd && uvVector.size() == 0) // last face and no "mu" m_ofs << " ;" << std::endl; else m_ofs << std::endl; } // if uv vector not empty if(uvVector.size() > 0) { m_ofs << "\t\tmu " << "0 " << uvCount; for(uvIt = uvVector.begin(); uvIt != uvEnd; ++uvIt ) // for each indexed UV coord { m_ofs << " " << (*uvIt); } if(polyFaceIt+1 == polyFaceEnd) // last face and no "mu" m_ofs << " ;" << std::endl; else m_ofs << std::endl; } } } } // Add shading groups / material / texture here CMtlFile* pMtlFile = m_pMayaFile->GetMaterialFile(); OBJ_ASSERT(pMtlFile); if(!pMtlFile) return true; CMtlFile::MaterialMap& materials = pMtlFile->GetMaterialMap(); CMtlFile::MaterialMap::iterator materialIt; CMtlFile::MaterialMap::const_iterator materialEnd = materials.end(); uint materialCount = materials.size(); uint textureCount = 0; uint materialID = 0; m_ofs << "createNode lightLinker -n \"lightLinker1\";" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".lnk\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "createNode displayLayerManager -n \"layerManager\";" << std::endl; m_ofs << "createNode displayLayer -n \"defaultLayer\";" << std::endl; m_ofs << "createNode renderLayerManager -n \"renderLayerManager\";" << std::endl; m_ofs << "createNode renderLayer -n \"defaultRenderLayer\";" << std::endl; m_ofs << "createNode renderLayer -s -n \"globalRender\";" << std::endl; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; OBJ_ASSERT(materialIt->first == pMaterial->GetMaterialName()); //MayaStringCheck(materialName); // TODO : look if we already created this material std::stringstream materialIDSS; materialIDSS << materialID; // Create the shading group m_ofs << "createNode shadingEngine -n \"" << shadingGroupName << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; // MaterialInfo, 1 per material (shading group) materialIDSS.str(""); materialIDSS << (materialID+1); // starts at 1, the first one is reserved ? m_ofs << "createNode materialInfo -n \"materialInfo" << materialIDSS.str() << "\";" << std::endl; // what is that ? 2 groupID per mesh materialIDSS.str(""); materialIDSS << (materialID*3+2); // starts at 2 m_ofs << "createNode groupId -n \"groupId" << materialIDSS.str() << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; materialIDSS.str(""); materialIDSS << (materialID*3+3); m_ofs << "createNode groupId -n \"groupId" << materialIDSS.str() << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; int number = 1; // TODO : increment std::string materialName(shadingGroupName + "1"); // TODO : support more type of material : phong, blinn, etc // Create the material m_ofs << "createNode phong -n \"" << materialName << "\";" << std::endl; // Phong by default m_ofs << "\tsetAttr \".cp\" 2.059999942779541;" << std::endl; // what is this number ? // Texture Map if(pMaterial->HasTexMap()) { // Create the texture file std::string textureName(materialName + "F"); m_ofs << "createNode file -n \"" << textureName << "\";" << std::endl; m_ofs << "\tsetAttr \".ftn\" -type \"string\" \"" << pMaterial->GetTexMap() << "\";" << std::endl; // Create the place2dTexture placement std::string place2dTextureName(materialName + "P2D"); m_ofs << "createNode place2dTexture -n \"" << place2dTextureName << "\";" << std::endl; ++textureCount; } ++materialID; } m_ofs << "select -ne :time1;" << std::endl; m_ofs << "\tsetAttr \".o\" 1;" << std::endl; m_ofs << "select -ne :renderPartition;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".st\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "select -ne :renderGlobalsList1;" << std::endl; m_ofs << "select -ne :defaultShaderList1;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".s\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "select -ne :postProcessList1;" << std::endl; m_ofs << "\tsetAttr -s 2 \".p\";" << std::endl; m_ofs << "select -ne :defaultRenderUtilityList1;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".u\";" << std::endl; // not sure about that : groups m_ofs << "select -ne :lightList1;" << std::endl; m_ofs << "select -ne :defaultTextureList1;" << std::endl; m_ofs << "\tsetAttr -s " << textureCount << " \".tx\";" << std::endl; // number of texture file m_ofs << "select -ne :initialShadingGroup;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".dsm\";" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".gn\";" << std::endl; m_ofs << "select -ne :initialParticleSE;" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; m_ofs << "select -ne :hardwareRenderGlobals;" << std::endl; m_ofs << "\taddAttr -ci true -sn \"ani\" -ln \"animation\" -bt \"ANIM\" -min 0 -max 1 -at \"bool\";" << std::endl; m_ofs << "\tsetAttr \".fn\" -type \"string\" \"%s.%e\";" << std::endl; m_ofs << "\tsetAttr \".ctrs\" 256;" << std::endl; m_ofs << "\tsetAttr \".btrs\" 512;" << std::endl; m_ofs << "\tsetAttr -k on \".ani\";" << std::endl; m_ofs << "select -ne :defaultHardwareRenderGlobals;" << std::endl; m_ofs << "\tsetAttr \".fn\" -type \"string\" \"im\";" << std::endl; m_ofs << "\tsetAttr \".res\" -type \"string\" \"ntsc_4d 646 485 1.333\";" << std::endl; // Useless commands : //m_ofs << "select -ne :ikSystem;" << std::endl; //m_ofs << "\tsetAttr -s 3 \".sol\";" << std::endl; //connectAttr "myMaterial.mwc" "swordShape.iog.og[1].gco"; // wireframe color StringVector vecShadingGroup; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; // hack : Assuming 1 shading group per mesh vecShadingGroup.push_back(shadingGroupName); } StringVector::iterator nodeIt; StringVector::const_iterator nodeEnd = validNodeVector.end(); StringVector vecMeshName; // for every groups for(meshIt = meshes.begin(); meshIt != meshEnd; ++meshIt) // for each mesh { std::string meshName(meshIt->GetMeshName()); vecMeshName.push_back(meshName); } StringVector::iterator meshNameIt; StringVector::const_iterator meshNameEnd = vecMeshName.end(); uint groupID = 2; for(nodeIt = validNodeVector.begin(); nodeIt != nodeEnd; ++nodeIt) { uint sgIndex = nodeIt - validNodeVector.begin(); if(sgIndex > vecShadingGroup.size()-1) continue; std::string shadingGroupName = vecShadingGroup[sgIndex]; // 3 groupID per mesh std::stringstream groupIDss; groupIDss << groupID+1; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".id\" \"" << (*nodeIt) << "Shape.iog.og[1].gid\";" << std::endl; groupIDss.str(""); groupIDss << groupID; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".id\" \"" << (*nodeIt) << "Shape.ciog.cog[0].cgid\";" << std::endl; groupID += 3; // the first one is always hidden } m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[0].llnk\";" << std::endl; m_ofs << "connectAttr \":initialShadingGroup.msg\" \"lightLinker1.lnk[0].olnk\";" << std::endl; m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[1].llnk\";" << std::endl; m_ofs << "connectAttr \":initialParticleSE.msg\" \"lightLinker1.lnk[1].olnk\";" << std::endl; uint lightLinkerIndex = 2; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::stringstream ssLightLinkerIndex; ssLightLinkerIndex << lightLinkerIndex; m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[" << ssLightLinkerIndex.str() << "].llnk\";" << std::endl; m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \"lightLinker1.lnk[" << ssLightLinkerIndex.str() << "].olnk\";" << std::endl; lightLinkerIndex++; } m_ofs << "connectAttr \"layerManager.dli[0]\" \"defaultLayer.id\";" << std::endl; m_ofs << "connectAttr \"renderLayerManager.rlmi[0]\" \"defaultRenderLayer.rlid\";" << std::endl; uint sgIndex = 0; // shading group index for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; //MayaStringCheck(materialName); std::string materialName(shadingGroupName + "1"); // Connection Material.outColor -> ShadingGroup.ss m_ofs << "connectAttr \"" << materialName << ".oc\" \"" << shadingGroupName << ".ss\";" << std::endl; std::stringstream ssSgIndex; ssSgIndex << sgIndex*3+3; m_ofs << "connectAttr \"groupId" << ssSgIndex.str() << ".msg\" \"" << shadingGroupName << ".gn\" -na;" << std::endl; // Assign Shading group to the Mesh first m_ofs << "connectAttr \"" << vecMeshName[sgIndex] << "Shape.iog.og[1]\" \"" << shadingGroupName << ".dsm\" -na;" << std::endl; // Material information ssSgIndex.str(""); ssSgIndex << (sgIndex+1); // starts at 1 m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".sg\";" << std::endl; m_ofs << "connectAttr \"" << materialName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".m\";" << std::endl; if(pMaterial->HasTexMap()) { // Connect texture std::string textureName(materialName + "F"); m_ofs << "connectAttr \"" << textureName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".t\" -na;" << std::endl; m_ofs << "connectAttr \"" << textureName << ".oc\" \"" << materialName << ".c\";" << std::endl; // Connect place2D texture std::string place2dTextureName(materialName + "P2D"); m_ofs << "connectAttr \"" << place2dTextureName << ".c\" \"" << textureName << ".c\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".tf\" \"" << textureName << ".tf\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".rf\" \"" << textureName << ".rf\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".s\" \"" << textureName << ".s\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".wu\" \"" << textureName << ".wu\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".wv\" \"" << textureName << ".wv\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".re\" \"" << textureName << ".re\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".of\" \"" << textureName << ".of\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".r\" \"" << textureName << ".ro\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".o\" \"" << textureName << ".uv\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".ofs\" \"" << textureName << ".fs\";" << std::endl; } ++sgIndex; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; m_ofs << "connectAttr \"" << shadingGroupName << ".pa\" \":renderPartition.st\" -na;" << std::endl; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \":defaultShaderList1.s\" -na;" << std::endl; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for place texture 2d { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::string place2dTextureName(shadingGroupName + "1P2D" ); // find a better way if(pMaterial->HasTexMap()) m_ofs << "connectAttr \"" << place2dTextureName << ".msg\" \":defaultRenderUtilityList1.u\" -na;" << std::endl; } // Light linker m_ofs << "connectAttr \"lightLinker1.msg\" \":lightList1.ln\" -na;" << std::endl; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each textures { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::string textureName(shadingGroupName + "1F" ); // find a better way if(pMaterial->HasTexMap()) m_ofs << "connectAttr \"" << textureName << ".msg\" \":defaultTextureList1.tx\" -na;" << std::endl; } for(meshNameIt = vecMeshName.begin(); meshNameIt != meshNameEnd; ++meshNameIt) // mesh -> initial shading group { // Assign Initial shading group to the Mesh second m_ofs << "connectAttr \"" << (*meshNameIt) << "Shape.ciog.cog[0]\" \":initialShadingGroup.dsm\" -na;" << std::endl; } groupID = 2; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each SG : group ID 2,5,8,... { std::stringstream groupIDss; groupIDss << groupID; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".msg\" \":initialShadingGroup.gn\" -na;" << std::endl; groupID += 3; } m_ofs << "// End of " << fileNameOnly; m_ofs.close(); MSG_DEBUG("Done."); return true; }
bool Object3D::load(const std::string& path) { if (loaded) { std::cerr << "Object already loaded" << std::endl; return false; } objLoader objData; if (!objData.load(const_cast<char*>(path.c_str()))) { std::cerr << "Object cannot be loaded" << std::endl; return false; } subObjects.clear(); subObjects.assign(objData.materialCount,SubObject()); for (int i = 0; i < objData.faceCount; ++i) { const obj_face& face = *objData.faceList[i]; if (face.material_index >= 0) subObjects[face.material_index].nbVertices += 3; } for (size_t i = 0; i < subObjects.size(); ++i) { if (subObjects[i].nbVertices == 0) continue; subObjects[i].vertices = new float[subObjects[i].nbVertices * 3]; subObjects[i].normals = new float[subObjects[i].nbVertices * 3]; subObjects[i].texCoords = new float[subObjects[i].nbVertices * 2]; } size_t* currentVertexIndex = new size_t[subObjects.size()]; for (size_t i = 0; i < subObjects.size(); ++i) currentVertexIndex[i] = 0; for (int i = 0; i < objData.faceCount; ++i) { const obj_face& face = *objData.faceList[i]; int currentObj = face.material_index; if (currentObj < 0) continue; for (size_t j = 0; j < 3; ++j) { int index = face.vertex_index[j]; if (index >= 0) { subObjects[currentObj].vertices[currentVertexIndex[currentObj] * 3 + 0] = static_cast<float>(objData.vertexList[index]->e[0]); subObjects[currentObj].vertices[currentVertexIndex[currentObj] * 3 + 1] = static_cast<float>(objData.vertexList[index]->e[1]); subObjects[currentObj].vertices[currentVertexIndex[currentObj] * 3 + 2] = static_cast<float>(objData.vertexList[index]->e[2]); } index = face.normal_index[j]; if (index >= 0) { subObjects[currentObj].normals[currentVertexIndex[currentObj] * 3 + 0] = static_cast<float>(objData.normalList[index]->e[0]); subObjects[currentObj].normals[currentVertexIndex[currentObj] * 3 + 1] = static_cast<float>(objData.normalList[index]->e[1]); subObjects[currentObj].normals[currentVertexIndex[currentObj] * 3 + 2] = static_cast<float>(objData.normalList[index]->e[2]); } index = face.texture_index[j]; if (index >= 0) { subObjects[currentObj].texCoords[currentVertexIndex[currentObj] * 2 + 0] = static_cast<float>(objData.textureList[index]->e[0]); subObjects[currentObj].texCoords[currentVertexIndex[currentObj] * 2 + 1] = static_cast<float>(objData.textureList[index]->e[1]); } ++currentVertexIndex[currentObj]; } } delete[] currentVertexIndex; for (size_t i = 0; i < subObjects.size(); ++i) { const obj_material& mat = *objData.materialList[i]; std::string textureName(mat.texture_filename); int pos = textureName.find(".bmp") + 4; loadTexture(subObjects[i].textureID,textureName.substr(0,pos).c_str(),GL_RGB,GL_CLAMP,true); } std::cout << "Object sucessfully loaded from " << path << std::endl; std::cout << "Nb of sub-objects : " << subObjects.size() << std::endl; for (size_t i = 0; i < subObjects.size(); ++i) std::cout << "Nb of faces of sub-object " << i << " : " << subObjects[i].nbVertices / 3 << std::endl; std::cout << "DONE" << std::endl; loaded = true; return true; }