Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package min3d.core;

import min3d.vos.Color4;
import min3d.vos.Number3d;
import min3d.vos.Uv;


public class Vertices
{
	private Number3dBufferList _points;
	private UvBufferList _uvs;
	private Number3dBufferList _normals;
	private Color4BufferList _colors;
	
	private boolean _hasUvs;
	private boolean _hasNormals;
	private boolean _hasColors;
	
	
	/**
	 * Used by Object3d to hold the lists of vertex points, texture coordinates (UV), normals, and vertex colors. 
	 * Use "addVertex()" to build the vertex data for the Object3d instance associated with this instance. 
	 * 
	 * Direct manipulation of position, UV, normal, or color data can be done directly through the associated 
	 * 'buffer list' instances contained herein.
	 */
	public Vertices(int $maxElements)
	{
		_points = new Number3dBufferList($maxElements);
		
		_hasUvs = true;
		_hasNormals = true;
		_hasColors = true;
		
		if (_hasUvs) _uvs = new UvBufferList($maxElements);
		if (_hasNormals) _normals = new Number3dBufferList($maxElements);
		if (_hasColors) _colors = new Color4BufferList($maxElements);
	}

	/**
	 * This version of the constructor adds 3 boolean arguments determine whether 
	 * uv, normal, and color lists will be used by this instance.
	 * Set to false when appropriate to save memory, increase performance. 
	 */
	public Vertices(int $maxElements, Boolean $useUvs, Boolean $useNormals, Boolean $useColors)
	{
		_points = new Number3dBufferList($maxElements);
		
		_hasUvs = $useUvs;
		_hasNormals = $useNormals;
		_hasColors = $useColors;
		
		if (_hasUvs) _uvs = new UvBufferList($maxElements);
		if (_hasNormals) _normals = new Number3dBufferList($maxElements);
		if (_hasColors) _colors = new Color4BufferList($maxElements);
	}
	
	public Vertices(Number3dBufferList $points, UvBufferList $uvs, Number3dBufferList $normals,
			Color4BufferList $colors)
	{
		_points = $points;
		_uvs = $uvs;
		_normals = $normals;
		_colors = $colors;
		
		_hasUvs = _uvs != null && _uvs.size() > 0;
		_hasNormals = _normals != null && _normals.size() > 0;
		_hasColors = _colors != null && _colors.size() > 0;
	}
	
	public int size()
	{
		return _points.size();
	}
	
	public int capacity()
	{
		return _points.capacity();
	}
	
	public boolean hasUvs()
	{
		return _hasUvs;
	}

	public boolean hasNormals()
	{
		return _hasNormals;
	}
	
	public boolean hasColors()
	{
		return _hasColors;
	}
	
	
	/**
	 * Use this to populate an Object3d's vertex data.
	 * Return's newly added vertex's index 
	 * 
	 *  	If hasUvs, hasNormals, or hasColors was set to false, 
	 * 		their corresponding arguments are just ignored.
	 */
	public short addVertex(
		float $pointX, float $pointY, float $pointZ,  
		float $textureU, float $textureV,  
		float $normalX, float $normalY, float $normalZ,  
		short $colorR, short $colorG, short $colorB, short $colorA)
	{
		_points.add($pointX, $pointY, $pointZ);
		
		if (_hasUvs) _uvs.add($textureU, $textureV);
		if (_hasNormals) _normals.add($normalX, $normalY, $normalZ);
		if (_hasColors) _colors.add($colorR, $colorG, $colorB, $colorA);
		
		return (short)(_points.size()-1);
	}
	
	/**
	 * More structured-looking way of adding a vertex (but potentially wasteful).
	 * The VO's taken in as arguments are only used to read the values they hold
	 * (no references are kept to them).  
	 * Return's newly added vertex's index 
	 * 
	 * 		If hasUvs, hasNormals, or hasColors was set to false, 
	 * 		their corresponding arguments are just ignored.
	 */
	public short addVertex(Number3d $point, Uv $textureUv, Number3d $normal, Color4 $color)
	{
		_points.add($point);
		
		if (_hasUvs) _uvs.add($textureUv);
		if (_hasNormals) _normals.add($normal);
		if (_hasColors) _colors.add($color);
		
		return (short)(_points.size()-1);
	}
	
	public void overwriteVerts(float[] $newVerts)
	{
		_points.overwrite($newVerts);
	}
	
	public void overwriteNormals(float[] $newNormals)
	{
		_normals.overwrite($newNormals);
	}
	
	Number3dBufferList points() /*package-private*/
	{
		return _points;
	}
	
	/**
	 * List of texture coordinates
	 */
	UvBufferList uvs() /*package-private*/
	{
		return _uvs;
	}
	
	/**
	 * List of normal values 
	 */
	Number3dBufferList normals() /*package-private*/
	{
		return _normals;
	}
	
	/**
	 * List of color values
	 */
	Color4BufferList colors() /*package-private*/
	{
		return _colors;
	}
	
	public Vertices clone()
	{
		Vertices v = new Vertices(_points.clone(), _uvs.clone(), _normals.clone(), _colors.clone());
		return v;
	}
}

Commits for Nextrek/Android/LibrerieNextrek/src/min3d/core/Vertices.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000