Beispiel #1
0
        void EntityRenderer::validateBounds(RenderContext& context) {
            delete m_boundsVertexArray;
            m_boundsVertexArray = NULL;

            Model::EntityList entities;
            Model::EntitySet::iterator entityIt, entityEnd;
            for (entityIt = m_entities.begin(), entityEnd = m_entities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity* entity = *entityIt;
                if (context.filter().entityVisible(*entity))
                    entities.push_back(entity);
            }

            if (entities.empty())
                return;

            SetVboState mapVbo(m_boundsVbo, Vbo::VboMapped);

            if (m_overrideBoundsColor) {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f());
                writeBounds(context, entities);
            } else {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f(),
                                                      Attribute::color4f());
                writeColoredBounds(context, entities);
            }

            m_boundsValid = true;
        }
Beispiel #2
0
        void EntityRenderer::writeColoredBounds(RenderContext& context, const Model::EntityList& entities) {
            if (entities.empty())
                return;

            Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences();
            Vec3f::List vertices(24);

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const BBoxf& bounds = entity->bounds();
                const Model::EntityDefinition* definition = entity->definition();
                Color entityColor;
                if (definition != NULL) {
                    entityColor = definition->color();
                    entityColor[3] = prefs.getColor(Preferences::EntityBoundsColor).a();
                } else {
                    entityColor = prefs.getColor(Preferences::EntityBoundsColor);
                }

                bounds.vertices(vertices);
                for (unsigned int j = 0; j < vertices.size(); j++) {
                    m_boundsVertexArray->addAttribute(vertices[j]);
                    m_boundsVertexArray->addAttribute(entityColor);
                }
            }
        }
 void SnapshotCommand::restoreSnapshots(const Model::EntityList& entities) {
     assert(m_entities.size() == entities.size());
     
     if (entities.empty())
         return;
     
     Model::EntityDefinitionManager& definitionManager = document().definitionManager();
     
     for (unsigned int i = 0; i < entities.size(); i++) {
         Model::Entity& entity = *entities[i];
         EntitySnapshot& snapshot = *m_entities[entity.uniqueId()];
         snapshot.restore(entity);
         
         const Model::PropertyValue* classname = entity.classname();
         if (classname != NULL)
             entity.setDefinition(definitionManager.definition(*classname));
     }
 }
Beispiel #4
0
        void EntityRenderer::removeEntities(const Model::EntityList& entities) {
            if (entities.empty())
                return;

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                m_modelRenderers.erase(entity);
                m_classnameRenderer->removeString(entity);
                m_entities.erase(entity);
            }
            m_boundsValid = false;
        }
Beispiel #5
0
 bool MapParser::parseEntities(const BBox& worldBounds, Model::EntityList& entities) {
     size_t oldSize = entities.size();
     try {
         Model::Entity* entity = NULL;
         while ((entity = parseEntity(worldBounds, NULL)) != NULL)
             entities.push_back(entity);
         return !entities.empty();
     } catch (MapParserException e) {
         Utility::deleteAll(entities, oldSize);
         m_tokenizer.reset();
         return false;
     }
 }
Beispiel #6
0
        void EntityRenderer::writeBounds(RenderContext& context, const Model::EntityList& entities) {
            if (entities.empty())
                return;

            Vec3f::List vertices(24);
            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const BBoxf& bounds = entity->bounds();
                bounds.vertices(vertices);

                for (unsigned int j = 0; j < vertices.size(); j++)
                    m_boundsVertexArray->addAttribute(vertices[j]);
            }
        }
Beispiel #7
0
        void EntityRenderer::addEntities(const Model::EntityList& entities) {
            if (entities.empty())
                return;

            EntityModelRendererManager& modelRendererManager = m_document.sharedResources().modelRendererManager();

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const String* classname = entity->classname();
                if (classname == NULL)
                    classname = &Model::Entity::NoClassnameValue;
                if (classname != NULL) {
                    EntityModelRenderer* renderer = modelRendererManager.modelRenderer(*entity, m_document.searchPaths());
                    if (renderer != NULL)
                        m_modelRenderers[entity] = CachedEntityModelRenderer(renderer, *classname);

                    m_classnameRenderer->addString(entity, *classname, Text::TextAnchor::Ptr(new EntityClassnameAnchor(*entity, renderer)));
                }
            }

            m_entities.insert(entities.begin(), entities.end());
            m_boundsValid = false;
        }
 void SnapshotCommand::makeSnapshots(const Model::EntityList& entities) {
     for (unsigned int i = 0; i < entities.size(); i++) {
         Model::Entity& entity = *entities[i];
         m_entities[entity.uniqueId()] = new EntitySnapshot(entity);
     }
 }