MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / createEntityFromSelection

Method createEntityFromSelection

radiantcore/entity/EntityModule.cpp:123–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123IEntityNodePtr 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

Callers 9

onCreateEntityMethod · 0.80
createEntityMethod · 0.80
callbackAddLightMethod · 0.80
callbackAddModelMethod · 0.80
callbackAddParticleMethod · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
CreateSpeakerFunction · 0.80

Calls 15

ExecutionFailureClass · 0.85
deleteSelectionFunction · 0.85
Node_setSelectedFunction · 0.85
applyShaderToSelectionFunction · 0.85
Doom3Light_getBoundsFunction · 0.85
getSpawnargsWithPrefixFunction · 0.85
findOrInsertMethod · 0.80
isFixedSizeMethod · 0.80
addChildNodeMethod · 0.80
reparentMethod · 0.80
isLightMethod · 0.80

Tested by

no test coverage detected