OSDN Git Service

Added ellipse builder
[mikumikustudio/libgdx-mikumikustudio.git] / gdx / src / com / badlogic / gdx / graphics / g3d / utils / MeshPartBuilder.java
1 package com.badlogic.gdx.graphics.g3d.utils;
2
3 import com.badlogic.gdx.graphics.Color;
4 import com.badlogic.gdx.graphics.GL10;
5 import com.badlogic.gdx.graphics.VertexAttributes;
6 import com.badlogic.gdx.graphics.g3d.Material;
7 import com.badlogic.gdx.graphics.g3d.Model;
8 import com.badlogic.gdx.graphics.g3d.model.MeshPart;
9 import com.badlogic.gdx.math.Matrix4;
10 import com.badlogic.gdx.math.Vector2;
11 import com.badlogic.gdx.math.Vector3;
12 import com.badlogic.gdx.utils.Pool.Poolable;
13
14 public interface MeshPartBuilder {
15         /** @return The {@link MeshPart} currently building. */
16         public MeshPart getMeshPart();
17         /** @return The {@link VertexAttributes} available for building. */
18         public VertexAttributes getAttributes();
19         /** Set the color used if no vertex color is provided, or null to not use a default color. */
20         public void setColor(final Color color);
21         /** Set the color used if no vertex color is provided. */
22         public void setColor(float r, float g, float b, float a);
23         /** Set range of texture coordinates used (default is 0,0,1,1). */
24         public void setUVRange(float u1, float v1, float u2, float v2);
25         /** Add one or more vertices, returns the index of the last vertex added. The length of values must a power of the vertex size. */
26         public short vertex(final float... values);
27         /** Add a vertex, returns the index. Null values are allowed. Use {@link #getAttributes} to check which values are available. */
28         public short vertex(Vector3 pos, Vector3 nor, Color col, Vector2 uv);
29         /** Add a vertex, returns the index. Use {@link #getAttributes} to check which values are available. */
30         public short vertex(final VertexInfo info);
31         /** @return The index of the last added vertex. */
32         public short lastIndex();
33         /** Add an index, MeshPartBuilder expects all meshes to be indexed. */
34         public void index(final short value);
35         /** Add multiple indices, MeshPartBuilder expects all meshes to be indexed. */
36         public void index(short value1, short value2);
37         /** Add multiple indices, MeshPartBuilder expects all meshes to be indexed. */
38         public void index(short value1, short value2, short value3);
39         /** Add multiple indices, MeshPartBuilder expects all meshes to be indexed. */
40         public void index(short value1, short value2, short value3, short value4);
41         /** Add multiple indices, MeshPartBuilder expects all meshes to be indexed. */
42         public void index(short value1, short value2, short value3, short value4, short value5, short value6);
43         /** Add multiple indices, MeshPartBuilder expects all meshes to be indexed. */
44         public void index(short value1, short value2, short value3, short value4, short value5, short value6, short value7, short value8);
45         /** Add a line by indices. Requires GL_LINES primitive type. */
46         public void line(short index1, short index2);
47         /** Add a line. Requires GL_LINES primitive type. */
48         public void line(VertexInfo p1, VertexInfo p2);
49         /** Add a line. Requires GL_LINES primitive type. */
50         public void line(Vector3 p1, Vector3 p2);
51         /** Add a line. Requires GL_LINES primitive type. */
52         public void line(float x1, float y1, float z1, float x2, float y2, float z2);
53         /** Add a line. Requires GL_LINES primitive type. */
54         public void line(Vector3 p1, Color c1, Vector3 p2, Color c2);
55         /** Add a triangle by indices. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
56         public void triangle(short index1, short index2, short index3);
57         /** Add a triangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
58         public void triangle(VertexInfo p1, VertexInfo p2, VertexInfo p3);
59         /** Add a triangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
60         public void triangle(Vector3 p1, Vector3 p2, Vector3 p3);
61         /** Add a triangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
62         public void triangle(Vector3 p1, Color c1, Vector3 p2, Color c2, Vector3 p3, Color c3);
63         /** Add a rectangle by indices. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
64         public void rect(short corner00, short corner10, short corner11, short corner01);
65         /** Add a rectangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
66         public void rect(VertexInfo corner00, VertexInfo corner10, VertexInfo corner11, VertexInfo corner01);
67         /** Add a rectangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
68         public void rect(Vector3 corner00, Vector3 corner10, Vector3 corner11, Vector3 corner01, Vector3 normal);
69         /** Add a rectangle Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
70         public void rect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ);
71         /** Add a rectangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
72         public void patch(VertexInfo corner00, VertexInfo corner10, VertexInfo corner11, VertexInfo corner01, int divisionsU, int divisionsV);
73         /** Add a rectangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
74         public void patch(Vector3 corner00, Vector3 corner10, Vector3 corner11, Vector3 corner01, Vector3 normal, int divisionsU, int divisionsV);
75         /** Add a rectangle. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
76         public void patch(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int divisionsU, int divisionsV);
77         /** Add a box. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
78         public void box(VertexInfo corner000, VertexInfo corner010, VertexInfo corner100, VertexInfo corner110,
79                                                 VertexInfo corner001, VertexInfo corner011, VertexInfo corner101, VertexInfo corner111);
80         /** Add a box. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
81         public void box(Vector3 corner000, Vector3 corner010, Vector3 corner100, Vector3 corner110,
82                                                 Vector3 corner001, Vector3 corner011, Vector3 corner101, Vector3 corner111);
83         /** Add a box given the matrix. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
84         public void box(Matrix4 transform);
85         /** Add a box with the specified dimensions. Requires GL_POINTS, GL_LINES or GL_TRIANGLES primitive type. */
86         public void box(float width, float height, float depth);
87         /** Add a box at the specified location, with the specified dimensions */
88         public void box(float x, float y, float z, float width, float height, float depth);
89         /** Add a circle */
90         public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
91         /** Add a circle */
92         public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions);
93         /** Add a circle */
94         public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions);
95         /** Add a circle */
96         public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions);
97         /** Add a circle */
98         public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
99         /** Add a circle */
100         public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo);
101         /** Add a circle */
102         public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo);
103         /** Add a circle */
104         public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo);
105         /**
106          * Add an ellipse
107          * @param width external width
108          * @param height external height
109          * @param innerWidth internal width
110          * @param innerHeight internal height
111          * @param centerX center
112          * @param centerY center
113          * @param centerZ center
114          * @param normalX normal
115          * @param normalY normal
116          * @param normalZ normal
117          * @param tangentX
118          * @param tangentY
119          * @param tangentZ
120          * @param binormalX
121          * @param binormalY
122          * @param binormalZ
123          * @param divisions number of subdivisions
124          * @param angleFrom
125          * @param angleTo
126          */
127         public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo);
128         /** Add an ellipse */
129         public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
130         /** Add an ellipse */
131         public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
132         /** Add an ellipse */
133         public void ellipse(float width, float height, float innerWidth, float innerHeight, Vector3 center, Vector3 normal, int divisions);
134         /** Add a cylinder */
135         public void cylinder(float width, float height, float depth, int divisions);
136         /** Add a cylinder */
137         public void cylinder(float width, float height, float depth, int divisions, float angleFrom, float angleTo);
138         /** Add a cylinder */
139         public void cylinder(float width, float height, float depth, int divisions, float angleFrom, float angleTo, boolean close);
140         /** Add a cone */
141         public void cone(float width, float height, float depth, int divisions);
142         /** Add a cone */
143         public void cone(float width, float height, float depth, int divisions, float angleFrom, float angleTo);
144         /** Add a sphere */
145         public void sphere(float width, float height, float depth, int divisionsU, int divisionsV);
146         /** Add a sphere */
147         public void sphere(final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV);
148         /** Add a sphere */
149         public void sphere(float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo);
150         /** Add a sphere */
151         public void sphere(final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo);
152         /** Add a capsule */
153         public void capsule(float radius, float height, int divisions);
154         
155         /** Class that contains all vertex information the builder can use.
156          * @author Xoppa */
157         public static class VertexInfo implements Poolable {
158                 public final Vector3 position = new Vector3();
159                 public boolean hasPosition;
160                 public final Vector3 normal = new Vector3(0, 1, 0);
161                 public boolean hasNormal;
162                 public final Color color = new Color(1, 1, 1, 1);
163                 public boolean hasColor;
164                 public final Vector2 uv = new Vector2();
165                 public boolean hasUV;
166                 @Override
167                 public void reset () {
168                         position.set(0,0,0);
169                         normal.set(0,1,0);
170                         color.set(1,1,1,1);
171                         uv.set(0,0);
172                 }
173                 public VertexInfo set(Vector3 pos, Vector3 nor, Color col, Vector2 uv) {
174                         reset();
175                         if ((hasPosition = pos != null) == true)
176                                 position.set(pos);
177                         if ((hasNormal = nor != null) == true)
178                                 normal.set(nor);
179                         if ((hasColor = col != null) == true)
180                                 color.set(col);
181                         if ((hasUV = uv != null) == true)
182                                 this.uv.set(uv);
183                         return this;
184                 }
185                 public VertexInfo set(final VertexInfo other) {
186                         if (other == null)
187                                 return set(null, null, null, null);
188                         hasPosition = other.hasPosition;
189                         position.set(other.position);
190                         hasNormal = other.hasNormal;
191                         normal.set(other.normal);
192                         hasColor = other.hasColor;
193                         color.set(other.color);
194                         hasUV = other.hasUV;
195                         uv.set(other.uv);
196                         return this;
197                 }
198                 public VertexInfo setPos(float x, float y, float z) {
199                         position.set(x,y,z);
200                         hasPosition = true;
201                         return this;
202                 }
203                 public VertexInfo setPos(Vector3 pos) {
204                         if ((hasPosition = pos != null)==true)
205                                 position.set(pos);
206                         return this;
207                 }
208                 public VertexInfo setNor(float x, float y, float z) {
209                         normal.set(x,y,z);
210                         hasNormal = true;
211                         return this;
212                 }
213                 public VertexInfo setNor(Vector3 nor) {
214                         if ((hasNormal = nor != null) == true)
215                                 normal.set(nor);
216                         return this;
217                 }
218                 public VertexInfo setCol(float r, float g, float b, float a) {
219                         color.set(r,g,b,a);
220                         hasColor = true;
221                         return this;
222                 }
223                 public VertexInfo setCol(Color col) {
224                         if ((hasColor = col != null)==true)
225                                 color.set(col);
226                         return this;
227                 }
228                 public VertexInfo setUV(float u, float v) {
229                         uv.set(u,v);
230                         hasUV = true;
231                         return this;
232                 }
233                 public VertexInfo setUV(Vector2 uv) {
234                         if ((hasUV = uv != null)==true)
235                                 this.uv.set(uv);
236                         return this;
237                 }
238                 public VertexInfo lerp(final VertexInfo target, float alpha) {
239                         if (hasPosition && target.hasPosition)
240                                 position.lerp(target.position, alpha);
241                         if (hasNormal && target.hasNormal)
242                                 normal.lerp(target.normal, alpha);
243                         if (hasColor && target.hasColor)
244                                 color.lerp(target.color, alpha);
245                         if (hasUV && target.hasUV)
246                                 uv.lerp(target.uv, alpha);
247                         return this;
248                 }
249         }
250 }