|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | +*/ |
| 17 | + |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +#include "test_config.h" |
| 21 | + |
| 22 | +#include "gz/common/Mesh.hh" |
| 23 | +#include "gz/common/SubMesh.hh" |
| 24 | +#include "gz/common/Material.hh" |
| 25 | +#include "gz/common/STLLoader.hh" |
| 26 | + |
| 27 | +using namespace ignition; |
| 28 | + |
| 29 | +class STLLoaderTest : public common::testing::AutoLogFixture { }; |
| 30 | + |
| 31 | +///////////////////////////////////////////////// |
| 32 | +TEST_F(STLLoaderTest, LoadSTL) |
| 33 | +{ |
| 34 | + common::STLLoader loader; |
| 35 | + auto mesh = loader.Load(""); |
| 36 | + EXPECT_EQ(nullptr, mesh); |
| 37 | + |
| 38 | + mesh = loader.Load( |
| 39 | + common::testing::TestFile("data", "cube.stl")); |
| 40 | + EXPECT_NE(nullptr, mesh); |
| 41 | + |
| 42 | + EXPECT_STREQ("unknown", mesh->Name().c_str()); |
| 43 | + EXPECT_EQ(math::Vector3d(20, 0, 20), mesh->Max()); |
| 44 | + EXPECT_EQ(math::Vector3d(0, -20, 0), mesh->Min()); |
| 45 | + // 36 vertices, 24 unique, 12 shared. |
| 46 | + EXPECT_EQ(36u, mesh->VertexCount()); |
| 47 | + EXPECT_EQ(36u, mesh->NormalCount()); |
| 48 | + EXPECT_EQ(36u, mesh->IndexCount()); |
| 49 | + EXPECT_EQ(0u, mesh->TexCoordCount()); |
| 50 | + EXPECT_EQ(1u, mesh->SubMeshCount()); |
| 51 | + EXPECT_EQ(0u, mesh->MaterialCount()); |
| 52 | + |
| 53 | + auto sm = mesh->SubMeshByIndex(0u); |
| 54 | + auto subMesh = sm.lock(); |
| 55 | + EXPECT_NE(nullptr, subMesh); |
| 56 | + EXPECT_EQ(math::Vector3d(20, 0, 0), subMesh->Vertex(0u)); |
| 57 | + EXPECT_EQ(math::Vector3d(0, -20, 0), subMesh->Vertex(1u)); |
| 58 | + EXPECT_EQ(math::Vector3d(0, 0, 0), subMesh->Vertex(2u)); |
| 59 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(0u)); |
| 60 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(1u)); |
| 61 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(2u)); |
| 62 | + |
| 63 | + EXPECT_STREQ("", mesh->SubMeshByIndex(0).lock()->Name().c_str()); |
| 64 | + |
| 65 | + mesh = loader.Load( |
| 66 | + common::testing::TestFile("data", "cube_binary.stl")); |
| 67 | + EXPECT_NE(nullptr, mesh); |
| 68 | + |
| 69 | + EXPECT_STREQ("unknown", mesh->Name().c_str()); |
| 70 | + EXPECT_EQ(math::Vector3d(20, 0, 20), mesh->Max()); |
| 71 | + EXPECT_EQ(math::Vector3d(0, -20, 0), mesh->Min()); |
| 72 | + // 36 vertices, 24 unique, 12 shared. |
| 73 | + EXPECT_EQ(36u, mesh->VertexCount()); |
| 74 | + EXPECT_EQ(36u, mesh->NormalCount()); |
| 75 | + EXPECT_EQ(36u, mesh->IndexCount()); |
| 76 | + EXPECT_EQ(0u, mesh->TexCoordCount()); |
| 77 | + EXPECT_EQ(1u, mesh->SubMeshCount()); |
| 78 | + EXPECT_EQ(0u, mesh->MaterialCount()); |
| 79 | + |
| 80 | + sm = mesh->SubMeshByIndex(0u); |
| 81 | + subMesh = sm.lock(); |
| 82 | + EXPECT_NE(nullptr, subMesh); |
| 83 | + EXPECT_EQ(math::Vector3d(20, 0, 0), subMesh->Vertex(0u)); |
| 84 | + EXPECT_EQ(math::Vector3d(0, -20, 0), subMesh->Vertex(1u)); |
| 85 | + EXPECT_EQ(math::Vector3d(0, 0, 0), subMesh->Vertex(2u)); |
| 86 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(0u)); |
| 87 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(1u)); |
| 88 | + EXPECT_EQ(math::Vector3d(0, 0, -1), subMesh->Normal(2u)); |
| 89 | + |
| 90 | + EXPECT_STREQ("", mesh->SubMeshByIndex(0).lock()->Name().c_str()); |
| 91 | +} |
0 commit comments