1 package com.badlogic.gdx.graphics.g3d.utils;
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;
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);
90 public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
92 public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions);
94 public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions);
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);
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);
100 public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo);
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);
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);
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
123 * @param divisions number of subdivisions
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);
141 public void cone(float width, float height, float depth, int divisions);
143 public void cone(float width, float height, float depth, int divisions, float angleFrom, float angleTo);
145 public void sphere(float width, float height, float depth, int divisionsU, int divisionsV);
147 public void sphere(final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV);
149 public void sphere(float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo);
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);
153 public void capsule(float radius, float height, int divisions);
155 /** Class that contains all vertex information the builder can use.
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;
167 public void reset () {
173 public VertexInfo set(Vector3 pos, Vector3 nor, Color col, Vector2 uv) {
175 if ((hasPosition = pos != null) == true)
177 if ((hasNormal = nor != null) == true)
179 if ((hasColor = col != null) == true)
181 if ((hasUV = uv != null) == true)
185 public VertexInfo set(final VertexInfo other) {
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);
198 public VertexInfo setPos(float x, float y, float z) {
203 public VertexInfo setPos(Vector3 pos) {
204 if ((hasPosition = pos != null)==true)
208 public VertexInfo setNor(float x, float y, float z) {
213 public VertexInfo setNor(Vector3 nor) {
214 if ((hasNormal = nor != null) == true)
218 public VertexInfo setCol(float r, float g, float b, float a) {
223 public VertexInfo setCol(Color col) {
224 if ((hasColor = col != null)==true)
228 public VertexInfo setUV(float u, float v) {
233 public VertexInfo setUV(Vector2 uv) {
234 if ((hasUV = uv != null)==true)
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);