Skip to content

Commit

Permalink
Migrate PatchInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 20, 2017
1 parent 4f54941 commit 51f09f2
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 228 deletions.
4 changes: 4 additions & 0 deletions install/scripts/test.py
Expand Up @@ -213,6 +213,10 @@ def pre(self, node):
# modelskin = GlobalModelSkinCache.capture(skin)
# print('Skin found: ' + modelskin.getName())

v = Vector3(6,6,6)
v += Vector3(10,10,10)
print(v)

# Test patch manipulation
class PatchManipulator(SceneNodeVisitor) :
def pre(self, node):
Expand Down
4 changes: 2 additions & 2 deletions plugins/script/interfaces/EClassInterface.h
Expand Up @@ -50,7 +50,7 @@ class EntityClassVisitorWrapper :
public EntityClassVisitor
{
public:
void visit(const IEntityClassPtr& eclass)
void visit(const IEntityClassPtr& eclass) override
{
// Wrap this method to python
PYBIND11_OVERLOAD_PURE(
Expand All @@ -67,7 +67,7 @@ class ModelDefVisitorWrapper :
public ModelDefVisitor
{
public:
void visit(const IModelDefPtr& modelDef)
void visit(const IModelDefPtr& modelDef) override
{
// Wrap this method to python
PYBIND11_OVERLOAD_PURE(
Expand Down
2 changes: 1 addition & 1 deletion plugins/script/interfaces/FileSystemInterface.h
Expand Up @@ -28,7 +28,7 @@ class FileVisitorWrapper :
public VirtualFileSystemVisitor
{
public:
void visit(const std::string& filename)
void visit(const std::string& filename) override
{
// Wrap this method to python
PYBIND11_OVERLOAD_PURE(
Expand Down
19 changes: 17 additions & 2 deletions plugins/script/interfaces/MathInterface.cpp
Expand Up @@ -9,6 +9,7 @@
#include "math/Vector3.h"
#include "math/Vector4.h"
#include "render/Vertex3f.h"
#include "string/convert.h"

namespace script {

Expand Down Expand Up @@ -38,9 +39,14 @@ void MathInterface::registerInterface(py::module& scope, py::dict& globals)
// Most important operators
vec3.def(py::self + py::self); // __add__
vec3.def(py::self - py::self); // __sub__
vec3.def(py::self += py::self);
vec3.def(py::self -= py::self);
vec3.def(py::self += py::self); // __iadd__
vec3.def(py::self -= py::self); // __isub__
vec3.def(py::self < py::self); // __lt__
vec3.def("__repr__", [](const Vector3& vec)
{
return "(" + string::to_string(vec.x()) + " " + string::to_string(vec.y()) +
" " + string::to_string(vec.z()) + ")";
});

// Register Vertex3f, which extends Vector3
py::class_<Vertex3f, Vector3> vertex3f(scope, "Vertex3f");
Expand All @@ -66,6 +72,10 @@ void MathInterface::registerInterface(py::module& scope, py::dict& globals)
vec2.def(py::self += py::self);
vec2.def(py::self -= py::self);
vec2.def(py::self < py::self); // __lt__
vec2.def("__repr__", [](const Vector2& vec)
{
return "(" + string::to_string(vec.x()) + " " + string::to_string(vec.y()) + ")";
});

// Add the Vector4 class
py::class_<Vector4> vec4(scope, "Vector4");
Expand All @@ -85,6 +95,11 @@ void MathInterface::registerInterface(py::module& scope, py::dict& globals)
vec4.def(py::self - py::self); // __sub__
vec4.def(py::self += py::self);
vec4.def(py::self -= py::self);
vec4.def("__repr__", [](const Vector4& vec)
{
return "(" + string::to_string(vec.x()) + " " + string::to_string(vec.y()) + " " +
string::to_string(vec.z()) + " " + string::to_string(vec.w()) + ")";
});

// Add the Vector4 and Quaternion with the same interface
scope.add_object("Quaternion", vec4);
Expand Down

0 comments on commit 51f09f2

Please sign in to comment.