Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

12046 Posts in 1593 Topics- by 597 Members - Latest Member: Cydfewoot

21. May 2013, 06:27:27 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Fast way for creating a TriangleArray
Pages: [1]
Print
Author Topic: Fast way for creating a TriangleArray  (Read 491 times)
maguila007
Enjoying the stay
*
Offline Offline

Posts: 43



View Profile Email
« on: 17. November 2008, 01:51:35 pm »

Hi
Which is the best (and fastest) way for setting many coordinates to a TriangleArray?
I' am loading the coordinates from a file.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #1 on: 17. November 2008, 03:04:23 pm »

I suggest something like this:
Code:
float[] coordsBuffer = new float[ BUFFER_SIZE * 3 ];
int numVerts = file.loadNumVertes();
int numSteps = (int)Math.ceil( numVerts / BUFFER_SIZE );
int j = 0;
for ( int i = 0; i < numSteps; i++ )
{
    int nv = Math.min( BUFFER_SIZE, numVerts - j );
    file.loadCoordinates( coordsBuffer, nv );
    geom.setCoordinates( j, coordsBuffer, 0, nv );
    j += BUFFER_SIZE;
}

If you read the file through something like a BufferedInputStream, BUFFER_SIZE can even be 1. But test it.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic