Skip to content

Commit

Permalink
#5584: Remove inactive code from MD5Model
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 26, 2022
1 parent 029b85d commit b623534
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 124 deletions.
117 changes: 28 additions & 89 deletions radiantcore/model/md5/MD5Model.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "MD5Model.h"

#include "ivolumetest.h"
#include "ishaders.h"
#include "texturelib.h"
#include "ifilter.h"
#include "string/convert.h"
#include "math/Quaternion.h"
#include "math/Ray.h"
#include "MD5DataStructures.h"

namespace md5 {
namespace md5
{

MD5Model::MD5Model() :
_polyCount(0),
Expand All @@ -28,12 +28,12 @@ MD5Model::MD5Model(const MD5Model& other) :
// Copy-construct the other model's surfaces, but not its shaders, revert to default
for (std::size_t i = 0; i < other._surfaces.size(); ++i)
{
_surfaces[i].surface.reset(new MD5Surface(*other._surfaces[i].surface));
_surfaces[i].surface->setActiveMaterial(_surfaces[i].surface->getDefaultMaterial());
_surfaces[i].reset(new MD5Surface(*other._surfaces[i]));
_surfaces[i]->setActiveMaterial(_surfaces[i]->getDefaultMaterial());

// Build the index array - this has to happen at least once
_surfaces[i].surface->buildIndexArray();
_surfaces[i].surface->updateToDefaultPose(_joints);
_surfaces[i]->buildIndexArray();
_surfaces[i]->updateToDefaultPose(_joints);
}

updateMaterialList();
Expand All @@ -43,23 +43,23 @@ void MD5Model::foreachSurface(const std::function<void(const MD5Surface&)>& func
{
for (const auto& surface : _surfaces)
{
functor(*surface.surface);
functor(*surface);
}
}

MD5Surface& MD5Model::createNewSurface()
{
_surfaces.push_back(MD5SurfacePtr(new MD5Surface));
return *(_surfaces.back().surface);
_surfaces.push_back(std::make_shared<MD5Surface>());
return *(_surfaces.back());
}

void MD5Model::updateAABB()
{
_aabb_local = AABB();

for(SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
_aabb_local.includeAABB(i->surface->localAABB());
_aabb_local.includeAABB(surface->localAABB());
}
}

Expand All @@ -70,11 +70,11 @@ const AABB& MD5Model::localAABB() const

void MD5Model::testSelect(Selector& selector, SelectionTest& test, const Matrix4& localToWorld)
{
for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
if (test.getVolume().TestAABB(i->surface->localAABB(), localToWorld) != VOLUME_OUTSIDE)
if (test.getVolume().TestAABB(surface->localAABB(), localToWorld) != VOLUME_OUTSIDE)
{
i->surface->testSelect(selector, test, localToWorld);
surface->testSelect(selector, test, localToWorld);
}
}
}
Expand All @@ -84,11 +84,11 @@ bool MD5Model::getIntersection(const Ray& ray, Vector3& intersection, const Matr
Vector3 bestIntersection = ray.origin;

// Test each surface and take the nearest point to the ray origin
for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
Vector3 surfaceIntersection;

if (i->surface->getIntersection(ray, surfaceIntersection, localToWorld))
if (surface->getIntersection(ray, surfaceIntersection, localToWorld))
{
// Test if this surface intersection is better than what we currently have
auto oldDistSquared = (bestIntersection - ray.origin).getLengthSquared();
Expand Down Expand Up @@ -131,10 +131,10 @@ void MD5Model::setModelPath(const std::string& modelPath) {
void MD5Model::applySkin(const ModelSkin& skin)
{
// Apply the skin to each surface, then try to capture shaders
for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
const std::string& defaultMaterial = i->surface->getDefaultMaterial();
const std::string& activeMaterial = i->surface->getActiveMaterial();
const std::string& defaultMaterial = surface->getDefaultMaterial();
const std::string& activeMaterial = surface->getActiveMaterial();

// Look up the remap for this surface's material name. If there is a remap
// change the Shader* to point to the new shader.
Expand All @@ -143,16 +143,15 @@ void MD5Model::applySkin(const ModelSkin& skin)
if (!remap.empty() && remap != activeMaterial)
{
// Save the remapped shader name
i->surface->setActiveMaterial(remap);
surface->setActiveMaterial(remap);
}
else if (remap.empty() && activeMaterial != defaultMaterial)
{
// No remap, so reset our shader to the original unskinned shader
i->surface->setActiveMaterial(defaultMaterial);
surface->setActiveMaterial(defaultMaterial);
}
}

captureShaders();
updateMaterialList();
}

Expand All @@ -175,11 +174,9 @@ void MD5Model::updateMaterialList()
{
_surfaceNames.clear();

for (SurfaceList::const_iterator i = _surfaces.begin();
i != _surfaces.end();
++i)
for (const auto& surface : _surfaces)
{
_surfaceNames.push_back(i->surface->getActiveMaterial());
_surfaceNames.push_back(surface->getActiveMaterial());
}
}

Expand All @@ -188,68 +185,10 @@ const model::StringList& MD5Model::getActiveMaterials() const
return _surfaceNames;
}

void MD5Model::captureShaders()
{
RenderSystemPtr renderSystem = _renderSystem.lock();

// Capture or release our shaders
for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
{
if (renderSystem)
{
i->shader = renderSystem->capture(i->surface->getActiveMaterial());
}
else
{
i->shader.reset();
}
}
}

const model::IIndexedModelSurface& MD5Model::getSurface(unsigned surfaceNum) const
{
assert(surfaceNum >= 0 && surfaceNum < _surfaces.size());
return *(_surfaces[surfaceNum].surface);
}

void MD5Model::render(const RenderInfo& info) const
{
#if 0 // greebo: No state changes in back-end render methods!
// Render options
if (info.checkFlag(RENDER_TEXTURE_2D))
{
glEnable(GL_TEXTURE_2D);
}

if (info.checkFlag(RENDER_SMOOTH))
{
glShadeModel(GL_SMOOTH);
}
#endif

// greebo: We don't need a back-end render method here, at least not yet (FIXME)
#if 0
for (SurfaceList::const_iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
{
// Get the Material to test the shader name against the filter system
const MaterialPtr& surfaceShader = (*i)->getState()->getMaterial();

if (surfaceShader->isVisible())
{
// Bind the OpenGL texture and render the surface geometry
TexturePtr tex = surfaceShader->getEditorImage();
glBindTexture(GL_TEXTURE_2D, tex->getGLTexNum());
(*i)->render(info.getFlags());
}
}
#endif
}

void MD5Model::setRenderSystem(const RenderSystemPtr& renderSystem)
{
_renderSystem = renderSystem;

captureShaders();
return *_surfaces[surfaceNum];
}

void MD5Model::parseFromTokens(parser::DefTokeniser& tok)
Expand Down Expand Up @@ -359,9 +298,9 @@ void MD5Model::setAnim(const IMD5AnimPtr& anim)

if (!_anim)
{
for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
i->surface->updateToDefaultPose(_joints);
surface->updateToDefaultPose(_joints);
}
}
}
Expand All @@ -378,9 +317,9 @@ void MD5Model::updateAnim(std::size_t time)
// Update our joint hierarchy first
_skeleton.update(_anim, time);

for (SurfaceList::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
for (const auto& surface : _surfaces)
{
i->surface->updateToSkeleton(_skeleton);
surface->updateToSkeleton(_skeleton);
}

signal_ModelAnimationUpdated().emit();
Expand Down
29 changes: 1 addition & 28 deletions radiantcore/model/md5/MD5Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,7 @@ class MD5Model :
private:
MD5Joints _joints;

struct Surface
{
// The MD5 mesh
MD5SurfacePtr surface;

// Mapped shader
ShaderPtr shader;

Surface()
{}

Surface(const MD5SurfacePtr& surface_) :
surface(surface_)
{}
};

typedef std::vector<Surface> SurfaceList;
SurfaceList _surfaces;
std::vector<MD5SurfacePtr> _surfaces;

AABB _aabb_local;

Expand All @@ -65,9 +48,6 @@ class MD5Model :
// The current state of our animated skeleton
MD5Skeleton _skeleton;

// We need to keep a reference for skin swapping
RenderSystemWeakPtr _renderSystem;

sigc::signal<void> _sigModelAnimationUpdated;

public:
Expand Down Expand Up @@ -130,11 +110,6 @@ class MD5Model :

const model::IIndexedModelSurface& getSurface(unsigned surfaceNum) const override;

// OpenGLRenderable implementation
virtual void render(const RenderInfo& info) const;

void setRenderSystem(const RenderSystemPtr& renderSystem);

// IMD5Model implementation
virtual void setAnim(const IMD5AnimPtr& anim) override;
virtual const IMD5AnimPtr& getAnim() const override;
Expand All @@ -155,8 +130,6 @@ class MD5Model :

// Re-populates the list of active shader names
void updateMaterialList();

void captureShaders();
};
typedef std::shared_ptr<MD5Model> MD5ModelPtr;

Expand Down
2 changes: 0 additions & 2 deletions radiantcore/model/md5/MD5ModelNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ void MD5ModelNode::setRenderSystem(const RenderSystemPtr& renderSystem)

// Detach renderables on render system change
detachFromShaders();

_model->setRenderSystem(renderSystem);
}

void MD5ModelNode::detachFromShaders()
Expand Down
5 changes: 1 addition & 4 deletions radiantcore/model/md5/MD5Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace md5

class MD5Skeleton;

class MD5Surface :
class MD5Surface final :
public model::IIndexedModelSurface,
public OpenGLRenderable
{
Expand Down Expand Up @@ -91,9 +91,6 @@ class MD5Surface :
// Updates this mesh to the state of the given skeleton
void updateToSkeleton(const MD5Skeleton& skeleton);

// Applies the given Skin to this surface.
void applySkin(const ModelSkin& skin);

// Back-end render function
void render(const RenderInfo& info) const;

Expand Down
1 change: 0 additions & 1 deletion radiantcore/selection/RadiantSelectionSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "i18n.h"
#include "iundo.h"
#include "igrid.h"
#include "igl.h"
#include "iselectiongroup.h"
#include "iradiant.h"
#include "ipreferencesystem.h"
Expand Down

0 comments on commit b623534

Please sign in to comment.