-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
606 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
render/include/rawrbox/render/scripting/wrapper/model_base_wrapper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <rawrbox/math/matrix4x4.hpp> | ||
#include <rawrbox/math/vector3.hpp> | ||
#include <rawrbox/math/vector4.hpp> | ||
#include <rawrbox/render/materials/base.hpp> | ||
#include <rawrbox/utils/reference.hpp> | ||
|
||
#include <sol/sol.hpp> | ||
|
||
namespace rawrbox { | ||
template <typename T> | ||
class ModelBase; | ||
|
||
class ModelBaseWrapper { | ||
protected: | ||
rawrbox::Reference<rawrbox::ModelBase<rawrbox::MaterialBase>> _ref; | ||
|
||
public: | ||
ModelBaseWrapper(rawrbox::ModelBase<rawrbox::MaterialBase>* ref); | ||
ModelBaseWrapper(const ModelBaseWrapper&) = default; | ||
ModelBaseWrapper(ModelBaseWrapper&&) = default; | ||
ModelBaseWrapper& operator=(const ModelBaseWrapper&) = default; | ||
ModelBaseWrapper& operator=(ModelBaseWrapper&&) = default; | ||
virtual ~ModelBaseWrapper(); | ||
|
||
// UTILS ---- | ||
[[nodiscard]] virtual const rawrbox::Vector3f getPos() const; | ||
virtual void setPos(const rawrbox::Vector3f& pos); | ||
|
||
[[nodiscard]] virtual const rawrbox::Vector3f getScale() const; | ||
virtual void setScale(const rawrbox::Vector3f& scale); | ||
|
||
[[nodiscard]] virtual const rawrbox::Vector4f getAngle() const; | ||
virtual void setAngle(const rawrbox::Vector4f& ang); | ||
|
||
virtual void setEulerAngle(const rawrbox::Vector3f& ang); | ||
|
||
[[nodiscard]] virtual const rawrbox::Matrix4x4 getMatrix() const; | ||
|
||
[[nodiscard]] virtual bool isDynamic() const; | ||
|
||
[[nodiscard]] virtual bool isUploaded() const; | ||
// ------ | ||
|
||
[[nodiscard]] bool isValid() const; | ||
|
||
static void registerLua(sol::state& lua); | ||
}; | ||
} // namespace rawrbox |
110 changes: 29 additions & 81 deletions
110
render/include/rawrbox/render/scripting/wrapper/model_wrapper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,47 @@ | ||
#pragma once | ||
|
||
#include <rawrbox/render/model/model.hpp> | ||
#include <rawrbox/math/matrix4x4.hpp> | ||
#include <rawrbox/math/vector3.hpp> | ||
#include <rawrbox/math/vector4.hpp> | ||
#include <rawrbox/render/materials/base.hpp> | ||
#include <rawrbox/render/scripting/wrapper/model_base_wrapper.hpp> | ||
#include <rawrbox/utils/reference.hpp> | ||
|
||
#include <sol/sol.hpp> | ||
|
||
namespace rawrbox { | ||
template <typename M = rawrbox::MaterialBase> | ||
class ModelWrapper { | ||
std::weak_ptr<rawrbox::ModelBase<M>> _ref; | ||
class ModelWrapper : public rawrbox::ModelBaseWrapper { | ||
|
||
public: | ||
ModelWrapper(rawrbox::ModelBase<M>& ref) : _ref(ref.weak_from_this()) {} | ||
ModelWrapper(rawrbox::ModelBase<rawrbox::MaterialBase>* ref); | ||
ModelWrapper(const ModelWrapper&) = default; | ||
ModelWrapper(ModelWrapper&&) noexcept = default; | ||
ModelWrapper(ModelWrapper&&) = default; | ||
ModelWrapper& operator=(const ModelWrapper&) = default; | ||
ModelWrapper& operator=(ModelWrapper&&) noexcept = default; | ||
virtual ~ModelWrapper() { this->_ref.reset(); } | ||
ModelWrapper& operator=(ModelWrapper&&) = default; | ||
~ModelWrapper() override = default; | ||
|
||
// UTILS ---- | ||
[[nodiscard]] virtual const rawrbox::Vector3f getPos() const { | ||
if (!this->isValid()) return {}; | ||
return this->_ref.lock()->getPos(); | ||
} | ||
// ANIMS --- | ||
virtual void playAnimation(const std::string& name, bool loop = true, float speed = 1.F); | ||
virtual void stopAnimation(const std::string& name); | ||
// --- | ||
|
||
virtual void setPos(const rawrbox::Vector3f& pos) { | ||
if (!this->isValid()) return; | ||
this->_ref.lock()->setPos(pos); | ||
} | ||
// UTILS --- | ||
virtual void setOptimizable(bool optimize); | ||
virtual void optimize(); | ||
|
||
[[nodiscard]] virtual const rawrbox::Vector3f getScale() const { | ||
if (!this->isValid()) return {}; | ||
return this->_ref.lock()->getScale(); | ||
} | ||
void setPos(const rawrbox::Vector3f& pos) override; | ||
void setAngle(const rawrbox::Vector4f& angle) override; | ||
void setEulerAngle(const rawrbox::Vector3f& angle) override; | ||
void setScale(const rawrbox::Vector3f& size) override; | ||
|
||
virtual void setScale(const rawrbox::Vector3f& scale) { | ||
if (!this->isValid()) return; | ||
this->_ref.lock()->setScale(scale); | ||
} | ||
[[nodiscard]] virtual const rawrbox::BBOX getBBOX() const; | ||
[[nodiscard]] virtual size_t totalMeshes() const; | ||
[[nodiscard]] virtual bool empty() const; | ||
|
||
[[nodiscard]] virtual const rawrbox::Vector4f getAngle() const { | ||
if (!this->isValid()) return {}; | ||
return this->_ref.lock()->getAngle(); | ||
} | ||
virtual void removeMeshByName(const std::string& id); | ||
virtual void removeMesh(size_t index); | ||
// --- | ||
|
||
virtual void setAngle(const rawrbox::Vector4f& ang) { | ||
if (!this->isValid()) return; | ||
this->_ref.lock()->setAngle(ang); | ||
} | ||
|
||
virtual void setEulerAngle(const rawrbox::Vector3f& ang) { | ||
if (!this->isValid()) return; | ||
this->_ref.lock()->setEulerAngle(ang); | ||
} | ||
|
||
[[nodiscard]] virtual const rawrbox::Matrix4x4 getMatrix() const { | ||
if (!this->isValid()) return {}; | ||
return this->_ref.lock()->getMatrix(); | ||
} | ||
|
||
[[nodiscard]] virtual bool isDynamic() const { | ||
if (!this->isValid()) return false; | ||
return this->_ref.lock()->isDynamic(); | ||
} | ||
|
||
[[nodiscard]] virtual bool isUploaded() const { | ||
if (!this->isValid()) return false; | ||
return this->_ref.lock()->isUploaded(); | ||
} | ||
// ------ | ||
|
||
[[nodiscard]] bool isValid() const { | ||
return !this->_ref.expired(); | ||
} | ||
|
||
static void registerLua(sol::state& lua) { | ||
lua.new_usertype<ModelWrapper<M>>("ModelBase<>", | ||
sol::no_constructor, | ||
|
||
// UTILS ---- | ||
"getPos", &ModelWrapper<M>::getPos, | ||
"setPos", &ModelWrapper<M>::setPos, | ||
|
||
"getScale", &ModelWrapper<M>::getScale, | ||
"setScale", &ModelWrapper<M>::setScale, | ||
|
||
"getAngle", &ModelWrapper<M>::getAngle, | ||
"setAngle", &ModelWrapper<M>::setAngle, | ||
"setEulerAngle", &ModelWrapper<M>::setEulerAngle, | ||
|
||
"getMatrix", &ModelWrapper<M>::getMatrix, | ||
"isDynamic", &ModelWrapper<M>::isDynamic, | ||
"isUploaded", &ModelWrapper<M>::isUploaded, | ||
// -------------- | ||
|
||
"isValid", &ModelWrapper<M>::isValid); | ||
} | ||
static void registerLua(sol::state& lua); | ||
}; | ||
} // namespace rawrbox |
Oops, something went wrong.