Exemplo n.º 1
0
void InfoFileExporter::writeLayerNames()
{
    // Open a "Layers" block
    _stream << "\t" << InfoFile::LAYERS << std::endl;
    _stream << "\t{" << std::endl;

    // Local helper to traverse the layers
    class LayerNameExporter :
        public scene::ILayerSystem::Visitor
    {
    private:
        // Stream to write to
        std::ostream& _os;
    public:
        // Constructor
        LayerNameExporter(std::ostream& os) :
            _os(os)
        {}

        // Required visit function
        void visit(int layerID, const std::string& layerName)
        {
            _os << "\t\t" << InfoFile::LAYER << " " << layerID << " { " << layerName << " }" << std::endl;
        }
    };

    // Visit all layers and write them to the stream
    LayerNameExporter visitor(_stream);
    GlobalLayerSystem().foreachLayer(visitor);

    _stream << "\t}" << std::endl;
}
Exemplo n.º 2
0
scene::INodePtr BrushModuleClass::createBrush()
{
    scene::INodePtr node(new BrushNode);

    // Move it to the active layer
    node->moveToLayer(GlobalLayerSystem().getActiveLayer());

    return node;
}
Exemplo n.º 3
0
scene::INodePtr Doom3PatchDef2Creator::createPatch()
{
	// The PatchNodeDoom3 constructor takes false == patchDef2
	scene::INodePtr node(new PatchNode(false));

	// Determine the layer patches should be created in
	int layer = GlobalLayerSystem().getActiveLayer();

	// Move it to the first visible layer
	node->moveToLayer(layer);
		
	return node;
}
Exemplo n.º 4
0
void Map::load(const std::string& filename) {
    rMessage() << "Loading map from " << filename << "\n";

    setMapName(filename);

    // Reset all layers before loading the file
    GlobalLayerSystem().reset();
    GlobalSelectionSystem().setSelectedAll(false);

    {
        ScopeTimer timer("map load");

        m_resource = GlobalMapResourceManager().capture(_mapName);
        // greebo: Add the observer, this usually triggers a onResourceRealise() call.
        m_resource->addObserver(*this);

        // Traverse the scenegraph and find the worldspawn
        MapWorldspawnFinder finder;
        GlobalSceneGraph().root()->traverse(finder);
    }

    rMessage() << "--- LoadMapFile ---\n";
    rMessage() << _mapName << "\n";

    rMessage() << GlobalCounters().getCounter(counterBrushes).get() << " brushes\n";
    rMessage() << GlobalCounters().getCounter(counterPatches).get() << " patches\n";
    rMessage() << GlobalCounters().getCounter(counterEntities).get() << " entities\n";

    // Move the view to a start position
    gotoStartPosition();

    // Load the stored map positions from the worldspawn entity
    GlobalMapPosition().loadPositions();
    // Remove them, so that the user doesn't get bothered with them
    GlobalMapPosition().removePositions();

    // Disable the region to make sure
    GlobalRegion().disable();

    // Clear the shaderclipboard, the references are most probably invalid now
    GlobalShaderClipboard().clear();

    // Let the filtersystem update the filtered status of all instances
    GlobalFilterSystem().update();

    // Update the layer control dialog
    ui::LayerControlDialog::Instance().refresh();

    // Clear the modified flag
    setModified(false);
}
Exemplo n.º 5
0
scene::INodePtr Doom3PatchCreator::createPatch()
{
	// Note the true as function argument:
	// this means that patchDef3 = true in the PatchNode constructor.
	scene::INodePtr node(new PatchNode(true));

	// Determine the layer patches should be created in
	int layer = GlobalLayerSystem().getActiveLayer();

	// Move it to the first visible layer
	node->moveToLayer(layer);
		
	return node;
}
Exemplo n.º 6
0
// free all map elements, reinitialize the structures that depend on them
void Map::freeMap() {
    map::PointFile::Instance().clear();

    GlobalSelectionSystem().setSelectedAll(false);
    GlobalSelectionSystem().setSelectedAllComponents(false);

    GlobalShaderClipboard().clear();
    GlobalRegion().clear();

    m_resource->removeObserver(*this);

    // Reset the resource pointer
    m_resource = IMapResourcePtr();

    GlobalLayerSystem().reset();
}
Exemplo n.º 7
0
scene::INodePtr BrushModuleClass::createBrush()
{
	// Determine the first visible layer
	int layer = GlobalLayerSystem().getFirstVisibleLayer();

	if (layer != -1)
	{
		scene::INodePtr node(new BrushNode);
		
		// Move it to the first visible layer
		node->moveToLayer(layer);
		return node;
	}
	
	return scene::INodePtr();
}
void LayerUsageBreakdown::InitialiseVector(LayerUsageBreakdown& bd)
{
	// Start with a reasonably large memory block
	bd.reserve(64);

	// We resize the vector to 0 length, such that each resize() call
	// below will fill the vector with zeros
	bd.resize(0, 0);

	GlobalLayerSystem().foreachLayer([&](int layerId, const std::string& layerName)
	{
		if (layerId >= static_cast<int>(bd.size()))
		{
			bd.resize(layerId+1, 0);
		}
	});
}
Exemplo n.º 9
0
/**
 * Create an instance of the given entity at the given position, and return
 * the Node containing the new entity.
 *
 * @returns: the scene::INodePtr referring to the new entity.
 */
scene::INodePtr createEntityFromSelection(const std::string& name, const Vector3& origin)
{
    // Obtain the structure containing the selection counts
    const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

    IEntityClassPtr entityClass = GlobalEntityClassManager().findOrInsert(name, true);

    // TODO: to be replaced by inheritance-based class detection
    bool isModel = (info.totalCount == 0 && name == "func_static");

    // Some entities are based on the size of the currently-selected primitive(s)
    bool primitivesSelected = info.brushCount > 0 || info.patchCount > 0;

    if (!(entityClass->isFixedSize() || isModel) && !primitivesSelected) {
        throw EntityCreationException(
            (boost::format(_("Unable to create entity %s, no brushes selected.")) % name).str()
        );
    }

    // Get the selection workzone bounds
    AABB workzone = GlobalSelectionSystem().getWorkZone().bounds;

    // Create the new node for the entity
    IEntityNodePtr node(GlobalEntityCreator().createEntity(entityClass));

    GlobalSceneGraph().root()->addChildNode(node);

    // The layer list we're moving the newly created node/subgraph into
    scene::LayerList targetLayers;

    if (entityClass->isFixedSize() || (isModel && !primitivesSelected))
    {
        selection::algorithm::deleteSelection();

        ITransformablePtr transform = Node_getTransformable(node);

        if (transform != 0) {
            transform->setType(TRANSFORM_PRIMITIVE);
            transform->setTranslation(origin);
            transform->freezeTransform();
        }

        GlobalSelectionSystem().setSelectedAll(false);

        // Move the item to the active layer
        targetLayers.insert(GlobalLayerSystem().getActiveLayer());

        Node_setSelected(node, true);
    }
    else // brush-based entity
    {
        // Add selected brushes as children of non-fixed entity
        node->getEntity().setKeyValue("model",
                                      node->getEntity().getKeyValue("name"));

        // Take the selection center as new origin
        Vector3 newOrigin = selection::algorithm::getCurrentSelectionCenter();
        node->getEntity().setKeyValue("origin", string::to_string(newOrigin));

        // If there is an "editor_material" class attribute, apply this shader
        // to all of the selected primitives before parenting them
        std::string material = node->getEntity().getEntityClass()->getAttribute("editor_material").getValue();

        if (!material.empty()) {
            selection::algorithm::applyShaderToSelection(material);
        }

        // If we had primitives to reparent, the new entity should inherit the layer info from them
        if (primitivesSelected)
        {
            scene::INodePtr primitive = GlobalSelectionSystem().ultimateSelected();
            targetLayers = primitive->getLayers();
        }
        else
        {
            // Otherwise move the item to the active layer
            targetLayers.insert(GlobalLayerSystem().getActiveLayer());
        }

        // Parent the selected primitives to the new node
        selection::algorithm::ParentPrimitivesToEntityWalker walker(node);
        GlobalSelectionSystem().foreachSelected(walker);
        walker.reparent();

        // De-select the children and select the newly created parent entity
        GlobalSelectionSystem().setSelectedAll(false);
        Node_setSelected(node, true);
    }

    // Assign the layers - including all child nodes (#2864)
    scene::AssignNodeToLayersWalker layerWalker(targetLayers);
    Node_traverseSubgraph(node, layerWalker);

    // Set the light radius and origin

    if (entityClass->isLight() && primitivesSelected)
    {
        AABB bounds(Doom3Light_getBounds(workzone));
        node->getEntity().setKeyValue("origin",
                                      string::to_string(bounds.getOrigin()));
        node->getEntity().setKeyValue("light_radius",
                                      string::to_string(bounds.getExtents()));
    }

    // Flag the map as unsaved after creating the entity
    GlobalMap().setModified(true);

    // Check for auto-setting key values. TODO: use forEachClassAttribute
    // directly here.
    eclass::AttributeList list = eclass::getSpawnargsWithPrefix(
        *entityClass, "editor_setKeyValue"
    );

    if (!list.empty())
    {
        for (eclass::AttributeList::const_iterator i = list.begin(); i != list.end(); ++i)
        {
            // Cut off the "editor_setKeyValueN " string from the key to get the spawnarg name
            std::string key = i->getName().substr(i->getName().find_first_of(' ') + 1);
            node->getEntity().setKeyValue(key, i->getValue());
        }
    }

    // Return the new node
    return node;
}
Exemplo n.º 10
0
void LayerOrthoContextMenuItem::RemoveFromLayer(int layerID)
{
    GlobalLayerSystem().removeSelectionFromLayer(layerID);
    GlobalMap().setModified(true);
}
Exemplo n.º 11
0
void LayerOrthoContextMenuItem::MoveToLayer(int layerID)
{
    GlobalLayerSystem().moveSelectionToLayer(layerID);
    GlobalMap().setModified(true);
}