Browse Source

EasyMesh tweaked : New Copy CTor & RenderMesh state.

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 years ago
parent
commit
0e8de199a7
5 changed files with 134 additions and 86 deletions
  1. +43
    -2
      src/easymesh/easymesh.cpp
  2. +21
    -12
      src/easymesh/easymesh.h
  3. +5
    -3
      test/data/mesh-buffer.txt
  4. +40
    -44
      test/meshviewer.cpp
  5. +25
    -25
      test/meshviewer_index.html

+ 43
- 2
src/easymesh/easymesh.cpp View File

@@ -426,6 +426,19 @@ EasyMesh::EasyMesh()
: m_build_data(nullptr) : m_build_data(nullptr)
{ {
m_cursors.Push(0, 0); 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++) for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++)
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); 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); m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode::Default), this);
for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++) for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++)
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); 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) void EasyMesh::AddVertex(vec3 const &coord)
{ {
m_vert.Push(VertexData(coord, vec3(0.f, 1.f, 0.f), BD()->Color())); m_vert.Push(VertexData(coord, vec3(0.f, 1.f, 0.f), BD()->Color()));
m_state = MeshRender::NeedConvert;
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AddDuplicateVertex(int i) void EasyMesh::AddDuplicateVertex(int i)
{ {
m_vert << m_vert[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), 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 ? */ ((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))); lol::lerp(m_vert[i].m_bone_weight, m_vert[j].m_bone_weight, alpha)));
m_state = MeshRender::NeedConvert;
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------


+ 21
- 12
src/easymesh/easymesh.h View File

@@ -26,14 +26,17 @@ struct MeshRender
{ {
enum Value enum Value
{ {
NeedInit,
NeedData,
NeedConvert,
CanRender, CanRender,
IgnoreRender
IgnoreRender,

Max
} }
m_value; m_value;


inline MeshRender(Value v) : m_value(v) {} inline MeshRender(Value v) : m_value(v) {}
inline MeshRender() : m_value(NeedInit) {}
inline MeshRender() : m_value(NeedData) {}
inline operator Value() { return m_value; } inline operator Value() { return m_value; }
}; };


@@ -106,6 +109,8 @@ public:


class GpuEasyMeshData class GpuEasyMeshData
{ {
friend class EasyMesh;

public: public:
//--- //---
GpuEasyMeshData(); GpuEasyMeshData();
@@ -520,14 +525,18 @@ struct Axis
class EasyMesh class EasyMesh
{ {
friend class EasyMeshParser; friend class EasyMeshParser;
friend class GpuEasyMeshData;


public: public:
EasyMesh(); 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: private:
void UpdateVertexDict(Array< int, int > &vertex_dict); void UpdateVertexDict(Array< int, int > &vertex_dict);
@@ -832,14 +841,14 @@ public:
vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; } vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; }


private: private:
Array<uint16_t> m_indices;
Array<VertexData> m_vert;
Array<uint16_t> m_indices;
Array<VertexData> m_vert;


//<vert count, indices count> //<vert count, indices count>
Array<int, int> m_cursors;
Array<int, int> m_cursors;


friend class GpuEasyMeshData;
GpuEasyMeshData m_gpu_data;
MeshRender m_state;
GpuEasyMeshData m_gpu_data;


public: public:
inline EasyMeshBuildData* BD() inline EasyMeshBuildData* BD()


+ 5
- 3
test/data/mesh-buffer.txt View File

@@ -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 //sc#fff
//[afcb 1 1 1 -.1 tx 1] //[afcb 1 1 1 -.1 tx 1]
//[afcb 1 1 1 -.1 tx 0] //[afcb 1 1 1 -.1 tx 0]


+ 40
- 44
test/meshviewer.cpp View File

@@ -268,8 +268,8 @@ public:
//Target List Setup //Target List Setup
Array<vec3> target_list; Array<vec3> target_list;
if (m_meshes.Count() && m_mesh_id >= 0) 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 //Update mesh screen location - Get the Min/Max needed
@@ -331,17 +331,15 @@ public:
int u = 4; int u = 4;
while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh)) while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh))
{ {
int o = 1;
int o = 4;
while (o-- > 0) while (o-- > 0)
{ {
if (m_mesh_id == m_meshes.Count() - 1) if (m_mesh_id == m_meshes.Count() - 1)
m_mesh_id++; m_mesh_id++;
//Create a new mesh //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); m_texture_shader->SetUniform(m_texture_uni, m_default_texture->GetTexture(), 0);
#endif //!__native_client__ #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)); g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));


vec3 x = vec3(1.f,0.f,0.f); vec3 x = vec3(1.f,0.f,0.f);
vec3 y = vec3(0.f,1.f,0.f); vec3 y = vec3(0.f,1.f,0.f);
for (int i = 0; i < m_meshes.Count(); i++) 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 //Mesh infos
int m_mesh_id; int m_mesh_id;
float m_mesh_id1; float m_mesh_id1;
Array<EasyMesh, bool> m_meshes;
Array<EasyMesh> m_meshes;


//File data //File data
String m_file_name; String m_file_name;


+ 25
- 25
test/meshviewer_index.html View File

@@ -11,18 +11,18 @@


<style type="text/css"> <style type="text/css">
#canvas_loading { #canvas_loading {
position: relative;
left: -2px;
top: -487px;
z-index: 1;
border:2px solid #c3c3c3;
width:640px;height:480px;
position: relative;
left: -2px;
top: -487px;
z-index: 1;
border:2px solid #c3c3c3;
width:640px;height:480px;
} }
#nacl_div { #nacl_div {
position: relative;
left: 0px;
top: 0px;
z-index: 0;
position: relative;
left: 0px;
top: 0px;
z-index: 0;
} }
</style> </style>
<!-- <!--
@@ -38,13 +38,13 @@
document.getElementById('prout').style.top = 0; document.getElementById('prout').style.top = 0;


function Tick() { function Tick() {
window.setTimeout("Tick()", 100);
window.setTimeout("Tick()", 100);
var truc = parseInt(document.getElementById('prout').style.top); var truc = parseInt(document.getElementById('prout').style.top);
//document.getElementById('prout').style.top = truc + 1 + "px";
//document.getElementById('prout').style.top = truc + 1 + "px";
var statusField = document.getElementById('tick_field'); var statusField = document.getElementById('tick_field');
if (statusField) { if (statusField) {
statusField.innerHTML = truc; statusField.innerHTML = truc;
}
}
} }




@@ -54,8 +54,8 @@
MeshCodeModule = document.getElementById('ID_MeshCode'); MeshCodeModule = document.getElementById('ID_MeshCode');
//document.getElementById('listener').style.visibility = "visible"; //document.getElementById('listener').style.visibility = "visible";
//document.getElementById('canvas_loading').style.display = "none"; //document.getElementById('canvas_loading').style.display = "none";
//document.getElementById('ID_NaClModule').width = 640;
//document.getElementById('ID_NaClModule').height = 480;
//document.getElementById('ID_NaClModule').width = 640;
//document.getElementById('ID_NaClModule').height = 480;


updateStatus('SUCCESS'); updateStatus('SUCCESS');
} }
@@ -153,17 +153,17 @@ visibility="hidden"
</td> </tr> </td> </tr>
--> -->


<div id="nacl_div">
<embed name="nacl_module"
id="ID_NaClModule"
width=770 height=200
src="nacl.nmf"
type="application/x-nacl" />
</div>
<div id="nacl_div">
<embed name="nacl_module"
id="ID_NaClModule"
width=770 height=200
src="nacl.nmf"
type="application/x-nacl" />
</div>
<!-- <!--
<div id="canvas_loading">
<canvas id="myCanvas" width="640" height="480" visibility="hidden"></canvas>
</div>
<div id="canvas_loading">
<canvas id="myCanvas" width="640" height="480" visibility="hidden"></canvas>
</div>
--> -->
<script> <script>


Loading…
Cancel
Save