1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
d333eb6b
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
46b572b5
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
d333eb6b
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
46b572b5
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
6c00149d
|
Leszek Koltunski
|
package org.distorted.library.mesh;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
e6519ac8
|
Leszek Koltunski
|
import android.opengl.GLES31;
|
23 |
c90aca24
|
Leszek Koltunski
|
import android.opengl.Matrix;
|
24 |
6c00149d
|
Leszek Koltunski
|
|
25 |
fa8bc998
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffect;
|
26 |
7602a827
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
27 |
|
|
import org.distorted.library.main.InternalBuffer;
|
28 |
da681e7e
|
Leszek Koltunski
|
import org.distorted.library.program.DistortedProgram;
|
29 |
6c00149d
|
Leszek Koltunski
|
|
30 |
da681e7e
|
Leszek Koltunski
|
import java.nio.ByteBuffer;
|
31 |
|
|
import java.nio.ByteOrder;
|
32 |
6a06a912
|
Leszek Koltunski
|
import java.nio.FloatBuffer;
|
33 |
c90aca24
|
Leszek Koltunski
|
import java.util.ArrayList;
|
34 |
6a06a912
|
Leszek Koltunski
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
e0b6c593
|
Leszek Koltunski
|
/**
|
37 |
e5ba319d
|
Leszek Koltunski
|
* Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
|
38 |
e0b6c593
|
Leszek Koltunski
|
* <p>
|
39 |
da681e7e
|
Leszek Koltunski
|
* If you want to render to a particular shape, extend from here, construct a float array
|
40 |
7a5e538a
|
Leszek Koltunski
|
* containing per-vertex attributes, and call back setAttribs().
|
41 |
e0b6c593
|
Leszek Koltunski
|
*/
|
42 |
715e7726
|
Leszek Koltunski
|
public abstract class MeshBase
|
43 |
6a06a912
|
Leszek Koltunski
|
{
|
44 |
227b9bca
|
Leszek Koltunski
|
// sizes of attributes of an individual vertex.
|
45 |
|
|
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
|
46 |
|
|
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
|
47 |
|
|
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z
|
48 |
7a5e538a
|
Leszek Koltunski
|
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
|
49 |
6f2d931d
|
Leszek Koltunski
|
|
50 |
|
|
static final int POS_ATTRIB = 0;
|
51 |
|
|
static final int NOR_ATTRIB = POS_DATA_SIZE;
|
52 |
|
|
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE;
|
53 |
|
|
static final int TEX_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE;
|
54 |
227b9bca
|
Leszek Koltunski
|
static final int VERT_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE + TEX_DATA_SIZE; // number of attributes of a 'normal' vertex
|
55 |
|
|
static final int TRAN_ATTRIBS = POS_DATA_SIZE + POS_DATA_SIZE; // number of attributes of a transform feedback vertex
|
56 |
6a06a912
|
Leszek Koltunski
|
|
57 |
da681e7e
|
Leszek Koltunski
|
private static final int BYTES_PER_FLOAT = 4;
|
58 |
3ef3364d
|
Leszek Koltunski
|
|
59 |
6f2d931d
|
Leszek Koltunski
|
private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
|
60 |
|
|
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
|
61 |
|
|
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT;
|
62 |
|
|
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
|
63 |
227b9bca
|
Leszek Koltunski
|
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT;
|
64 |
|
|
private static final int VERT_SIZE = VERT_ATTRIBS*BYTES_PER_FLOAT;
|
65 |
a51fe521
|
Leszek Koltunski
|
|
66 |
fa8bc998
|
Leszek Koltunski
|
private boolean mShowNormals; // when rendering this mesh, draw normal vectors?
|
67 |
|
|
private InternalBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer
|
68 |
da681e7e
|
Leszek Koltunski
|
private int mNumVertices;
|
69 |
fa8bc998
|
Leszek Koltunski
|
private float[] mVertAttribs; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT
|
70 |
7a5e538a
|
Leszek Koltunski
|
private float mInflate;
|
71 |
1b059065
|
Leszek Koltunski
|
private float mBoundingX, mBoundingY, mBoundingZ;
|
72 |
3ef3364d
|
Leszek Koltunski
|
|
73 |
c90aca24
|
Leszek Koltunski
|
private class Component
|
74 |
|
|
{
|
75 |
|
|
private int mEndIndex;
|
76 |
|
|
private float[] mTextureMap;
|
77 |
|
|
|
78 |
|
|
Component()
|
79 |
|
|
{
|
80 |
|
|
mTextureMap = new float[8];
|
81 |
|
|
|
82 |
9099e567
|
Leszek Koltunski
|
mTextureMap[ 0] = 0.0f; // LD_X
|
83 |
|
|
mTextureMap[ 1] = 0.0f; // LD_Y
|
84 |
|
|
mTextureMap[ 2] = 0.0f; // LU_X
|
85 |
|
|
mTextureMap[ 3] = 1.0f; // LU_Y
|
86 |
|
|
mTextureMap[ 4] = 1.0f; // RU_X
|
87 |
|
|
mTextureMap[ 5] = 1.0f; // RU_Y
|
88 |
|
|
mTextureMap[ 6] = 1.0f; // RD_X
|
89 |
|
|
mTextureMap[ 7] = 0.0f; // RD_Y
|
90 |
c90aca24
|
Leszek Koltunski
|
}
|
91 |
|
|
Component(Component original)
|
92 |
|
|
{
|
93 |
|
|
mEndIndex = original.mEndIndex;
|
94 |
|
|
mTextureMap = new float[8];
|
95 |
|
|
System.arraycopy(original.mTextureMap,0,mTextureMap,0,8);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
private ArrayList<Component> mComponent;
|
100 |
|
|
|
101 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
3ef3364d
|
Leszek Koltunski
|
|
103 |
1b059065
|
Leszek Koltunski
|
MeshBase(float bx, float by, float bz)
|
104 |
3ef3364d
|
Leszek Koltunski
|
{
|
105 |
1b059065
|
Leszek Koltunski
|
mBoundingX = bx/2;
|
106 |
|
|
mBoundingY = by/2;
|
107 |
|
|
mBoundingZ = bz/2;
|
108 |
044b5494
|
Leszek Koltunski
|
|
109 |
3fc9327a
|
Leszek Koltunski
|
mShowNormals = false;
|
110 |
c90aca24
|
Leszek Koltunski
|
mInflate = 0.0f;
|
111 |
|
|
mComponent = new ArrayList<>();
|
112 |
|
|
mComponent.add(new Component());
|
113 |
|
|
|
114 |
|
|
mVBO = new InternalBuffer(GLES31.GL_ARRAY_BUFFER , GLES31.GL_STATIC_READ);
|
115 |
|
|
mTFO = new InternalBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ);
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
|
|
// copy constructor
|
120 |
|
|
|
121 |
|
|
MeshBase(MeshBase original)
|
122 |
|
|
{
|
123 |
1b059065
|
Leszek Koltunski
|
mBoundingX = original.mBoundingX;
|
124 |
|
|
mBoundingY = original.mBoundingY;
|
125 |
|
|
mBoundingZ = original.mBoundingZ;
|
126 |
044b5494
|
Leszek Koltunski
|
|
127 |
c90aca24
|
Leszek Koltunski
|
mShowNormals = original.mShowNormals;
|
128 |
|
|
mInflate = original.mInflate;
|
129 |
|
|
|
130 |
|
|
int size = original.mComponent.size();
|
131 |
|
|
mComponent = new ArrayList<>();
|
132 |
|
|
for(int i=0; i<size; i++)
|
133 |
|
|
{
|
134 |
|
|
Component comp = new Component(original.mComponent.get(i));
|
135 |
|
|
mComponent.add(comp);
|
136 |
|
|
}
|
137 |
42571056
|
Leszek Koltunski
|
|
138 |
7602a827
|
Leszek Koltunski
|
mVBO = new InternalBuffer(GLES31.GL_ARRAY_BUFFER , GLES31.GL_STATIC_READ);
|
139 |
|
|
mTFO = new InternalBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ);
|
140 |
c90aca24
|
Leszek Koltunski
|
|
141 |
|
|
System.arraycopy(original.mVertAttribs,0,mVertAttribs,0,original.mNumVertices*VERT_ATTRIBS);
|
142 |
|
|
setAttribs(mVertAttribs);
|
143 |
42571056
|
Leszek Koltunski
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
6c00149d
|
Leszek Koltunski
|
// when a derived class is done computing its mesh, it has to call this method.
|
147 |
42571056
|
Leszek Koltunski
|
|
148 |
227b9bca
|
Leszek Koltunski
|
void setAttribs(float[] vertexAttribs)
|
149 |
42571056
|
Leszek Koltunski
|
{
|
150 |
227b9bca
|
Leszek Koltunski
|
mNumVertices = vertexAttribs.length/VERT_ATTRIBS;
|
151 |
fa8bc998
|
Leszek Koltunski
|
mVertAttribs = vertexAttribs;
|
152 |
da681e7e
|
Leszek Koltunski
|
|
153 |
c90aca24
|
Leszek Koltunski
|
mComponent.get(0).mEndIndex = mNumVertices;
|
154 |
|
|
|
155 |
fa8bc998
|
Leszek Koltunski
|
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
156 |
|
|
attribs.put(vertexAttribs).position(0);
|
157 |
da681e7e
|
Leszek Koltunski
|
|
158 |
fa8bc998
|
Leszek Koltunski
|
mVBO.setData(mNumVertices*VERT_SIZE, attribs);
|
159 |
|
|
mTFO.setData(mNumVertices*TRAN_SIZE, null );
|
160 |
42571056
|
Leszek Koltunski
|
}
|
161 |
|
|
|
162 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
6c00149d
|
Leszek Koltunski
|
/**
|
164 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
165 |
|
|
*
|
166 |
|
|
* @y.exclude
|
167 |
|
|
*/
|
168 |
da681e7e
|
Leszek Koltunski
|
public int getTFO()
|
169 |
42571056
|
Leszek Koltunski
|
{
|
170 |
da681e7e
|
Leszek Koltunski
|
return mTFO.mIndex[0];
|
171 |
42571056
|
Leszek Koltunski
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
6c00149d
|
Leszek Koltunski
|
/**
|
175 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
176 |
|
|
*
|
177 |
|
|
* @y.exclude
|
178 |
|
|
*/
|
179 |
da681e7e
|
Leszek Koltunski
|
public int getNumVertices()
|
180 |
226144d0
|
leszek
|
{
|
181 |
da681e7e
|
Leszek Koltunski
|
return mNumVertices;
|
182 |
226144d0
|
leszek
|
}
|
183 |
42571056
|
Leszek Koltunski
|
|
184 |
6c00149d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185 |
044b5494
|
Leszek Koltunski
|
/**
|
186 |
1b059065
|
Leszek Koltunski
|
* Each mesh has its 'bounding box' - return half of its X-length.
|
187 |
|
|
* <p>
|
188 |
|
|
* In case of all 'simple' Meshes, the bounding box is always 1x1x1 (Sphere, Cubes) or 1x1x0
|
189 |
|
|
* (Rectangles, Triangles, Quad - i.e. all 'flat' Meshes). But this can be something else in case of
|
190 |
|
|
* MeshComponent.
|
191 |
044b5494
|
Leszek Koltunski
|
*/
|
192 |
1b059065
|
Leszek Koltunski
|
public float getBoundingX()
|
193 |
044b5494
|
Leszek Koltunski
|
{
|
194 |
1b059065
|
Leszek Koltunski
|
return mBoundingX;
|
195 |
044b5494
|
Leszek Koltunski
|
}
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
/**
|
199 |
1b059065
|
Leszek Koltunski
|
* Each mesh has its 'bounding box' - return half of its Y-length.
|
200 |
044b5494
|
Leszek Koltunski
|
*/
|
201 |
1b059065
|
Leszek Koltunski
|
public float getBoundingY()
|
202 |
044b5494
|
Leszek Koltunski
|
{
|
203 |
1b059065
|
Leszek Koltunski
|
return mBoundingY;
|
204 |
044b5494
|
Leszek Koltunski
|
}
|
205 |
|
|
|
206 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207 |
|
|
/**
|
208 |
1b059065
|
Leszek Koltunski
|
* Each mesh has its 'bounding box' - return half of its Z-length.
|
209 |
044b5494
|
Leszek Koltunski
|
*/
|
210 |
1b059065
|
Leszek Koltunski
|
public float getBoundingZ()
|
211 |
044b5494
|
Leszek Koltunski
|
{
|
212 |
1b059065
|
Leszek Koltunski
|
return mBoundingZ;
|
213 |
044b5494
|
Leszek Koltunski
|
}
|
214 |
|
|
|
215 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216 |
6c00149d
|
Leszek Koltunski
|
/**
|
217 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
218 |
|
|
*
|
219 |
|
|
* @y.exclude
|
220 |
|
|
*/
|
221 |
da681e7e
|
Leszek Koltunski
|
public void bindVertexAttribs(DistortedProgram program)
|
222 |
6c00149d
|
Leszek Koltunski
|
{
|
223 |
da681e7e
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mVBO.mIndex[0] );
|
224 |
227b9bca
|
Leszek Koltunski
|
GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_POS);
|
225 |
|
|
GLES31.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_NOR);
|
226 |
|
|
GLES31.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_INF);
|
227 |
|
|
GLES31.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_TEX);
|
228 |
da681e7e
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
/**
|
233 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
234 |
|
|
*
|
235 |
|
|
* @y.exclude
|
236 |
|
|
*/
|
237 |
|
|
public void bindTransformAttribs(DistortedProgram program)
|
238 |
|
|
{
|
239 |
|
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mTFO.mIndex[0] );
|
240 |
227b9bca
|
Leszek Koltunski
|
GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
|
241 |
da681e7e
|
Leszek Koltunski
|
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
|
242 |
6c00149d
|
Leszek Koltunski
|
}
|
243 |
|
|
|
244 |
7a5e538a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
/**
|
246 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
247 |
|
|
*
|
248 |
|
|
* @y.exclude
|
249 |
|
|
*/
|
250 |
|
|
public void setInflate(float inflate)
|
251 |
|
|
{
|
252 |
|
|
mInflate = inflate;
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
|
|
/**
|
257 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
258 |
|
|
*
|
259 |
|
|
* @y.exclude
|
260 |
|
|
*/
|
261 |
|
|
public float getInflate()
|
262 |
|
|
{
|
263 |
|
|
return mInflate;
|
264 |
|
|
}
|
265 |
|
|
|
266 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267 |
|
|
// PUBLIC API
|
268 |
3fc9327a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269 |
|
|
/**
|
270 |
|
|
* When rendering this Mesh, do we want to render the Normal vectors as well?
|
271 |
420836fc
|
leszek
|
* <p>
|
272 |
|
|
* Will work only on OpenGL ES >= 3.0 devices.
|
273 |
3fc9327a
|
Leszek Koltunski
|
*
|
274 |
|
|
* @param show Controls if we render the Normal vectors or not.
|
275 |
|
|
*/
|
276 |
|
|
public void setShowNormals(boolean show)
|
277 |
|
|
{
|
278 |
7602a827
|
Leszek Koltunski
|
mShowNormals = (DistortedLibrary.GLSL >= 300 && show);
|
279 |
3fc9327a
|
Leszek Koltunski
|
}
|
280 |
466450b5
|
Leszek Koltunski
|
|
281 |
6c00149d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
282 |
|
|
/**
|
283 |
|
|
* When rendering this mesh, should we also draw the normal vectors?
|
284 |
|
|
*
|
285 |
|
|
* @return <i>true</i> if we do render normal vectors
|
286 |
|
|
*/
|
287 |
|
|
public boolean getShowNormals()
|
288 |
|
|
{
|
289 |
|
|
return mShowNormals;
|
290 |
|
|
}
|
291 |
|
|
|
292 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
293 |
|
|
/**
|
294 |
|
|
* Release all internal resources.
|
295 |
|
|
*/
|
296 |
|
|
public void markForDeletion()
|
297 |
|
|
{
|
298 |
fa8bc998
|
Leszek Koltunski
|
mVertAttribs = null;
|
299 |
466450b5
|
Leszek Koltunski
|
|
300 |
|
|
mVBO.markForDeletion();
|
301 |
|
|
mTFO.markForDeletion();
|
302 |
|
|
}
|
303 |
fa8bc998
|
Leszek Koltunski
|
|
304 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305 |
|
|
/**
|
306 |
c90aca24
|
Leszek Koltunski
|
* Apply all Effects to the vertex mesh. Overwrite the mesh in place.
|
307 |
fa8bc998
|
Leszek Koltunski
|
* <p>
|
308 |
c90aca24
|
Leszek Koltunski
|
* This is a static, permanent modification of the vertices contained in this Mesh. If the effects
|
309 |
|
|
* contain any Dynamics, they will be evaluated at 0.
|
310 |
fa8bc998
|
Leszek Koltunski
|
*
|
311 |
|
|
* Please note that calling this once with the complete list of Effects will be much faster than
|
312 |
|
|
* calling it repeatedly with one Effect at a time, as we have to reallocate the array of vertices
|
313 |
|
|
* each time.
|
314 |
|
|
*/
|
315 |
|
|
public void apply(MatrixEffect[] effects)
|
316 |
|
|
{
|
317 |
c90aca24
|
Leszek Koltunski
|
float[][] matrix = new float[effects.length][16];
|
318 |
|
|
float[] tmp;
|
319 |
|
|
float[] array = new float[4];
|
320 |
|
|
float x,y,z;
|
321 |
|
|
int numEffects = 0;
|
322 |
|
|
|
323 |
|
|
for(MatrixEffect eff: effects)
|
324 |
fa8bc998
|
Leszek Koltunski
|
{
|
325 |
c90aca24
|
Leszek Koltunski
|
if( eff!=null )
|
326 |
fa8bc998
|
Leszek Koltunski
|
{
|
327 |
c90aca24
|
Leszek Koltunski
|
Matrix.setIdentityM(matrix[numEffects],0);
|
328 |
|
|
eff.compute(array,0,0,0);
|
329 |
|
|
eff.apply(matrix[numEffects], array, 0);
|
330 |
|
|
numEffects++;
|
331 |
fa8bc998
|
Leszek Koltunski
|
}
|
332 |
|
|
}
|
333 |
|
|
|
334 |
7594a5d2
|
Leszek Koltunski
|
for(int index=0; index<mNumVertices*VERT_ATTRIBS; index+=VERT_ATTRIBS )
|
335 |
c90aca24
|
Leszek Koltunski
|
{
|
336 |
|
|
for(int mat=0; mat<numEffects; mat++)
|
337 |
|
|
{
|
338 |
|
|
tmp = matrix[mat];
|
339 |
|
|
|
340 |
|
|
x = mVertAttribs[index+POS_ATTRIB ];
|
341 |
|
|
y = mVertAttribs[index+POS_ATTRIB+1];
|
342 |
|
|
z = mVertAttribs[index+POS_ATTRIB+2];
|
343 |
|
|
|
344 |
|
|
mVertAttribs[index+POS_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z + tmp[12];
|
345 |
|
|
mVertAttribs[index+POS_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z + tmp[13];
|
346 |
|
|
mVertAttribs[index+POS_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z + tmp[14];
|
347 |
|
|
|
348 |
|
|
x = mVertAttribs[index+NOR_ATTRIB ];
|
349 |
|
|
y = mVertAttribs[index+NOR_ATTRIB+1];
|
350 |
|
|
z = mVertAttribs[index+NOR_ATTRIB+2];
|
351 |
|
|
|
352 |
|
|
mVertAttribs[index+NOR_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z;
|
353 |
|
|
mVertAttribs[index+NOR_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z;
|
354 |
|
|
mVertAttribs[index+NOR_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z;
|
355 |
|
|
|
356 |
|
|
x = mVertAttribs[index+INF_ATTRIB ];
|
357 |
|
|
y = mVertAttribs[index+INF_ATTRIB+1];
|
358 |
|
|
z = mVertAttribs[index+INF_ATTRIB+2];
|
359 |
|
|
|
360 |
|
|
mVertAttribs[index+INF_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z;
|
361 |
|
|
mVertAttribs[index+INF_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z;
|
362 |
|
|
mVertAttribs[index+INF_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z;
|
363 |
|
|
}
|
364 |
|
|
}
|
365 |
|
|
|
366 |
|
|
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
367 |
|
|
attribs.put(mVertAttribs).position(0);
|
368 |
|
|
|
369 |
|
|
mVBO.setData(mNumVertices*VERT_SIZE, attribs);
|
370 |
|
|
mTFO.setData(mNumVertices*TRAN_SIZE, null );
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
374 |
|
|
/**
|
375 |
|
|
* Join a list of Meshes into this one.
|
376 |
|
|
* <p>
|
377 |
|
|
* Please note that calling this once with the complete list of Meshes will be much faster than
|
378 |
|
|
* calling it repeatedly with one Mesh at a time, as we have to reallocate the array of vertices
|
379 |
|
|
* each time.
|
380 |
|
|
*/
|
381 |
|
|
public void join(MeshBase[] meshes)
|
382 |
|
|
{
|
383 |
ea88d502
|
Leszek Koltunski
|
MeshBase mesh;
|
384 |
|
|
Component comp;
|
385 |
|
|
int com, num, len = meshes.length;
|
386 |
|
|
int origVertices = mNumVertices;
|
387 |
|
|
|
388 |
|
|
// compute new numVertices; take care of Components
|
389 |
|
|
mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
|
390 |
|
|
com = mComponent.size();
|
391 |
|
|
mComponent.get(com-1).mEndIndex = mNumVertices;
|
392 |
|
|
|
393 |
|
|
for(int i=0; i<len; i++)
|
394 |
|
|
{
|
395 |
|
|
mesh = meshes[i];
|
396 |
|
|
com = mesh.mComponent.size();
|
397 |
|
|
|
398 |
|
|
for(int j=0; j<com; j++)
|
399 |
|
|
{
|
400 |
|
|
comp = new Component(mesh.mComponent.get(j));
|
401 |
|
|
comp.mEndIndex += mNumVertices;
|
402 |
|
|
mComponent.add(comp);
|
403 |
|
|
}
|
404 |
|
|
|
405 |
|
|
num = mesh.mNumVertices;
|
406 |
|
|
mNumVertices+= (i<len-1 ? ( num%2==1 ? num+2 : num+1 ) : num);
|
407 |
|
|
}
|
408 |
|
|
|
409 |
|
|
// allocate new attrib array
|
410 |
|
|
float[] newAttribs = new float[VERT_ATTRIBS*mNumVertices];
|
411 |
|
|
num = origVertices;
|
412 |
|
|
|
413 |
|
|
System.arraycopy(mVertAttribs, 0, newAttribs, 0, VERT_ATTRIBS*num);
|
414 |
|
|
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS );
|
415 |
|
|
origVertices++;
|
416 |
|
|
|
417 |
|
|
if( num%2==1 )
|
418 |
|
|
{
|
419 |
|
|
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
|
420 |
|
|
origVertices++;
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
for(int i=0; i<len; i++)
|
424 |
|
|
{
|
425 |
|
|
mesh = meshes[i];
|
426 |
|
|
num = mesh.mNumVertices;
|
427 |
|
|
|
428 |
|
|
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS );
|
429 |
|
|
origVertices++;
|
430 |
|
|
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*num);
|
431 |
|
|
origVertices+=num;
|
432 |
|
|
|
433 |
|
|
if( i<len-1 )
|
434 |
|
|
{
|
435 |
|
|
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
|
436 |
|
|
origVertices++;
|
437 |
|
|
|
438 |
|
|
if( num%2==1 )
|
439 |
|
|
{
|
440 |
|
|
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS);
|
441 |
|
|
origVertices++;
|
442 |
|
|
}
|
443 |
|
|
}
|
444 |
|
|
}
|
445 |
c90aca24
|
Leszek Koltunski
|
|
446 |
ea88d502
|
Leszek Koltunski
|
if( origVertices!=mNumVertices )
|
447 |
|
|
{
|
448 |
|
|
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
mVertAttribs = newAttribs;
|
452 |
|
|
|
453 |
|
|
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
454 |
|
|
attribs.put(mVertAttribs).position(0);
|
455 |
|
|
|
456 |
|
|
mVBO.setData(mNumVertices*VERT_SIZE, attribs);
|
457 |
|
|
mTFO.setData(mNumVertices*TRAN_SIZE, null );
|
458 |
fa8bc998
|
Leszek Koltunski
|
}
|
459 |
9099e567
|
Leszek Koltunski
|
|
460 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461 |
|
|
/**
|
462 |
|
|
* Sets texture maps for all components of this mesh.
|
463 |
|
|
* <p>
|
464 |
|
|
* Please note that calling this once with the complete list of Maps will be much faster than
|
465 |
|
|
* calling it repeatedly with one Maps at a time, as we have to reallocate the array of vertices
|
466 |
|
|
* each time.
|
467 |
|
|
*/
|
468 |
|
|
public void setTextureMap(float[][] maps)
|
469 |
|
|
{
|
470 |
|
|
int components = mComponent.size();
|
471 |
|
|
|
472 |
|
|
for(int comp=0; comp<components; comp++)
|
473 |
|
|
{
|
474 |
|
|
|
475 |
|
|
}
|
476 |
|
|
}
|
477 |
1b059065
|
Leszek Koltunski
|
|
478 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479 |
571aa3fa
|
Leszek Koltunski
|
// all 4 APIs depreciated - being removed from the apps. When done, we will also remove the
|
480 |
|
|
// premultiply of the Object vertices by m_objD in the vertex shader.
|
481 |
1b059065
|
Leszek Koltunski
|
|
482 |
571aa3fa
|
Leszek Koltunski
|
@Deprecated
|
483 |
1b059065
|
Leszek Koltunski
|
public void setStretch(int sx, int sy, int sz)
|
484 |
|
|
{
|
485 |
|
|
mBoundingX = sx/2.0f;
|
486 |
|
|
mBoundingY = sy/2.0f;
|
487 |
|
|
mBoundingZ = sz/2.0f;
|
488 |
|
|
}
|
489 |
|
|
|
490 |
571aa3fa
|
Leszek Koltunski
|
@Deprecated
|
491 |
1b059065
|
Leszek Koltunski
|
public float getStretchX()
|
492 |
|
|
{
|
493 |
|
|
return mBoundingX*2;
|
494 |
|
|
}
|
495 |
571aa3fa
|
Leszek Koltunski
|
@Deprecated
|
496 |
1b059065
|
Leszek Koltunski
|
public float getStretchY()
|
497 |
|
|
{
|
498 |
|
|
return mBoundingY*2;
|
499 |
|
|
}
|
500 |
571aa3fa
|
Leszek Koltunski
|
@Deprecated
|
501 |
1b059065
|
Leszek Koltunski
|
public float getStretchZ()
|
502 |
|
|
{
|
503 |
|
|
return mBoundingZ*2;
|
504 |
|
|
}
|
505 |
6a06a912
|
Leszek Koltunski
|
}
|
506 |
226144d0
|
leszek
|
|
507 |
3fc9327a
|
Leszek Koltunski
|
|