diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index d7bc2b1c..a901bb84 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -237,6 +237,37 @@ void EasyMesh::Rotate(float t, vec3 const &axis) } } +void EasyMesh::RadialJitter(float r) +{ + Array Welded; + Welded.Push(-1); + for (int i = m_cursors.Last().m1 + 1; i < m_vert.Count(); i++) + { + int j; + for (j = m_cursors.Last().m1; j < i; j++) + { + if(sqlength(m_vert[i].m1 - m_vert[j].m1) < 0.1f) + break; + } + + if(j == i) + Welded.Push(-1); + else + Welded.Push(j); + } + + int i, j; + for (i = m_cursors.Last().m1, j = 0; i < m_vert.Count(); i++, j++) + { + if(Welded[j] == -1) + m_vert[i].m1 *= 1.0f + RandF(r); + else + m_vert[i].m1 = m_vert[Welded[j]].m1; + } + + ComputeNormals(m_cursors.Last().m2, m_indices.Count() - m_cursors.Last().m2); +} + void EasyMesh::TaperX(float y, float z, float xoff) { /* FIXME: this code breaks normals! */ diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 73dde073..e4d94207 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -52,6 +52,8 @@ public: void SetCurVertNormal(vec3 const &normal); void SetCurVertColor(vec4 const &color); + void RadialJitter(float r); + void Translate(vec3 const &v); void RotateX(float t); void RotateY(float t); diff --git a/tutorial/05_easymesh.cpp b/tutorial/05_easymesh.cpp index 972a0563..fefd741b 100644 --- a/tutorial/05_easymesh.cpp +++ b/tutorial/05_easymesh.cpp @@ -29,20 +29,23 @@ public: m_mesh.OpenBrace(); m_mesh.Compile("ad12,2.2,0 ty.1 ac12,.2,2.4,2.2,0,1 ty.8 ac12,1.7,2.4,2.4,0,1 ty2.5"); m_mesh.Translate(vec3(i * 8.f, (h - 1) * 3.2f, j * 8.f)); - m_mesh.CloseBrace(); + + m_mesh.CloseBrace(); } m_mesh.OpenBrace(); m_mesh.AppendFlatChamfBox(vec3(x * 8.f, h * 3.2f, y * 8.f), -.1f); m_mesh.Translate(vec3((x - 1) * 4.f, (h - 1) * 1.6f, (y - 1) * 4.f)); m_mesh.CloseBrace(); m_mesh.Translate(vec3(dx * 8.f, dh * 3.2f, dy * 8.f)); + m_mesh.CloseBrace(); } EasyMeshTutorial() { m_angle = 0; - //m_mesh.Compile("sc#e94 scb#964 [asph11 7 7 7 tx10]"); + m_mesh.Compile("sc#800 [asph10 20 20 20]"); + m_mesh.RadialJitter(0.2f); //m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx-6 tz-9]"); //m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx-6 tz9]"); m_mesh.Compile("sc#1c1 scb#1c1");