[1510] | 1 | // |
---|
| 2 | // Lol Engine |
---|
| 3 | // |
---|
[2226] | 4 | // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> |
---|
| 5 | // (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> |
---|
| 6 | // (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> |
---|
[1510] | 7 | // This program is free software; you can redistribute it and/or |
---|
| 8 | // modify it under the terms of the Do What The Fuck You Want To |
---|
| 9 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
[2183] | 10 | // http://www.wtfpl.net/ for more details. |
---|
[1510] | 11 | // |
---|
| 12 | |
---|
| 13 | // |
---|
| 14 | // The EasyMesh class |
---|
| 15 | // ------------------ |
---|
| 16 | // |
---|
| 17 | |
---|
| 18 | #if !defined __EASYMESH_EASYMESH_H__ |
---|
| 19 | #define __EASYMESH_EASYMESH_H__ |
---|
| 20 | |
---|
| 21 | namespace lol |
---|
| 22 | { |
---|
| 23 | |
---|
[2350] | 24 | /* A safe enum for MeshCSG operations. */ |
---|
| 25 | struct CSGUsage |
---|
| 26 | { |
---|
| 27 | enum Value |
---|
| 28 | { |
---|
[2356] | 29 | Union, |
---|
| 30 | Substract, |
---|
| 31 | SubstractLoss, //will remove B from A, but not add inverted B |
---|
| 32 | And, |
---|
[2350] | 33 | Xor, |
---|
| 34 | } |
---|
| 35 | m_value; |
---|
| 36 | |
---|
| 37 | inline CSGUsage(Value v) : m_value(v) {} |
---|
| 38 | inline operator Value() { return m_value; } |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | |
---|
[1510] | 42 | class EasyMesh |
---|
| 43 | { |
---|
| 44 | friend class EasyMeshParser; |
---|
| 45 | |
---|
| 46 | public: |
---|
| 47 | EasyMesh(); |
---|
| 48 | |
---|
| 49 | bool Compile(char const *command); |
---|
[2209] | 50 | void MeshConvert(Shader* ProvidedShader = NULL); |
---|
[1510] | 51 | void Render(mat4 const &model, float damage = 0.f); |
---|
| 52 | |
---|
[2226] | 53 | private: |
---|
| 54 | void UpdateVertexDict(Array< int, int > &vertex_dict); |
---|
[2350] | 55 | |
---|
| 56 | //------------------------------------------------------------------------- |
---|
| 57 | //Mesh CSG operations |
---|
| 58 | //------------------------------------------------------------------------- |
---|
| 59 | private: |
---|
| 60 | void MeshCsg(CSGUsage csg_operation); |
---|
[2226] | 61 | public: |
---|
[2350] | 62 | void CsgUnion() { MeshCsg(CSGUsage::Union); } |
---|
| 63 | void CsgSubstract() { MeshCsg(CSGUsage::Substract); } |
---|
| 64 | void CsgSubstractLoss() { MeshCsg(CSGUsage::SubstractLoss); } |
---|
| 65 | void CsgAnd() { MeshCsg(CSGUsage::And); } |
---|
| 66 | void CsgXor() { MeshCsg(CSGUsage::Xor); } |
---|
[2226] | 67 | |
---|
| 68 | public: |
---|
[1510] | 69 | void OpenBrace(); |
---|
| 70 | void CloseBrace(); |
---|
| 71 | |
---|
[2226] | 72 | void ToggleScaleWinding(); |
---|
[1510] | 73 | void SetCurColor(vec4 const &color); |
---|
| 74 | void SetCurColor2(vec4 const &color); |
---|
[1705] | 75 | |
---|
| 76 | private: |
---|
[1510] | 77 | void AddVertex(vec3 const &coord); |
---|
| 78 | void AddDuplicateVertex(int i); |
---|
| 79 | void AppendQuad(int i1, int i2, int i3, int i4, int base); |
---|
| 80 | void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base); |
---|
| 81 | void AppendTriangle(int i1, int i2, int i3, int base); |
---|
| 82 | void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base); |
---|
| 83 | void ComputeNormals(int start, int vcount); |
---|
| 84 | void SetVertColor(vec4 const &color); |
---|
[1705] | 85 | |
---|
[1510] | 86 | void SetCurVertNormal(vec3 const &normal); |
---|
| 87 | void SetCurVertColor(vec4 const &color); |
---|
| 88 | |
---|
[2350] | 89 | public: |
---|
| 90 | //------------------------------------------------------------------------- |
---|
| 91 | //Mesh transform operations |
---|
| 92 | //------------------------------------------------------------------------- |
---|
[1510] | 93 | void Translate(vec3 const &v); |
---|
| 94 | void RotateX(float t); |
---|
| 95 | void RotateY(float t); |
---|
| 96 | void RotateZ(float t); |
---|
| 97 | void Rotate(float t, vec3 const &axis); |
---|
[2350] | 98 | void RadialJitter(float r); |
---|
[1510] | 99 | void TaperX(float y, float z, float xoff); |
---|
| 100 | void TaperY(float x, float z, float yoff); |
---|
| 101 | void TaperZ(float x, float y, float zoff); |
---|
| 102 | void Scale(vec3 const &s); |
---|
| 103 | void MirrorX(); |
---|
| 104 | void MirrorY(); |
---|
| 105 | void MirrorZ(); |
---|
| 106 | void DupAndScale(vec3 const &s); |
---|
| 107 | void Chamfer(float f); |
---|
| 108 | |
---|
[2350] | 109 | //------------------------------------------------------------------------- |
---|
| 110 | //Mesh shape operations |
---|
| 111 | //------------------------------------------------------------------------- |
---|
[1510] | 112 | void AppendCylinder(int nsides, float h, float r1, float r2, |
---|
| 113 | int dualside, int smooth); |
---|
[1619] | 114 | void AppendCapsule(int ndivisions, float h, float r); |
---|
[1510] | 115 | void AppendSphere(int ndivisions, vec3 const &size); |
---|
[1875] | 116 | void AppendTorus(int ndivisions, float r1, float r2); |
---|
[1510] | 117 | void AppendBox(vec3 const &size, float chamf = 0.f); |
---|
| 118 | void AppendSmoothChamfBox(vec3 const &size, float chamf); |
---|
| 119 | void AppendFlatChamfBox(vec3 const &size, float chamf); |
---|
| 120 | void AppendBox(vec3 const &size, float chamf, bool smooth); |
---|
| 121 | void AppendStar(int nbranches, float r1, float r2, |
---|
| 122 | int fade = 0, int fade2 = 0); |
---|
| 123 | void AppendExpandedStar(int nbranches, float r1, float r2, float extrar); |
---|
| 124 | void AppendDisc(int nsides, float r, int fade = 0); |
---|
| 125 | void AppendSimpleTriangle(float size, int fade = 0); |
---|
| 126 | void AppendSimpleQuad(float size, int fade = 0); |
---|
| 127 | void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0); |
---|
[2151] | 128 | void AppendCog(int nbsides, float h, float r10, float r20, float r1, |
---|
| 129 | float r2, float r12, float r22, float sidemul, int offset); |
---|
[1510] | 130 | |
---|
[2350] | 131 | //------------------------------------------------------------------------- |
---|
| 132 | //TODO : Mesh Bone operations |
---|
| 133 | //------------------------------------------------------------------------- |
---|
| 134 | //void AddBone(int parent_id) {} |
---|
| 135 | |
---|
[2294] | 136 | //Convenience functions |
---|
| 137 | public: |
---|
| 138 | int GetVertexCount() { return m_vert.Count(); } |
---|
| 139 | vec3 const &GetVertexLocation(int i) { return m_vert[i].m1; } |
---|
| 140 | |
---|
[1510] | 141 | private: |
---|
| 142 | vec4 m_color, m_color2; |
---|
| 143 | Array<uint16_t> m_indices; |
---|
[2350] | 144 | //TODO : <coord, norm, color, bone_id, bone_weight> |
---|
| 145 | //TODO : Array<vec3, vec3, vec4, ivec2, vec2> m_vert; |
---|
| 146 | //TODO : More bone blend support than 2 ? |
---|
[2226] | 147 | //<coord, norm, color> |
---|
[1510] | 148 | Array<vec3, vec3, vec4> m_vert; |
---|
[2226] | 149 | //<vert count, indices count> |
---|
[1510] | 150 | Array<int, int> m_cursors; |
---|
[2350] | 151 | //When this flag is up, negative scaling will not invert faces. |
---|
[2226] | 152 | bool m_ignore_winding_on_scale; |
---|
[1510] | 153 | |
---|
| 154 | /* FIXME: put this in a separate class so that we can copy meshes. */ |
---|
| 155 | struct |
---|
| 156 | { |
---|
[2370] | 157 | /* FIXME: very naughty way of handling debug render modes */ |
---|
| 158 | Array<Shader *>shader; |
---|
| 159 | Array<ShaderAttrib> coord, norm, color; |
---|
| 160 | Array<ShaderUniform> modelview, view, invview, proj, normalmat, damage, lights; |
---|
| 161 | |
---|
[1510] | 162 | VertexDeclaration *vdecl; |
---|
| 163 | VertexBuffer *vbo; |
---|
| 164 | IndexBuffer *ibo; |
---|
| 165 | int vertexcount, indexcount; |
---|
| 166 | } |
---|
| 167 | m_gpu; |
---|
| 168 | }; |
---|
| 169 | |
---|
| 170 | } /* namespace lol */ |
---|
| 171 | |
---|
| 172 | #endif /* __EASYMESH_EASYMESH_H__ */ |
---|
| 173 | |
---|