コード例 #1
0
TEST(TriangleMesh3, ReadObj) {
    std::string objStr = getCubeTriMesh3x3x3Obj();
    std::istringstream objStream(objStr);

    TriangleMesh3 mesh;
    mesh.readObj(&objStream);

    EXPECT_EQ(56u, mesh.numberOfPoints());
    EXPECT_EQ(96u, mesh.numberOfNormals());
    EXPECT_EQ(76u, mesh.numberOfUvs());
    EXPECT_EQ(108u, mesh.numberOfTriangles());
}
コード例 #2
0
TEST(TriangleMesh3, Builder) {
    TriangleMesh3::PointArray points = {
        Vector3D(1, 2, 3),
        Vector3D(4, 5, 6),
        Vector3D(7, 8, 9),
        Vector3D(10, 11, 12)
    };

    TriangleMesh3::NormalArray normals = {
        Vector3D(10, 11, 12),
        Vector3D(7, 8, 9),
        Vector3D(4, 5, 6),
        Vector3D(1, 2, 3)
    };

    TriangleMesh3::UvArray uvs = {
        Vector2D(13, 14),
        Vector2D(15, 16)
    };

    TriangleMesh3::IndexArray pointIndices = {
        Point3UI(0, 1, 2),
        Point3UI(0, 1, 3)
    };

    TriangleMesh3::IndexArray normalIndices = {
        Point3UI(1, 2, 3),
        Point3UI(2, 1, 0)
    };

    TriangleMesh3::IndexArray uvIndices = {
        Point3UI(1, 0, 2),
        Point3UI(3, 1, 0)
    };

    TriangleMesh3 mesh = TriangleMesh3::builder()
        .withPoints(points)
        .withNormals(normals)
        .withUvs(uvs)
        .withPointIndices(pointIndices)
        .withNormalIndices(normalIndices)
        .withUvIndices(uvIndices)
        .build();

    EXPECT_EQ(4u, mesh.numberOfPoints());
    EXPECT_EQ(4u, mesh.numberOfNormals());
    EXPECT_EQ(2u, mesh.numberOfUvs());
    EXPECT_EQ(2u, mesh.numberOfTriangles());

    for (size_t i = 0; i < mesh.numberOfPoints(); ++i) {
        EXPECT_EQ(points[i], mesh.point(i));
    }

    for (size_t i = 0; i < mesh.numberOfNormals(); ++i) {
        EXPECT_EQ(normals[i], mesh.normal(i));
    }

    for (size_t i = 0; i < mesh.numberOfUvs(); ++i) {
        EXPECT_EQ(uvs[i], mesh.uv(i));
    }

    for (size_t i = 0; i < mesh.numberOfTriangles(); ++i) {
        EXPECT_EQ(pointIndices[i], mesh.pointIndex(i));
        EXPECT_EQ(normalIndices[i], mesh.normalIndex(i));
        EXPECT_EQ(uvIndices[i], mesh.uvIndex(i));
    }
}