diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index 84ee0ee3..bab89185 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -426,6 +426,19 @@ EasyMesh::EasyMesh() : m_build_data(nullptr) { m_cursors.Push(0, 0); + m_state = MeshRender::NeedData; +} + +//----------------------------------------------------------------------------- +EasyMesh::EasyMesh(const EasyMesh& em) +{ + *this = em; + m_build_data = nullptr; + m_gpu_data = GpuEasyMeshData(); + if (m_indices.Count() && m_vert.Count() && m_cursors.Count()) + m_state = MeshRender::NeedConvert; + else + m_state = MeshRender::NeedData; } //----------------------------------------------------------------------------- @@ -458,6 +471,7 @@ void EasyMesh::MeshConvert(GpuShaderData* new_gpu_sdata) for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++) m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); } + m_state = MeshRender::CanRender; } //----------------------------------------------------------------------------- @@ -476,12 +490,36 @@ void EasyMesh::MeshConvert(Shader* provided_shader) m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode::Default), this); for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++) m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); + m_state = MeshRender::CanRender; +} + +//----------------------------------------------------------------------------- +bool EasyMesh::Render(mat4 const &model) +{ + if (m_state == MeshRender::CanRender) + { + m_gpu_data.RenderMeshData(model); + return true; + } + return false; } //----------------------------------------------------------------------------- -void EasyMesh::Render(mat4 const &model) +bool EasyMesh::SetRender(bool should_render) { - m_gpu_data.RenderMeshData(model); + if (m_state == MeshRender::CanRender) + { + if (!should_render) + m_state = MeshRender::IgnoreRender; + return true; + } + else if (m_state == MeshRender::IgnoreRender) + { + if (should_render) + m_state = MeshRender::CanRender; + return true; + } + return false; } //------------------- @@ -851,12 +889,14 @@ void EasyMesh::SetCurColor2(vec4 const &color) void EasyMesh::AddVertex(vec3 const &coord) { m_vert.Push(VertexData(coord, vec3(0.f, 1.f, 0.f), BD()->Color())); + m_state = MeshRender::NeedConvert; } //----------------------------------------------------------------------------- void EasyMesh::AddDuplicateVertex(int i) { m_vert << m_vert[i]; + m_state = MeshRender::NeedConvert; } //----------------------------------------------------------------------------- @@ -869,6 +909,7 @@ void EasyMesh::AddLerpVertex(int i, int j, float alpha) lol::lerp(m_vert[i].m_texcoord, m_vert[j].m_texcoord, alpha), ((alpha < .5f) ? (m_vert[i].m_bone_id) : (m_vert[j].m_bone_id)), /* FIXME ? */ lol::lerp(m_vert[i].m_bone_weight, m_vert[j].m_bone_weight, alpha))); + m_state = MeshRender::NeedConvert; } //----------------------------------------------------------------------------- diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 91dd23f3..56ce8514 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -26,14 +26,17 @@ struct MeshRender { enum Value { - NeedInit, + NeedData, + NeedConvert, CanRender, - IgnoreRender + IgnoreRender, + + Max } m_value; inline MeshRender(Value v) : m_value(v) {} - inline MeshRender() : m_value(NeedInit) {} + inline MeshRender() : m_value(NeedData) {} inline operator Value() { return m_value; } }; @@ -106,6 +109,8 @@ public: class GpuEasyMeshData { + friend class EasyMesh; + public: //--- GpuEasyMeshData(); @@ -520,14 +525,18 @@ struct Axis class EasyMesh { friend class EasyMeshParser; + friend class GpuEasyMeshData; public: EasyMesh(); + EasyMesh(const EasyMesh& em); - bool Compile(char const *command); - void MeshConvert(GpuShaderData* new_gpu_sdata); - void MeshConvert(Shader* ProvidedShader = nullptr); - void Render(mat4 const &model); + bool Compile(char const *command); + void MeshConvert(GpuShaderData* new_gpu_sdata); + void MeshConvert(Shader* ProvidedShader = nullptr); + bool Render(mat4 const &model); + MeshRender GetMeshState() { return m_state; } + bool SetRender(bool should_render); private: void UpdateVertexDict(Array< int, int > &vertex_dict); @@ -832,14 +841,14 @@ public: vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; } private: - Array m_indices; - Array m_vert; + Array m_indices; + Array m_vert; // - Array m_cursors; + Array m_cursors; - friend class GpuEasyMeshData; - GpuEasyMeshData m_gpu_data; + MeshRender m_state; + GpuEasyMeshData m_gpu_data; public: inline EasyMeshBuildData* BD() diff --git a/test/data/mesh-buffer.txt b/test/data/mesh-buffer.txt index 8aa4c780..c6a8ea47 100644 --- a/test/data/mesh-buffer.txt +++ b/test/data/mesh-buffer.txt @@ -1,7 +1,9 @@ -[sc#f8f ab 1 splt 3 twy 90] -// splt 5 twy 90 0 -//[sc#f8f afcb 10 10 10 .25 tx 0 splt 3 twy 1.6 0 ] +[sc#f8f ab 1 splt 4 twy 90] + + +// splt 5 twy 90 0 +//[sc#f8f afcb 10 10 10 .25 tx 0 splt 4 twy 1.6 0 ] //sc#fff //[afcb 1 1 1 -.1 tx 1] //[afcb 1 1 1 -.1 tx 0] diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 41dff2ac..795fa62a 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -268,8 +268,8 @@ public: //Target List Setup Array target_list; if (m_meshes.Count() && m_mesh_id >= 0) - for (int i = 0; i < m_meshes[m_mesh_id].m1.GetVertexCount(); i++) - target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id].m1.GetVertexLocation(i))).v3.xyz; + for (int i = 0; i < m_meshes[m_mesh_id].GetVertexCount(); i++) + target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id].GetVertexLocation(i))).v3.xyz; //-- //Update mesh screen location - Get the Min/Max needed @@ -331,17 +331,15 @@ public: int u = 4; while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh)) { - int o = 1; + int o = 4; while (o-- > 0) { if (m_mesh_id == m_meshes.Count() - 1) m_mesh_id++; //Create a new mesh - m_meshes.Push(EasyMesh(), false); - if (!m_meshes.Last().m1.Compile(mesh.C())) - m_meshes.Pop(); - //else - // m_meshes.Last().m1.ComputeTexCoord(0.2f, 2); + EasyMesh tmp; + if (tmp.Compile(mesh.C())) + m_meshes.Push(tmp); } } @@ -431,49 +429,47 @@ public: m_texture_shader->SetUniform(m_texture_uni, m_default_texture->GetTexture(), 0); #endif //!__native_client__ - for (int i = 0; i < m_meshes.Count(); i++) - { - if (!m_meshes[i].m2) - { -#if WITH_TEXTURE - m_meshes[i].m1.MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) | - (1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)), - m_texture_shader, true)); -#else - m_meshes[i].m1.MeshConvert(); -#endif - m_meshes[i].m2 = true; - } - } - g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); vec3 x = vec3(1.f,0.f,0.f); vec3 y = vec3(0.f,1.f,0.f); for (int i = 0; i < m_meshes.Count(); i++) { - mat4 save_proj = m_camera->GetProjection(); - float j = -(float)(m_meshes.Count() - (i + 1)) + (-m_mesh_id1 + (float)(m_meshes.Count() - 1)); - if (m_meshes[i].m2) { - mat4 new_proj = - //Y object Offset - mat4::translate(x * m_screen_offset.x + y * m_screen_offset.y) * - //Mesh Pos Offset - mat4::translate((x * m_pos_mesh.x * RATIO_HW + y * m_pos_mesh.y) * 2.f * (1.f + .5f * m_zoom_mesh / SCREEN_LIMIT)) * - //Mesh count offset - mat4::translate(x * RATIO_HW * 2.f * j) * - //Align right meshes - mat4::translate(x - x * RATIO_HW) * - //Mesh count scale - //mat4::scale(1.f - .2f * j * (1.f / (float)m_meshes.Count())) * - //Camera projection - save_proj; - m_camera->SetProjection(new_proj); - m_meshes[i].m1.Render(m_mat); - g_renderer->Clear(ClearMask::Depth); + if (m_meshes[i].GetMeshState() == MeshRender::NeedConvert) + { +#if WITH_TEXTURE + m_meshes[i].MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) | + (1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)), + m_texture_shader, true)); +#else + m_meshes[i].MeshConvert(); +#endif //WITH_TEXTURE + } + mat4 save_proj = m_camera->GetProjection(); + float j = -(float)(m_meshes.Count() - (i + 1)) + (-m_mesh_id1 + (float)(m_meshes.Count() - 1)); + + if (m_meshes[i].GetMeshState() > MeshRender::NeedConvert) + { + mat4 new_proj = + //Y object Offset + mat4::translate(x * m_screen_offset.x + y * m_screen_offset.y) * + //Mesh Pos Offset + mat4::translate((x * m_pos_mesh.x * RATIO_HW + y * m_pos_mesh.y) * 2.f * (1.f + .5f * m_zoom_mesh / SCREEN_LIMIT)) * + //Mesh count offset + mat4::translate(x * RATIO_HW * 2.f * j) * + //Align right meshes + mat4::translate(x - x * RATIO_HW) * + //Mesh count scale + //mat4::scale(1.f - .2f * j * (1.f / (float)m_meshes.Count())) * + //Camera projection + save_proj; + m_camera->SetProjection(new_proj); + m_meshes[i].Render(m_mat); + g_renderer->Clear(ClearMask::Depth); + } + m_camera->SetProjection(save_proj); } - m_camera->SetProjection(save_proj); } } @@ -502,7 +498,7 @@ private: //Mesh infos int m_mesh_id; float m_mesh_id1; - Array m_meshes; + Array m_meshes; //File data String m_file_name; diff --git a/test/meshviewer_index.html b/test/meshviewer_index.html index 0a148970..d05668ae 100644 --- a/test/meshviewer_index.html +++ b/test/meshviewer_index.html @@ -11,18 +11,18 @@ -
- -
+
+ +