Browse Source

python: expose MeshTools::compile().

pull/1/head
Vladimír Vondruš 7 years ago
parent
commit
2b0dfaa22a
  1. 3
      doc/python/conf.py
  2. 2
      package/ci/travis-desktop-gles.sh
  3. 2
      package/ci/travis-desktop.sh
  4. 1
      src/python/CMakeLists.txt
  5. 15
      src/python/magnum/CMakeLists.txt
  6. 42
      src/python/magnum/PyMesh.h
  7. 8
      src/python/magnum/gl.cpp
  8. 56
      src/python/magnum/meshtools.cpp
  9. 44
      src/python/magnum/test/test_meshtools_gl.py
  10. 1
      src/python/setup.py.cmake

3
doc/python/conf.py

@ -9,6 +9,7 @@ import corrade.containers
import magnum import magnum
import magnum.gl import magnum.gl
import magnum.meshtools
import magnum.platform import magnum.platform
import magnum.platform.egl import magnum.platform.egl
import magnum.platform.glx import magnum.platform.glx
@ -21,7 +22,7 @@ import magnum.trade
# So the doc see everything # So the doc see everything
# TODO: use just +=, m.css should reorder this on its own # TODO: use just +=, m.css should reorder this on its own
magnum.__all__ = ['math', 'gl', 'platform', 'primitives', 'shaders', 'scenegraph', 'trade'] + magnum.__all__ magnum.__all__ = ['math', 'gl', 'meshtools', 'platform', 'primitives', 'shaders', 'scenegraph', 'trade'] + magnum.__all__
# TODO ugh... can this be expressed directly in pybind? # TODO ugh... can this be expressed directly in pybind?
magnum.gl.__annotations__ = {} magnum.gl.__annotations__ = {}

2
package/ci/travis-desktop-gles.sh

@ -34,7 +34,7 @@ cmake .. \
-DWITH_AUDIO=OFF \ -DWITH_AUDIO=OFF \
-DWITH_DEBUGTOOLS=OFF \ -DWITH_DEBUGTOOLS=OFF \
-DWITH_GL=ON \ -DWITH_GL=ON \
-DWITH_MESHTOOLS=OFF \ -DWITH_MESHTOOLS=ON \
-DWITH_PRIMITIVES=ON \ -DWITH_PRIMITIVES=ON \
-DWITH_SCENEGRAPH=ON \ -DWITH_SCENEGRAPH=ON \
-DWITH_SHADERS=ON \ -DWITH_SHADERS=ON \

2
package/ci/travis-desktop.sh

@ -28,7 +28,7 @@ cmake .. \
-DWITH_AUDIO=OFF \ -DWITH_AUDIO=OFF \
-DWITH_DEBUGTOOLS=OFF \ -DWITH_DEBUGTOOLS=OFF \
-DWITH_GL=ON \ -DWITH_GL=ON \
-DWITH_MESHTOOLS=OFF \ -DWITH_MESHTOOLS=ON \
-DWITH_PRIMITIVES=ON \ -DWITH_PRIMITIVES=ON \
-DWITH_SCENEGRAPH=ON \ -DWITH_SCENEGRAPH=ON \
-DWITH_SHADERS=ON \ -DWITH_SHADERS=ON \

1
src/python/CMakeLists.txt

@ -41,6 +41,7 @@ add_subdirectory(magnum)
# configure_file() and then replacing generator expressions with file(GENERATE) # configure_file() and then replacing generator expressions with file(GENERATE)
foreach(target foreach(target
magnum_gl magnum_gl
magnum_meshtools
magnum_primitives magnum_primitives
magnum_scenegraph magnum_scenegraph
magnum_shaders magnum_shaders

15
src/python/magnum/CMakeLists.txt

@ -24,7 +24,7 @@
# #
# *Not* REQUIRED # *Not* REQUIRED
find_package(Magnum COMPONENTS GL Shaders SceneGraph Primitives Trade) find_package(Magnum COMPONENTS GL Shaders SceneGraph MeshTools Primitives Trade)
set(magnum_SRCS set(magnum_SRCS
magnum.cpp magnum.cpp
@ -55,6 +55,19 @@ if(Magnum_GL_FOUND)
LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum) LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum)
endif() endif()
if(Magnum_MeshTools_FOUND)
set(magnum_meshtools_SRCS
meshtools.cpp)
pybind11_add_module(magnum_meshtools ${magnum_meshtools_SRCS})
target_include_directories(magnum_meshtools PRIVATE ${PROJECT_SOURCE_DIR}/src/python)
target_link_libraries(magnum_meshtools PRIVATE Magnum::MeshTools)
set_target_properties(magnum_meshtools PROPERTIES
FOLDER "python"
OUTPUT_NAME "meshtools"
LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum)
endif()
if(Magnum_Primitives_FOUND) if(Magnum_Primitives_FOUND)
set(magnum_primitives_SRCS set(magnum_primitives_SRCS
primitives.cpp) primitives.cpp)

42
src/python/magnum/PyMesh.h

@ -0,0 +1,42 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
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 <pybind11/pybind11.h>
#include <vector>
#include <Magnum/GL/Mesh.h>
#include "magnum/bootstrap.h"
namespace magnum {
struct PyMesh: GL::Mesh {
explicit PyMesh(GL::MeshPrimitive primitive): GL::Mesh(primitive) {}
explicit PyMesh(MeshPrimitive primitive): GL::Mesh(primitive) {}
explicit PyMesh(GL::Mesh&& mesh): GL::Mesh(std::move(mesh)) {}
std::vector<py::object> buffers;
};
}

8
src/python/magnum/gl.cpp

@ -36,16 +36,10 @@
#include "corrade/EnumOperators.h" #include "corrade/EnumOperators.h"
#include "magnum/bootstrap.h" #include "magnum/bootstrap.h"
#include "magnum/NonDestructible.h" #include "magnum/NonDestructible.h"
#include "magnum/PyMesh.h"
namespace magnum { namespace { namespace magnum { namespace {
struct PyMesh: GL::Mesh {
explicit PyMesh(GL::MeshPrimitive primitive): GL::Mesh(primitive) {}
explicit PyMesh(MeshPrimitive primitive): GL::Mesh(primitive) {}
std::vector<py::object> buffers;
};
void gl(py::module& m) { void gl(py::module& m) {
py::module::import("corrade.containers"); py::module::import("corrade.containers");

56
src/python/magnum/meshtools.cpp

@ -0,0 +1,56 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
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 <pybind11/pybind11.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/Trade/MeshData2D.h>
#include <Magnum/Trade/MeshData3D.h>
#include "magnum/bootstrap.h"
#include "magnum/PyMesh.h"
namespace magnum { namespace {
void meshtools(py::module& m) {
m.import("magnum.gl");
m.import("magnum.trade");
m
.def("compile", [](const Trade::MeshData2D& data) {
return PyMesh{MeshTools::compile(data)};
}, "Compile 2D mesh data")
.def("compile", [](const Trade::MeshData3D& data) {
return PyMesh{MeshTools::compile(data)};
}, "Compile 3D mesh data");
}
}}
PYBIND11_MODULE(meshtools, m) {
m.doc() = "Mesh tools";
magnum::meshtools(m);
}

44
src/python/magnum/test/test_meshtools_gl.py

@ -0,0 +1,44 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
# Vladimír Vondruš <mosra@centrum.cz>
#
# 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
# setUpModule gets called before everything else, skipping if GL tests can't
# be run
from . import GLTestCase, setUpModule
from magnum import *
from magnum import gl, meshtools, primitives
class Compile(GLTestCase):
def test_2d(self):
a = meshtools.compile(primitives.square_wireframe())
self.assertEqual(a.primitive, gl.MeshPrimitive.LINE_LOOP)
self.assertEqual(a.count, 4)
def test_3d(self):
a = meshtools.compile(primitives.cube_solid())
self.assertEqual(a.primitive, gl.MeshPrimitive.TRIANGLES)
self.assertEqual(a.count, 36)

1
src/python/setup.py.cmake

@ -34,6 +34,7 @@ extension_paths = {
'corrade.containers': '$<TARGET_FILE:corrade_containers>', 'corrade.containers': '$<TARGET_FILE:corrade_containers>',
'magnum._magnum': '$<TARGET_FILE:magnum>', 'magnum._magnum': '$<TARGET_FILE:magnum>',
'magnum.gl': '${magnum_gl_file}', 'magnum.gl': '${magnum_gl_file}',
'magnum.meshtools': '${magnum_meshtools_file}',
'magnum.primitives': '${magnum_primitives_file}', 'magnum.primitives': '${magnum_primitives_file}',
'magnum.scenegraph': '${magnum_scenegraph_file}', 'magnum.scenegraph': '${magnum_scenegraph_file}',
'magnum.shaders': '${magnum_shaders_file}', 'magnum.shaders': '${magnum_shaders_file}',

Loading…
Cancel
Save