// Mesh2String.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #include #include #include #include #include using namespace std; #define DLLEXPORT extern "C" __declspec(dllexport) #define UCLASS() #define GENERATED_BODY() #define UFUNCTION() DLLEXPORT void vertex2string1(int precision, int c_precision, float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin, A, R, G, B; float f; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Do first value. f = verts[j]; // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. // This loop finishes sooner when there are more digits. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = verts[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = verts[j + 2]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. str[i++] = ' '; // Get 32-bit color to convert. a = colors[j / 3]; // Convert to normalize R,G,B. // Shift off possible A. A = a >> 24; a -= (A << 24); R = a >> 16; a -= (R << 16); G = a >> 8; B = a - (G << 8); // Do first value. a = R; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do second value. // Put space after R. str[i++] = ' '; a = G; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do third value. // Put space after G. str[i++] = ' '; a = B; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Write vertex lines to file. size_of_line = i - i_begin; } DLLEXPORT void vertex2string2(int precision, int c_precision, float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin, A, R, G, B; float f; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Do first value. f = verts[j]; // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. // This loop finishes sooner when there are more digits. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = verts[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = verts[j + 2]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. str[i++] = ' '; // Get 32-bit color to convert. a = colors[j / 3]; // Convert to normalize R,G,B. // Shift off possible A. A = a >> 24; a -= (A << 24); R = a >> 16; a -= (R << 16); G = a >> 8; B = a - (G << 8); // Do first value. a = R; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do second value. // Put space after R. str[i++] = ' '; a = G; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do third value. // Put space after G. str[i++] = ' '; a = B; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Write vertex lines to file. size_of_line = i - i_begin; } DLLEXPORT void vertex2string3(int precision, int c_precision, float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin, A, R, G, B; float f; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Do first value. f = verts[j]; // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. // This loop finishes sooner when there are more digits. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = verts[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = verts[j + 2]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. str[i++] = ' '; // Get 32-bit color to convert. a = colors[j / 3]; // Convert to normalize R,G,B. // Shift off possible A. A = a >> 24; a -= (A << 24); R = a >> 16; a -= (R << 16); G = a >> 8; B = a - (G << 8); // Do first value. a = R; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do second value. // Put space after R. str[i++] = ' '; a = G; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do third value. // Put space after G. str[i++] = ' '; a = B; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Write vertex lines to file. size_of_line = i - i_begin; } DLLEXPORT void vertex2string4(int precision, int c_precision, float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin, A, R, G, B; float f; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Do first value. f = verts[j]; // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. // This loop finishes sooner when there are more digits. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = verts[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = verts[j + 2]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k - 1; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. str[i++] = ' '; // Get 32-bit color to convert. a = colors[j / 3]; // Convert to normalize R,G,B. // Shift off possible A. A = a >> 24; a -= (A << 24); R = a >> 16; a -= (R << 16); G = a >> 8; B = a - (G << 8); // Do first value. a = R; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do second value. // Put space after R. str[i++] = ' '; a = G; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Do third value. // Put space after G. str[i++] = ' '; a = B; k = c_precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Write vertex lines to file. size_of_line = i - i_begin; } DLLEXPORT void textures2string1(int precision, float *tcs, int num_tcs, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Do first value. f = tcs[j]; str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for texture coordinates which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = tcs[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write texture lines to file. size_of_line = i - i_begin; } DLLEXPORT void textures2string2(int precision, float *tcs, int num_tcs, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Do first value. f = tcs[j]; str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for texture coordinates which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = tcs[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write texture lines to file. size_of_line = i - i_begin; } DLLEXPORT void textures2string3(int precision, float *tcs, int num_tcs, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Do first value. f = tcs[j]; str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for texture coordinates which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = tcs[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write texture lines to file. size_of_line = i - i_begin; } DLLEXPORT void textures2string4(int precision, float *tcs, int num_tcs, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Do first value. f = tcs[j]; str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for texture coordinates which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = tcs[j + 1]; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write texture lines to file. size_of_line = i - i_begin; } DLLEXPORT void normals2string1(int precision, float *normals, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // // Process normals. // i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Save starting value of i. // Do first value. f = normals[j]; str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = normals[j + 1]; // Put in space str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = normals[j + 2]; // Put in space. str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write normal lines to file. size_of_line = i - i_begin; } DLLEXPORT void normals2string2(int precision, float *normals, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // // Process normals. // i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Save starting value of i. // Do first value. f = normals[j]; str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = normals[j + 1]; // Put in space str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = normals[j + 2]; // Put in space. str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write normal lines to file. size_of_line = i - i_begin; } DLLEXPORT void normals2string3(int precision, float *normals, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // // Process normals. // i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Save starting value of i. // Do first value. f = normals[j]; str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = normals[j + 1]; // Put in space str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = normals[j + 2]; // Put in space. str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write normal lines to file. size_of_line = i - i_begin; } DLLEXPORT void normals2string4(int precision, float *normals, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, i, j, i_begin; float f; // // Process normals. // i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Save starting value of i. // Do first value. f = normals[j]; str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do second value. f = normals[j + 1]; // Put in space str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Do third value. f = normals[j + 2]; // Put in space. str[i++] = ' '; // check for negative float if (f < 0.0) { str[i++] = '-'; f *= -1; } // Extract the whole number. a = f; // Extract the decimal part. f -= a; // Get the number of digits in the whole number = k. // This loop finishes sooner when there are fewer digits in front of the decimal point. // So it is a good choice for normals which have no leading digits. for (k = 0; k < precision + 2; k++) { l = pow10[k]; m = a / l; if (m == 0) { break; } } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Add decimal point. str[i++] = '.'; // Extract decimal digits till precision met. for (l = 0; l < precision - k; l++) { f *= 10.0; b = f; str[i++] = b + 48; f -= b; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write normal lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string1(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string2(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string3(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string4(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string5(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string6(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string7(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void faces2string8(int precision, int *faces, int num_faces, bool no_quads, int num_tcs, int num_normals, char *str, long &size_of_line) { static int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // Used to convert to string. int a, b, c, k, l, m, n, i, i_begin, j, jmax; // Used when processing faces. int i3, i4, i_start, i_end; // Setup flags that control generation of texture coordinants and vertex normals. bool do_one = false, do_two = false; if (num_tcs or num_normals) { do_one = true; } if (num_tcs and num_normals) { do_two = true; } jmax = 4; if (no_quads) { jmax = 3; } // // Process faces. 8 precision supports 999,999,999 vertices or 2G faces. // // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += jmax) { //Do first index. Increment index by 1 since .obj file is 1 based not 0. a = faces[j] + 1; str[i++] = 'f'; str[i++] = ' '; // Save i for making copies of a. i_start = i; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do second index. Increment index by 1 since .obj file is 1 based not 0. // a = faces[j + 1] + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // Add space. str[i++] = ' '; // Save i. i_start = i; // // Do third index. Increment index by 1 since .obj file is 1 based not 0. // i3 = faces[j + 2]; a = i3 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } // // Do fourth index if quads are present and i4 is different from i3. // if (not no_quads) { i4 = faces[j + 3]; if (i4 != i3) { // Add space. str[i++] = ' '; // Save i. i_start = i; // Add one to index since .obj file is one based. a = i4 + 1; // check for negative int if (a < 0) { str[i++] = '-'; a *= -1; } k = precision; // Get the number of digits in the whole number = k+1. while (k > -1) { l = pow10[k]; m = a / l; if (m > 0) { break; } k--; } // Extract most significant digit and concatenate to string obtained as // quotient by dividing number by 10^k where k = (number of digit - 1) for (l = k + 1; l > 0; l--) { b = pow10[l - 1]; c = a / b; str[i++] = c + 48; a %= b; } // Capture end of a. i_end = i; // Add more info if texture or normals are present. if (do_one) { // Add separator for texture. str[i++] = '/'; // Copy 2nd a to make: f i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } if (do_two) { // Add separator for normal. str[i++] = '/'; // Copy third a to make: f i1/i1/i1 for (n = i_start; n < i_end; n++) { str[i++] = str[n]; } } } } } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Write faces lines to file. size_of_line = i - i_begin; } DLLEXPORT void verts2file(wchar_t *file_name, char *str, int num) { // Set size_of_line as streampos type so multi-line output can be supported. streampos size_of_line = 0; // Open file for binary writing at end of exising file (to preserve header written in Python script). ofstream out_file(file_name, ios::binary | ios::out | ios::app); if (out_file.is_open()) { // Write data to file. size_of_line = num; out_file.write(str, size_of_line); } // Close file. out_file.close(); } DLLEXPORT void texts2file(wchar_t *file_name, char *str, int num) { // Set size_of_line as streampos type so multi-line output can be supported. streampos size_of_line = 0; // Open file for binary writing at end of exising file (to preserve header written in Python script). ofstream out_file(file_name, ios::binary | ios::out | ios::app); if (out_file.is_open()) { // Write data to file. size_of_line = num; out_file.write(str, size_of_line); } // Close file. out_file.close(); } DLLEXPORT void norms2file(wchar_t *file_name, char *str, int num) { // Set size_of_line as streampos type so multi-line output can be supported. streampos size_of_line = 0; // Open file for binary writing at end of exising file (to preserve header written in Python script). ofstream out_file(file_name, ios::binary | ios::out | ios::app); if (out_file.is_open()) { // Write data to file. size_of_line = num; out_file.write(str, size_of_line); } // Close file. out_file.close(); } DLLEXPORT void faces2file(wchar_t *file_name, char *str, int num) { // Set size_of_line as streampos type so multi-line output can be supported. streampos size_of_line = 0; // Open file for binary writing at end of exising file (to preserve header written in Python script). ofstream out_file(file_name, ios::binary | ios::out | ios::app); if (out_file.is_open()) { // Write data to file. size_of_line = num; out_file.write(str, size_of_line); } // Close file. out_file.close(); } DLLEXPORT void data2file(wchar_t *file_name, char *str1, int num1, char *str2, int num2, char *str3, int num3, char *str4, int num4, char *str5, int num5, char *str6, int num6, char *str7, int num7, char *str8, int num8, char *str9, int num9, char *str10, int num10, char *str11, int num11, char *str12, int num12, char *str13, int num13, char *str14, int num14, char *str15, int num15, char *str16, int num16, char *str17, int num17) { // Set size_of_line as streampos type so multi-line output can be supported. // Open file for binary writing at end of exising file (to preserve header written in Python script). ofstream out_file(file_name, ios::binary | ios::out | ios::app); if (out_file.is_open()) { // Write data to file. out_file.write(str1, num1); out_file.write(str2, num2); out_file.write(str3, num3); out_file.write(str4, num4); out_file.write(str5, num5); out_file.write(str6, num6); out_file.write(str7, num7); out_file.write(str8, num8); out_file.write(str9, num9); out_file.write(str10, num10); out_file.write(str11, num11); out_file.write(str12, num12); out_file.write(str13, num13); out_file.write(str14, num14); out_file.write(str15, num15); out_file.write(str16, num16); out_file.write(str17, num17); } // Close file. out_file.close(); } DLLEXPORT void vertex2binary1(float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { int i, i_begin, j; // Define unions for accessing float or int as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; union { unsigned int integer; unsigned char byte[4]; } i2b; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // Do first value. f2b.finput = verts[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = verts[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = verts[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. // Get 32-bit color to convert. i2b.integer = colors[j / 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void vertex2binary2(float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { int i, i_begin, j; // Define unions for accessing float or int as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; union { unsigned int integer; unsigned char byte[4]; } i2b; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // Do first value. f2b.finput = verts[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = verts[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = verts[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. // Get 32-bit color to convert. i2b.integer = colors[j / 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void vertex2binary3(float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { int i, i_begin, j; // Define unions for accessing float or int as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; union { unsigned int integer; unsigned char byte[4]; } i2b; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // Do first value. f2b.finput = verts[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = verts[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = verts[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. // Get 32-bit color to convert. i2b.integer = colors[j / 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void vertex2binary4(float *verts, int *colors, int num_verts, int num_colors, char *str, long &size_of_line) { int i, i_begin, j; // Define unions for accessing float or int as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; union { unsigned int integer; unsigned char byte[4]; } i2b; // Process vertices. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_verts; j += 3) { // Start vertex line with 'v '. str[i++] = 'v'; str[i++] = ' '; // Do first value. f2b.finput = verts[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = verts[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = verts[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add vertex color if present. if (num_colors) { // Put space after Z of vertex. // Get 32-bit color to convert. i2b.integer = colors[j / 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Add CR LF to terminate line with vertex and colors. str[i++] = '\r'; str[i++] = '\n'; } else { // Add CR LF when no color. str[i++] = '\r'; str[i++] = '\n'; } } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void textures2binary1(float *tcs, int num_tcs, char *str, long &size_of_line) { // Used to convert to string. int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process textures. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Start textures line with 'vt '. str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // Do first value. f2b.finput = tcs[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = tcs[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void textures2binary2(float *tcs, int num_tcs, char *str, long &size_of_line) { // Used to convert to string. int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process textures. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Start textures line with 'vt '. str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // Do first value. f2b.finput = tcs[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = tcs[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void textures2binary3(float *tcs, int num_tcs, char *str, long &size_of_line) { // Used to convert to string. int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process textures. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Start textures line with 'vt '. str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // Do first value. f2b.finput = tcs[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = tcs[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void textures2binary4(float *tcs, int num_tcs, char *str, long &size_of_line) { // Used to convert to string. int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process textures. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_tcs; j += 2) { // Start textures line with 'vt '. str[i++] = 'v'; str[i++] = 't'; str[i++] = ' '; // Do first value. f2b.finput = tcs[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = tcs[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void normals2binary1(float *normals, int num_normals, char *str, long &size_of_line) { int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process normals. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Start normals line with 'vn '. str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // Do first value. f2b.finput = normals[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = normals[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = normals[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void normals2binary2(float *normals, int num_normals, char *str, long &size_of_line) { int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process normals. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Start normals line with 'vn '. str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // Do first value. f2b.finput = normals[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = normals[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = normals[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void normals2binary3(float *normals, int num_normals, char *str, long &size_of_line) { int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process normals. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Start normals line with 'vn '. str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // Do first value. f2b.finput = normals[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = normals[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = normals[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void normals2binary4(float *normals, int num_normals, char *str, long &size_of_line) { int i, i_begin, j; // Define union for accessing float as 4 bytes. union { float finput; unsigned char byte[4]; } f2b; // Process normals. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_normals; j += 3) { // Start normals line with 'vn '. str[i++] = 'v'; str[i++] = 'n'; str[i++] = ' '; // Do first value. f2b.finput = normals[j]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do second value. f2b.finput = normals[j + 1]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Do third value. f2b.finput = normals[j + 2]; str[i++] = f2b.byte[3]; str[i++] = f2b.byte[2]; str[i++] = f2b.byte[1]; str[i++] = f2b.byte[0]; // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary1(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary2(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary3(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary4(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary5(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary6(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary7(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; } DLLEXPORT void faces2binary8(int *faces, int num_faces, char *str, bool no_quads, long &size_of_line) { int i, i_begin, j; // Define union for accessing int as 4 bytes. union { unsigned int integer; unsigned char byte[4]; } i2b; // Process faces. // Save starting value of i. i = 0; i_begin = i; for (j = 0; j < num_faces; j += 3) { // Start face line with 'f '. str[i++] = 'f'; str[i++] = ' '; // Do first value. i2b.integer = faces[j]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do second value. i2b.integer = faces[j + 1]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do third value. i2b.integer = faces[j + 2]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; // Do 4th value if quads are present. if (not no_quads) { i2b.integer = faces[j + 3]; str[i++] = i2b.byte[3]; str[i++] = i2b.byte[2]; str[i++] = i2b.byte[1]; str[i++] = i2b.byte[0]; } // Add CR LF. str[i++] = '\r'; str[i++] = '\n'; } // Return total length of line. size_of_line = i - i_begin; }