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);
105 /** Add a cylinder */
106 public void cylinder(float width, float height, float depth, int divisions);
107 /** Add a cylinder */
108 public void cylinder(float width, float height, float depth, int divisions, float angleFrom, float angleTo);
109 /** Add a cylinder */
110 public void cylinder(float width, float height, float depth, int divisions, float angleFrom, float angleTo, boolean close);
112 public void cone(float width, float height, float depth, int divisions);
114 public void cone(float width, float height, float depth, int divisions, float angleFrom, float angleTo);
116 public void sphere(float width, float height, float depth, int divisionsU, int divisionsV);
118 public void sphere(final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV);
120 public void sphere(float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo);
122 public void sphere(final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo);
124 public void capsule(float radius, float height, int divisions);
126 /** Class that contains all vertex information the builder can use.
128 public static class VertexInfo implements Poolable {
129 public final Vector3 position = new Vector3();
130 public boolean hasPosition;
131 public final Vector3 normal = new Vector3(0, 1, 0);
132 public boolean hasNormal;
133 public final Color color = new Color(1, 1, 1, 1);
134 public boolean hasColor;
135 public final Vector2 uv = new Vector2();
136 public boolean hasUV;
138 public void reset () {
144 public VertexInfo set(Vector3 pos, Vector3 nor, Color col, Vector2 uv) {
146 if ((hasPosition = pos != null) == true)
148 if ((hasNormal = nor != null) == true)
150 if ((hasColor = col != null) == true)
152 if ((hasUV = uv != null) == true)
156 public VertexInfo set(final VertexInfo other) {
158 return set(null, null, null, null);
159 hasPosition = other.hasPosition;
160 position.set(other.position);
161 hasNormal = other.hasNormal;
162 normal.set(other.normal);
163 hasColor = other.hasColor;
164 color.set(other.color);
169 public VertexInfo setPos(float x, float y, float z) {
174 public VertexInfo setPos(Vector3 pos) {
175 if ((hasPosition = pos != null)==true)
179 public VertexInfo setNor(float x, float y, float z) {
184 public VertexInfo setNor(Vector3 nor) {
185 if ((hasNormal = nor != null) == true)
189 public VertexInfo setCol(float r, float g, float b, float a) {
194 public VertexInfo setCol(Color col) {
195 if ((hasColor = col != null)==true)
199 public VertexInfo setUV(float u, float v) {
204 public VertexInfo setUV(Vector2 uv) {
205 if ((hasUV = uv != null)==true)
209 public VertexInfo lerp(final VertexInfo target, float alpha) {
210 if (hasPosition && target.hasPosition)
211 position.lerp(target.position, alpha);
212 if (hasNormal && target.hasNormal)
213 normal.lerp(target.normal, alpha);
214 if (hasColor && target.hasColor)
215 color.lerp(target.color, alpha);
216 if (hasUV && target.hasUV)
217 uv.lerp(target.uv, alpha);