void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const std::string& shader) { if(GlobalSelectionSystem().countSelected() != 0) { const scene::INodePtr& node = GlobalSelectionSystem().ultimateSelected(); Brush* brush = Node_getBrush(node); if(brush != 0) { AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } }
void resizeBrushesToBounds(const AABB& aabb, const std::string& shader) { if (GlobalSelectionSystem().getSelectionInfo().brushCount == 0) { gtkutil::MessageBox::ShowError(_("No brushes selected."), GlobalMainFrame().getTopLevelWindow()); return; } GlobalSelectionSystem().foreachBrush([&] (Brush& brush) { brush.constructCuboid(aabb, shader, TextureProjection()); }); SceneChangeNotify(); }
void cloneSelected(const cmd::ArgumentList& args) { // Check for the correct editing mode (don't clone components) if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) { return; } UndoableCommand undo("cloneSelected"); // Create the list that will take the cloned instances SelectionCloner::Map cloned; SelectionCloner cloner; GlobalSceneGraph().root()->traverse(cloner); // Create a new namespace and move all cloned nodes into it INamespacePtr clonedNamespace = GlobalNamespaceFactory().createNamespace(); assert(clonedNamespace != NULL); // Move items into the temporary namespace, this will setup the links clonedNamespace->connect(cloner.getCloneRoot()); // Get the namespace of the current map scene::IMapRootNodePtr mapRoot = GlobalMapModule().getRoot(); if (mapRoot == NULL) return; // not map root (this can happen) INamespacePtr nspace = mapRoot->getNamespace(); if (nspace) { // Prepare the nodes for import nspace->ensureNoConflicts(cloner.getCloneRoot()); // Now move all nodes into the target namespace nspace->connect(cloner.getCloneRoot()); } // Unselect the current selection GlobalSelectionSystem().setSelectedAll(false); // Finally, move the cloned nodes to their destination and select them cloner.moveClonedNodes(true); if (registry::getValue<int>(RKEY_OFFSET_CLONED_OBJECTS) == 1) { // Move the current selection by one grid unit to the "right" and "downwards" nudgeSelected(eNudgeDown); nudgeSelected(eNudgeRight); } }
void mergeSelectedBrushes(const cmd::ArgumentList& args) { // Get the current selection BrushPtrVector brushes = selection::algorithm::getSelectedBrushes(); if (brushes.empty()) { rMessage() << _("CSG Merge: No brushes selected.") << std::endl; wxutil::Messagebox::ShowError(_("CSG Merge: No brushes selected.")); return; } if (brushes.size() < 2) { rMessage() << "CSG Merge: At least two brushes have to be selected.\n"; wxutil::Messagebox::ShowError("CSG Merge: At least two brushes have to be selected."); return; } rMessage() << "CSG Merge: Merging " << brushes.size() << " brushes." << std::endl; UndoableCommand undo("mergeSelectedBrushes"); // Take the last selected node as reference for layers and parent scene::INodePtr merged = GlobalSelectionSystem().ultimateSelected(); scene::INodePtr parent = merged->getParent(); assert(parent != NULL); // Create a new BrushNode scene::INodePtr node = GlobalBrushCreator().createBrush(); // Insert the newly created brush into the (same) parent entity parent->addChildNode(node); // Move the new brush to the same layers as the merged one node->assignToLayers(merged->getLayers()); // Get the contained brush Brush* brush = Node_getBrush(node); // Attempt to merge the selected brushes into the new one if (!Brush_merge(*brush, brushes, true)) { rWarning() << "CSG Merge: Failed - result would not be convex." << std::endl; return; } ASSERT_MESSAGE(!brush->empty(), "brush left with no faces after merge"); // Remove the original brushes for (BrushPtrVector::iterator i = brushes.begin(); i != brushes.end(); ++i) { scene::removeNodeFromParent(*i); } // Select the new brush Node_setSelected(node, true); rMessage() << "CSG Merge: Succeeded." << std::endl; SceneChangeNotify(); }
void SelectionSetToolmenu::onEntryActivated() { // Create new selection set if possible std::string name = _entry->get_entry()->get_text(); if (name.empty()) return; // don't create empty sets if (GlobalSelectionSystem().countSelected() == 0) { ui::IDialogPtr dialog = GlobalDialogManager().createMessageBox( _("Cannot create selection set"), _("Cannot create a selection set, there is nothing selected in the current scene."), ui::IDialog::MESSAGE_CONFIRM); dialog->run(); return; } ISelectionSetPtr set = GlobalSelectionSetManager().createSelectionSet(name); assert(set != NULL); set->assignFromCurrentScene(); // Clear the entry again _entry->get_entry()->set_text(""); }
void surroundWithMonsterclip(const cmd::ArgumentList& args) { UndoableCommand command("addMonsterclip"); // create a ModelFinder and retrieve the modelList selection::algorithm::ModelFinder visitor; GlobalSelectionSystem().foreachSelected(visitor); // Retrieve the list with all the found models from the visitor selection::algorithm::ModelFinder::ModelList list = visitor.getList(); selection::algorithm::ModelFinder::ModelList::iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) { // one of the models in the SelectionStack const scene::INodePtr& node = *iter; // retrieve the AABB AABB brushAABB(node->worldAABB()); // create the brush scene::INodePtr brushNode(GlobalBrushCreator().createBrush()); if (brushNode != NULL) { scene::addNodeToContainer(brushNode, GlobalMap().findOrInsertWorldspawn()); Brush* theBrush = Node_getBrush(brushNode); std::string clipShader = GlobalRegistry().get(RKEY_MONSTERCLIP_SHADER); Scene_BrushResize(*theBrush, brushAABB, clipShader); } } }
void PatchInspector::emitTesselation() { UndoableCommand setFixedTessCmd("patchSetFixedTesselation"); wxSpinCtrl* fixedSubdivX = findNamedObject<wxSpinCtrl>(this, "PatchInspectorSubdivisionsX"); wxSpinCtrl* fixedSubdivY = findNamedObject<wxSpinCtrl>(this, "PatchInspectorSubdivisionsY"); Subdivisions tess( fixedSubdivX->GetValue(), fixedSubdivY->GetValue() ); bool fixed = findNamedObject<wxCheckBox>(this, "PatchInspectorFixedSubdivisions")->GetValue(); // Save the setting into the selected patch(es) GlobalSelectionSystem().foreachPatch([&] (Patch& patch) { patch.setFixedSubdivisions(fixed, tess); }); fixedSubdivX->Enable(fixed); fixedSubdivY->Enable(fixed); findNamedObject<wxStaticText>(this, "PatchInspectorSubdivisionsXLabel")->Enable(fixed); findNamedObject<wxStaticText>(this, "PatchInspectorSubdivisionsYLabel")->Enable(fixed); GlobalMainFrame().updateAllWindows(); }
void ModelCache::refreshSelectedModels(const cmd::ArgumentList& args) { // Disable screen updates for the scope of this function ui::ScreenUpdateBlocker blocker(_("Processing..."), _("Reloading Models")); // Find all models in the current selection ModelFinder walker; GlobalSelectionSystem().foreachSelected(walker); // Remove the selected models from the cache ModelFinder::ModelPaths models = walker.getModelPaths(); for (ModelFinder::ModelPaths::const_iterator i = models.begin(); i != models.end(); ++i) { ModelMap::iterator found = _modelMap.find(*i); if (found != _modelMap.end()) { _modelMap.erase(found); } } // Traverse the entities and submit a refresh call ModelFinder::Entities entities = walker.getEntities(); for (ModelFinder::Entities::const_iterator i = entities.begin(); i != entities.end(); ++i) { (*i)->refreshModel(); } }
void PasteToCamera (void) { CamWnd& camwnd = *g_pParentWnd->GetCamWnd(); GlobalSelectionSystem().setSelectedAll(false); UndoableCommand undo("pasteToCamera"); Selection_Paste(); // Work out the delta Vector3 mid = selection::algorithm::getCurrentSelectionCenter(); Vector3 delta = vector3_snapped(camwnd.getCameraOrigin(), GlobalGrid().getGridSize()) - mid; // Move to camera GlobalSelectionSystem().translateSelected(delta); }
void Scene_BrushResize_Selected(scene::Graph& graph, const AABB& bounds, const char* shader) { if(GlobalSelectionSystem().countSelected() != 0) { const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path(); Brush* brush = Node_getBrush(path.top()); if(brush != 0) { TextureProjection projection; TexDef_Construct_Default(projection); Brush_ConstructCuboid(*brush, bounds, shader, projection); SceneChangeNotify(); } } }
AABB getCurrentSelectionBounds() { // Construct a walker to traverse the selection BoundsAccumulator walker; GlobalSelectionSystem().foreachSelected(walker); return walker.getBounds(); }
Vector3 getCurrentSelectionCenter() { // Construct a walker to traverse the selection BoundsAccumulator walker; GlobalSelectionSystem().foreachSelected(walker); return vector3_snapped(walker.getBounds().getOrigin()); }
/// moves selected primitives to entity, which is or its primitive is ultimateSelected() or firstSelected() void Entity_moveSelectedPrimitives( bool toLast ){ if ( GlobalSelectionSystem().countSelected() < 2 ) { globalErrorStream() << "Source and target entity primitives should be selected!\n"; return; } const scene::Path& path = toLast? GlobalSelectionSystem().ultimateSelected().path() : GlobalSelectionSystem().firstSelected().path(); scene::Node& node = ( !Node_isEntity( path.top() ) && path.size() > 1 )? path.parent() : path.top(); if ( Node_isEntity( node ) && node_is_group( node ) ) { StringOutputStream command; command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getEntityClass().name() ); UndoableCommand undo( command.c_str() ); Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); } }
/** * Callback common to all of the commands that trigger a processing by mesh * visitor when selected. This callback does its own internal dispatch to * distinctly handle the various commands. * * @param commandString The command token. */ void MainMenu::CommandMeshVisitor(const std::string& commandString) { // Look up the registered mesh visitor for this command. VisitorMap::const_iterator visitorMapIter = _visitorMap.find(commandString); MeshVisitor *meshVisitor; if (visitorMapIter == _visitorMap.end() || (meshVisitor = visitorMapIter->second) == NULL) { // That's odd, there isn't one. Bail out. std::string message(commandString + ": " + DIALOG_INTERNAL_ERROR); GenericPluginUI::ErrorReportDialog(DIALOG_ERROR_TITLE, message.c_str()); return; } // Let Radiant know the name of the operation responsible for the changes // that are about to happen. UndoableCommand undo(commandString.c_str()); // Apply the visitor to every selected mesh. meshVisitor->ResetVisitedCount(); GlobalSelectionSystem().foreachSelected(*meshVisitor); if (meshVisitor->GetVisitedCount() == 0) { // Warn if there weren't any meshes selected (so nothing happened). GenericPluginUI::WarningReportDialog(DIALOG_WARNING_TITLE, DIALOG_NOMESHES_MSG); } }
void LightNode::renderInactiveComponents(RenderableCollector& collector, const VolumeTest& volume, const bool selected) const { // greebo: We are not in component selection mode (and the light is still selected), // check if we should draw the center of the light anyway if (selected && GlobalSelectionSystem().ComponentMode() != SelectionSystem::eVertex && EntitySettings::InstancePtr()->alwaysShowLightVertices()) { if (_light.isProjected()) { EntitySettings& settings = *EntitySettings::InstancePtr(); const Vector3& colourStartEndInactive = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_DESELECTED); const Vector3& colourVertexInactive = settings.getLightVertexColour(EntitySettings::VERTEX_DESELECTED); const_cast<Light&>(_light).colourLightStart() = colourStartEndInactive; const_cast<Light&>(_light).colourLightEnd() = colourStartEndInactive; const_cast<Light&>(_light).colourLightTarget() = colourVertexInactive; const_cast<Light&>(_light).colourLightRight() = colourVertexInactive; const_cast<Light&>(_light).colourLightUp() = colourVertexInactive; // Render the projection points _light.renderProjectionPoints(collector, volume, localToWorld()); } else { const Vector3& colourVertexInactive = EntitySettings::InstancePtr()->getLightVertexColour( EntitySettings::VERTEX_INACTIVE); const_cast<Light&>(_light).getDoom3Radius().setCenterColour(colourVertexInactive); _light.renderLightCentre(collector, volume, localToWorld()); } } }
void NudgeSelection (ENudgeDirection direction, float fAmount, EViewType viewtype) { AxisBase axes(AxisBase_forViewType(viewtype)); Vector3 view_direction(-axes.z); Vector3 nudge(AxisBase_axisForDirection(axes, direction) * fAmount); GlobalSelectionSystem().NudgeManipulator(nudge, view_direction); }
void LightNode::evaluateTransform() { if (getType() == TRANSFORM_PRIMITIVE) { _light.translate(getTranslation()); _light.rotate(getRotation()); } else { // Check if the light center is selected, if yes, transform it, if not, it's a drag plane operation if (GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex) { if (_lightCenterInstance.isSelected()) { // Retrieve the translation and apply it to the temporary light center variable // This adds the translation vector to the previous light origin _light.getDoom3Radius().m_centerTransformed = _light.getDoom3Radius().m_center + getTranslation(); } if (_lightTargetInstance.isSelected()) { // Delegate the work to the Light class _light.translateLightTarget(getTranslation()); } if (_lightRightInstance.isSelected()) { // Save the new light_right vector _light.rightTransformed() = _light.right() + getTranslation(); } if (_lightUpInstance.isSelected()) { // Save the new light_up vector _light.upTransformed() = _light.up() + getTranslation(); } if (_lightStartInstance.isSelected()) { // Delegate the work to the Light class (including boundary checks) _light.translateLightStart(getTranslation()); } if (_lightEndInstance.isSelected()) { // Save the new light_up vector _light.endTransformed() = _light.end() + getTranslation(); } // If this is a projected light, then it is likely for the according vertices to have changed, so update the projection if (_light.isProjected()) { // Call projection changed, so that the recalculation can be triggered (call for projection() would be ignored otherwise) _light.projectionChanged(); // Recalculate the frustum _light.projection(); } } else { // Ordinary Drag manipulator //m_dragPlanes.m_bounds = _light.aabb(); // greebo: Be sure to use the actual lightAABB for evaluating the drag operation, NOT // the aabb() or localABB() method, that returns the bounding box including the light center, // which may be positioned way out of the volume m_dragPlanes.m_bounds = _light.lightAABB(); _light.setLightRadius(m_dragPlanes.evaluateResize(getTranslation(), rotation())); } } }
void WaveFrontModule::exportSelectionAsOBJ(const cmd::ArgumentList& args) { const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo(); if (info.totalCount == 0) { globalErrorStream() << "Nothing selected, cannot export." << std::endl; return; } // Query the filename from the user ui::IFileChooserPtr chooser = GlobalDialogManager().createFileChooser( _("Save as Obj"), false, false, "*.obj", ".obj" ); chooser->setCurrentPath(GlobalRegistry().get(RKEY_MAP_PATH)); std::string path = chooser->display(); if (!path.empty()) { globalOutputStream() << "Exporting selection as OBJ to " << path << std::endl; // Instantiate a new exporter WaveFrontExporter exporter(path); exporter.exportSelection(); } }
// 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(); }
void Select_SetShader (const std::string& shader) { if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent) { Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader); } Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader); }
void BrushInstance::renderComponents (Renderer& renderer, const VolumeTest& volume) const { m_brush.evaluateBRep(); const Matrix4& localToWorld = Instance::localToWorld(); renderer.SetState(m_brush.m_state_point, Renderer::eWireframeOnly); renderer.SetState(m_brush.m_state_point, Renderer::eFullMaterials); if (volume.fill() && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace) { evaluateViewDependent(volume, localToWorld); renderer.addRenderable(m_render_faces_wireframe, localToWorld); } else { m_brush.renderComponents(GlobalSelectionSystem().ComponentMode(), renderer, volume, localToWorld); } }
AABB getDefaultBoundsFromSelection() { AABB aabb = GlobalSelectionSystem().getWorkZone().bounds; float gridSize = GlobalGrid().getGridSize(); if (aabb.extents[0] == 0) { aabb.extents[0] = gridSize; } if (aabb.extents[1] == 0) { aabb.extents[1] = gridSize; } if (aabb.extents[2] == 0) { aabb.extents[2] = gridSize; } if (aabb.isValid()) { return aabb; } return AABB(Vector3(0, 0, 0), Vector3(64, 64, 64)); }
GroupCycle::GroupCycle() : _index(0), _updateActive(false) { GlobalSelectionSystem().addObserver(this); rescanSelection(); }
static gboolean entitylist_tree_select(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data) { GtkTreeIter iter; gtk_tree_model_get_iter(model, &iter, path); scene::Node* node; gtk_tree_model_get_pointer(model, &iter, 0, &node); scene::Instance* instance; gtk_tree_model_get_pointer(model, &iter, 1, &instance); Selectable* selectable = Instance_getSelectable(*instance); if(node == 0) { if(path_currently_selected != FALSE) { getEntityList().m_selection_disabled = true; GlobalSelectionSystem().setSelectedAll(false); getEntityList().m_selection_disabled = false; } } else if(selectable != 0) { getEntityList().m_selection_disabled = true; selectable->setSelected(path_currently_selected == FALSE); getEntityList().m_selection_disabled = false; return TRUE; } return FALSE; }
void mirrorSelection(int axis) { Vector3 flip(1, 1, 1); flip[axis] = -1; GlobalSelectionSystem().scaleSelected(flip); }
void nudgeByAxis(int nDim, float fNudge) { Vector3 translate(0, 0, 0); translate[nDim] = fNudge; GlobalSelectionSystem().translateSelected(translate); }
/** * greebo: Creates a new entity with an attached curve * * @key: The curve type: pass either "curve_CatmullRomSpline" or "curve_Nurbs". */ void createCurve(const std::string& key) { UndoableCommand undo(std::string("createCurve: ") + key); // De-select everything before we proceed GlobalSelectionSystem().setSelectedAll(false); GlobalSelectionSystem().setSelectedAllComponents(false); std::string curveEClass = game::current::getValue<std::string>(GKEY_DEFAULT_CURVE_ENTITY); // Fallback to func_static, if nothing defined in the registry if (curveEClass.empty()) { curveEClass = "func_static"; } // Find the default curve entity IEntityClassPtr entityClass = GlobalEntityClassManager().findOrInsert( curveEClass, true ); // Create a new entity node deriving from this entityclass IEntityNodePtr curve(GlobalEntityCreator().createEntity(entityClass)); // Insert this new node into the scenegraph root GlobalSceneGraph().root()->addChildNode(curve); // Select this new curve node Node_setSelected(curve, true); // Set the model key to be the same as the name curve->getEntity().setKeyValue("model", curve->getEntity().getKeyValue("name")); // Initialise the curve using three pre-defined points curve->getEntity().setKeyValue( key, "3 ( 0 0 0 50 50 0 50 100 0 )" ); ITransformablePtr transformable = Node_getTransformable(curve); if (transformable != NULL) { // Translate the entity to the center of the current workzone transformable->setTranslation(GlobalXYWnd().getActiveXY()->getOrigin()); transformable->freezeTransform(); } }
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); } }
void GroupCycle::rescanSelection() { if (_updateActive) { return; } const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo(); _list.clear(); _index = 0; if (info.totalCount == 1 && info.entityCount == 1) { const scene::INodePtr& node = GlobalSelectionSystem().ultimateSelected(); algorithm::ChildNodeFinder finder(_list); node->traverse(finder); } }
// greebo: see header for documentation void rotateSelected(const Vector3& eulerXYZ) { std::string command("rotateSelectedEulerXYZ: "); command += string::to_string(eulerXYZ); UndoableCommand undo(command.c_str()); GlobalSelectionSystem().rotateSelected(Quaternion::createForEulerXYZDegrees(eulerXYZ)); }