10 changed files with 163 additions and 11 deletions
@ -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; |
||||||
|
}; |
||||||
|
|
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
@ -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) |
||||||
Loading…
Reference in new issue