浏览代码

easymesh : all radius are now diameters so all mesh operation size values are coherent.

legacy
Benjamin ‘Touky’ Huet touky 12 年前
父节点
当前提交
73fd59c69a
共有 3 个文件被更改,包括 90 次插入55 次删除
  1. +45
    -12
      src/easymesh/easymesh.cpp
  2. +41
    -41
      src/easymesh/easymesh.h
  3. +4
    -2
      test/MeshViewerBuffer.txt

+ 45
- 12
src/easymesh/easymesh.cpp 查看文件

@@ -1006,9 +1006,13 @@ void EasyMesh::DupAndScale(vec3 const &s)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendCylinder(int nsides, float h, float r1, float r2, void EasyMesh::AppendCylinder(int nsides, float h, float d1, float d2,
int dualside, int smooth, int close) int dualside, int smooth, int close)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r1 = d1 * .5f;
float r2 = d2 * .5f;

//SAVE //SAVE
vec4 Saved_Color = m_color; vec4 Saved_Color = m_color;
vec4 Saved_Color2 = m_color2; vec4 Saved_Color2 = m_color2;
@@ -1090,14 +1094,17 @@ void EasyMesh::AppendCylinder(int nsides, float h, float r1, float r2,
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendSphere(int ndivisions, float r) void EasyMesh::AppendSphere(int ndivisions, float d)
{ {
AppendCapsule(ndivisions, 0.f, r); AppendCapsule(ndivisions, 0.f, d);
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendCapsule(int ndivisions, float h, float r) void EasyMesh::AppendCapsule(int ndivisions, float h, float d)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r = d * .5f;

int ibase = m_indices.Count(); int ibase = m_indices.Count();


Array<vec3> vertices; Array<vec3> vertices;
@@ -1237,8 +1244,12 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float r)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendTorus(int ndivisions, float r1, float r2) void EasyMesh::AppendTorus(int ndivisions, float d1, float d2)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r1 = d1 * .5f;
float r2 = d2 * .5f;

int ibase = m_indices.Count(); int ibase = m_indices.Count();
int nidiv = ndivisions; /* Cross-section */ int nidiv = ndivisions; /* Cross-section */
int njdiv = ndivisions; /* Full circumference */ int njdiv = ndivisions; /* Full circumference */
@@ -1418,9 +1429,13 @@ void EasyMesh::AppendBox(vec3 const &size, float chamf, bool smooth)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendStar(int nbranches, float r1, float r2, void EasyMesh::AppendStar(int nbranches, float d1, float d2,
int fade, int fade2) int fade, int fade2)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r1 = d1 * .5f;
float r2 = d2 * .5f;

//TODO: It would probably be good to think of another way of UV painting this, like "branch repeating" //TODO: It would probably be good to think of another way of UV painting this, like "branch repeating"
int vbase = m_vert.Count(); int vbase = m_vert.Count();
float maxr = max(r1, r2); float maxr = max(r1, r2);
@@ -1454,9 +1469,13 @@ void EasyMesh::AppendStar(int nbranches, float r1, float r2,
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendExpandedStar(int nbranches, float r1, void EasyMesh::AppendExpandedStar(int nbranches, float d1, float d2, float extrad)
float r2, float extrar)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r1 = d1 * .5f;
float r2 = d2 * .5f;
float extrar = extrad * .5f;

int vbase = m_vert.Count(); int vbase = m_vert.Count();
float maxr = (float)max(max(r1, r2), max(r1 + extrar, r2 + extrar)); float maxr = (float)max(max(r1, r2), max(r1 + extrar, r2 + extrar));


@@ -1494,8 +1513,11 @@ void EasyMesh::AppendExpandedStar(int nbranches, float r1,
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendDisc(int nsides, float r, int fade) void EasyMesh::AppendDisc(int nsides, float d, int fade)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r = d * .5f;

int vbase = m_vert.Count(); int vbase = m_vert.Count();


AddVertex(vec3(0.f, 0.f, 0.f)); SetCurVertTexCoord(vec2(.5f, .5f)); AddVertex(vec3(0.f, 0.f, 0.f)); SetCurVertTexCoord(vec2(.5f, .5f));
@@ -1516,8 +1538,11 @@ void EasyMesh::AppendDisc(int nsides, float r, int fade)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendSimpleTriangle(float size, int fade) void EasyMesh::AppendSimpleTriangle(float d, int fade)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float size = d * .5f;

mat3 m = mat3::rotate(120.f, 0.f, 1.f, 0.f); mat3 m = mat3::rotate(120.f, 0.f, 1.f, 0.f);
vec3 p(0.f, 0.f, size); vec3 p(0.f, 0.f, size);


@@ -1557,10 +1582,18 @@ void EasyMesh::AppendSimpleQuad(vec2 p1, vec2 p2, float z, int fade)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::AppendCog(int nbsides, float h, float r10, float r20, void EasyMesh::AppendCog(int nbsides, float h, float d10, float d20,
float r1, float r2, float r12, float r22, float d1, float d2, float d12, float d22,
float sidemul, int offset) float sidemul, int offset)
{ {
//XXX : This operation is done to convert radius to diameter without changing all the code.
float r10 = d10 * .5f;
float r20 = d20 * .5f;
float r1 = d1 * .5f;
float r2 = d2 * .5f;
float r12 = d12 * .5f;
float r22 = d22 * .5f;

int ibase = m_indices.Count(); int ibase = m_indices.Count();
int vbase = m_vert.Count(); int vbase = m_vert.Count();




+ 41
- 41
src/easymesh/easymesh.h 查看文件

@@ -235,34 +235,34 @@ public:
//Mesh shape operations //Mesh shape operations
//------------------------------------------------------------------------- //-------------------------------------------------------------------------


/* [cmd:ac] Cylinder centered on (0,0,0) with BBox [-max(r1, r2), -.5*h, -max(r1, r2)][max(r1, r2), .5*h, max(r1, r2)] /* [cmd:ac] Cylinder centered on (0,0,0) with BBox [-.5*max(d1, d2), -.5*h, -.5*max(d1, d2)]
- nbsides : Number of sides. - nbsides : Number of sides. [+.5*max(d1, d2), +.5*h, +.5*max(d1, d2)]
- h : Height of the cylinder. - h : Height of the cylinder.
- r1 : Lower radius. TODO:convert to diameter to be coherent with other funcs - d1 : Lower diameter.
- r2 : Upper radius. TODO:convert to diameter to be coherent with other funcs - d2 : Upper diameter.
- dualside : if (1) will also create inner sides : TOOD:TOREMOVE?? : needed ? - dualside : if (1) will also create inner sides : TOOD:TOREMOVE?? : needed ?
- smooth : if (1) will smooth normals : TOOD:TOREMOVE : smooth should be handled elsewhere - smooth : if (1) will smooth normals : TOOD:TOREMOVE : smooth should be handled elsewhere
- close : if (1) will add discs to close the cylinder - close : if (1) will add discs to close the cylinder
*/ */
void AppendCylinder(int nsides, float h, float r1, float r2, void AppendCylinder(int nsides, float h, float d1, float d2,
int dualside, int smooth, int close); int dualside, int smooth, int close);
/* [cmd:asph] Sphere centered on (0,0,0) with BBox [-size][size] /* [cmd:asph] Sphere centered on (0,0,0) with BBox [-.5*d][.5*d]
- ndivisions : number of subdivisions each Sphere triangle will sustain. - ndivisions : number of subdivisions each Sphere triangle will sustain.
- size : size of the Sphere. - d : Diameter.
*/ */
void AppendSphere(int ndivisions, float r); void AppendSphere(int ndivisions, float d);
/* [cmd:acap] Capsule centered on (0,0,0) with BBox [-r, -(r+h) ,-r][r, (r+h) ,r] /* [cmd:acap] Capsule centered on (0,0,0) with BBox [-.5*d, -(.5*d+h), -.5*d][.5*d, (.5*d+h), .5*d]
- ndivisions : number of subdivisions each Sphere triangle will sustain. - ndivisions : number of subdivisions each Sphere triangle will sustain.
- h : Inner height. - h : Inner height.
- r : Radius. TODO:convert to diameter to be coherent with other funcs - d : Diameter.
*/ */
void AppendCapsule(int ndivisions, float h, float r); void AppendCapsule(int ndivisions, float h, float d);
/* [cmd:ato] Torus centered on (0,0,0) with BBox [-r2][r2] /* [cmd:ato] Torus centered on (0,0,0) with BBox [-.5*d2][.5*d2]
- ndivisions : number of subdivisions of the torus. - ndivisions : number of subdivisions of the torus.
- r1 : Inner radius. TODO:convert to diameter to be coherent with other funcs - d1 : Inner diameter.
- r2 : Outer radius. TODO:convert to diameter to be coherent with other funcs - d2 : Outer diameter.
*/ */
void AppendTorus(int ndivisions, float r1, float r2); void AppendTorus(int ndivisions, float d1, float d2);
/* [cmd:ab] Box centered on (0,0,0) with BBox [-.5 * size][.5 * size] /* [cmd:ab] Box centered on (0,0,0) with BBox [-.5 * size][.5 * size]
- size : size of the box. - size : size of the box.
- chamf : size of the chamfer. - chamf : size of the chamfer.
@@ -276,35 +276,35 @@ public:
//Same as AppendBox //Same as AppendBox
void AppendBox(vec3 const &size, float chamf, bool smooth); void AppendBox(vec3 const &size, float chamf, bool smooth);
/* [cmd:as] /* [cmd:as]
Append a Star centered on (0,0,0) contained within a disc of "max(r1, r2)" radius. Append a Star centered on (0,0,0) contained within a disc of "max(d1, d2)" diameter.
- nbranches : Number of branches. - nbranches : Number of branches.
- r1 : Length of the branches. - d1 : double Length of the branches.
- r2 : Length of the "branch" located between r1-branches. - d2 : double Length of the "branch" located between d1-branches.
- fade : if (1) in-between branches use Color2. - fade : if (1) in-between branches use Color2.
- fade2 : if (1) Star branches use Color2. - fade2 : if (1) Star branches use Color2.
*/ */
void AppendStar(int nbranches, float r1, float r2, void AppendStar(int nbranches, float d1, float d2,
int fade = 0, int fade2 = 0); int fade = 0, int fade2 = 0);
/* [cmd:aes] Star centered on (0,0,0) contained within a disc of "max(max(r1, r2), max(r1 + extrar, r2 + extrar))" radius. /* [cmd:aes] Star centered on (0,0,0) contained within a disc of "max(max(d1, d2), max(d1 + extrad, d2 + extrad))" diameter.
Expanded star branches use Color2. Expanded star branches use Color2.
- nbranches : Number of branches. - nbranches : Number of branches.
- r1 : Length of the branches. - d1 : Double Length of the branches.
- r2 : Length of the "branch" located between r1-branches. - d2 : Double Length of the "branch" located between r1-branches.
- extrar : Extra length added to expand all branches. - extrad : Extra length added to expand all branches.
*/ */
void AppendExpandedStar(int nbranches, float r1, float r2, float extrar); void AppendExpandedStar(int nbranches, float d1, float d2, float extrad);
/* [cmd:ad] Disc centered on (0,0,0) with BBox [-size][size] /* [cmd:ad] Disc centered on (0,0,0) with d diameter.
- nbsides : Number of sides. - nbsides : Number of sides.
- r : Radius. TODO:convert to diameter to be coherent with other funcs - d : Diameter.
- fade : if (1) Outer vertices will use Color2 - fade : if (1) Outer vertices will use Color2
*/ */
void AppendDisc(int nsides, float r, int fade = 0); void AppendDisc(int nsides, float d, int fade = 0);
/* [cmd:at] Triangle centered on (0,0,0) contained within a disc of "size" radius. /* [cmd:at] Triangle centered on (0,0,0) contained within a disc of "d" diameter.
- size : Size of vector : origin-TO-vertex. - d : diameter of the containing disc..
- fade : if (1) 2nd & 3rd Vertices will use Color2 - fade : if (1) 2nd & 3rd Vertices will use Color2
*/ */
void AppendSimpleTriangle(float size, int fade = 0); void AppendSimpleTriangle(float d, int fade = 0);
/* [cmd:aq] Quad centered on (0,0,0) contained within BBox [-size,0,-size][size,0,size] /* [cmd:aq] Quad centered on (0,0,0) contained within BBox [-size*.5f, 0, -size*.5f][size*.5f, 0, size*.5f]
- size : Size of quad. - size : Size of quad.
- fade : if (1) 3rd & 4th Vertices will use Color2 - fade : if (1) 3rd & 4th Vertices will use Color2
*/ */
@@ -313,19 +313,19 @@ private:
//complex version of above one //complex version of above one
void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0); void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0);
public: public:
/* [cmd:acg] Gear centered on (0,0,0) contained within BBox [-max(r1,r2), -.5*h, -max(r1, r2)][max(r1, r2), .5*h, max(r1, r2)] /* [cmd:acg] Gear centered on (0,0,0) contained within BBox [-.5*max(d1,d2), -.5*h, -.5*max(d1, d2)]
- h : Height of the Gear. - h : Height of the Gear. [+.5*max(d1,d2), +.5*h, +.5*max(d1, d2)]
- r10 : Upper Inner radius. - d10 : Upper Inner diameter.
- r20 : Lower Inner radius. - d20 : Lower Inner diameter.
- r1 : Upper Outer radius. - d1 : Upper Outer diameter.
- r2 : Lower Outer radius. - d2 : Lower Outer diameter.
- r12 : Upper Cog radius. - d12 : Upper Cog diameter.
- r22 : Lower Cog radius. - d22 : Lower Cog diameter.
- sidemul : multiplier for the size of the cogs. - sidemul : multiplier for the size of the cogs.
- offset : useless - offset : useless
*/ */
void AppendCog(int nbsides, float h, float r10, float r20, float r1, void AppendCog(int nbsides, float h, float d10, float d20, float d1,
float r2, float r12, float r22, float sidemul, int offset); float d2, float d12, float d22, float sidemul, int offset);


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
//TODO : Mesh Bone operations //TODO : Mesh Bone operations


+ 4
- 2
test/MeshViewerBuffer.txt 查看文件

@@ -1,5 +1,7 @@
[sc#88f ab 4 4 4 tx 4 ab 4 4 4 tx -2 tax .4 .4 0] //[sc#88f ab 4 4 4 tx 4 ab 4 4 4 tx -2 tax .4 .4 0]
//[sc#88f ab 4 4 4]
//[sc#ff2 asph 2 4 tx 4 tax 1 1 0] //[sc#ff2 asph 2 4 tx 4 tax 1 1 0]
[sc#ff2 asph 2 4]
//[sc#ff2 acap 1 4 4] //[sc#ff2 acap 1 4 4]
//[sc#ff2 scb#ff2 ac 10 4 4 4 0 0 1] //[sc#ff2 scb#ff2 ac 10 4 4 4 0 0 1]
//[sc#ff2 scb#ff2 ad 10 4 0] //[sc#ff2 scb#ff2 ad 10 4 0]
@@ -7,7 +9,7 @@
//[sc#ff2 scb#2ff at 4 1] //[sc#ff2 scb#2ff at 4 1]
//[sc#ff2 scb#2ff aq 4 0] //[sc#ff2 scb#2ff aq 4 0]
//[sc#ff2 scb#2ff aes 5 3 6 2] //[sc#ff2 scb#2ff aes 5 3 6 2]
//[sc#ff2 scb#2ff as 5 2 5 0 0] //[sc#ff2 scb#2ff as 4 2 4 0 0]
//[sc#ff2 scb#2ff acg 2 10 .1 .1 .4 .4 .1 .1 0 1] //[sc#ff2 scb#2ff acg 2 10 .1 .1 .4 .4 .1 .1 0 1]
//[sc#ff2 asph 2 10 10 10] //[sc#ff2 asph 2 10 10 10]


||||||
x
 
000:0
正在加载...
取消
保存