diff --git a/doc/python/conf.py b/doc/python/conf.py index 75a1646..7c81499 100644 --- a/doc/python/conf.py +++ b/doc/python/conf.py @@ -14,13 +14,14 @@ import magnum.platform.egl import magnum.platform.glx import magnum.platform.glfw import magnum.platform.sdl2 +import magnum.primitives import magnum.shaders import magnum.scenegraph import magnum.trade # So the doc see everything # TODO: use just +=, m.css should reorder this on its own -magnum.__all__ = ['math', 'gl', 'platform', 'shaders', 'scenegraph', 'trade'] + magnum.__all__ +magnum.__all__ = ['math', 'gl', 'platform', 'primitives', 'shaders', 'scenegraph', 'trade'] + magnum.__all__ # TODO ugh... can this be expressed directly in pybind? magnum.gl.__annotations__ = {} diff --git a/package/ci/travis-desktop-gles.sh b/package/ci/travis-desktop-gles.sh index 3562623..d2598ba 100755 --- a/package/ci/travis-desktop-gles.sh +++ b/package/ci/travis-desktop-gles.sh @@ -35,7 +35,7 @@ cmake .. \ -DWITH_DEBUGTOOLS=OFF \ -DWITH_GL=ON \ -DWITH_MESHTOOLS=OFF \ - -DWITH_PRIMITIVES=OFF \ + -DWITH_PRIMITIVES=ON \ -DWITH_SCENEGRAPH=ON \ -DWITH_SHADERS=ON \ -DWITH_TEXT=OFF \ diff --git a/package/ci/travis-desktop.sh b/package/ci/travis-desktop.sh index f1d47ef..8685af4 100755 --- a/package/ci/travis-desktop.sh +++ b/package/ci/travis-desktop.sh @@ -29,7 +29,7 @@ cmake .. \ -DWITH_DEBUGTOOLS=OFF \ -DWITH_GL=ON \ -DWITH_MESHTOOLS=OFF \ - -DWITH_PRIMITIVES=OFF \ + -DWITH_PRIMITIVES=ON \ -DWITH_SCENEGRAPH=ON \ -DWITH_SHADERS=ON \ -DWITH_TEXT=OFF \ diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 4899adc..fa51edc 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -41,6 +41,7 @@ add_subdirectory(magnum) # configure_file() and then replacing generator expressions with file(GENERATE) foreach(target magnum_gl + magnum_primitives magnum_scenegraph magnum_shaders magnum_platform_egl diff --git a/src/python/magnum/CMakeLists.txt b/src/python/magnum/CMakeLists.txt index 444c132..53a784a 100644 --- a/src/python/magnum/CMakeLists.txt +++ b/src/python/magnum/CMakeLists.txt @@ -24,7 +24,7 @@ # # *Not* REQUIRED -find_package(Magnum COMPONENTS GL Shaders SceneGraph Trade) +find_package(Magnum COMPONENTS GL Shaders SceneGraph Primitives Trade) set(magnum_SRCS magnum.cpp @@ -55,6 +55,19 @@ if(Magnum_GL_FOUND) LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum) endif() +if(Magnum_Primitives_FOUND) + set(magnum_primitives_SRCS + primitives.cpp) + + pybind11_add_module(magnum_primitives ${magnum_primitives_SRCS}) + target_include_directories(magnum_primitives PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + target_link_libraries(magnum_primitives PRIVATE Magnum::Primitives) + set_target_properties(magnum_primitives PROPERTIES + FOLDER "python" + OUTPUT_NAME "primitives" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum) +endif() + if(Magnum_SceneGraph_FOUND) set(magnum_scenegraph_SRCS scenegraph.cpp) diff --git a/src/python/magnum/primitives.cpp b/src/python/magnum/primitives.cpp new file mode 100644 index 0000000..6960a52 --- /dev/null +++ b/src/python/magnum/primitives.cpp @@ -0,0 +1,58 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include + +#include "magnum/bootstrap.h" + +namespace magnum { namespace { + +void primitives(py::module& m) { + m.import("magnum.trade"); + + py::enum_{m, "SquareTextureCoords", "Whether to generate square texture coordinates"} + .value("DONT_GENERATE", Primitives::SquareTextureCoords::DontGenerate) + .value("GENERATE", Primitives::SquareTextureCoords::Generate); + + m + .def("cube_solid", Primitives::cubeSolid, "Solid 3D cube") + .def("cube_solid_strip", Primitives::cubeSolidStrip, "Solid 3D cube as a single strip") + .def("cube_wireframe", Primitives::cubeWireframe, "Wireframe 3D cube") + + .def("square_solid", Primitives::squareSolid, "Solid 2D square") + .def("square_wireframe", Primitives::squareWireframe, "Wireframe 2D square"); +} + +}} + +PYBIND11_MODULE(primitives, m) { + m.doc() = "Primitive library"; + + magnum::primitives(m); +} diff --git a/src/python/magnum/test/test_primitives.py b/src/python/magnum/test/test_primitives.py new file mode 100644 index 0000000..5079ac6 --- /dev/null +++ b/src/python/magnum/test/test_primitives.py @@ -0,0 +1,56 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +import unittest + +from magnum import * +from magnum import primitives + +class Cube(unittest.TestCase): + def test_solid(self): + a = primitives.cube_solid() + self.assertEqual(a.primitive, MeshPrimitive.TRIANGLES) + self.assertTrue(a.is_indexed()) + + def test_solid_strip(self): + a = primitives.cube_solid_strip() + self.assertEqual(a.primitive, MeshPrimitive.TRIANGLE_STRIP) + self.assertFalse(a.is_indexed()) + + def test_wireframe(self): + a = primitives.cube_wireframe() + self.assertEqual(a.primitive, MeshPrimitive.LINES) + self.assertTrue(a.is_indexed()) + +class Square(unittest.TestCase): + def test_solid(self): + a = primitives.square_solid(primitives.SquareTextureCoords.GENERATE) + self.assertEqual(a.primitive, MeshPrimitive.TRIANGLE_STRIP) + self.assertFalse(a.is_indexed()) + + def test_wireframe(self): + a = primitives.square_wireframe() + self.assertEqual(a.primitive, MeshPrimitive.LINE_LOOP) + self.assertFalse(a.is_indexed()) diff --git a/src/python/setup.py.cmake b/src/python/setup.py.cmake index 2769667..f03fec2 100644 --- a/src/python/setup.py.cmake +++ b/src/python/setup.py.cmake @@ -34,6 +34,7 @@ extension_paths = { 'corrade.containers': '$', 'magnum._magnum': '$', 'magnum.gl': '${magnum_gl_file}', + 'magnum.primitives': '${magnum_primitives_file}', 'magnum.scenegraph': '${magnum_scenegraph_file}', 'magnum.shaders': '${magnum_shaders_file}', 'magnum.platform.egl': '${magnum_platform_egl_file}',