| 121 | } |
| 122 | |
| 123 | IEntityNodePtr Doom3EntityModule::createEntityFromSelection(const std::string& name, const Vector3& origin) |
| 124 | { |
| 125 | // Obtain the structure containing the selection counts |
| 126 | const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo(); |
| 127 | |
| 128 | IEntityClassPtr entityClass = GlobalEntityClassManager().findOrInsert(name, true); |
| 129 | |
| 130 | // TODO: to be replaced by inheritance-based class detection |
| 131 | bool isModel = (info.totalCount == 0 && name == "func_static"); |
| 132 | |
| 133 | // Some entities are based on the size of the currently-selected primitive(s) |
| 134 | bool primitivesSelected = info.brushCount > 0 || info.patchCount > 0; |
| 135 | |
| 136 | if (!(entityClass->isFixedSize() || isModel) && !primitivesSelected) { |
| 137 | throw cmd::ExecutionFailure( |
| 138 | fmt::format(_("Unable to create entity {0}, no brushes selected."), name) |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | // Get the selection workzone bounds |
| 143 | AABB workzone = GlobalSelectionSystem().getWorkZone().bounds; |
| 144 | |
| 145 | // Create the new node for the entity |
| 146 | IEntityNodePtr node(GlobalEntityModule().createEntity(entityClass)); |
| 147 | |
| 148 | GlobalSceneGraph().root()->addChildNode(node); |
| 149 | |
| 150 | // The layer list we're moving the newly created node/subgraph into |
| 151 | scene::LayerList targetLayers; |
| 152 | |
| 153 | if (entityClass->isFixedSize() || (isModel && !primitivesSelected)) |
| 154 | { |
| 155 | selection::algorithm::deleteSelection(); |
| 156 | |
| 157 | ITransformablePtr transform = scene::node_cast<ITransformable>(node); |
| 158 | |
| 159 | if (transform != 0) { |
| 160 | transform->setType(TRANSFORM_PRIMITIVE); |
| 161 | transform->setTranslation(origin); |
| 162 | transform->freezeTransform(); |
| 163 | } |
| 164 | |
| 165 | GlobalSelectionSystem().setSelectedAll(false); |
| 166 | |
| 167 | // Move the item to the active layer |
| 168 | if (GlobalMapModule().getRoot()) |
| 169 | { |
| 170 | targetLayers.insert(GlobalMapModule().getRoot()->getLayerManager().getActiveLayer()); |
| 171 | } |
| 172 | |
| 173 | Node_setSelected(node, true); |
| 174 | } |
| 175 | else // brush-based entity |
| 176 | { |
| 177 | // Add selected brushes as children of non-fixed entity |
| 178 | node->getEntity().setKeyValue("model", node->getEntity().getKeyValue("name")); |
| 179 | |
| 180 | // Take the selection center as new origin |
no test coverage detected