void ObjLoader::addRawVerticePart (ObjMesh *mesh, FaceList &faces, int num) { std::vector<Face *>::iterator it = faces.begin(); // Etape 1 : construire la liste des faces std::vector<int> triangleBuffer; std::vector<int> quadBuffer; std::vector<float> glVertexBuffer; int reservedSize = faces.size(); triangleBuffer.reserve (reservedSize); quadBuffer.reserve (reservedSize); glVertexBuffer.reserve (3.*reservedSize); int indexVertex = 0; it = faces.begin(); do { VertexObj v1 (*this, (*it)->vertices[0]); VertexObj v2 (*this, (*it)->vertices[1]); VertexObj v3 (*this, (*it)->vertices[2]); glVertexBuffer.push_back (v1.vertex.x); glVertexBuffer.push_back (v1.vertex.y); glVertexBuffer.push_back (v1.vertex.z); glVertexBuffer.push_back (v2.vertex.x); glVertexBuffer.push_back (v2.vertex.y); glVertexBuffer.push_back (v2.vertex.z); glVertexBuffer.push_back (v3.vertex.x); glVertexBuffer.push_back (v3.vertex.y); glVertexBuffer.push_back (v3.vertex.z); int index1 = indexVertex++; int index2 = indexVertex++; int index3 = indexVertex++; if ( (*it)->type == TRIANGLE) { triangleBuffer.push_back (index1); triangleBuffer.push_back (index2); triangleBuffer.push_back (index3); } else { VertexObj v4 (*this, (*it)->vertices[3]); glVertexBuffer.push_back (v4.vertex.x); glVertexBuffer.push_back (v4.vertex.y); glVertexBuffer.push_back (v4.vertex.z); int index4 = indexVertex++; quadBuffer.push_back (index1); quadBuffer.push_back (index2); quadBuffer.push_back (index3); quadBuffer.push_back (index4); } delete (*it); } while (++it != faces.end()); // etape 2 : construire le Mesh pour le renderer SmoothGroup *theSmoothGroup = new SmoothGroup (glVertexBuffer, triangleBuffer, quadBuffer, false, false); mesh->addSmoothGroup (theSmoothGroup); // On nettoie tout ! glVertexBuffer.erase (glVertexBuffer.begin(), glVertexBuffer.end()); triangleBuffer.erase (triangleBuffer.begin(), triangleBuffer.end()); quadBuffer.erase (quadBuffer.begin(), quadBuffer.end()); }
bool PolyMesh::convertFacesToGeometry( FaceList faces, GEOMETRY_FIX* geom ) { if ( !faces.size() || !geom ) return false; osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 ); unsigned int i, index=0, firstIndex=0, lastIndex=0; for ( FaceList::iterator itr=faces.begin(); itr!=faces.end(); ++itr ) { Face f = *(*itr); unsigned int size=f._pts.size(); for ( i=0; i<size; ++i ) { if ( i>2 ) { indices->push_back( firstIndex ); indices->push_back( lastIndex ); } indices->push_back( f(i) ); if ( !i ) firstIndex = indices->back(); lastIndex = indices->back(); } } geom->removePrimitiveSet( 0, geom->getPrimitiveSetList().size() ); geom->addPrimitiveSet( indices.get() ); geom->setTexCoordArray( 0, NULL ); // TEMP NormalVisitor::buildNormal( *geom ); geom->dirtyDisplayList(); return true; }
void Brush::restore(const FaceList& faces) { Utility::deleteAll(m_faces); FaceList::const_iterator it, end; for (it = faces.begin(), end = faces.end(); it != end; ++it) { Face* face = *it; face->setBrush(this); m_faces.push_back(face); } rebuildGeometry(); }
Brush::Brush(const BBoxf& worldBounds, bool forceIntegerFacePoints, const FaceList& faces) : MapObject(), m_geometry(NULL), m_worldBounds(worldBounds), m_forceIntegerFacePoints(forceIntegerFacePoints) { init(); FaceList::const_iterator it, end; for (it = faces.begin(), end = faces.end(); it != end; ++it) { Face* face = *it; face->setBrush(this); m_faces.push_back(face); } rebuildGeometry(); }
void CustomSmileyManager::loadSmileys( int groupIndex ) { // clear the table first for(int row = 0; row < tblFaceList->numRows(); row++){ tblFaceList->removeRow(row); } tblFaceList->setNumRows(0); TQString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/"; if(groupIndex>0) dir += (m_Config->groupName( groupIndex) + "/"); FaceList list = m_Config->groupMembers( groupIndex ); int row = 0; if(list.size()){ tblFaceList->setNumRows(list.size()); tblFaceList->horizontalHeader()->setLabel( 0, i18n("No." ) ); tblFaceList->horizontalHeader()->setLabel( 1, i18n("Smiley" ) ); tblFaceList->horizontalHeader()->setLabel( 2, i18n("Shortcut" ) ); for( FaceList::Iterator it = list.begin(); it != list.end(); ++it){ //tblFaceList->setText(row, 0, TQString::number( row + 1)); tblFaceList->setItem(row, 0, new TQTableItem(tblFaceList, TQTableItem::Never, TQString::number(row + 1))); TQPixmap *pixmap = new TQPixmap(dir + (*it).fixed()); CustomItem *item = new CustomItem(tblFaceList, (*it).tip(), *pixmap); tblFaceList->setItem(row, 1, item); CustomItem *itemSC = new CustomItem(tblFaceList, (*it).shortcut() ); tblFaceList->setItem(row, 2, itemSC); tblFaceList->setRowHeight(row, pixmap->width() + 2); delete pixmap; row++; } tblFaceList->setColumnWidth(0, 20); tblFaceList->setColumnWidth(1, tblFaceList->visibleWidth() - 20 - 50 ); } }
void ObjLoader::addVerticePart (ObjMesh *mesh, FaceList &faces, int num) { std::vector<Face *>::iterator it = faces.begin(); std::map<VertexObj, int> vertexBuffer; // Etape 1 : construire la liste des sommets (vert) uniques int addedVerticesNumber = 0; do { VertexObj v1 (*this, (*it)->vertices[0]); vertexBuffer[v1] = ++addedVerticesNumber; VertexObj v2 (*this, (*it)->vertices[1]); vertexBuffer[v2] = ++addedVerticesNumber; VertexObj v3 (*this, (*it)->vertices[2]); vertexBuffer[v3] = ++addedVerticesNumber; if ( (*it)->type == QUAD) { VertexObj v4 (*this, (*it)->vertices[3]); vertexBuffer[v4] = ++addedVerticesNumber; } } while (++it != faces.end()); // Etape 2 : numeroter les sommets int newnumber = 0; for (std::map<VertexObj, int>::iterator vm = vertexBuffer.begin(); vm != vertexBuffer.end(); ++vm) vm->second = newnumber++; // Etape 3 : construire la liste des faces std::vector<int> triangleBuffer; std::vector<int> quadBuffer; int reservedSize = faces.size(); triangleBuffer.reserve (reservedSize); quadBuffer.reserve (reservedSize); it = faces.begin(); do { VertexObj v1 (*this, (*it)->vertices[0]); VertexObj v2 (*this, (*it)->vertices[1]); VertexObj v3 (*this, (*it)->vertices[2]); int index1 = vertexBuffer.find (v1)->second; int index2 = vertexBuffer.find (v2)->second; int index3 = vertexBuffer.find (v3)->second; if ( (*it)->type == TRIANGLE) { triangleBuffer.push_back (index1); triangleBuffer.push_back (index2); triangleBuffer.push_back (index3); } else { VertexObj v4 (*this, (*it)->vertices[3]); int index4 = vertexBuffer.find (v4)->second; quadBuffer.push_back (index1); quadBuffer.push_back (index2); quadBuffer.push_back (index3); quadBuffer.push_back (index4); } delete (*it); } while (++it != faces.end()); // etape4 : construire le tableau de sommet final std::vector<float> glVertexBuffer; for (std::map<VertexObj, int>::iterator vm = vertexBuffer.begin(); vm != vertexBuffer.end(); ++vm) { glVertexBuffer.push_back (vm->first.vertex.x); glVertexBuffer.push_back (vm->first.vertex.y); glVertexBuffer.push_back (vm->first.vertex.z); } // etape 5 : construire le Mesh pour le renderer SmoothGroup *theSmoothGroup = new SmoothGroup (glVertexBuffer, triangleBuffer, quadBuffer, false, false); mesh->addSmoothGroup (theSmoothGroup); // On nettoie tout ! glVertexBuffer.erase (glVertexBuffer.begin(), glVertexBuffer.end()); triangleBuffer.erase (triangleBuffer.begin(), triangleBuffer.end()); quadBuffer.erase (quadBuffer.begin(), quadBuffer.end()); vertexBuffer.erase (vertexBuffer.begin(), vertexBuffer.end()); }