Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved RenderEngine and Mesh coverage #739

Merged
merged 5 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/Mesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <string>

#include <ignition/common/Console.hh>
#include <ignition/common/MeshManager.hh>
#include <ignition/common/Skeleton.hh>
#include <ignition/common/SkeletonAnimation.hh>

#include "test_config.h" // NOLINT(build/include)
#include "ignition/rendering/Camera.hh"
Expand All @@ -35,6 +38,13 @@ class MeshTest : public testing::Test,
{
/// \brief Test mesh and submesh basic API
public: void MeshSubMesh(const std::string &_renderEngine);

/// \brief Test mesh skeleton
public: void MeshSkeleton(const std::string &_renderEngine);

public: const std::string TEST_MEDIA_PATH =
common::joinPaths(std::string(PROJECT_SOURCE_PATH),
"test", "media", "skeleton");
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -67,6 +77,8 @@ void MeshTest::MeshSubMesh(const std::string &_renderEngine)

EXPECT_EQ(submesh, mesh->SubMeshByName(submesh->Name()));

EXPECT_FALSE(mesh->HasSkeleton());

// test submesh API
MaterialPtr mat = submesh->Material();
ASSERT_TRUE(mat != nullptr);
Expand All @@ -90,12 +102,102 @@ void MeshTest::MeshSubMesh(const std::string &_renderEngine)
unloadEngine(engine->Name());
}

/////////////////////////////////////////////////
void MeshTest::MeshSkeleton(const std::string &_renderEngine)
{
RenderEngine *engine = rendering::engine(_renderEngine);
if (!engine)
{
igndbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

ScenePtr scene = engine->CreateScene("scene");
ASSERT_NE(nullptr, scene);

VisualPtr root = scene->RootVisual();

// create a visual for the actor, attach mesh and get skeleton
// Skeleton will be animated by GlutWindow
VisualPtr actorVisual = scene->CreateVisual("actor");
actorVisual->SetLocalPosition(0, 0, 0);
actorVisual->SetLocalRotation(0, 0, 0);

MeshDescriptor descriptor;
descriptor.meshName = common::joinPaths(TEST_MEDIA_PATH, "walk.dae");
common::MeshManager *meshManager = common::MeshManager::Instance();
descriptor.mesh = meshManager->Load(descriptor.meshName);

MeshPtr mesh = scene->CreateMesh(descriptor);
actorVisual->AddGeometry(mesh);
root->AddChild(actorVisual);

common::SkeletonPtr skel;

if (mesh && descriptor.mesh->HasSkeleton())
{
skel = descriptor.mesh->MeshSkeleton();

if (!skel || skel->AnimationCount() == 0)
{
FAIL();
}
}
else
{
FAIL();
}

EXPECT_TRUE(mesh->HasSkeleton());

std::string bvhFile = common::joinPaths(TEST_MEDIA_PATH, "cmu-13_26.bvh");

double scale = 0.055;
skel->AddBvhAnimation(bvhFile, scale);

int g_animIdx = 1;
auto * skelAnim = skel->Animation(g_animIdx);
for (double i = 0; i < 10; i+=0.01)
{
std::map<std::string, ignition::math::Matrix4d> animFrames;
animFrames = skelAnim->PoseAt(i, true);

std::map<std::string, ignition::math::Matrix4d> skinFrames;

for (auto pair : animFrames)
{
std::string animName = pair.first;
auto animTf = pair.second;

std::string skinName = skel->NodeNameAnimToSkin(g_animIdx, animName);
ignition::math::Matrix4d skinTf =
skel->AlignTranslation(g_animIdx, animName)
* animTf * skel->AlignRotation(g_animIdx, animName);

skinFrames[skinName] = skinTf;
}

mesh->SetSkeletonLocalTransforms(skinFrames);
}

// Clean up
engine->DestroyScene(scene);
unloadEngine(engine->Name());
}

/////////////////////////////////////////////////
TEST_P(MeshTest, MeshSubMesh)
{
MeshSubMesh(GetParam());
}

/////////////////////////////////////////////////
TEST_P(MeshTest, MeshSkeleton)
{
MeshSkeleton(GetParam());
}

INSTANTIATE_TEST_CASE_P(Mesh, MeshTest,
RENDER_ENGINE_VALUES,
PrintToStringParam());
Expand Down
5 changes: 5 additions & 0 deletions src/RenderEngine_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ void RenderEngineTest::RenderEngine(const std::string &_renderEngine)
return;
}

EXPECT_EQ(_renderEngine, engine->Name());
EXPECT_TRUE(engine->IsEnabled());

engine->AddResourcePath("none");

// Check there are no scenes
EXPECT_EQ(0u, engine->SceneCount());
EXPECT_FALSE(engine->HasSceneName("scene1"));
Expand Down
Loading