Commit 1afb0498 authored by dickelbeck's avatar dickelbeck
Browse files

beautify

parent 4eac2675
Loading
Loading
Loading
Loading
+480 −446
Original line number Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////

// Name:        3d_read_mesh.cpp
/////////////////////////////////////////////////////////////////////////////

@@ -32,8 +33,10 @@ int LineNum = 0;
        return 1;
    }

	if ( wxIsAbsolutePath(m_Shape3DName) ) fullfilename.Empty();
	else fullfilename =  g_RealLibDirBuffer + LIB3D_PATH;
    if( wxIsAbsolutePath( m_Shape3DName ) )
        fullfilename.Empty();
    else
        fullfilename = g_RealLibDirBuffer + LIB3D_PATH;
    fullfilename += m_Shape3DName;
#if defined (__WINDOWS__)
    fullfilename.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
@@ -59,8 +62,10 @@ int LineNum = 0;
            while( GetLine( file, line, &LineNum, 512 ) )
            {
                text = strtok( line, " \t\n\r" );
				if ( text == NULL ) continue;
				if ( * text == '}' ) break;
                if( text == NULL )
                    continue;
                if( *text == '}' )
                    break;
                if( stricmp( text, "children" ) == 0 )
                {
                    ReadChildren( file, &LineNum );
@@ -74,21 +79,23 @@ int LineNum = 0;
    return 0;
}


/*********************************************************/
int Struct3D_Master:: ReadMaterial( FILE* file, int* LineNum )
/*********************************************************/

/*
analyse la description du type:
        material DEF yellow Material {
          diffuseColor 1.00000 1.00000 0.00000e+0
          emissiveColor 0.00000e+0 0.00000e+0 0.00000e+0
          specularColor 1.00000 1.00000 1.00000
          ambientIntensity 1.00000
          transparency 0.00000e+0
          shininess 1.00000
        }
ou du type:
        material USE yellow
 *  analyse la description du type:
 *      material DEF yellow Material {
 *        diffuseColor 1.00000 1.00000 0.00000e+0
 *        emissiveColor 0.00000e+0 0.00000e+0 0.00000e+0
 *        specularColor 1.00000 1.00000 1.00000
 *        ambientIntensity 1.00000
 *        transparency 0.00000e+0
 *        shininess 1.00000
 *      }
 *  ou du type:
 *      material USE yellow
 */
{
    char          line[512], * text, * command;
@@ -101,7 +108,6 @@ S3D_Material * material = NULL;
    mat_name = CONV_FROM_UTF8( text );
    if( stricmp( command, "USE" ) == 0 )
    {

        for( material = m_Materials; material != NULL;
             material = (S3D_Material*) material->Pnext )
        {
@@ -119,12 +125,14 @@ S3D_Material * material = NULL;
    if( stricmp( command, "DEF" ) == 0 )
    {
        material = new S3D_Material( this, mat_name );

        material->Pnext = m_Materials;
        m_Materials = material;
        while( GetLine( file, line, LineNum, 512 ) )
        {
            text = strtok( line, " \t\n\r" );
			if ( text == NULL ) continue;
            if( text == NULL )
                continue;
            if( text[0] == '}' )
            {
                material->SetMaterial();
@@ -187,8 +195,10 @@ char line[1024], *text;
    while( GetLine( file, line, LineNum, 512 ) )
    {
        text = strtok( line, " \t\n\r" );
		if ( * text == ']' ) return 0;
		if ( * text == ',' ) continue;
        if( *text == ']' )
            return 0;
        if( *text == ',' )
            continue;

        if( stricmp( text, "Shape" ) == 0 )
        {
@@ -200,9 +210,11 @@ char line[1024], *text;
            break;
        }
    }

    return 1;
}


/********************************************************/
int Struct3D_Master::ReadShape( FILE* file, int* LineNum )
/********************************************************/
@@ -237,6 +249,7 @@ int err = 1;
    return err;
}


/*************************************************************/
int Struct3D_Master::ReadAppearance( FILE* file, int* LineNum )
/*************************************************************/
@@ -266,26 +279,28 @@ int err = 1;
    return err;
}


#define BUFSIZE 2000

/************************************************************************************/
double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNum )
/************************************************************************************/

/* Read a coordinate liste like:
        coord Coordinate { point [
          -5.24489 6.57640e-3 -9.42129e-2,
          -5.11821 6.57421e-3 0.542654,
          -3.45868 0.256565 1.32000 ] }
	or:
	normal Normal { vector [
          0.995171 -6.08102e-6 9.81541e-2,
          0.923880 -4.09802e-6 0.382683,
          0.707107 -9.38186e-7 0.707107]
		}

	Return the coordinate list
	text_buffer contains the first line of this node :
       "coord Coordinate { point ["
 *      coord Coordinate { point [
 *        -5.24489 6.57640e-3 -9.42129e-2,
 *        -5.11821 6.57421e-3 0.542654,
 *        -3.45868 0.256565 1.32000 ] }
 *  or:
 *  normal Normal { vector [
 *        0.995171 -6.08102e-6 9.81541e-2,
 *        0.923880 -4.09802e-6 0.382683,
 *        0.707107 -9.38186e-7 0.707107]
 *      }
 * 
 *  Return the coordinate list
 *  text_buffer contains the first line of this node :
 *     "coord Coordinate { point ["
 */
{
    double*      data_list = NULL;
@@ -325,7 +340,8 @@ char string_num[512];
            case ' ':
            case ',':
                jj = 0;
					if ( ! StartData || !HasData) break;
                if( !StartData || !HasData )
                    break;
                data_list[ii]  = atof( string_num );
                string_num[jj] = 0;
                ii++;
@@ -343,23 +359,28 @@ char string_num[512];
                break;

            default:
					if ( ! StartData ) break;
					if ( jj >= sizeof(string_num) ) break;
                if( !StartData )
                    break;
                if( jj >= sizeof(string_num) )
                    break;
                string_num[jj] = *text;
                jj++; string_num[jj] = 0;
                HasData = TRUE;
                break;
            }

            text++;
        }
    }

    if( data_list )
        data_list = (double*) realloc( data_list, ( ii * sizeof(double) ) );
	if ( bufsize ) *bufsize = ii;
    if( bufsize )
        *bufsize = ii;
    return data_list;
}


/***********************************************************/
int Struct3D_Master::ReadGeometry( FILE* file, int* LineNum )
/***********************************************************/
@@ -418,11 +439,15 @@ int * index = NULL;
                text = strtok( line, " ,\t\n\r" );
                while( text )
                {
					if ( *text == ']') break;
                    if( *text == ']' )
                        break;
                    text = strtok( NULL, " ,\t\n\r" );
                }
				if ( text && (*text == ']') ) break;

                if( text && (*text == ']') )
                    break;
            }

            continue;
        }

@@ -441,11 +466,15 @@ int * index = NULL;
                text = strtok( line, " ,\t\n\r" );
                while( text )
                {
					if ( *text == ']') break;
                    if( *text == ']' )
                        break;
                    text = strtok( NULL, " ,\t\n\r" );
                }
				if ( text && (*text == ']') ) break;

                if( text && (*text == ']') )
                    break;
            }

            continue;
        }

@@ -465,7 +494,8 @@ int * index = NULL;
                text = strtok( line, " ,\t\n\r" );
                while( text )
                {
					if ( *text == ']') break;
                    if( *text == ']' )
                        break;
                    jj = atoi( text );
                    if( jj < 0 )
                    {
@@ -478,6 +508,7 @@ int * index = NULL;
                            curr_coord->z = points[kk + 2];
                            curr_coord++;
                        }

                        Set_Object_Coords( coords, coord_count );
                        Set_Object_Data( coords, coord_count );
                        coord_count = 0;
@@ -488,8 +519,11 @@ int * index = NULL;
                    }
                    text = strtok( NULL, " ,\t\n\r" );
                }
			if ( text && (*text == ']') ) break;

                if( text && (*text == ']') )
                    break;
            }

            free( index );
            free( coords );
        }
@@ -499,13 +533,14 @@ int * index = NULL;
            break;
        }
    }
	if ( points ) free (points);

    if( points )
        free( points );

    return err;
}



/*********************************************************/
int Struct3D_Shape:: ReadData( FILE* file, int* LineNum )
/*********************************************************/
@@ -518,4 +553,3 @@ char line[512];

    return -1;
}