Skip to content

Commit

Permalink
#6009: ModelNodeBase subtypes need to implement createRenderableSurfa…
Browse files Browse the repository at this point in the history
…ces to populate the renderable surface collection
  • Loading branch information
codereader committed Oct 29, 2022
1 parent 84248c4 commit f4a5b59
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
7 changes: 7 additions & 0 deletions radiantcore/model/ModelNodeBase.cpp
Expand Up @@ -17,6 +17,13 @@ void ModelNodeBase::renderHighlights(IRenderableCollector& collector, const Volu
}
}

void ModelNodeBase::destroyRenderableSurfaces()
{
detachFromShaders();

_renderableSurfaces.clear();
}

void ModelNodeBase::detachFromShaders()
{
// Detach any existing surfaces. In case we need them again,
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/model/ModelNodeBase.h
Expand Up @@ -26,6 +26,12 @@ class ModelNodeBase :
void renderHighlights(IRenderableCollector& collector, const VolumeTest& volume) override;

protected:
// To be implemented by subclasses, this should populate the _renderableSurfaces collection
virtual void createRenderableSurfaces() = 0;

// Detaches all surfaces from their shaders and clears the _renderableSurfaces collection
virtual void destroyRenderableSurfaces();

void attachToShaders();
void detachFromShaders();
void queueRenderableUpdate();
Expand Down
20 changes: 10 additions & 10 deletions radiantcore/model/StaticModelNode.cpp
Expand Up @@ -20,11 +20,8 @@ StaticModelNode::StaticModelNode(const StaticModelPtr& picoModel) :
skinChanged("");
}

void StaticModelNode::onInsertIntoScene(scene::IMapRootNode& root)
void StaticModelNode::createRenderableSurfaces()
{
_model->connectUndoSystem(root.getUndoSystem());

// Renderables will acquire their shaders in onPreRender
_model->foreachSurface([&](const StaticModelSurface& surface)
{
if (surface.getVertexArray().empty() || surface.getIndexArray().empty())
Expand All @@ -34,6 +31,14 @@ void StaticModelNode::onInsertIntoScene(scene::IMapRootNode& root)

_renderableSurfaces.emplace_back(std::make_shared<RenderableModelSurface>(surface, _renderEntity, localToWorld()));
});
}

void StaticModelNode::onInsertIntoScene(scene::IMapRootNode& root)
{
_model->connectUndoSystem(root.getUndoSystem());

// Renderables will acquire their shaders in onPreRender
createRenderableSurfaces();

Node::onInsertIntoScene(root);
}
Expand All @@ -42,12 +47,7 @@ void StaticModelNode::onRemoveFromScene(scene::IMapRootNode& root)
{
_model->disconnectUndoSystem(root.getUndoSystem());

for (auto& surface : _renderableSurfaces)
{
surface->detach();
}

_renderableSurfaces.clear();
destroyRenderableSurfaces();

Node::onRemoveFromScene(root);
}
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/model/StaticModelNode.h
Expand Up @@ -90,6 +90,8 @@ class StaticModelNode final :
void onModelScaleApplied();

protected:
void createRenderableSurfaces() override;

void _onTransformationChanged() override;
void _applyTransformation() override;
void onVisibilityChanged(bool isVisibleNow) override;
Expand Down
18 changes: 9 additions & 9 deletions radiantcore/model/md5/MD5ModelNode.cpp
Expand Up @@ -72,9 +72,8 @@ scene::INode::Type MD5ModelNode::getNodeType() const
return Type::Model;
}

void MD5ModelNode::onInsertIntoScene(scene::IMapRootNode& root)
void MD5ModelNode::createRenderableSurfaces()
{
// Renderables will acquire their shaders in onPreRender
_model->foreachSurface([&](const MD5Surface& surface)
{
if (surface.getVertexArray().empty() || surface.getIndexArray().empty())
Expand All @@ -86,20 +85,21 @@ void MD5ModelNode::onInsertIntoScene(scene::IMapRootNode& root)
std::make_shared<model::RenderableModelSurface>(surface, _renderEntity, localToWorld())
);
});
}

void MD5ModelNode::onInsertIntoScene(scene::IMapRootNode& root)
{
// Renderables will acquire their shaders in onPreRender
createRenderableSurfaces();

Node::onInsertIntoScene(root);
}

void MD5ModelNode::onRemoveFromScene(scene::IMapRootNode& root)
{
Node::onRemoveFromScene(root);

for (auto& surface : _renderableSurfaces)
{
surface->detach();
}
destroyRenderableSurfaces();

_renderableSurfaces.clear();
Node::onRemoveFromScene(root);
}

void MD5ModelNode::testSelect(Selector& selector, SelectionTest& test)
Expand Down
1 change: 1 addition & 0 deletions radiantcore/model/md5/MD5ModelNode.h
Expand Up @@ -78,6 +78,7 @@ class MD5ModelNode :
void transformChangedLocal() override;

protected:
void createRenderableSurfaces() override;
void onVisibilityChanged(bool isVisibleNow) override;

private:
Expand Down

0 comments on commit f4a5b59

Please sign in to comment.