From 4ea4bbfcb03091cb987dc151d41980ec16f3d18d Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 8 Apr 2019 22:31:12 +0800 Subject: *misc --- source/modules/asura-core/mesh/am2_handler.cpp | 36 ++++++++++++++ source/modules/asura-core/mesh/am2_handler.h | 32 +++++++++++++ source/modules/asura-core/mesh/mesh2d_data.h | 58 +++++++++++++++++++++++ source/modules/asura-core/mesh/mesh2d_handler.cpp | 0 source/modules/asura-core/mesh/mesh2d_handler.h | 34 +++++++++++++ source/modules/asura-core/mesh/obj_handler.cpp | 0 source/modules/asura-core/mesh/obj_handler.h | 0 7 files changed, 160 insertions(+) create mode 100644 source/modules/asura-core/mesh/am2_handler.cpp create mode 100644 source/modules/asura-core/mesh/am2_handler.h create mode 100644 source/modules/asura-core/mesh/mesh2d_handler.cpp create mode 100644 source/modules/asura-core/mesh/mesh2d_handler.h create mode 100644 source/modules/asura-core/mesh/obj_handler.cpp create mode 100644 source/modules/asura-core/mesh/obj_handler.h (limited to 'source/modules/asura-core/mesh') diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/mesh/am2_handler.cpp new file mode 100644 index 0000000..fce7817 --- /dev/null +++ b/source/modules/asura-core/mesh/am2_handler.cpp @@ -0,0 +1,36 @@ +#include "am2_handler.h" + +namespace AsuraEngine +{ + namespace Mesh + { +/* +Asura定义的mesh2D格式称为.am2,具体格式如下。 +开头11个字节表明这是一个AsuraMesh2D文件 +ASURAMESH2D +v position +t tangent +n normal +[c color] +[u texcoord0] +[u texcoord1] +[u texcoord2] +[u texcoord3] + +f surface + +举例: +ASURAMESH2D +p0 +v 0, 0 +t -0.2, 0.45 +n -0.3, 0.6 +p1 + + +*/ + + + + } +} diff --git a/source/modules/asura-core/mesh/am2_handler.h b/source/modules/asura-core/mesh/am2_handler.h new file mode 100644 index 0000000..de93be9 --- /dev/null +++ b/source/modules/asura-core/mesh/am2_handler.h @@ -0,0 +1,32 @@ +#ifndef __ASURA_MESH2D_AM2_HANDLER_H__ +#define __ASURA_MESH2D_AM2_HANDLER_H__ + +#include "mesh2d_handler.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// Asura Mesh Format handler。解析和构建Asura定义的.am2格式的mesh文件。 + /// + class AM2Handler ASURA_FINAL : public Mesh2DHandler + { + public: + + AM2Handler(); + ~AM2Handler(); + + bool CanDecode(AEIO::DataBuffer& input) override; + + void Decode(AEIO::DataBuffer& input, Mesh2DData& target) override; + + void Encode(Mesh2DData& input, AEIO::DataBuffer& target) override; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h index e69de29..ad4b6c8 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/mesh/mesh2d_data.h @@ -0,0 +1,58 @@ +#ifndef __ASURA_MESH2D_DATA_H__ +#define __ASURA_MESH2D_DATA_H__ + +#include +#include +#include + +#include + +#include "../graphics/color.h" +#include "../graphics/gpu_buffer.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// Mesh2D的顶点数据,和index数据配合使用。Asura 2D mesh支持4套UV运用在一个顶点上。 + /// + struct Vertex + { + AEMath::Vector2f position; ///< 坐标 + AEMath::Vector2f tangent; ///< 切线 + AEMath::Vector2f normal; ///< 法线 + AEGraphics::Color color; ///< 颜色 + AEMath::Vector2f texCoord[4]; ///< UVs + }; + + /// + /// mesh的顶点数据和索引数据 + /// + class Mesh2DData + : AEIO::DecodedData + , AEScripting::Portable + { + public: + + void Decode(AEIO::DataBuffer& buffer) override; + + private: + + /// + /// mesh的所有顶点。 + /// + std::vector mVertices; + + /// + /// 索引,用来构建ebo。 + /// + std::vector mIndices; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_handler.cpp b/source/modules/asura-core/mesh/mesh2d_handler.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/mesh/mesh2d_handler.h b/source/modules/asura-core/mesh/mesh2d_handler.h new file mode 100644 index 0000000..05e12f0 --- /dev/null +++ b/source/modules/asura-core/mesh/mesh2d_handler.h @@ -0,0 +1,34 @@ +#ifndef __ASURA_MESH2D_HANDLER_H__ +#define __ASURA_MESH2D_HANDLER_H__ + +#include +#include + +#include "mesh2d_data.h" + +namespace AsuraEngine +{ + namespace Mesh + { + + /// + /// 解析和保存mesh数据 + /// + ASURA_ABSTRACT class Mesh2DHandler + { + public: + Mesh2DHandler() {}; + virtual ~Mesh2DHandler() {}; + + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + + virtual void Decode(AEIO::DataBuffer& input, Mesh2DData& target) = 0; + + virtual void Encode(Mesh2DData& input, AEIO::DataBuffer& target) = 0; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/mesh/obj_handler.cpp b/source/modules/asura-core/mesh/obj_handler.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/mesh/obj_handler.h b/source/modules/asura-core/mesh/obj_handler.h new file mode 100644 index 0000000..e69de29 -- cgit v1.1-26-g67d0