Revision 2beb0a96
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java | ||
---|---|---|
131 | 131 |
} |
132 | 132 |
|
133 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
134 |
// mesh multigon |
|
134 | 135 |
|
135 |
private FaceInfo[] computeInfos(float[][] vertices, int[][] indices, float[] position, Static4D quat, float size) |
|
136 |
private FaceInfo[] computeInfos(float[][] vertices, int[][][] indices, float[] position, Static4D quat, float size)
|
|
136 | 137 |
{ |
138 |
int len = position.length/3; |
|
139 |
float avgX = 0.0f; |
|
140 |
float avgY = 0.0f; |
|
141 |
float avgZ = 0.0f; |
|
142 |
|
|
143 |
for(int i=0; i<len; i++) |
|
144 |
{ |
|
145 |
avgX += position[3*i ]; |
|
146 |
avgY += position[3*i+1]; |
|
147 |
avgZ += position[3*i+2]; |
|
148 |
} |
|
149 |
|
|
150 |
avgX /= len; |
|
151 |
avgY /= len; |
|
152 |
avgZ /= len; |
|
153 |
|
|
137 | 154 |
int numFaces = indices.length; |
155 |
FaceInfo[] infos = new FaceInfo[numFaces]; |
|
156 |
Static4D tmp; |
|
157 |
|
|
158 |
for(int f=0; f<numFaces; f++) |
|
159 |
{ |
|
160 |
int[][] inds = indices[f]; |
|
161 |
int numSegments = inds.length; |
|
162 |
int numVerts = 0; |
|
163 |
for(int[] ind : inds) numVerts += ind.length; |
|
164 |
|
|
165 |
float[][] verts = new float[numVerts][4]; |
|
166 |
int pointer = 0; |
|
167 |
|
|
168 |
for(int s=0; s<numSegments; s++) |
|
169 |
{ |
|
170 |
int numV = inds[s].length; |
|
171 |
|
|
172 |
for(int v=0; v<numV; v++) |
|
173 |
{ |
|
174 |
int index = indices[f][s][v]; |
|
175 |
float x = vertices[index][0]; |
|
176 |
float y = vertices[index][1]; |
|
177 |
float z = vertices[index][2]; |
|
178 |
float w = 1.0f; |
|
179 |
|
|
180 |
tmp = QuatHelper.rotateVectorByQuat(x,y,z,w,quat); |
|
181 |
|
|
182 |
verts[pointer][0] = tmp.get0() + avgX; |
|
183 |
verts[pointer][1] = tmp.get1() + avgY; |
|
184 |
verts[pointer][2] = tmp.get2() + avgZ; |
|
185 |
verts[pointer][3] = 1.0f; |
|
186 |
pointer++; |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
infos[f] = new FaceInfo(verts,size); |
|
191 |
} |
|
192 |
|
|
193 |
return infos; |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
// mesh polygon |
|
138 | 198 |
|
199 |
private FaceInfo[] computeInfos(float[][] vertices, int[][] indices, float[] position, Static4D quat, float size) |
|
200 |
{ |
|
139 | 201 |
int len = position.length/3; |
140 | 202 |
float avgX = 0.0f; |
141 | 203 |
float avgY = 0.0f; |
... | ... | |
152 | 214 |
avgY /= len; |
153 | 215 |
avgZ /= len; |
154 | 216 |
|
217 |
int numFaces = indices.length; |
|
155 | 218 |
FaceInfo[] infos = new FaceInfo[numFaces]; |
156 | 219 |
Static4D tmp; |
157 | 220 |
|
158 |
for(int i=0; i<numFaces; i++)
|
|
221 |
for(int f=0; f<numFaces; f++)
|
|
159 | 222 |
{ |
160 |
int numVerts = indices[i].length;
|
|
223 |
int numVerts = indices[f].length;
|
|
161 | 224 |
float[][] verts = new float[numVerts][4]; |
162 | 225 |
|
163 |
for(int j=0; j<numVerts; j++)
|
|
226 |
for(int v=0; v<numVerts; v++)
|
|
164 | 227 |
{ |
165 |
int index = indices[i][j];
|
|
228 |
int index = indices[f][v];
|
|
166 | 229 |
float x = vertices[index][0]; |
167 | 230 |
float y = vertices[index][1]; |
168 | 231 |
float z = vertices[index][2]; |
... | ... | |
170 | 233 |
|
171 | 234 |
tmp = QuatHelper.rotateVectorByQuat(x,y,z,w,quat); |
172 | 235 |
|
173 |
verts[j][0] = tmp.get0() + avgX;
|
|
174 |
verts[j][1] = tmp.get1() + avgY;
|
|
175 |
verts[j][2] = tmp.get2() + avgZ;
|
|
176 |
verts[j][3] = 1.0f;
|
|
236 |
verts[v][0] = tmp.get0() + avgX;
|
|
237 |
verts[v][1] = tmp.get1() + avgY;
|
|
238 |
verts[v][2] = tmp.get2() + avgZ;
|
|
239 |
verts[v][3] = 1.0f;
|
|
177 | 240 |
} |
178 | 241 |
|
179 |
infos[i] = new FaceInfo(verts,size);
|
|
242 |
infos[f] = new FaceInfo(verts,size);
|
|
180 | 243 |
} |
181 | 244 |
|
182 | 245 |
return infos; |
... | ... | |
241 | 304 |
ObjectShape shape = mObject.getObjectShape(variant); |
242 | 305 |
Static4D quat = mObject.getCubitQuats(i,numLayers); |
243 | 306 |
float[][] vertices = shape.getVertices(); |
244 |
int[][] indices = shape.getVertIndices(); |
|
245 | 307 |
if( pillow!=1.0f ) vertices = adjustVerticesForPillow(pillow,radius,vertices); |
246 |
|
|
247 |
mInfos[i] = computeInfos(vertices,indices,positions[i],quat,size); |
|
248 | 308 |
mNumFaces[i] =shape.getNumFaces(); |
309 |
|
|
310 |
int[][] indices = shape.getVertIndices(); |
|
311 |
|
|
312 |
if( indices!=null ) |
|
313 |
{ |
|
314 |
mInfos[i] = computeInfos(vertices, indices, positions[i], quat, size); |
|
315 |
} |
|
316 |
else |
|
317 |
{ |
|
318 |
int[][][] ind = shape.getMultigonIndices(); |
|
319 |
mInfos[i] = computeInfos(vertices, ind, positions[i], quat, size); |
|
320 |
} |
|
249 | 321 |
} |
250 | 322 |
|
251 | 323 |
Static4D[] quats = mObject.getQuats(); |
Also available in: Unified diff
Support both MeshPolygon and MeshMultigon in TouchControlShapeChanging