コード例 #1
0
ファイル: MapWriter.cpp プロジェクト: ProPuke/TrenchBroom
        void MapWriter::writeObjectsToStream(const Model::EntityList& pointEntities, const Model::BrushList& brushes, std::ostream& stream) {
            assert(stream.good());
            stream.unsetf(std::ios::floatfield);

            Model::Entity* worldspawn = NULL;
            
            // group the brushes by their containing entities
            typedef std::map<Model::Entity*, Model::BrushList> EntityBrushMap;
            EntityBrushMap entityToBrushes;
            
            Model::BrushList::const_iterator brushIt, brushEnd;
            for (brushIt = brushes.begin(), brushEnd = brushes.end(); brushIt != brushEnd; ++brushIt) {
                Model::Brush& brush = **brushIt;
                Model::Entity& entity = *brush.entity();
                entityToBrushes[&entity].push_back(&brush);
                if (entity.worldspawn())
                    worldspawn = &entity;
            }
            
            // write worldspawn first
            if (worldspawn != NULL) {
                Model::BrushList& brushList = entityToBrushes[worldspawn];
                writeEntityHeader(*worldspawn, stream);
                for (brushIt = brushList.begin(), brushEnd = brushList.end(); brushIt != brushEnd; ++brushIt) {
                    writeBrush(**brushIt, stream);
                }
                writeEntityFooter(stream);
            }
            
            // now write the point entities
            Model::EntityList::const_iterator entityIt, entityEnd;
            for (entityIt = pointEntities.begin(), entityEnd = pointEntities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity& entity = **entityIt;
                writeEntity(entity, stream);
            }

            // finally write the brush entities
            EntityBrushMap::iterator it, end;
            for (it = entityToBrushes.begin(), end = entityToBrushes.end(); it != end; ++it) {
                Model::Entity* entity = it->first;
                if (entity != worldspawn) {
                    Model::BrushList& brushList = it->second;
                    writeEntityHeader(*entity, stream);
                    for (brushIt = brushList.begin(), brushEnd = brushList.end(); brushIt != brushEnd; ++brushIt) {
                        writeBrush(**brushIt, stream);
                    }
                    writeEntityFooter(stream);
                }
            }
        }
コード例 #2
0
 SnapBrushVerticesCommand::Ptr SnapBrushVerticesCommand::snap(const Model::BrushList& brushes, const size_t snapTo) {
     Model::BrushVerticesMap brushVertices;
     Vec3::List vertexPositions;
     
     Model::BrushList::const_iterator bIt, bEnd;
     Model::Brush::VertexList::const_iterator vIt, vEnd;
     
     for (bIt = brushes.begin(), bEnd = brushes.end(); bIt != bEnd; ++bIt) {
         Model::Brush* brush = *bIt;
         const Model::Brush::VertexList vertices = brush->vertices();
         for (vIt = vertices.begin(), vEnd = vertices.end(); vIt != vEnd; ++vIt) {
             const Model::BrushVertex* vertex = *vIt;
             brushVertices[brush].push_back(vertex->position());
             vertexPositions.push_back(vertex->position());
         }
     }
     
     return Ptr(new SnapBrushVerticesCommand(brushes, brushVertices, vertexPositions, snapTo));
 }
コード例 #3
0
 void SnapBrushVerticesCommand::doSelectNewHandlePositions(VertexHandleManager& manager, const Model::BrushList& brushes) {
     const Model::BrushSet brushSet(brushes.begin(), brushes.end());
     manager.reselectVertexHandles(brushSet, m_newVertexPositions, 0.01);
 }