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 |
b7074bc6
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
23 |
e8925fcd
|
Leszek Koltunski
|
import android.opengl.Matrix;
|
24 |
f046b159
|
Leszek Koltunski
|
import android.util.Log;
|
25 |
6c00149d
|
Leszek Koltunski
|
|
26 |
e8925fcd
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffect;
|
27 |
f046b159
|
Leszek Koltunski
|
import org.distorted.library.effect.VertexEffect;
|
28 |
9f9924f8
|
Leszek Koltunski
|
import org.distorted.library.effectqueue.EffectQueue;
|
29 |
7602a827
|
Leszek Koltunski
|
import org.distorted.library.main.InternalBuffer;
|
30 |
da681e7e
|
Leszek Koltunski
|
import org.distorted.library.program.DistortedProgram;
|
31 |
a3a05347
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
32 |
6c00149d
|
Leszek Koltunski
|
|
33 |
bc2ab8c5
|
Leszek Koltunski
|
import java.io.DataOutputStream;
|
34 |
22422a76
|
Leszek Koltunski
|
import java.io.IOException;
|
35 |
bc2ab8c5
|
Leszek Koltunski
|
import java.io.DataInputStream;
|
36 |
f046b159
|
Leszek Koltunski
|
import java.nio.ByteBuffer;
|
37 |
|
|
import java.nio.ByteOrder;
|
38 |
|
|
import java.nio.FloatBuffer;
|
39 |
c90aca24
|
Leszek Koltunski
|
import java.util.ArrayList;
|
40 |
6a06a912
|
Leszek Koltunski
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
e0b6c593
|
Leszek Koltunski
|
/**
|
43 |
e5ba319d
|
Leszek Koltunski
|
* Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
|
44 |
e0b6c593
|
Leszek Koltunski
|
* <p>
|
45 |
da681e7e
|
Leszek Koltunski
|
* If you want to render to a particular shape, extend from here, construct a float array
|
46 |
7a5e538a
|
Leszek Koltunski
|
* containing per-vertex attributes, and call back setAttribs().
|
47 |
e0b6c593
|
Leszek Koltunski
|
*/
|
48 |
715e7726
|
Leszek Koltunski
|
public abstract class MeshBase
|
49 |
6a06a912
|
Leszek Koltunski
|
{
|
50 |
a2878a67
|
Leszek Koltunski
|
private static final int ASSOC_UBO_BINDING = 3;
|
51 |
|
|
private static final int CENTER_UBO_BINDING = 4;
|
52 |
87a48d8e
|
Leszek Koltunski
|
static final int MAX_EFFECT_COMPONENTS= 110;
|
53 |
bc208a9c
|
Leszek Koltunski
|
|
54 |
227b9bca
|
Leszek Koltunski
|
// sizes of attributes of an individual vertex.
|
55 |
|
|
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
|
56 |
|
|
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
|
57 |
7a5e538a
|
Leszek Koltunski
|
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
|
58 |
36d65d88
|
Leszek Koltunski
|
private static final int COM_DATA_SIZE= 1; // component number, a single float
|
59 |
6f2d931d
|
Leszek Koltunski
|
|
60 |
|
|
static final int POS_ATTRIB = 0;
|
61 |
|
|
static final int NOR_ATTRIB = POS_DATA_SIZE;
|
62 |
e54bfada
|
Leszek Koltunski
|
static final int TEX_ATTRIB = 0;
|
63 |
36d65d88
|
Leszek Koltunski
|
static final int COM_ATTRIB = TEX_DATA_SIZE;
|
64 |
bc208a9c
|
Leszek Koltunski
|
|
65 |
a2878a67
|
Leszek Koltunski
|
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply)
|
66 |
|
|
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
67 |
|
|
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE; // number of attributes of a transform feedback vertex
|
68 |
6a06a912
|
Leszek Koltunski
|
|
69 |
da681e7e
|
Leszek Koltunski
|
private static final int BYTES_PER_FLOAT = 4;
|
70 |
3ef3364d
|
Leszek Koltunski
|
|
71 |
6f2d931d
|
Leszek Koltunski
|
private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
|
72 |
|
|
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
|
73 |
|
|
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
|
74 |
36d65d88
|
Leszek Koltunski
|
private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
|
75 |
bc208a9c
|
Leszek Koltunski
|
|
76 |
227b9bca
|
Leszek Koltunski
|
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT;
|
77 |
e54bfada
|
Leszek Koltunski
|
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
|
78 |
|
|
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
|
79 |
a51fe521
|
Leszek Koltunski
|
|
80 |
e54bfada
|
Leszek Koltunski
|
private boolean mShowNormals; // when rendering this mesh, draw normal vectors?
|
81 |
|
|
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
|
82 |
da681e7e
|
Leszek Koltunski
|
private int mNumVertices;
|
83 |
a2878a67
|
Leszek Koltunski
|
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ
|
84 |
36d65d88
|
Leszek Koltunski
|
private float[] mVertAttribs2; // packed: TexS,TexT, Component
|
85 |
7a5e538a
|
Leszek Koltunski
|
private float mInflate;
|
86 |
a2878a67
|
Leszek Koltunski
|
private UniformBlockAssociation mUBA;
|
87 |
|
|
private UniformBlockCenter mUBC;
|
88 |
36d65d88
|
Leszek Koltunski
|
|
89 |
71d8aba1
|
Leszek Koltunski
|
DeferredJobs.JobNode[] mJobNode;
|
90 |
07206c71
|
Leszek Koltunski
|
|
91 |
9f9924f8
|
Leszek Koltunski
|
private static int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
|
92 |
|
|
private static int[] mAssocBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
|
93 |
|
|
|
94 |
a2878a67
|
Leszek Koltunski
|
private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
|
95 |
22422a76
|
Leszek Koltunski
|
|
96 |
e8925fcd
|
Leszek Koltunski
|
private static class TexComponent
|
97 |
c90aca24
|
Leszek Koltunski
|
{
|
98 |
|
|
private int mEndIndex;
|
99 |
a3a05347
|
Leszek Koltunski
|
private Static4D mTextureMap;
|
100 |
c90aca24
|
Leszek Koltunski
|
|
101 |
e8925fcd
|
Leszek Koltunski
|
TexComponent(int end)
|
102 |
c90aca24
|
Leszek Koltunski
|
{
|
103 |
a3a05347
|
Leszek Koltunski
|
mEndIndex = end;
|
104 |
|
|
mTextureMap= new Static4D(0,0,1,1);
|
105 |
c90aca24
|
Leszek Koltunski
|
}
|
106 |
e8925fcd
|
Leszek Koltunski
|
TexComponent(TexComponent original)
|
107 |
c90aca24
|
Leszek Koltunski
|
{
|
108 |
|
|
mEndIndex = original.mEndIndex;
|
109 |
a3a05347
|
Leszek Koltunski
|
|
110 |
|
|
float x = original.mTextureMap.get0();
|
111 |
|
|
float y = original.mTextureMap.get1();
|
112 |
|
|
float z = original.mTextureMap.get2();
|
113 |
|
|
float w = original.mTextureMap.get3();
|
114 |
|
|
mTextureMap = new Static4D(x,y,z,w);
|
115 |
0d4aae88
|
Leszek Koltunski
|
}
|
116 |
|
|
|
117 |
a3a05347
|
Leszek Koltunski
|
void setMap(Static4D map)
|
118 |
0d4aae88
|
Leszek Koltunski
|
{
|
119 |
a3a05347
|
Leszek Koltunski
|
mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
|
120 |
c90aca24
|
Leszek Koltunski
|
}
|
121 |
|
|
}
|
122 |
|
|
|
123 |
e8925fcd
|
Leszek Koltunski
|
private ArrayList<TexComponent> mTexComponent;
|
124 |
|
|
private ArrayList<Integer> mEffComponent;
|
125 |
c90aca24
|
Leszek Koltunski
|
|
126 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
3ef3364d
|
Leszek Koltunski
|
|
128 |
0f10a0b6
|
Leszek Koltunski
|
MeshBase()
|
129 |
3ef3364d
|
Leszek Koltunski
|
{
|
130 |
e8925fcd
|
Leszek Koltunski
|
mShowNormals = false;
|
131 |
|
|
mInflate = 0.0f;
|
132 |
|
|
mTexComponent = new ArrayList<>();
|
133 |
|
|
mEffComponent = new ArrayList<>();
|
134 |
|
|
|
135 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = new DeferredJobs.JobNode[1];
|
136 |
|
|
|
137 |
a2878a67
|
Leszek Koltunski
|
mUBA = new UniformBlockAssociation();
|
138 |
|
|
mUBC = new UniformBlockCenter();
|
139 |
4f81e0c8
|
Leszek Koltunski
|
|
140 |
e54bfada
|
Leszek Koltunski
|
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ);
|
141 |
|
|
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ);
|
142 |
b7074bc6
|
Leszek Koltunski
|
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
|
143 |
c90aca24
|
Leszek Koltunski
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
// copy constructor
|
147 |
|
|
|
148 |
4f81e0c8
|
Leszek Koltunski
|
MeshBase(MeshBase original, boolean deep)
|
149 |
c90aca24
|
Leszek Koltunski
|
{
|
150 |
1fad573e
|
Leszek Koltunski
|
mShowNormals= original.mShowNormals;
|
151 |
|
|
mInflate = original.mInflate;
|
152 |
|
|
mNumVertices= original.mNumVertices;
|
153 |
42571056
|
Leszek Koltunski
|
|
154 |
a2878a67
|
Leszek Koltunski
|
mUBA = new UniformBlockAssociation(original.mUBA);
|
155 |
|
|
mUBC = new UniformBlockCenter(original.mUBC);
|
156 |
36d65d88
|
Leszek Koltunski
|
|
157 |
4f81e0c8
|
Leszek Koltunski
|
if( deep )
|
158 |
|
|
{
|
159 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = new DeferredJobs.JobNode[1];
|
160 |
1fad573e
|
Leszek Koltunski
|
if( original.mJobNode[0]==null ) copy(original);
|
161 |
|
|
else mJobNode[0] = DeferredJobs.copy(this,original);
|
162 |
4f81e0c8
|
Leszek Koltunski
|
}
|
163 |
|
|
else
|
164 |
|
|
{
|
165 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = original.mJobNode;
|
166 |
|
|
mVBO1 = original.mVBO1;
|
167 |
|
|
mVertAttribs1 = original.mVertAttribs1;
|
168 |
1fad573e
|
Leszek Koltunski
|
shallowCopy(original);
|
169 |
4f81e0c8
|
Leszek Koltunski
|
}
|
170 |
cbd502ec
|
Leszek Koltunski
|
|
171 |
4f81e0c8
|
Leszek Koltunski
|
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
|
172 |
42571056
|
Leszek Koltunski
|
}
|
173 |
|
|
|
174 |
36d65d88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175 |
|
|
|
176 |
1fad573e
|
Leszek Koltunski
|
void copy(MeshBase original)
|
177 |
36d65d88
|
Leszek Koltunski
|
{
|
178 |
1fad573e
|
Leszek Koltunski
|
shallowCopy(original);
|
179 |
|
|
|
180 |
|
|
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
|
181 |
|
|
mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
|
182 |
|
|
System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
|
183 |
|
|
mVBO1.invalidate();
|
184 |
36d65d88
|
Leszek Koltunski
|
}
|
185 |
|
|
|
186 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187 |
|
|
|
188 |
1fad573e
|
Leszek Koltunski
|
private void shallowCopy(MeshBase original)
|
189 |
36d65d88
|
Leszek Koltunski
|
{
|
190 |
e8925fcd
|
Leszek Koltunski
|
int texComSize = original.mTexComponent.size();
|
191 |
|
|
mTexComponent = new ArrayList<>();
|
192 |
36d65d88
|
Leszek Koltunski
|
|
193 |
e8925fcd
|
Leszek Koltunski
|
for(int i=0; i<texComSize; i++)
|
194 |
1fad573e
|
Leszek Koltunski
|
{
|
195 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp = new TexComponent(original.mTexComponent.get(i));
|
196 |
|
|
mTexComponent.add(comp);
|
197 |
1fad573e
|
Leszek Koltunski
|
}
|
198 |
f4c5a46e
|
Leszek Koltunski
|
|
199 |
e8925fcd
|
Leszek Koltunski
|
mEffComponent = new ArrayList<>();
|
200 |
|
|
mEffComponent.addAll(original.mEffComponent);
|
201 |
|
|
|
202 |
1fad573e
|
Leszek Koltunski
|
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
|
203 |
|
|
mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
|
204 |
|
|
System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
|
205 |
|
|
mVBO2.invalidate();
|
206 |
f4c5a46e
|
Leszek Koltunski
|
}
|
207 |
|
|
|
208 |
a8dfedcc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209 |
|
|
|
210 |
e8925fcd
|
Leszek Koltunski
|
void mergeTexComponentsNow()
|
211 |
a8dfedcc
|
Leszek Koltunski
|
{
|
212 |
e8925fcd
|
Leszek Koltunski
|
int num = mTexComponent.size();
|
213 |
a8dfedcc
|
Leszek Koltunski
|
|
214 |
|
|
if( num>1 )
|
215 |
|
|
{
|
216 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.clear();
|
217 |
|
|
mTexComponent.add(new TexComponent(mNumVertices-1));
|
218 |
|
|
|
219 |
|
|
mVBO2.invalidate();
|
220 |
|
|
}
|
221 |
|
|
}
|
222 |
|
|
|
223 |
c92c163c
|
Leszek Koltunski
|
|
224 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225 |
|
|
|
226 |
|
|
void addEmptyTexComponentNow()
|
227 |
|
|
{
|
228 |
|
|
mTexComponent.add(new TexComponent(mNumVertices-1));
|
229 |
|
|
}
|
230 |
|
|
|
231 |
e8925fcd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
|
|
void mergeEffComponentsNow()
|
234 |
|
|
{
|
235 |
|
|
int num = mEffComponent.size();
|
236 |
|
|
|
237 |
|
|
if( num>1 )
|
238 |
|
|
{
|
239 |
|
|
mEffComponent.clear();
|
240 |
|
|
mEffComponent.add(mNumVertices-1);
|
241 |
a8dfedcc
|
Leszek Koltunski
|
|
242 |
|
|
for(int index=0; index<mNumVertices; index++)
|
243 |
|
|
{
|
244 |
|
|
mVertAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = 0;
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
mVBO2.invalidate();
|
248 |
|
|
}
|
249 |
|
|
}
|
250 |
|
|
|
251 |
0d4aae88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252 |
|
|
|
253 |
e8925fcd
|
Leszek Koltunski
|
void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
|
254 |
|
|
{
|
255 |
62c869ad
|
Leszek Koltunski
|
float[] matrixP = new float[16];
|
256 |
|
|
float[] matrixV = new float[16];
|
257 |
e8925fcd
|
Leszek Koltunski
|
float[] uniforms = new float[7];
|
258 |
|
|
int start, end=-1, numComp = mEffComponent.size();
|
259 |
|
|
|
260 |
62c869ad
|
Leszek Koltunski
|
Matrix.setIdentityM(matrixP,0);
|
261 |
|
|
Matrix.setIdentityM(matrixV,0);
|
262 |
e8925fcd
|
Leszek Koltunski
|
effect.compute(uniforms,0,0,0);
|
263 |
62c869ad
|
Leszek Koltunski
|
effect.apply(matrixP, matrixV, uniforms, 0);
|
264 |
e8925fcd
|
Leszek Koltunski
|
|
265 |
97755c02
|
Leszek Koltunski
|
for(int comp=0; comp<numComp; comp++)
|
266 |
e8925fcd
|
Leszek Koltunski
|
{
|
267 |
f45e4279
|
Leszek Koltunski
|
start = end+1;
|
268 |
97755c02
|
Leszek Koltunski
|
end = mEffComponent.get(comp);
|
269 |
e8925fcd
|
Leszek Koltunski
|
|
270 |
a2878a67
|
Leszek Koltunski
|
if( mUBA.matchesAssociation(comp, andAssoc, equAssoc) )
|
271 |
e8925fcd
|
Leszek Koltunski
|
{
|
272 |
62c869ad
|
Leszek Koltunski
|
applyMatrixToComponent(matrixP, matrixV, start, end);
|
273 |
e8925fcd
|
Leszek Koltunski
|
}
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
mVBO1.invalidate();
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280 |
|
|
|
281 |
62c869ad
|
Leszek Koltunski
|
private void applyMatrixToComponent(float[] matrixP, float[] matrixV, int start, int end)
|
282 |
e8925fcd
|
Leszek Koltunski
|
{
|
283 |
|
|
float x,y,z;
|
284 |
|
|
|
285 |
f45e4279
|
Leszek Koltunski
|
for(int index=start*VERT1_ATTRIBS; index<=end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
|
286 |
e8925fcd
|
Leszek Koltunski
|
{
|
287 |
|
|
x = mVertAttribs1[index+POS_ATTRIB ];
|
288 |
|
|
y = mVertAttribs1[index+POS_ATTRIB+1];
|
289 |
|
|
z = mVertAttribs1[index+POS_ATTRIB+2];
|
290 |
|
|
|
291 |
62c869ad
|
Leszek Koltunski
|
mVertAttribs1[index+POS_ATTRIB ] = matrixP[0]*x + matrixP[4]*y + matrixP[ 8]*z + matrixP[12];
|
292 |
|
|
mVertAttribs1[index+POS_ATTRIB+1] = matrixP[1]*x + matrixP[5]*y + matrixP[ 9]*z + matrixP[13];
|
293 |
|
|
mVertAttribs1[index+POS_ATTRIB+2] = matrixP[2]*x + matrixP[6]*y + matrixP[10]*z + matrixP[14];
|
294 |
e8925fcd
|
Leszek Koltunski
|
|
295 |
|
|
x = mVertAttribs1[index+NOR_ATTRIB ];
|
296 |
|
|
y = mVertAttribs1[index+NOR_ATTRIB+1];
|
297 |
|
|
z = mVertAttribs1[index+NOR_ATTRIB+2];
|
298 |
|
|
|
299 |
62c869ad
|
Leszek Koltunski
|
mVertAttribs1[index+NOR_ATTRIB ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
|
300 |
|
|
mVertAttribs1[index+NOR_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
|
301 |
|
|
mVertAttribs1[index+NOR_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
|
302 |
|
|
|
303 |
|
|
x = mVertAttribs1[index+NOR_ATTRIB ];
|
304 |
|
|
y = mVertAttribs1[index+NOR_ATTRIB+1];
|
305 |
|
|
z = mVertAttribs1[index+NOR_ATTRIB+2];
|
306 |
|
|
|
307 |
|
|
float len1 = (float)Math.sqrt(x*x + y*y + z*z);
|
308 |
|
|
|
309 |
|
|
if( len1>0.0f )
|
310 |
|
|
{
|
311 |
|
|
mVertAttribs1[index+NOR_ATTRIB ] /= len1;
|
312 |
|
|
mVertAttribs1[index+NOR_ATTRIB+1] /= len1;
|
313 |
|
|
mVertAttribs1[index+NOR_ATTRIB+2] /= len1;
|
314 |
|
|
}
|
315 |
e8925fcd
|
Leszek Koltunski
|
}
|
316 |
|
|
}
|
317 |
|
|
|
318 |
26671ef8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
319 |
|
|
|
320 |
|
|
void setEffectAssociationNow(int component, int andAssociation, int equAssociation)
|
321 |
|
|
{
|
322 |
a2878a67
|
Leszek Koltunski
|
mUBA.setEffectAssociationNow(component, andAssociation, equAssociation);
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
326 |
|
|
|
327 |
7a9edb92
|
Leszek Koltunski
|
void setComponentCenterNow(int component, float x, float y, float z)
|
328 |
a2878a67
|
Leszek Koltunski
|
{
|
329 |
|
|
mUBC.setEffectCenterNow(component, x, y, z);
|
330 |
26671ef8
|
Leszek Koltunski
|
}
|
331 |
|
|
|
332 |
42571056
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
333 |
6c00149d
|
Leszek Koltunski
|
// when a derived class is done computing its mesh, it has to call this method.
|
334 |
42571056
|
Leszek Koltunski
|
|
335 |
e54bfada
|
Leszek Koltunski
|
void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
|
336 |
42571056
|
Leszek Koltunski
|
{
|
337 |
e54bfada
|
Leszek Koltunski
|
mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
|
338 |
|
|
mVertAttribs1= vert1Attribs;
|
339 |
|
|
mVertAttribs2= vert2Attribs;
|
340 |
da681e7e
|
Leszek Koltunski
|
|
341 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.add(new TexComponent(mNumVertices-1));
|
342 |
|
|
mEffComponent.add(mNumVertices-1);
|
343 |
c90aca24
|
Leszek Koltunski
|
|
344 |
e54bfada
|
Leszek Koltunski
|
mVBO1.invalidate();
|
345 |
|
|
mVBO2.invalidate();
|
346 |
42571056
|
Leszek Koltunski
|
}
|
347 |
|
|
|
348 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
349 |
|
|
|
350 |
1fad573e
|
Leszek Koltunski
|
void joinAttribs(MeshBase[] meshes)
|
351 |
226144d0
|
leszek
|
{
|
352 |
0d4aae88
|
Leszek Koltunski
|
MeshBase mesh;
|
353 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp;
|
354 |
a8dfedcc
|
Leszek Koltunski
|
int numMeshes = meshes.length;
|
355 |
e8925fcd
|
Leszek Koltunski
|
int numVertices,origVertices = mNumVertices;
|
356 |
26671ef8
|
Leszek Koltunski
|
int origTexComponents,numTexComponents;
|
357 |
e8925fcd
|
Leszek Koltunski
|
int origEffComponents=0,numEffComponents;
|
358 |
044b5494
|
Leszek Koltunski
|
|
359 |
0d4aae88
|
Leszek Koltunski
|
if( origVertices>0 )
|
360 |
|
|
{
|
361 |
e8925fcd
|
Leszek Koltunski
|
origTexComponents = mTexComponent.size();
|
362 |
1fad573e
|
Leszek Koltunski
|
mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
|
363 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
|
364 |
|
|
origEffComponents = mEffComponent.size();
|
365 |
|
|
mEffComponent.set(origEffComponents-1,mNumVertices-1);
|
366 |
0d4aae88
|
Leszek Koltunski
|
}
|
367 |
044b5494
|
Leszek Koltunski
|
|
368 |
e7f85322
|
Leszek Koltunski
|
for(int i=0; i<numMeshes; i++)
|
369 |
0d4aae88
|
Leszek Koltunski
|
{
|
370 |
|
|
mesh = meshes[i];
|
371 |
e8925fcd
|
Leszek Koltunski
|
numTexComponents = mesh.mTexComponent.size();
|
372 |
|
|
numEffComponents = mesh.mEffComponent.size();
|
373 |
36d65d88
|
Leszek Koltunski
|
numVertices = mesh.mNumVertices;
|
374 |
|
|
|
375 |
1fad573e
|
Leszek Koltunski
|
int extraVerticesBefore = mNumVertices==0 ? 0:1;
|
376 |
|
|
int extraVerticesAfter = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
|
377 |
36d65d88
|
Leszek Koltunski
|
|
378 |
e8925fcd
|
Leszek Koltunski
|
for(int j=0; j<numTexComponents; j++)
|
379 |
0d4aae88
|
Leszek Koltunski
|
{
|
380 |
e8925fcd
|
Leszek Koltunski
|
comp = new TexComponent(mesh.mTexComponent.get(j));
|
381 |
e0343804
|
Leszek Koltunski
|
comp.mEndIndex += (extraVerticesBefore+mNumVertices);
|
382 |
|
|
if( j==numTexComponents-1) comp.mEndIndex += extraVerticesAfter;
|
383 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.add(comp);
|
384 |
|
|
}
|
385 |
23b733db
|
Leszek Koltunski
|
|
386 |
e8925fcd
|
Leszek Koltunski
|
for(int j=0; j<numEffComponents; j++)
|
387 |
|
|
{
|
388 |
|
|
int index = mesh.mEffComponent.get(j);
|
389 |
e0343804
|
Leszek Koltunski
|
index += (extraVerticesBefore+mNumVertices);
|
390 |
|
|
if( j==numEffComponents-1 ) index += extraVerticesAfter;
|
391 |
e8925fcd
|
Leszek Koltunski
|
mEffComponent.add(index);
|
392 |
|
|
|
393 |
|
|
if( origEffComponents<MAX_EFFECT_COMPONENTS )
|
394 |
36d65d88
|
Leszek Koltunski
|
{
|
395 |
a2878a67
|
Leszek Koltunski
|
mUBA.copy(origEffComponents, mesh.mUBA, j);
|
396 |
|
|
mUBC.copy(origEffComponents, mesh.mUBC, j);
|
397 |
e8925fcd
|
Leszek Koltunski
|
origEffComponents++;
|
398 |
36d65d88
|
Leszek Koltunski
|
}
|
399 |
e7f85322
|
Leszek Koltunski
|
}
|
400 |
a8dfedcc
|
Leszek Koltunski
|
|
401 |
1fad573e
|
Leszek Koltunski
|
mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
|
402 |
|
|
}
|
403 |
a8dfedcc
|
Leszek Koltunski
|
|
404 |
1fad573e
|
Leszek Koltunski
|
float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
|
405 |
e54bfada
|
Leszek Koltunski
|
float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
|
406 |
1fad573e
|
Leszek Koltunski
|
numVertices = origVertices;
|
407 |
0d4aae88
|
Leszek Koltunski
|
|
408 |
|
|
if( origVertices>0 )
|
409 |
|
|
{
|
410 |
e8925fcd
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs1, 0, newAttribs1, 0, VERT1_ATTRIBS*numVertices);
|
411 |
|
|
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS );
|
412 |
|
|
System.arraycopy(mVertAttribs2, 0, newAttribs2, 0, VERT2_ATTRIBS*numVertices);
|
413 |
|
|
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS );
|
414 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
415 |
|
|
|
416 |
e7f85322
|
Leszek Koltunski
|
if( numVertices%2==1 )
|
417 |
0d4aae88
|
Leszek Koltunski
|
{
|
418 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
419 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
420 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
421 |
|
|
}
|
422 |
|
|
}
|
423 |
|
|
|
424 |
e7f85322
|
Leszek Koltunski
|
for(int i=0; i<numMeshes; i++)
|
425 |
0d4aae88
|
Leszek Koltunski
|
{
|
426 |
|
|
mesh = meshes[i];
|
427 |
e7f85322
|
Leszek Koltunski
|
numVertices = mesh.mNumVertices;
|
428 |
0d4aae88
|
Leszek Koltunski
|
|
429 |
22e60fba
|
Leszek Koltunski
|
if( origVertices>0 )
|
430 |
|
|
{
|
431 |
e8925fcd
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
432 |
|
|
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
433 |
22e60fba
|
Leszek Koltunski
|
origVertices++;
|
434 |
|
|
}
|
435 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
|
436 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
|
437 |
e7f85322
|
Leszek Koltunski
|
origVertices+=numVertices;
|
438 |
0d4aae88
|
Leszek Koltunski
|
|
439 |
e7f85322
|
Leszek Koltunski
|
if( i<numMeshes-1 )
|
440 |
0d4aae88
|
Leszek Koltunski
|
{
|
441 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
442 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
443 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
444 |
|
|
|
445 |
e7f85322
|
Leszek Koltunski
|
if( numVertices%2==1 )
|
446 |
0d4aae88
|
Leszek Koltunski
|
{
|
447 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
448 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
449 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
450 |
|
|
}
|
451 |
|
|
}
|
452 |
|
|
}
|
453 |
|
|
|
454 |
|
|
if( origVertices!=mNumVertices )
|
455 |
|
|
{
|
456 |
|
|
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
|
457 |
|
|
}
|
458 |
|
|
|
459 |
e8925fcd
|
Leszek Koltunski
|
int endIndex, index=0, numEffComp = mEffComponent.size();
|
460 |
36d65d88
|
Leszek Koltunski
|
|
461 |
e8925fcd
|
Leszek Koltunski
|
for(int component=0; component<numEffComp; component++)
|
462 |
36d65d88
|
Leszek Koltunski
|
{
|
463 |
e8925fcd
|
Leszek Koltunski
|
endIndex = mEffComponent.get(component);
|
464 |
36d65d88
|
Leszek Koltunski
|
|
465 |
|
|
for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
|
466 |
|
|
}
|
467 |
|
|
|
468 |
1fad573e
|
Leszek Koltunski
|
mVertAttribs1 = newAttribs1;
|
469 |
e54bfada
|
Leszek Koltunski
|
mVertAttribs2 = newAttribs2;
|
470 |
1fad573e
|
Leszek Koltunski
|
mVBO1.invalidate();
|
471 |
e54bfada
|
Leszek Koltunski
|
mVBO2.invalidate();
|
472 |
23b733db
|
Leszek Koltunski
|
}
|
473 |
|
|
|
474 |
a8dfedcc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475 |
|
|
// called from MeshJoined
|
476 |
|
|
|
477 |
|
|
void join(MeshBase[] meshes)
|
478 |
|
|
{
|
479 |
1fad573e
|
Leszek Koltunski
|
boolean immediateJoin = true;
|
480 |
a8dfedcc
|
Leszek Koltunski
|
|
481 |
1fad573e
|
Leszek Koltunski
|
for (MeshBase mesh : meshes)
|
482 |
a8dfedcc
|
Leszek Koltunski
|
{
|
483 |
1fad573e
|
Leszek Koltunski
|
if (mesh.mJobNode[0] != null)
|
484 |
|
|
{
|
485 |
|
|
immediateJoin = false;
|
486 |
|
|
break;
|
487 |
|
|
}
|
488 |
a8dfedcc
|
Leszek Koltunski
|
}
|
489 |
|
|
|
490 |
1fad573e
|
Leszek Koltunski
|
if( immediateJoin ) joinAttribs(meshes);
|
491 |
|
|
else mJobNode[0] = DeferredJobs.join(this,meshes);
|
492 |
|
|
}
|
493 |
a8dfedcc
|
Leszek Koltunski
|
|
494 |
1fad573e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
495 |
a8dfedcc
|
Leszek Koltunski
|
|
496 |
dbe3079d
|
Leszek Koltunski
|
void textureMap(Static4D[] maps, int startComponent)
|
497 |
1fad573e
|
Leszek Koltunski
|
{
|
498 |
e8925fcd
|
Leszek Koltunski
|
int num_comp = mTexComponent.size();
|
499 |
92403ff8
|
Leszek Koltunski
|
if( startComponent>num_comp ) return;
|
500 |
|
|
|
501 |
1fad573e
|
Leszek Koltunski
|
int num_maps = maps.length;
|
502 |
dbe3079d
|
Leszek Koltunski
|
int min = Math.min(num_comp-startComponent, num_maps);
|
503 |
96877ab4
|
Leszek Koltunski
|
int vertex = startComponent>0 ? mTexComponent.get(startComponent-1).mEndIndex+1 : 0;
|
504 |
1fad573e
|
Leszek Koltunski
|
Static4D newMap, oldMap;
|
505 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp;
|
506 |
1fad573e
|
Leszek Koltunski
|
float newW, newH, ratW, ratH, movX, movY;
|
507 |
a8dfedcc
|
Leszek Koltunski
|
|
508 |
1fad573e
|
Leszek Koltunski
|
for(int i=0; i<min; i++)
|
509 |
|
|
{
|
510 |
|
|
newMap = maps[i];
|
511 |
dbe3079d
|
Leszek Koltunski
|
comp = mTexComponent.get(i+startComponent);
|
512 |
1fad573e
|
Leszek Koltunski
|
|
513 |
|
|
if( newMap!=null )
|
514 |
a8dfedcc
|
Leszek Koltunski
|
{
|
515 |
1fad573e
|
Leszek Koltunski
|
newW = newMap.get2();
|
516 |
|
|
newH = newMap.get3();
|
517 |
a8dfedcc
|
Leszek Koltunski
|
|
518 |
1fad573e
|
Leszek Koltunski
|
if( newW!=0.0f && newH!=0.0f )
|
519 |
a8dfedcc
|
Leszek Koltunski
|
{
|
520 |
1fad573e
|
Leszek Koltunski
|
oldMap = comp.mTextureMap;
|
521 |
|
|
ratW = newW/oldMap.get2();
|
522 |
|
|
ratH = newH/oldMap.get3();
|
523 |
|
|
movX = newMap.get0() - ratW*oldMap.get0();
|
524 |
|
|
movY = newMap.get1() - ratH*oldMap.get1();
|
525 |
|
|
|
526 |
|
|
for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
|
527 |
|
|
{
|
528 |
|
|
mVertAttribs2[index ] = ratW*mVertAttribs2[index ] + movX;
|
529 |
|
|
mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
|
530 |
|
|
}
|
531 |
|
|
comp.setMap(newMap);
|
532 |
a8dfedcc
|
Leszek Koltunski
|
}
|
533 |
|
|
}
|
534 |
|
|
|
535 |
1fad573e
|
Leszek Koltunski
|
vertex= comp.mEndIndex+1;
|
536 |
a8dfedcc
|
Leszek Koltunski
|
}
|
537 |
|
|
|
538 |
1fad573e
|
Leszek Koltunski
|
mVBO2.invalidate();
|
539 |
|
|
}
|
540 |
|
|
|
541 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
542 |
a8dfedcc
|
Leszek Koltunski
|
|
543 |
e8925fcd
|
Leszek Koltunski
|
public static int getMaxEffComponents()
|
544 |
1fad573e
|
Leszek Koltunski
|
{
|
545 |
e8925fcd
|
Leszek Koltunski
|
return MAX_EFFECT_COMPONENTS;
|
546 |
1fad573e
|
Leszek Koltunski
|
}
|
547 |
|
|
|
548 |
9f9924f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
549 |
|
|
|
550 |
|
|
public static void getUniforms(int programH, int variant)
|
551 |
|
|
{
|
552 |
|
|
mCenterBlockIndex[variant]= GLES30.glGetUniformBlockIndex(programH, "componentCenter");
|
553 |
|
|
mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation");
|
554 |
|
|
}
|
555 |
|
|
|
556 |
f046b159
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
557 |
|
|
/**
|
558 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
559 |
|
|
*
|
560 |
|
|
* @y.exclude
|
561 |
|
|
*/
|
562 |
|
|
public void copyTransformToVertex()
|
563 |
|
|
{
|
564 |
e54bfada
|
Leszek Koltunski
|
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
|
565 |
|
|
TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
|
566 |
f046b159
|
Leszek Koltunski
|
if( buffer!=null )
|
567 |
|
|
{
|
568 |
e54bfada
|
Leszek Koltunski
|
FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
569 |
|
|
feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
|
570 |
0bd9f644
|
Leszek Koltunski
|
mVBO1.updateFloat(mVertAttribs1);
|
571 |
f046b159
|
Leszek Koltunski
|
}
|
572 |
|
|
else
|
573 |
|
|
{
|
574 |
b5be333a
|
Leszek Koltunski
|
int error = GLES30.glGetError();
|
575 |
|
|
Log.e("mesh", "failed to map tf buffer, error="+error);
|
576 |
f046b159
|
Leszek Koltunski
|
}
|
577 |
|
|
|
578 |
b5be333a
|
Leszek Koltunski
|
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
|
579 |
f046b159
|
Leszek Koltunski
|
}
|
580 |
|
|
|
581 |
1fad573e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
582 |
|
|
/**
|
583 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
584 |
|
|
*
|
585 |
|
|
* @y.exclude
|
586 |
|
|
*/
|
587 |
|
|
public void debug()
|
588 |
|
|
{
|
589 |
|
|
if( mJobNode[0]!=null )
|
590 |
|
|
{
|
591 |
|
|
mJobNode[0].print(0);
|
592 |
|
|
}
|
593 |
|
|
else
|
594 |
|
|
{
|
595 |
|
|
android.util.Log.e("mesh", "JobNode null");
|
596 |
|
|
}
|
597 |
|
|
}
|
598 |
|
|
|
599 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
600 |
|
|
/**
|
601 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
602 |
|
|
*
|
603 |
|
|
* @y.exclude
|
604 |
|
|
*/
|
605 |
e0343804
|
Leszek Koltunski
|
public void printPos()
|
606 |
1fad573e
|
Leszek Koltunski
|
{
|
607 |
26671ef8
|
Leszek Koltunski
|
StringBuilder sb = new StringBuilder();
|
608 |
1fad573e
|
Leszek Koltunski
|
|
609 |
|
|
for(int i=0; i<mNumVertices; i++)
|
610 |
|
|
{
|
611 |
|
|
sb.append('(');
|
612 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB ]);
|
613 |
|
|
sb.append(',');
|
614 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+1]);
|
615 |
|
|
sb.append(',');
|
616 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+2]);
|
617 |
|
|
sb.append(") ");
|
618 |
|
|
}
|
619 |
e0343804
|
Leszek Koltunski
|
Log.d("mesh", sb.toString());
|
620 |
|
|
}
|
621 |
1fad573e
|
Leszek Koltunski
|
|
622 |
e0343804
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
623 |
|
|
/**
|
624 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
625 |
|
|
*
|
626 |
|
|
* @y.exclude
|
627 |
|
|
*/
|
628 |
|
|
public void printCom()
|
629 |
|
|
{
|
630 |
|
|
StringBuilder sb = new StringBuilder();
|
631 |
1fad573e
|
Leszek Koltunski
|
|
632 |
|
|
for(int i=0; i<mNumVertices; i++)
|
633 |
|
|
{
|
634 |
e0343804
|
Leszek Koltunski
|
sb.append(mVertAttribs2[VERT2_ATTRIBS*i+COM_ATTRIB]);
|
635 |
|
|
sb.append(' ');
|
636 |
|
|
}
|
637 |
|
|
|
638 |
|
|
Log.d("mesh", sb.toString());
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
642 |
|
|
/**
|
643 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
644 |
|
|
*
|
645 |
|
|
* @y.exclude
|
646 |
|
|
*/
|
647 |
|
|
public void printTex()
|
648 |
|
|
{
|
649 |
|
|
int vert=0;
|
650 |
|
|
int num = numTexComponents();
|
651 |
|
|
StringBuilder sb = new StringBuilder();
|
652 |
|
|
sb.append("tex components: ").append(num);
|
653 |
|
|
|
654 |
|
|
for(int i=0; i<num; i++)
|
655 |
|
|
{
|
656 |
|
|
int end = mTexComponent.get(i).mEndIndex;
|
657 |
|
|
sb.append("\n");
|
658 |
|
|
|
659 |
|
|
for( ; vert<=end; vert++)
|
660 |
|
|
{
|
661 |
|
|
sb.append(' ');
|
662 |
|
|
sb.append('(');
|
663 |
|
|
sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB]);
|
664 |
|
|
sb.append(',');
|
665 |
|
|
sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB+1]);
|
666 |
|
|
sb.append(')');
|
667 |
|
|
}
|
668 |
1fad573e
|
Leszek Koltunski
|
}
|
669 |
|
|
|
670 |
e0343804
|
Leszek Koltunski
|
Log.d("mesh", sb.toString());
|
671 |
1fad573e
|
Leszek Koltunski
|
}
|
672 |
|
|
|
673 |
23b733db
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
674 |
|
|
/**
|
675 |
0d4aae88
|
Leszek Koltunski
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
676 |
|
|
*
|
677 |
|
|
* @y.exclude
|
678 |
23b733db
|
Leszek Koltunski
|
*/
|
679 |
0d4aae88
|
Leszek Koltunski
|
public int getTFO()
|
680 |
23b733db
|
Leszek Koltunski
|
{
|
681 |
0bd9f644
|
Leszek Koltunski
|
return mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
|
682 |
23b733db
|
Leszek Koltunski
|
}
|
683 |
|
|
|
684 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
685 |
|
|
/**
|
686 |
0d4aae88
|
Leszek Koltunski
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
687 |
|
|
*
|
688 |
|
|
* @y.exclude
|
689 |
23b733db
|
Leszek Koltunski
|
*/
|
690 |
0d4aae88
|
Leszek Koltunski
|
public int getNumVertices()
|
691 |
23b733db
|
Leszek Koltunski
|
{
|
692 |
0d4aae88
|
Leszek Koltunski
|
return mNumVertices;
|
693 |
23b733db
|
Leszek Koltunski
|
}
|
694 |
|
|
|
695 |
36d65d88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
696 |
|
|
/**
|
697 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
698 |
|
|
*
|
699 |
|
|
* @y.exclude
|
700 |
|
|
*/
|
701 |
9f9924f8
|
Leszek Koltunski
|
public void send(int programH, int variant)
|
702 |
36d65d88
|
Leszek Koltunski
|
{
|
703 |
a2878a67
|
Leszek Koltunski
|
int indexA = mUBA.getIndex();
|
704 |
|
|
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
|
705 |
9f9924f8
|
Leszek Koltunski
|
GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING);
|
706 |
a2878a67
|
Leszek Koltunski
|
|
707 |
|
|
int indexC = mUBC.getIndex();
|
708 |
|
|
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
|
709 |
9f9924f8
|
Leszek Koltunski
|
GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
|
710 |
36d65d88
|
Leszek Koltunski
|
}
|
711 |
|
|
|
712 |
044b5494
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
713 |
6c00149d
|
Leszek Koltunski
|
/**
|
714 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
715 |
|
|
*
|
716 |
|
|
* @y.exclude
|
717 |
|
|
*/
|
718 |
da681e7e
|
Leszek Koltunski
|
public void bindVertexAttribs(DistortedProgram program)
|
719 |
6c00149d
|
Leszek Koltunski
|
{
|
720 |
71d8aba1
|
Leszek Koltunski
|
if( mJobNode[0]!=null )
|
721 |
f046b159
|
Leszek Koltunski
|
{
|
722 |
71d8aba1
|
Leszek Koltunski
|
mJobNode[0].execute(); // this will set itself to null
|
723 |
bc2ab8c5
|
Leszek Koltunski
|
/*
|
724 |
|
|
try
|
725 |
|
|
{
|
726 |
|
|
String name = "/sdcard/"+mNumVertices+".dmesh";
|
727 |
7a9edb92
|
Leszek Koltunski
|
DataOutputStream dos = new DataOutputStream(new java.io.FileOutputStream(name));
|
728 |
bc2ab8c5
|
Leszek Koltunski
|
write(dos);
|
729 |
9f28e9b6
|
Leszek Koltunski
|
android.util.Log.e("mesh", "file written: "+name);
|
730 |
bc2ab8c5
|
Leszek Koltunski
|
}
|
731 |
7a9edb92
|
Leszek Koltunski
|
catch(java.io.FileNotFoundException ex)
|
732 |
bc2ab8c5
|
Leszek Koltunski
|
{
|
733 |
|
|
android.util.Log.e("mesh", "file not found exception: "+ex.toString());
|
734 |
|
|
}
|
735 |
|
|
*/
|
736 |
f046b159
|
Leszek Koltunski
|
}
|
737 |
|
|
|
738 |
0bd9f644
|
Leszek Koltunski
|
int index1 = mVBO1.createImmediatelyFloat(mNumVertices*VERT1_SIZE, mVertAttribs1);
|
739 |
|
|
int index2 = mVBO2.createImmediatelyFloat(mNumVertices*VERT2_SIZE, mVertAttribs2);
|
740 |
22e60fba
|
Leszek Koltunski
|
|
741 |
e54bfada
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
|
742 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
|
743 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
|
744 |
|
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
|
745 |
a2878a67
|
Leszek Koltunski
|
GLES30.glVertexAttribPointer(program.mAttribute[2], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
|
746 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[3], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
|
747 |
b7074bc6
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
|
748 |
da681e7e
|
Leszek Koltunski
|
}
|
749 |
|
|
|
750 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
751 |
|
|
/**
|
752 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
753 |
|
|
*
|
754 |
|
|
* @y.exclude
|
755 |
|
|
*/
|
756 |
|
|
public void bindTransformAttribs(DistortedProgram program)
|
757 |
|
|
{
|
758 |
0bd9f644
|
Leszek Koltunski
|
int index = mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
|
759 |
22e60fba
|
Leszek Koltunski
|
|
760 |
b7074bc6
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
|
761 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
|
762 |
|
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
|
763 |
6c00149d
|
Leszek Koltunski
|
}
|
764 |
|
|
|
765 |
7a5e538a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
766 |
|
|
/**
|
767 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
768 |
|
|
*
|
769 |
|
|
* @y.exclude
|
770 |
|
|
*/
|
771 |
|
|
public void setInflate(float inflate)
|
772 |
|
|
{
|
773 |
|
|
mInflate = inflate;
|
774 |
|
|
}
|
775 |
|
|
|
776 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
777 |
|
|
/**
|
778 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
779 |
|
|
*
|
780 |
|
|
* @y.exclude
|
781 |
|
|
*/
|
782 |
|
|
public float getInflate()
|
783 |
|
|
{
|
784 |
|
|
return mInflate;
|
785 |
|
|
}
|
786 |
|
|
|
787 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
788 |
54ce4c6f
|
Leszek Koltunski
|
// Return the number of bytes read.
|
789 |
22422a76
|
Leszek Koltunski
|
|
790 |
54ce4c6f
|
Leszek Koltunski
|
int read(DataInputStream stream)
|
791 |
10836924
|
Leszek Koltunski
|
{
|
792 |
bc2ab8c5
|
Leszek Koltunski
|
byte[] buffer = new byte[BYTES_PER_FLOAT*4];
|
793 |
|
|
int version, numEff, numTex;
|
794 |
22422a76
|
Leszek Koltunski
|
|
795 |
7a9edb92
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////
|
796 |
|
|
// read version, number of vertices, number of tex components, number of effect components
|
797 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
798 |
|
|
|
799 |
22422a76
|
Leszek Koltunski
|
try
|
800 |
|
|
{
|
801 |
bc2ab8c5
|
Leszek Koltunski
|
stream.read(buffer);
|
802 |
|
|
ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
|
803 |
22422a76
|
Leszek Koltunski
|
|
804 |
bc2ab8c5
|
Leszek Koltunski
|
version = byteBuf.getInt(0);
|
805 |
22422a76
|
Leszek Koltunski
|
|
806 |
a2878a67
|
Leszek Koltunski
|
if( version==1 || version==2 )
|
807 |
22422a76
|
Leszek Koltunski
|
{
|
808 |
bc2ab8c5
|
Leszek Koltunski
|
mNumVertices= byteBuf.getInt(4);
|
809 |
|
|
numTex = byteBuf.getInt(8);
|
810 |
|
|
numEff = byteBuf.getInt(12);
|
811 |
22422a76
|
Leszek Koltunski
|
}
|
812 |
|
|
else
|
813 |
|
|
{
|
814 |
bc2ab8c5
|
Leszek Koltunski
|
android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
|
815 |
54ce4c6f
|
Leszek Koltunski
|
return 0;
|
816 |
22422a76
|
Leszek Koltunski
|
}
|
817 |
|
|
}
|
818 |
|
|
catch(IOException e)
|
819 |
|
|
{
|
820 |
bc2ab8c5
|
Leszek Koltunski
|
android.util.Log.e("mesh", "IOException1 trying to read file: "+e.toString());
|
821 |
54ce4c6f
|
Leszek Koltunski
|
return 0;
|
822 |
22422a76
|
Leszek Koltunski
|
}
|
823 |
|
|
|
824 |
7a9edb92
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////
|
825 |
|
|
// read contents of all texture and effect components
|
826 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
827 |
|
|
|
828 |
bc2ab8c5
|
Leszek Koltunski
|
if( mNumVertices>0 && numEff>0 && numTex>0 )
|
829 |
22422a76
|
Leszek Koltunski
|
{
|
830 |
|
|
int size = numEff+TEX_COMP_SIZE*numTex;
|
831 |
|
|
float[] tmp = new float[size];
|
832 |
bc2ab8c5
|
Leszek Koltunski
|
mVertAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
|
833 |
|
|
mVertAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
|
834 |
22422a76
|
Leszek Koltunski
|
|
835 |
a2878a67
|
Leszek Koltunski
|
// version 1 had extra 3 floats (the 'inflate' vector) in its vert1 array
|
836 |
7a9edb92
|
Leszek Koltunski
|
int vert1InFile = version==2 ? VERT1_ATTRIBS : VERT1_ATTRIBS+3;
|
837 |
|
|
// ... and there was no center.
|
838 |
|
|
int centerSize = version==2 ? 3*numEff : 0;
|
839 |
a2878a67
|
Leszek Koltunski
|
|
840 |
7a9edb92
|
Leszek Koltunski
|
buffer = new byte[BYTES_PER_FLOAT*(size + centerSize + mNumVertices*(vert1InFile+VERT2_ATTRIBS))];
|
841 |
22422a76
|
Leszek Koltunski
|
|
842 |
bc2ab8c5
|
Leszek Koltunski
|
try
|
843 |
|
|
{
|
844 |
|
|
stream.read(buffer);
|
845 |
|
|
}
|
846 |
|
|
catch(IOException e)
|
847 |
|
|
{
|
848 |
|
|
android.util.Log.e("mesh", "IOException2 trying to read file: "+e.toString());
|
849 |
54ce4c6f
|
Leszek Koltunski
|
return 0;
|
850 |
bc2ab8c5
|
Leszek Koltunski
|
}
|
851 |
|
|
|
852 |
|
|
ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
|
853 |
|
|
FloatBuffer floatBuf = byteBuf.asFloatBuffer();
|
854 |
22422a76
|
Leszek Koltunski
|
|
855 |
bc2ab8c5
|
Leszek Koltunski
|
floatBuf.get(tmp,0,size);
|
856 |
a2878a67
|
Leszek Koltunski
|
|
857 |
22422a76
|
Leszek Koltunski
|
TexComponent tex;
|
858 |
|
|
int index, texComp;
|
859 |
|
|
float x, y, z, w;
|
860 |
|
|
|
861 |
|
|
for(texComp=0; texComp<numTex; texComp++)
|
862 |
|
|
{
|
863 |
|
|
index = (int)tmp[TEX_COMP_SIZE*texComp];
|
864 |
|
|
|
865 |
|
|
x= tmp[TEX_COMP_SIZE*texComp+1];
|
866 |
|
|
y= tmp[TEX_COMP_SIZE*texComp+2];
|
867 |
|
|
z= tmp[TEX_COMP_SIZE*texComp+3];
|
868 |
|
|
w= tmp[TEX_COMP_SIZE*texComp+4];
|
869 |
|
|
|
870 |
|
|
tex = new TexComponent(index);
|
871 |
|
|
tex.setMap(new Static4D(x,y,z,w));
|
872 |
10836924
|
Leszek Koltunski
|
|
873 |
22422a76
|
Leszek Koltunski
|
mTexComponent.add(tex);
|
874 |
|
|
}
|
875 |
|
|
|
876 |
|
|
for(int effComp=0; effComp<numEff; effComp++)
|
877 |
|
|
{
|
878 |
|
|
index = (int)tmp[TEX_COMP_SIZE*texComp + effComp ];
|
879 |
|
|
mEffComponent.add(index);
|
880 |
|
|
}
|
881 |
7a9edb92
|
Leszek Koltunski
|
|
882 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
883 |
|
|
// read vert1 array, vert2 array and (if version>1) the component centers.
|
884 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
885 |
|
|
|
886 |
|
|
switch(version)
|
887 |
|
|
{
|
888 |
|
|
case 1 : index = floatBuf.position();
|
889 |
|
|
|
890 |
|
|
for(int vert=0; vert<mNumVertices; vert++)
|
891 |
|
|
{
|
892 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB ] = floatBuf.get(index+POS_ATTRIB );
|
893 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+1] = floatBuf.get(index+POS_ATTRIB+1);
|
894 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+2] = floatBuf.get(index+POS_ATTRIB+2);
|
895 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB ] = floatBuf.get(index+NOR_ATTRIB );
|
896 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+1] = floatBuf.get(index+NOR_ATTRIB+1);
|
897 |
|
|
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+2] = floatBuf.get(index+NOR_ATTRIB+2);
|
898 |
|
|
index+=vert1InFile;
|
899 |
|
|
}
|
900 |
|
|
floatBuf.position(index);
|
901 |
|
|
break;
|
902 |
|
|
case 2 : float[] centers = new float[3*numEff];
|
903 |
|
|
floatBuf.get(centers,0,3*numEff);
|
904 |
|
|
|
905 |
|
|
for(int eff=0; eff<numEff; eff++)
|
906 |
|
|
{
|
907 |
|
|
mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
|
908 |
|
|
}
|
909 |
|
|
|
910 |
|
|
floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices);
|
911 |
|
|
break;
|
912 |
|
|
default: android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
|
913 |
|
|
return 0;
|
914 |
|
|
}
|
915 |
|
|
|
916 |
|
|
floatBuf.get(mVertAttribs2, 0, VERT2_ATTRIBS*mNumVertices);
|
917 |
22422a76
|
Leszek Koltunski
|
}
|
918 |
54ce4c6f
|
Leszek Koltunski
|
|
919 |
|
|
return BYTES_PER_FLOAT*( 4 + numEff+TEX_COMP_SIZE*numTex + VERT1_ATTRIBS*mNumVertices + VERT2_ATTRIBS*mNumVertices );
|
920 |
10836924
|
Leszek Koltunski
|
}
|
921 |
|
|
|
922 |
524e4fe7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
923 |
|
|
/**
|
924 |
|
|
* @y.exclude
|
925 |
|
|
*/
|
926 |
|
|
public int getLastVertexEff(int effComponent)
|
927 |
|
|
{
|
928 |
|
|
if( effComponent>=0 && effComponent<mTexComponent.size() )
|
929 |
|
|
{
|
930 |
|
|
return mEffComponent.get(effComponent);
|
931 |
|
|
}
|
932 |
|
|
|
933 |
|
|
return 0;
|
934 |
|
|
}
|
935 |
|
|
|
936 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
937 |
|
|
/**
|
938 |
|
|
* @y.exclude
|
939 |
|
|
*/
|
940 |
|
|
public int getLastVertexTex(int texComponent)
|
941 |
|
|
{
|
942 |
|
|
if( texComponent>=0 && texComponent<mTexComponent.size() )
|
943 |
|
|
{
|
944 |
|
|
return mTexComponent.get(texComponent).mEndIndex;
|
945 |
|
|
}
|
946 |
|
|
|
947 |
|
|
return 0;
|
948 |
|
|
}
|
949 |
|
|
|
950 |
22422a76
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
951 |
|
|
// PUBLIC API
|
952 |
10836924
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
953 |
|
|
/**
|
954 |
22422a76
|
Leszek Koltunski
|
* Write the Mesh to a File.
|
955 |
10836924
|
Leszek Koltunski
|
*/
|
956 |
bc2ab8c5
|
Leszek Koltunski
|
public void write(DataOutputStream stream)
|
957 |
10836924
|
Leszek Koltunski
|
{
|
958 |
22422a76
|
Leszek Koltunski
|
TexComponent tex;
|
959 |
|
|
|
960 |
|
|
int numTex = mTexComponent.size();
|
961 |
|
|
int numEff = mEffComponent.size();
|
962 |
|
|
|
963 |
bc2ab8c5
|
Leszek Koltunski
|
try
|
964 |
22422a76
|
Leszek Koltunski
|
{
|
965 |
a2878a67
|
Leszek Koltunski
|
stream.writeInt(2); // version
|
966 |
bc2ab8c5
|
Leszek Koltunski
|
stream.writeInt(mNumVertices);
|
967 |
|
|
stream.writeInt(numTex);
|
968 |
|
|
stream.writeInt(numEff);
|
969 |
22422a76
|
Leszek Koltunski
|
|
970 |
bc2ab8c5
|
Leszek Koltunski
|
for(int i=0; i<numTex; i++)
|
971 |
|
|
{
|
972 |
|
|
tex = mTexComponent.get(i);
|
973 |
22422a76
|
Leszek Koltunski
|
|
974 |
bc2ab8c5
|
Leszek Koltunski
|
stream.writeFloat((float)tex.mEndIndex);
|
975 |
|
|
stream.writeFloat(tex.mTextureMap.get0());
|
976 |
|
|
stream.writeFloat(tex.mTextureMap.get1());
|
977 |
|
|
stream.writeFloat(tex.mTextureMap.get2());
|
978 |
|
|
stream.writeFloat(tex.mTextureMap.get3());
|
979 |
|
|
}
|
980 |
22422a76
|
Leszek Koltunski
|
|
981 |
bc2ab8c5
|
Leszek Koltunski
|
for(int i=0; i<numEff; i++)
|
982 |
|
|
{
|
983 |
|
|
stream.writeFloat((float)mEffComponent.get(i));
|
984 |
|
|
}
|
985 |
10836924
|
Leszek Koltunski
|
|
986 |
7a9edb92
|
Leszek Koltunski
|
float[] centers = mUBC.getBackingArray();
|
987 |
|
|
|
988 |
|
|
for(int i=0; i<numEff; i++)
|
989 |
|
|
{
|
990 |
|
|
stream.writeFloat(centers[4*i ]);
|
991 |
|
|
stream.writeFloat(centers[4*i+1]);
|
992 |
|
|
stream.writeFloat(centers[4*i+2]);
|
993 |
|
|
}
|
994 |
|
|
|
995 |
bc2ab8c5
|
Leszek Koltunski
|
ByteBuffer vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*mNumVertices);
|
996 |
|
|
vertBuf1.asFloatBuffer().put(mVertAttribs1);
|
997 |
|
|
ByteBuffer vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*mNumVertices);
|
998 |
|
|
vertBuf2.asFloatBuffer().put(mVertAttribs2);
|
999 |
|
|
|
1000 |
|
|
stream.write(vertBuf1.array());
|
1001 |
|
|
stream.write(vertBuf2.array());
|
1002 |
22422a76
|
Leszek Koltunski
|
}
|
1003 |
bc2ab8c5
|
Leszek Koltunski
|
catch(IOException ex)
|
1004 |
22422a76
|
Leszek Koltunski
|
{
|
1005 |
bc2ab8c5
|
Leszek Koltunski
|
android.util.Log.e("mesh", "IOException trying to write a mesh: "+ex.toString());
|
1006 |
22422a76
|
Leszek Koltunski
|
}
|
1007 |
10836924
|
Leszek Koltunski
|
}
|
1008 |
|
|
|
1009 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1010 |
3fc9327a
|
Leszek Koltunski
|
/**
|
1011 |
|
|
* When rendering this Mesh, do we want to render the Normal vectors as well?
|
1012 |
420836fc
|
leszek
|
* <p>
|
1013 |
|
|
* Will work only on OpenGL ES >= 3.0 devices.
|
1014 |
3fc9327a
|
Leszek Koltunski
|
*
|
1015 |
|
|
* @param show Controls if we render the Normal vectors or not.
|
1016 |
|
|
*/
|
1017 |
|
|
public void setShowNormals(boolean show)
|
1018 |
|
|
{
|
1019 |
b7074bc6
|
Leszek Koltunski
|
mShowNormals = show;
|
1020 |
3fc9327a
|
Leszek Koltunski
|
}
|
1021 |
466450b5
|
Leszek Koltunski
|
|
1022 |
6c00149d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1023 |
|
|
/**
|
1024 |
|
|
* When rendering this mesh, should we also draw the normal vectors?
|
1025 |
|
|
*
|
1026 |
|
|
* @return <i>true</i> if we do render normal vectors
|
1027 |
|
|
*/
|
1028 |
|
|
public boolean getShowNormals()
|
1029 |
|
|
{
|
1030 |
|
|
return mShowNormals;
|
1031 |
|
|
}
|
1032 |
|
|
|
1033 |
a8dfedcc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1034 |
|
|
/**
|
1035 |
e8925fcd
|
Leszek Koltunski
|
* Merge all texture components of this Mesh into a single one.
|
1036 |
a8dfedcc
|
Leszek Koltunski
|
*/
|
1037 |
e8925fcd
|
Leszek Koltunski
|
public void mergeTexComponents()
|
1038 |
a8dfedcc
|
Leszek Koltunski
|
{
|
1039 |
1fad573e
|
Leszek Koltunski
|
if( mJobNode[0]==null )
|
1040 |
a8dfedcc
|
Leszek Koltunski
|
{
|
1041 |
e8925fcd
|
Leszek Koltunski
|
mergeTexComponentsNow();
|
1042 |
a8dfedcc
|
Leszek Koltunski
|
}
|
1043 |
|
|
else
|
1044 |
|
|
{
|
1045 |
e8925fcd
|
Leszek Koltunski
|
mJobNode[0] = DeferredJobs.mergeTex(this);
|
1046 |
|
|
}
|
1047 |
|
|
}
|
1048 |
|
|
|
1049 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1050 |
|
|
/**
|
1051 |
|
|
* Merge all effect components of this Mesh into a single one.
|
1052 |
|
|
*/
|
1053 |
|
|
public void mergeEffComponents()
|
1054 |
|
|
{
|
1055 |
|
|
if( mJobNode[0]==null )
|
1056 |
|
|
{
|
1057 |
|
|
mergeEffComponentsNow();
|
1058 |
|
|
}
|
1059 |
|
|
else
|
1060 |
|
|
{
|
1061 |
|
|
mJobNode[0] = DeferredJobs.mergeEff(this);
|
1062 |
a8dfedcc
|
Leszek Koltunski
|
}
|
1063 |
|
|
}
|
1064 |
|
|
|
1065 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1066 |
|
|
/**
|
1067 |
|
|
* Release all internal resources.
|
1068 |
|
|
*/
|
1069 |
|
|
public void markForDeletion()
|
1070 |
|
|
{
|
1071 |
e54bfada
|
Leszek Koltunski
|
mVertAttribs1 = null;
|
1072 |
|
|
mVertAttribs2 = null;
|
1073 |
466450b5
|
Leszek Koltunski
|
|
1074 |
e54bfada
|
Leszek Koltunski
|
mVBO1.markForDeletion();
|
1075 |
|
|
mVBO2.markForDeletion();
|
1076 |
466450b5
|
Leszek Koltunski
|
mTFO.markForDeletion();
|
1077 |
|
|
}
|
1078 |
fa8bc998
|
Leszek Koltunski
|
|
1079 |
e8925fcd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1080 |
|
|
/**
|
1081 |
|
|
* Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
|
1082 |
|
|
* <p>
|
1083 |
|
|
* This is a static, permanent modification of the vertices contained in this Mesh. If the effect
|
1084 |
|
|
* contains any Dynamics, they will be evaluated at 0.
|
1085 |
|
|
*
|
1086 |
|
|
* @param effect List of Matrix Effects to apply to the Mesh.
|
1087 |
|
|
* @param andAssoc 'Logical AND' association which defines which components will be affected.
|
1088 |
|
|
* @param equAssoc 'equality' association which defines which components will be affected.
|
1089 |
|
|
*/
|
1090 |
|
|
public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
|
1091 |
|
|
{
|
1092 |
|
|
if( mJobNode[0]==null )
|
1093 |
|
|
{
|
1094 |
|
|
applyMatrix(effect,andAssoc,equAssoc);
|
1095 |
|
|
}
|
1096 |
|
|
else
|
1097 |
|
|
{
|
1098 |
|
|
mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
|
1099 |
|
|
}
|
1100 |
|
|
}
|
1101 |
|
|
|
1102 |
fa8bc998
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1103 |
|
|
/**
|
1104 |
f046b159
|
Leszek Koltunski
|
* Apply a Vertex Effect to the vertex mesh.
|
1105 |
fa8bc998
|
Leszek Koltunski
|
* <p>
|
1106 |
c90aca24
|
Leszek Koltunski
|
* This is a static, permanent modification of the vertices contained in this Mesh. If the effects
|
1107 |
f046b159
|
Leszek Koltunski
|
* contain any Dynamics, the Dynamics will be evaluated at 0.
|
1108 |
fa8bc998
|
Leszek Koltunski
|
*
|
1109 |
f046b159
|
Leszek Koltunski
|
* We would call this several times building up a list of Effects to do. This list of effects gets
|
1110 |
|
|
* lazily executed only when the Mesh is used for rendering for the first time.
|
1111 |
e172985c
|
Leszek Koltunski
|
*
|
1112 |
f046b159
|
Leszek Koltunski
|
* @param effect Vertex Effect to apply to the Mesh.
|
1113 |
fa8bc998
|
Leszek Koltunski
|
*/
|
1114 |
f046b159
|
Leszek Koltunski
|
public void apply(VertexEffect effect)
|
1115 |
fa8bc998
|
Leszek Koltunski
|
{
|
1116 |
71d8aba1
|
Leszek Koltunski
|
mJobNode[0] = DeferredJobs.vertex(this,effect);
|
1117 |
c90aca24
|
Leszek Koltunski
|
}
|
1118 |
|
|
|
1119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1120 |
|
|
/**
|
1121 |
a3a05347
|
Leszek Koltunski
|
* Sets texture maps for (some of) the components of this mesh.
|
1122 |
c90aca24
|
Leszek Koltunski
|
* <p>
|
1123 |
a3a05347
|
Leszek Koltunski
|
* Format: ( x of lower-left corner, y of lower-left corner, width, height ).
|
1124 |
|
|
* For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
|
1125 |
0d4aae88
|
Leszek Koltunski
|
* upper-left quadrant of the texture.
|
1126 |
a3a05347
|
Leszek Koltunski
|
* <p>
|
1127 |
|
|
* Probably the most common user case would be sending as many maps as there are components in this
|
1128 |
|
|
* Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
|
1129 |
|
|
* to null (those will be ignored as well). So if there are 5 components, and we want to set the map
|
1130 |
|
|
* of the 2nd and 4rd one, call this with
|
1131 |
|
|
* maps = new Static4D[4]
|
1132 |
|
|
* maps[0] = null
|
1133 |
|
|
* maps[1] = the map for the 2nd component
|
1134 |
|
|
* maps[2] = null
|
1135 |
|
|
* maps[3] = the map for the 4th component
|
1136 |
|
|
*
|
1137 |
|
|
* A map's width and height have to be non-zero (but can be negative!)
|
1138 |
e172985c
|
Leszek Koltunski
|
*
|
1139 |
dbe3079d
|
Leszek Koltunski
|
* @param maps List of texture maps to apply to the texture's components.
|
1140 |
|
|
* @param startComponent the component the first of the maps refers to.
|
1141 |
c90aca24
|
Leszek Koltunski
|
*/
|
1142 |
dbe3079d
|
Leszek Koltunski
|
public void setTextureMap(Static4D[] maps, int startComponent)
|
1143 |
c90aca24
|
Leszek Koltunski
|
{
|
1144 |
1fad573e
|
Leszek Koltunski
|
if( mJobNode[0]==null )
|
1145 |
ea88d502
|
Leszek Koltunski
|
{
|
1146 |
dbe3079d
|
Leszek Koltunski
|
textureMap(maps,startComponent);
|
1147 |
1fad573e
|
Leszek Koltunski
|
}
|
1148 |
|
|
else
|
1149 |
|
|
{
|
1150 |
dbe3079d
|
Leszek Koltunski
|
mJobNode[0] = DeferredJobs.textureMap(this,maps,startComponent);
|
1151 |
ea88d502
|
Leszek Koltunski
|
}
|
1152 |
fa8bc998
|
Leszek Koltunski
|
}
|
1153 |
9099e567
|
Leszek Koltunski
|
|
1154 |
e172985c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1155 |
|
|
/**
|
1156 |
|
|
* Return the texture map of one of the components.
|
1157 |
|
|
*
|
1158 |
|
|
* @param component The component number whose texture map we want to retrieve.
|
1159 |
|
|
*/
|
1160 |
|
|
public Static4D getTextureMap(int component)
|
1161 |
|
|
{
|
1162 |
e8925fcd
|
Leszek Koltunski
|
return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
|
1163 |
e172985c
|
Leszek Koltunski
|
}
|
1164 |
cbd502ec
|
Leszek Koltunski
|
|
1165 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1166 |
|
|
/**
|
1167 |
1e672c1d
|
Leszek Koltunski
|
* Set Effect association.
|
1168 |
bc208a9c
|
Leszek Koltunski
|
*
|
1169 |
1e672c1d
|
Leszek Koltunski
|
* This creates an association between a Component of this Mesh and a Vertex Effect.
|
1170 |
2aeb75aa
|
Leszek Koltunski
|
* One can set two types of associations - an 'logical and' and a 'equal' associations and the Effect
|
1171 |
|
|
* will only be active on vertices of Components such that
|
1172 |
36d65d88
|
Leszek Koltunski
|
*
|
1173 |
2aeb75aa
|
Leszek Koltunski
|
* (effect andAssoc) & (component andAssoc) != 0 || (effect equAssoc) == (mesh equAssoc)
|
1174 |
36d65d88
|
Leszek Koltunski
|
*
|
1175 |
|
|
* (see main_vertex_shader)
|
1176 |
bc208a9c
|
Leszek Koltunski
|
*
|
1177 |
|
|
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain
|
1178 |
1e672c1d
|
Leszek Koltunski
|
* subset of a Mesh, thus potentially significantly reducing the number of render calls.
|
1179 |
cbd502ec
|
Leszek Koltunski
|
*/
|
1180 |
26671ef8
|
Leszek Koltunski
|
public void setEffectAssociation(int component, int andAssociation, int equAssociation)
|
1181 |
|
|
{
|
1182 |
|
|
if( component>=0 && component<MAX_EFFECT_COMPONENTS )
|
1183 |
|
|
{
|
1184 |
|
|
if( mJobNode[0]==null )
|
1185 |
|
|
{
|
1186 |
|
|
setEffectAssociationNow(component, andAssociation, equAssociation);
|
1187 |
|
|
}
|
1188 |
|
|
else
|
1189 |
|
|
{
|
1190 |
|
|
mJobNode[0] = DeferredJobs.effectAssoc(this,component,andAssociation,equAssociation);
|
1191 |
|
|
}
|
1192 |
|
|
}
|
1193 |
|
|
}
|
1194 |
bc208a9c
|
Leszek Koltunski
|
|
1195 |
7a9edb92
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1196 |
|
|
/**
|
1197 |
|
|
* Set center of a Component.
|
1198 |
|
|
*
|
1199 |
|
|
* A 'center' of a (effect) component is a 3D point in space. The array of centers gets sent to
|
1200 |
|
|
* the vertex shader as a Uniform Buffer Object; in the vertex shader we can then use it to compute
|
1201 |
|
|
* the 'Inflation' of the whole Mesh per-component. 'Inflation' is needed by postprocess effects to
|
1202 |
|
|
* add the 'halo' around an object.
|
1203 |
|
|
*
|
1204 |
|
|
* This is all 'per-component' so that a user has a chance to make the halo look right in case of
|
1205 |
|
|
* non-convex meshes: then we need to ensure that each component of such a mesh is a convex
|
1206 |
|
|
* sub-mesh with its center being more-or-less the center of gravity of the sub-mesh.
|
1207 |
|
|
*/
|
1208 |
|
|
public void setComponentCenter(int component, float centerX, float centerY, float centerZ)
|
1209 |
|
|
{
|
1210 |
|
|
if( component>=0 && component<MAX_EFFECT_COMPONENTS )
|
1211 |
|
|
{
|
1212 |
|
|
if( mJobNode[0]==null )
|
1213 |
|
|
{
|
1214 |
|
|
setComponentCenterNow(component, centerX, centerY, centerZ);
|
1215 |
|
|
}
|
1216 |
|
|
else
|
1217 |
|
|
{
|
1218 |
|
|
mJobNode[0] = DeferredJobs.componentCenter(this,component,centerX, centerY, centerZ);
|
1219 |
|
|
}
|
1220 |
|
|
}
|
1221 |
|
|
}
|
1222 |
|
|
|
1223 |
c92c163c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1224 |
|
|
/**
|
1225 |
|
|
* Adds an empty (no vertices) texture component to the end of the text component list.
|
1226 |
|
|
*
|
1227 |
|
|
* Sometimes we want to do this to have several Meshes with equal number of tex components each.
|
1228 |
|
|
*/
|
1229 |
|
|
public void addEmptyTexComponent()
|
1230 |
|
|
{
|
1231 |
|
|
if( mJobNode[0]==null )
|
1232 |
|
|
{
|
1233 |
|
|
addEmptyTexComponentNow();
|
1234 |
|
|
}
|
1235 |
|
|
else
|
1236 |
|
|
{
|
1237 |
|
|
mJobNode[0] = DeferredJobs.addEmptyTex(this);
|
1238 |
|
|
}
|
1239 |
|
|
}
|
1240 |
|
|
|
1241 |
524e4fe7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1242 |
|
|
/**
|
1243 |
|
|
* Return the number of texture components, i.e. individual subsets of the whole set of vertices
|
1244 |
|
|
* which can be independently textured.
|
1245 |
|
|
*
|
1246 |
|
|
* @return The number of Texture Components of this Mesh.
|
1247 |
|
|
*/
|
1248 |
|
|
public int numTexComponents()
|
1249 |
|
|
{
|
1250 |
|
|
return mTexComponent.size();
|
1251 |
|
|
}
|
1252 |
|
|
|
1253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1254 |
|
|
/**
|
1255 |
|
|
* Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
|
1256 |
|
|
* to which a VertexEffect can be addressed, independently of other vertices.
|
1257 |
|
|
*
|
1258 |
|
|
* @return The number of Effect Components of this Mesh.
|
1259 |
|
|
*/
|
1260 |
|
|
public int numEffComponents()
|
1261 |
|
|
{
|
1262 |
|
|
return mEffComponent.size();
|
1263 |
|
|
}
|
1264 |
|
|
|
1265 |
bc208a9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1266 |
|
|
/**
|
1267 |
4f81e0c8
|
Leszek Koltunski
|
* Copy the Mesh.
|
1268 |
|
|
*
|
1269 |
|
|
* @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
|
1270 |
a2878a67
|
Leszek Koltunski
|
* and normals (the rest, in particular the mVertAttribs2 containing texture
|
1271 |
36d65d88
|
Leszek Koltunski
|
* coordinates and effect associations, is always deep copied)
|
1272 |
bc208a9c
|
Leszek Koltunski
|
*/
|
1273 |
4f81e0c8
|
Leszek Koltunski
|
public abstract MeshBase copy(boolean deep);
|
1274 |
bc208a9c
|
Leszek Koltunski
|
}
|