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

Method attachModelNode

radiantcore/entity/ModelKey.cpp:60–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60void ModelKey::attachModelNode()
61{
62 // Remove the old model node first (this also clears the pointer)
63 detachModelNode();
64
65 // If the "model" spawnarg is empty, there's nothing to attach
66 if (_model.path.empty()) return;
67
68 // The actual model path to request the model from the file cache
69 std::string actualModelPath(_model.path);
70
71 // Check if the model key is pointing to a def
72 auto modelDef = GlobalEntityClassManager().findModel(_model.path);
73
74 if (modelDef)
75 {
76 // We have a valid modelDef, use the mesh defined there
77 actualModelPath = modelDef->getMesh();
78
79 // Start watching the modelDef for changes
80 subscribeToModelDef(modelDef);
81 }
82
83 // We have a non-empty model key, send the request to
84 // the model cache to acquire a new child node
85 _model.node = GlobalModelCache().getModelNode(actualModelPath);
86
87 // The model loader should not return NULL, but a sanity check is always ok
88 if (!_model.node) return;
89
90 // Add the model node as child of the entity node
91 _parentNode.addChildNode(_model.node);
92
93 // Assign the model node to the same layers as the parent entity
94 _model.node->assignToLayers(_parentNode.getLayers());
95
96 // Inherit the parent node's visibility. This should do the trick to resolve #2709
97 // but is not as heavy on performance as letting the Filtersystem check the whole subgraph
98
99 // Copy the visibility flags from the parent node (#4141 and #5134)
100 scene::assignVisibilityFlagsFromNode(*_model.node, _parentNode);
101
102 // Assign idle pose to modelDef meshes
103 if (modelDef)
104 {
105 // Set the default skin to the one defined in the modelDef
106 auto skinned = std::dynamic_pointer_cast<SkinnedModel>(_model.node);
107
108 if (skinned && !modelDef->getSkin().empty())
109 {
110 skinned->setDefaultSkin(modelDef->getSkin());
111 skinned->skinChanged(std::string()); // trigger a remap
112 }
113
114 scene::applyIdlePose(_model.node, modelDef);
115 }
116
117 // Mark the transform of this model as changed, it must re-evaluate itself

Callers

nothing calls this directly

Calls 12

applyIdlePoseFunction · 0.85
getMeshMethod · 0.80
addChildNodeMethod · 0.80
assignToLayersMethod · 0.80
emptyMethod · 0.45
findModelMethod · 0.45
getModelNodeMethod · 0.45
getSkinMethod · 0.45
setDefaultSkinMethod · 0.45
skinChangedMethod · 0.45
transformChangedMethod · 0.45

Tested by

no test coverage detected