예제 #1
0
파일: Map.cpp 프로젝트: Zbyl/DarkRadiant
void Map::onResourceRealise() {
    if (m_resource == NULL) {
        return;
    }

    if (isUnnamed() || !m_resource->load()) {
        // Map is unnamed or load failed, reset map resource node to empty
        m_resource->setNode(NewMapRoot(""));
        MapFilePtr map = Node_getMapFile(m_resource->getNode());

        if (map != NULL) {
            map->save();
        }

        // Rename the map to "unnamed" in any case to avoid overwriting the failed map
        setMapName(_(MAP_UNNAMED_STRING));
    }

    // Take the new node and insert it as map root
    GlobalSceneGraph().setRoot(m_resource->getNode());

    // Associate the Scenegaph with the global RenderSystem
    // This usually takes a while since all editor textures are loaded - display a dialog to inform the user
    {
        ui::ScreenUpdateBlocker blocker(_("Processing..."), _("Loading textures..."), true); // force display

        GlobalSceneGraph().root()->setRenderSystem(boost::dynamic_pointer_cast<RenderSystem>(
            module::GlobalModuleRegistry().getModule(MODULE_RENDERSYSTEM)));
    }

    AutoSaver().clearChanges();

    setValid(true);
}
예제 #2
0
    void redo() {
        if (_redoStack.empty()) {
            rMessage() << "Redo: no redo available" << std::endl;
        }
        else {
            Operation* operation = _redoStack.back();
            rMessage() << "Redo: " << operation->_command << std::endl;

            startUndo();
            trackersRedo();
            operation->_snapshot.restore();
            finishUndo(operation->_command);
            _redoStack.pop_back();

            for (Observers::iterator i = _observers.begin(); i != _observers.end(); /* in-loop */) {
                Observer* observer = *(i++);
                observer->postRedo();
            }

            // Trigger the onPostUndo event on all scene nodes
            PostRedoWalker walker;
            GlobalSceneGraph().root()->traverse(walker);

            GlobalSceneGraph().sceneChanged();
        }
    }
예제 #3
0
void selectAllOfType(const cmd::ArgumentList& args) {
	if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) {
		if (GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace) {
			// Deselect all faces
			GlobalSelectionSystem().setSelectedAllComponents(false);
			// Select all faces carrying the shader selected in the Texture Browser
			Scene_BrushSelectByShader_Component(GlobalSceneGraph(), GlobalTextureBrowser().getSelectedShader());
		}
	}
	else {
		// Find any classnames of selected entities
		EntityGetSelectedClassnamesWalker classnameFinder;
		GlobalSelectionSystem().foreachSelected(classnameFinder);

		// De-select everything
		GlobalSelectionSystem().setSelectedAll(false);

		if (!classnameFinder.getClassnameList().empty()) {
			// Instantiate a selector class
			EntitySelectByClassnameWalker classnameSelector(
				classnameFinder.getClassnameList()
			);

			// Traverse the scenegraph, select all matching the classname list
			Node_traverseSubgraph(GlobalSceneGraph().root(), classnameSelector);
		}
		else {
			Scene_BrushSelectByShader(GlobalSceneGraph(), GlobalTextureBrowser().getSelectedShader());
			Scene_PatchSelectByShader(GlobalSceneGraph(), GlobalTextureBrowser().getSelectedShader());
		}
	}

	SceneChangeNotify();
}
void RadiantSelectionSystem::cancelMove() {

    // Unselect any currently selected manipulators to be sure
    _manipulator->setSelected(false);

    // Tell all the scene objects to revert their transformations
    RevertTransformForSelected walker;
    Node_traverseSubgraph(GlobalSceneGraph().root(), walker);

    _pivotMoving = false;
    pivotChanged();

    // greebo: Deselect all faces if we are in brush and drag mode
    if (Mode() == ePrimitive && ManipulatorMode() == eDrag)
    {
        SelectAllComponentWalker faceSelector(false, SelectionSystem::eFace);
        Node_traverseSubgraph(GlobalSceneGraph().root(), faceSelector);
    }

    if (_undoBegun) {
        // Cancel the undo operation, if one has been begun
        GlobalUndoSystem().cancel();
        _undoBegun = false;
    }

    // Update the views
    SceneChangeNotify();
}
예제 #5
0
파일: select.cpp 프로젝트: chrisglass/ufoai
void Select_SetShader (const std::string& shader)
{
	if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent) {
		Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader);
	}
	Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader);
}
// Add a new conversations entity button
void ConversationDialog::onAddEntity()
{
	// Obtain the entity class object
	IEntityClassPtr eclass =
		GlobalEntityClassManager().findClass(CONVERSATION_ENTITY_CLASS);

    if (eclass)
    {
        // Construct a Node of this entity type
        IEntityNodePtr node(GlobalEntityCreator().createEntity(eclass));

        // Create a random offset
		node->getEntity().setKeyValue(
            "origin", RandomOrigin::generate(128)
        );

        // Insert the node into the scene graph
        assert(GlobalSceneGraph().root());
        GlobalSceneGraph().root()->addChildNode(node);

        // Refresh the widgets
        populateWidgets();
    }
    else
    {
        // conversation entityclass was not found
        gtkutil::MessageBox::ShowError(
			(boost::format(_("Unable to create conversation Entity: class '%s' not found."))
				% CONVERSATION_ENTITY_CLASS).str(),
            GlobalMainFrame().getTopLevelWindow()
        );
    }
}
예제 #7
0
// Deselect or select all the component instances in the scenegraph and notify the manipulator class as well
void RadiantSelectionSystem::setSelectedAllComponents(bool selected) {
	// Select all components in the scene, be it vertices, edges or faces
	GlobalSceneGraph().traverse(SelectAllComponentWalker(selected, SelectionSystem::eVertex));
	GlobalSceneGraph().traverse(SelectAllComponentWalker(selected, SelectionSystem::eEdge));
	GlobalSceneGraph().traverse(SelectAllComponentWalker(selected, SelectionSystem::eFace));

	_manipulator->setSelected(selected);
}
예제 #8
0
/* greebo: This calculates and constructs the pivot point of the selection.
 * It cycles through all selected objects and creates its AABB. The origin point of the AABB
 * is basically the pivot point. Pivot2World is therefore a translation from (0,0,0) to the calculated origin.
 *
 * The pivot point is also snapped to the grid.
 */
void RadiantSelectionSystem::ConstructPivot() const {
	if (!_pivotChanged || _pivotMoving)
		return;

	_pivotChanged = false;

	Vector3 objectPivot;

	if (!nothingSelected()) {
	    {
		// Create a local variable where the aabb information is stored
			AABB bounds;

			// Traverse through the selection and update the <bounds> variable
			if (Mode() == eComponent) {
				GlobalSceneGraph().traverse(BoundsSelectedComponent(bounds));
			}
			else {
				GlobalSceneGraph().traverse(BoundsSelected(bounds));
			}
			// the <bounds> variable now contains the AABB of the selection, retrieve the origin
			objectPivot = bounds.origin;
		}

		// Snap the pivot point to the grid
		vector3_snap(objectPivot, GlobalGrid().getGridSize());

		// The pivot2world matrix is just a translation from the world origin (0,0,0) to the object pivot
		_pivot2world = Matrix4::getTranslation(objectPivot);

		// Only rotation and scaling need further calculations
		switch (_manipulatorMode) {
			case eTranslate:
				break;
			case eRotate:
				if (Mode() == eComponent) {
					matrix4_assign_rotation_for_pivot(_pivot2world, _componentSelection.back());
				}
				else {
					matrix4_assign_rotation_for_pivot(_pivot2world, _selection.back());
				}
				break;
			case eScale:
				if (Mode() == eComponent) {
					matrix4_assign_rotation_for_pivot(_pivot2world, _componentSelection.back());
				}
				else {
					matrix4_assign_rotation_for_pivot(_pivot2world, _selection.back());
				}
				break;
			default:
				break;
		} // switch
	}
}
예제 #9
0
	void TextureOverviewDialog::onSelectionChanged (GtkWidget* widget, TextureOverviewDialog* self)
	{
		self->_selectedTexture = gtkutil::TreeModel::getSelectedString(self->_selection, TEXTUREOVERVIEW_NAME);
		GlobalSelectionSystem().setSelectedAllComponents(false);
		GlobalSelectionSystem().setSelectedAll(false);
		if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) {
			Scene_BrushSelectByShader_Component(GlobalSceneGraph(), self->_selectedTexture);
		} else {
			Scene_BrushSelectByShader(GlobalSceneGraph(), self->_selectedTexture);
		}
	}
예제 #10
0
void Selection_SnapToGrid (void)
{
	StringOutputStream command;
	command << "snapSelected -grid " << GlobalGrid().getGridSize();
	UndoableCommand undo(command.toString());

	if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) {
		GlobalSceneGraph().traverse(ComponentSnappableSnapToGridSelected(GlobalGrid().getGridSize()));
	} else {
		GlobalSceneGraph().traverse(SnappableSnapToGridSelected(GlobalGrid().getGridSize()));
	}
}
예제 #11
0
파일: Map.cpp 프로젝트: Zbyl/DarkRadiant
void Map::exportSelected(std::ostream& out)
{
    MapFormatPtr format = getFormat();

    IMapWriterPtr writer = format->getMapWriter();

    // Create our main MapExporter walker for traversal
    MapExporter exporter(*writer, GlobalSceneGraph().root(), out);

    // Pass the traverseSelected function and start writing selected nodes
    exporter.exportMap(GlobalSceneGraph().root(), traverseSelected);
}
// Deselect or select all the component instances in the scenegraph and notify the manipulator class as well
void RadiantSelectionSystem::setSelectedAllComponents(bool selected) {
    // Select all components in the scene, be it vertices, edges or faces
    SelectAllComponentWalker vertexSelector(selected, SelectionSystem::eVertex);
    Node_traverseSubgraph(GlobalSceneGraph().root(), vertexSelector);

    SelectAllComponentWalker edgeSelector(selected, SelectionSystem::eEdge);
    Node_traverseSubgraph(GlobalSceneGraph().root(), edgeSelector);

    SelectAllComponentWalker faceSelector(selected, SelectionSystem::eFace);
    Node_traverseSubgraph(GlobalSceneGraph().root(), faceSelector);

    _manipulator->setSelected(selected);
}
예제 #13
0
void MD5ModelNode::constructRemaps() {
	// greebo: Acquire the ModelSkin reference from the SkinCache
	// Note: This always returns a valid reference
	ModelSkin& skin = GlobalModelSkinCache().capture(_skin);

	// Iterate over all surfaces and remaps
	_surfaceRemaps.resize(_model->size());
	MD5ModelNode::SurfaceRemaps::iterator j = _surfaceRemaps.begin();
	for (MD5Model::const_iterator i = _model->begin(); i != _model->end(); ++i,++j) {
		// Get the replacement shadername
		std::string remap = skin.getRemap((*i)->getShader());

		if (!remap.empty()) {
			// We have a valid remap, store it
			j->name = remap;
			j->shader = GlobalRenderSystem().capture(remap);
		} else {
			// No remap, leave the name as it is
			j->shader = ShaderPtr();
		}
	}

	// Refresh the scene
	GlobalSceneGraph().sceneChanged();
}
void RadiantSelectionSystem::initialiseModule(const ApplicationContext& ctx) 
{
    rMessage() << "RadiantSelectionSystem::initialiseModule called.\n";

    constructStatic();

    SetManipulatorMode(eTranslate);
    pivotChanged();

    _sigSelectionChanged.connect(
        sigc::mem_fun(this, &RadiantSelectionSystem::pivotChangedSelection)
    );

    GlobalGrid().signal_gridChanged().connect(
        sigc::mem_fun(this, &RadiantSelectionSystem::pivotChanged)
    );

    GlobalRegistry().signalForKey(RKEY_ROTATION_PIVOT).connect(
        sigc::mem_fun(this, &RadiantSelectionSystem::keyChanged)
    );

    // Pass a reference to self to the global event manager
    GlobalEventManager().connectSelectionSystem(this);

    // Connect the bounds changed caller
    GlobalSceneGraph().signal_boundsChanged().connect(
        sigc::mem_fun(this, &RadiantSelectionSystem::onSceneBoundsChanged)
    );

    GlobalRenderSystem().attachRenderable(*this);
}
// Deselect or select all the instances in the scenegraph and notify the manipulator class as well
void RadiantSelectionSystem::setSelectedAll(bool selected)
{
    SelectAllWalker walker(selected);
    Node_traverseSubgraph(GlobalSceneGraph().root(), walker);

    _manipulator->setSelected(selected);
}
예제 #16
0
void GraphTreeModel::refresh()
{
	// Instantiate a scenegraph walker and visit every node in the graph
	// The walker also clears the graph in its constructor
	GraphTreeModelPopulator populator(*this, _visibleNodesOnly);
	Node_traverseSubgraph(GlobalSceneGraph().root(), populator);
}
예제 #17
0
void DEntity::BuildInRadiant( bool allowDestruction ){
	bool makeEntity = strcmp( m_Classname, "worldspawn" ) ? true : false;

	if ( makeEntity ) {
		NodeSmartReference node( GlobalEntityCreator().createEntity( GlobalEntityClassManager().findOrInsert( m_Classname.GetBuffer(), !brushList.empty() || !patchList.empty() ) ) );

		for ( std::list<DEPair* >::const_iterator buildEPair = epairList.begin(); buildEPair != epairList.end(); buildEPair++ )
		{
			Node_getEntity( node )->setKeyValue( ( *buildEPair )->key, ( *buildEPair )->value );
		}

		Node_getTraversable( GlobalSceneGraph().root() )->insert( node );

		for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
			( *buildBrush )->BuildInRadiant( allowDestruction, NULL, node.get_pointer() );

		for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
			( *buildPatch )->BuildInRadiant( node.get_pointer() );

		QER_Entity = node.get_pointer();
	}
	else
	{
		for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
			( *buildBrush )->BuildInRadiant( allowDestruction, NULL );

		for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
			( *buildPatch )->BuildInRadiant();
	}
}
예제 #18
0
	/**
	 * Performs selection operation on the global scenegraph.
	 * If delete_bounds_src is true, then the objects which were
	 * used as source for the selection aabbs will be deleted.
	 */
	static void DoSelection(bool deleteBoundsSrc = true) {
		if (GlobalSelectionSystem().Mode() != SelectionSystem::ePrimitive) {
			// Wrong selection mode
			return;
		}

		// we may not need all AABBs since not all selected objects have to be brushes
		const std::size_t max = GlobalSelectionSystem().countSelected();
		AABB* aabbs = new AABB[max];
            
		CollectSelectedBrushesBounds collector(aabbs, max);
		GlobalSelectionSystem().foreachSelected(collector);

		std::size_t count = collector.getCount();

		// nothing usable in selection
		if (!count) {
			delete[] aabbs;
			return;
		}
      
		// delete selected objects?
		if (deleteBoundsSrc) {
			UndoableCommand undo("deleteSelected");
			selection::algorithm::deleteSelection();
		}

		// Instantiate a "self" object SelectByBounds and use it as visitor
		SelectByBounds<TSelectionPolicy> walker(aabbs, count);
		Node_traverseSubgraph(GlobalSceneGraph().root(), walker);
		
		SceneChangeNotify();
		delete[] aabbs;
	}
예제 #19
0
void Entity_ungroupSelected(){
	if ( GlobalSelectionSystem().countSelected() < 1 ) {
		return;
	}

	UndoableCommand undo( "ungroupSelectedEntities" );

	scene::Path world_path( makeReference( GlobalSceneGraph().root() ) );
	world_path.push( makeReference( Map_FindOrInsertWorldspawn( g_map ) ) );

	scene::Instance &instance = GlobalSelectionSystem().ultimateSelected();
	scene::Path path = instance.path();

	if ( !Node_isEntity( path.top() ) ) {
		path.pop();
	}

	if ( Node_getEntity( path.top() ) != 0
		 && node_is_group( path.top() ) ) {
		if ( world_path.top().get_pointer() != path.top().get_pointer() ) {
			parentBrushes( path.top(), world_path.top() );
			Path_deleteTop( path );
		}
	}
}
예제 #20
0
void DragManipulator::testSelect(const View& view, const Matrix4& pivot2world) {
    SelectionPool selector;

    SelectionVolume test(view);

    if (GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive) {
        BooleanSelector booleanSelector;

        Scene_TestSelect_Primitive(booleanSelector, test, view);

        if (booleanSelector.isSelected()) {
            selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
            _selected = false;
        } else {
            _selected = Scene_forEachPlaneSelectable_selectPlanes(GlobalSceneGraph(), selector, test);
        }
    }
    // Check for entities that can be selected
    else if (GlobalSelectionSystem().Mode() == SelectionSystem::eEntity) {
        // Create a boolean selection pool (can have exactly one selectable or none)
        BooleanSelector booleanSelector;

        // Find the visible entities
        Scene_forEachVisible(GlobalSceneGraph(), view, testselect_entity_visible(booleanSelector, test));

        // Check, if an entity could be found
        if (booleanSelector.isSelected()) {
            selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
            _selected = false;
        }
    } else {
        BestSelector bestSelector;
        Scene_TestSelect_Component_Selected(bestSelector, test, view, GlobalSelectionSystem().ComponentMode());
        for (std::list<Selectable*>::iterator i = bestSelector.best().begin(); i != bestSelector.best().end(); ++i) {
            if (!(*i)->isSelected()) {
                GlobalSelectionSystem().setSelectedAllComponents(false);
            }
            _selected = false;
            selector.addSelectable(SelectionIntersection(0, 0), (*i));
            _dragSelectable.setSelected(true);
        }
    }

    for (SelectionPool::iterator i = selector.begin(); i != selector.end(); ++i) {
        (*i).second->setSelected(true);
    }
}
예제 #21
0
void ReloadSkins(const cmd::ArgumentList& args) {
    GlobalModelSkinCache().refresh();
    RefreshSkinWalker walker;
    Node_traverseSubgraph(GlobalSceneGraph().root(), walker);

    // Refresh the ModelSelector too
    ui::ModelSelector::refresh();
}
예제 #22
0
// This actually applies the transformation to the objects
void RadiantSelectionSystem::freezeTransforms() {
	GlobalSceneGraph().traverse(FreezeTransforms());

	// The selection bounds have possibly changed, request an idle callback
	_requestWorkZoneRecalculation = true;

	requestIdleCallback();
}
예제 #23
0
void Scene_copyClosestFaceTexture(SelectionTest& test)
{
  CopiedString shader;
  if(Scene_BrushGetClosestFaceTexture(GlobalSceneGraph(), test, shader, g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags))
  {
    TextureBrowser_SetSelectedShader(g_TextureBrowser, shader.c_str());
  }
}
예제 #24
0
void Scene_applyClosestFaceTexture(SelectionTest& test)
{
  UndoableCommand command("facePaintTexture");

  Scene_BrushSetClosestFaceTexture(GlobalSceneGraph(), test, TextureBrowser_GetSelectedShader(g_TextureBrowser), g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags);

  SceneChangeNotify();
}
예제 #25
0
		bool pre( scene::Node& node ) const {
			scene::Path path( NodeReference( GlobalSceneGraph().root() ) );
			path.push( NodeReference( *m_entity->QER_Entity ) );
			path.push( NodeReference( node ) );
			scene::Instance* instance = GlobalSceneGraph().find( path );
			ASSERT_MESSAGE( instance != 0, "" );

			if ( Node_isPatch( node ) ) {
				DPatch* loadPatch = m_entity->NewPatch();
				loadPatch->LoadFromPatch( *instance );
			}
			else if ( Node_isBrush( node ) ) {
				DBrush* loadBrush = m_entity->NewBrush( m_count++ );
				loadBrush->LoadFromBrush( *instance, true );
			}
			return false;
		}
예제 #26
0
void FixupMap::replaceShader(const std::string& oldShader, const std::string& newShader)
{
	// Instantiate a walker
	ShaderReplacer replacer(oldShader, newShader);
	GlobalSceneGraph().root()->traverse(replacer);

	_result.replacedShaders += replacer.getReplaceCount();
}
예제 #27
0
// Delete the entity's world node
void ObjectiveEntity::deleteWorldNode() {
	// Try to convert the weak_ptr reference to a shared_ptr
	scene::INodePtr node = _entityNode.lock();

	if (node != NULL) {
		GlobalSceneGraph().root()->removeChildNode(node);
	}
}
void SpacePartitionRenderer::installRenderer()
{
	_renderableSP.setSpacePartition(GlobalSceneGraph().getSpacePartition());
	_renderableSP.setRenderSystem(boost::dynamic_pointer_cast<RenderSystem>(
		module::GlobalModuleRegistry().getModule(MODULE_RENDERSYSTEM)));

	GlobalRenderSystem().attachRenderable(_renderableSP);
}
예제 #29
0
void OverlayDialog::toggleUseImage()
{
    registry::setValue(RKEY_OVERLAY_VISIBLE, _useImageBtn->get_active());
	updateSensitivity();

	// Refresh
	GlobalSceneGraph().sceneChanged();
}
void DifficultySettingsManager::saveSettings()
{
    // Locates all difficulty entities
    DifficultyEntityFinder finder;
    GlobalSceneGraph().root()->traverse(finder);

    // Copy the list from the finder to a local list
    DifficultyEntityFinder::EntityList entities = finder.getEntities();

    if (entities.empty())
    {
        // Create a new difficulty entity
        std::string eclassName = game::current::getValue<std::string>(GKEY_DIFFICULTY_ENTITYDEF_MAP);
        IEntityClassPtr diffEclass = GlobalEntityClassManager().findClass(eclassName);

        if (diffEclass == NULL) {
            rError() << "[Diff]: Cannot create difficulty entity!\n";
            return;
        }

        // Create and insert a new entity node into the scenegraph root
        IEntityNodePtr entNode = GlobalEntityCreator().createEntity(diffEclass);
        GlobalSceneGraph().root()->addChildNode(entNode);

        // Add the entity to the list
        entities.push_back(&entNode->getEntity());
    }

    // Clear all difficulty-spawnargs from existing entities
    for (DifficultyEntityFinder::EntityList::const_iterator i = entities.begin();
         i != entities.end(); i++)
    {
        // Construct a difficulty entity using the raw Entity* pointer
        DifficultyEntity diffEnt(*i);
        // Clear the difficulty-related spawnargs from the entity
        diffEnt.clear();
    }

    // Take the first entity
    DifficultyEntity diffEnt(*entities.begin());

    // Cycle through all settings objects and issue save call
    for (std::size_t i = 0; i < _settings.size(); i++) {
        _settings[i]->saveToEntity(diffEnt);
    }
}