Revision ea88d502
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/library/mesh/MeshBase.java | ||
|---|---|---|
| 94 | 94 |
mTextureMap = new float[8]; |
| 95 | 95 |
System.arraycopy(original.mTextureMap,0,mTextureMap,0,8); |
| 96 | 96 |
} |
| 97 |
|
|
| 98 | 97 |
} |
| 99 | 98 |
|
| 100 | 99 |
private ArrayList<Component> mComponent; |
| ... | ... | |
| 388 | 387 |
*/ |
| 389 | 388 |
public void join(MeshBase[] meshes) |
| 390 | 389 |
{
|
| 390 |
MeshBase mesh; |
|
| 391 |
Component comp; |
|
| 392 |
int com, num, len = meshes.length; |
|
| 393 |
int origVertices = mNumVertices; |
|
| 394 |
|
|
| 395 |
// compute new numVertices; take care of Components |
|
| 396 |
mNumVertices+= ( mNumVertices%2==1 ? 2:1 ); |
|
| 397 |
com = mComponent.size(); |
|
| 398 |
mComponent.get(com-1).mEndIndex = mNumVertices; |
|
| 399 |
|
|
| 400 |
for(int i=0; i<len; i++) |
|
| 401 |
{
|
|
| 402 |
mesh = meshes[i]; |
|
| 403 |
com = mesh.mComponent.size(); |
|
| 404 |
|
|
| 405 |
for(int j=0; j<com; j++) |
|
| 406 |
{
|
|
| 407 |
comp = new Component(mesh.mComponent.get(j)); |
|
| 408 |
comp.mEndIndex += mNumVertices; |
|
| 409 |
mComponent.add(comp); |
|
| 410 |
} |
|
| 411 |
|
|
| 412 |
num = mesh.mNumVertices; |
|
| 413 |
mNumVertices+= (i<len-1 ? ( num%2==1 ? num+2 : num+1 ) : num); |
|
| 414 |
} |
|
| 415 |
|
|
| 416 |
// allocate new attrib array |
|
| 417 |
float[] newAttribs = new float[VERT_ATTRIBS*mNumVertices]; |
|
| 418 |
num = origVertices; |
|
| 419 |
|
|
| 420 |
System.arraycopy(mVertAttribs, 0, newAttribs, 0, VERT_ATTRIBS*num); |
|
| 421 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
| 422 |
origVertices++; |
|
| 423 |
|
|
| 424 |
if( num%2==1 ) |
|
| 425 |
{
|
|
| 426 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 427 |
origVertices++; |
|
| 428 |
} |
|
| 429 |
|
|
| 430 |
for(int i=0; i<len; i++) |
|
| 431 |
{
|
|
| 432 |
mesh = meshes[i]; |
|
| 433 |
num = mesh.mNumVertices; |
|
| 434 |
|
|
| 435 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
| 436 |
origVertices++; |
|
| 437 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*num); |
|
| 438 |
origVertices+=num; |
|
| 439 |
|
|
| 440 |
if( i<len-1 ) |
|
| 441 |
{
|
|
| 442 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 443 |
origVertices++; |
|
| 444 |
|
|
| 445 |
if( num%2==1 ) |
|
| 446 |
{
|
|
| 447 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(num-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 448 |
origVertices++; |
|
| 449 |
} |
|
| 450 |
} |
|
| 451 |
} |
|
| 391 | 452 |
|
| 453 |
if( origVertices!=mNumVertices ) |
|
| 454 |
{
|
|
| 455 |
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
|
|
| 456 |
} |
|
| 457 |
|
|
| 458 |
mVertAttribs = newAttribs; |
|
| 459 |
|
|
| 460 |
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 461 |
attribs.put(mVertAttribs).position(0); |
|
| 462 |
|
|
| 463 |
mVBO.setData(mNumVertices*VERT_SIZE, attribs); |
|
| 464 |
mTFO.setData(mNumVertices*TRAN_SIZE, null ); |
|
| 392 | 465 |
} |
| 393 | 466 |
|
| 394 | 467 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
New API: MeshBase.join() and a skeleton of an App to test it.