|
From: <hsu...@us...> - 2008-12-29 20:55:23
|
Revision: 8642
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=8642&view=rev
Author: hsujohnhsu
Date: 2008-12-29 20:55:18 +0000 (Mon, 29 Dec 2008)
Log Message:
-----------
move ivcon to it's own separate package in 3rdparty.
Modified Paths:
--------------
pkg/trunk/robot_descriptions/wg_robot_description/CMakeLists.txt
pkg/trunk/robot_descriptions/wg_robot_description/manifest.xml
Added Paths:
-----------
pkg/trunk/3rdparty/ivcon/
pkg/trunk/3rdparty/ivcon/CMakeLists.txt
pkg/trunk/3rdparty/ivcon/Makefile
pkg/trunk/3rdparty/ivcon/manifest.xml
pkg/trunk/3rdparty/ivcon/src/
pkg/trunk/3rdparty/ivcon/src/ivcon.c
Removed Paths:
-------------
pkg/trunk/robot_descriptions/wg_robot_description/src/ivcon.c
Added: pkg/trunk/3rdparty/ivcon/CMakeLists.txt
===================================================================
--- pkg/trunk/3rdparty/ivcon/CMakeLists.txt (rev 0)
+++ pkg/trunk/3rdparty/ivcon/CMakeLists.txt 2008-12-29 20:55:18 UTC (rev 8642)
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.6)
+include(rosbuild)
+rospack(ivcon)
+
+#uncomment for profiling
+set(ROS_LINK_FLAGS "-lm" ${ROS_LINK_FLAGS})
+
+rospack_add_executable(bin/ivcon src/ivcon.c)
+
Added: pkg/trunk/3rdparty/ivcon/Makefile
===================================================================
--- pkg/trunk/3rdparty/ivcon/Makefile (rev 0)
+++ pkg/trunk/3rdparty/ivcon/Makefile 2008-12-29 20:55:18 UTC (rev 8642)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
Added: pkg/trunk/3rdparty/ivcon/manifest.xml
===================================================================
--- pkg/trunk/3rdparty/ivcon/manifest.xml (rev 0)
+++ pkg/trunk/3rdparty/ivcon/manifest.xml 2008-12-29 20:55:18 UTC (rev 8642)
@@ -0,0 +1,14 @@
+<package>
+<description brief="Mesh Conversion Utility">
+
+Mesh Conversion Utility
+
+</description>
+<author>John Burkardt</author>
+<license>GPL</license>
+<review status="3rdparty" notes=""/>
+<url>https://sourceforge.net/projects/ivcon/</url>
+<export>
+ <cpp lflags="" cflags=""/>
+</export>
+</package>
Copied: pkg/trunk/3rdparty/ivcon/src/ivcon.c (from rev 8634, pkg/trunk/robot_descriptions/wg_robot_description/src/ivcon.c)
===================================================================
--- pkg/trunk/3rdparty/ivcon/src/ivcon.c (rev 0)
+++ pkg/trunk/3rdparty/ivcon/src/ivcon.c 2008-12-29 20:55:18 UTC (rev 8642)
@@ -0,0 +1,16707 @@
+/* ivcon.c 24 May 2001 */
+
+/*
+ Purpose:
+
+ IVCON converts various 3D graphics files.
+
+ Acknowledgements:
+
+ Coding, comments, and advice were supplied by a number of collaborators.
+
+ John F Flanagan made some corrections to the 3D Studio Max routines.
+
+ Zik Saleeba (zi...@zi...) enhanced the DXF routines, and added the
+ Golgotha GMOD routines.
+
+ Thanks to Susan M. Fisher, University of North Carolina,
+ Department of Computer Science, for pointing out a coding error
+ in FACE_NULL_DELETE that was overwriting all the data!
+
+ Modified:
+
+ 04 July 2000
+
+ Author:
+
+ John Burkardt
+*/
+
+#include <ctype.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define FALSE 0
+#define TRUE 1
+
+#define ERROR 1
+#define G1_SECTION_MODEL_QUADS 18
+#define G1_SECTION_MODEL_TEXTURE_NAMES 19
+#define G1_SECTION_MODEL_VERT_ANIMATION 20
+#define GMOD_MAX_SECTIONS 32
+#define GMOD_UNUSED_VERTEX 65535
+#define PI 3.141592653589793238462643
+#define SUCCESS 0
+
+#define DEG_TO_RAD ( PI / 180.0 )
+#define RAD_TO_DEG ( 180.0 / PI )
+
+/******************************************************************************/
+
+/* GLOBAL DATA */
+
+/******************************************************************************/
+
+/*
+ BACKGROUND_RGB[3], the background color.
+
+ BYTE_SWAP, byte swapping option.
+
+ COR3[3][COR3_MAX], the coordinates of nodes.
+
+ COR3_MATERIAL[COR3_MAX], the index of the material of each node.
+
+ COR3_MAX, the maximum number of points.
+
+ COR3_NORMAL[3][COR3_MAX], normal vectors associated with nodes.
+
+ COR3_NUM, the number of points.
+
+ COR3_RGB[3][COR3_MAX], RGB colors associated with nodes.
+
+ COR3_TEX_UV[2][COR3_MAX], texture coordinates associated with nodes.
+
+ FACE[ORDER_MAX][FACE_MAX] contains the index of the I-th node making up face J.
+
+ FACE_AREA(FACE_MAX), the area of each face.
+
+ FACE_MATERIAL[FACE_MAX]; the material of each face.
+
+ FACE_MAX, the maximum number of faces.
+
+ FACE_NORMAL[3][FACE_MAX], the face normal vectors.
+
+ FACE_NUM, the number of faces.
+
+ FACE_ORDER[FACE_MAX], the number of vertices per face.
+
+ FACE_TEX_UV[2][FACE_MAX], texture coordinates associated with faces.
+
+ LINE_DEX[LINES_MAX], node indices, denoting polylines, each terminated by -1.
+
+ LINE_MATERIAL[LINES_MAX], index into RGBCOLOR for line color.
+
+ LINES_MAX, the maximum number of line definition items.
+
+ LINE_NUM, the number of line definition items.
+
+ LINE_PRUNE, pruning option ( 0 = no pruning, nonzero = pruning).
+
+ MATERIAL_MAX, the maximum number of materials.
+
+ MATERIAL_NUM, the number of materials.
+
+ ORDER_MAX, the maximum number of vertices per face.
+
+ TEXTURE_MAX, the maximum number of textures.
+
+ TEXTURE_NAME[TEXTURE_MAX][LINE_MAX_LEN], ...
+
+ TEXTURE_NUM, the number of textures.
+
+ TRANSFORM_MATRIX[4][4], the current transformation matrix.
+
+ VERTEX_MATERIAL[ORDER_MAX][FACE_MAX]; the material of vertices of faces.
+
+ VERTEX_NORMAL[3][ORDER_MAX][FACE_MAX], normals at vertices of faces.
+
+ VERTEX_RGB[3][ORDER_MAX][FACE_MAX], colors of vertices of faces.
+
+ VERTEX_TEX_UV[2][ORDER_MAX][FACE_MAX], texture coordinates of vertices of faces.
+*/
+
+#define COLOR_MAX 1000
+#define COR3_MAX 200000
+#define FACE_MAX 200000
+#define LINE_MAX_LEN 256
+#define LEVEL_MAX 10
+#define LINES_MAX 100000
+#define MATERIAL_MAX 100
+#define ORDER_MAX 10
+#define TEXTURE_MAX 100
+
+char anim_name[LINE_MAX_LEN];
+float background_rgb[3];
+int bad_num;
+int byte_swap;
+int bytes_num;
+int color_num;
+int comment_num;
+
+float cor3[3][COR3_MAX];
+int cor3_material[COR3_MAX];
+float cor3_normal[3][COR3_MAX];
+int cor3_num;
+float cor3_tex_uv[3][COR3_MAX];
+
+int debug;
+
+int dup_num;
+
+int face[ORDER_MAX][FACE_MAX];
+float face_area[FACE_MAX];
+int face_flags[FACE_MAX];
+int face_material[FACE_MAX];
+float face_normal[3][FACE_MAX];
+int face_num;
+int face_object[FACE_MAX];
+int face_order[FACE_MAX];
+int face_smooth[FACE_MAX];
+float face_tex_uv[2][FACE_MAX];
+
+char filein_name[1024];
+char fileout_name[1024];
+
+int group_num;
+
+int i;
+char input[LINE_MAX_LEN];
+int k;
+char level_name[LEVEL_MAX][LINE_MAX_LEN];
+
+int line_dex[LINES_MAX];
+int line_material[LINES_MAX];
+int line_num;
+int line_prune;
+
+int list[COR3_MAX];
+
+char material_binding[80];
+char material_name[MATERIAL_MAX][LINE_MAX_LEN];
+int material_num;
+float material_rgba[4][MATERIAL_MAX];
+
+char mat_name[81];
+int max_order2;
+
+char normal_binding[80];
+float normal_temp[3][ORDER_MAX*FACE_MAX];
+
+char object_name[81];
+int object_num;
+
+float origin[3];
+float pivot[3];
+float rgbcolor[3][COLOR_MAX];
+char temp_name[81];
+
+int text_num;
+
+char texture_binding[80];
+char texture_name[TEXTURE_MAX][LINE_MAX_LEN];
+int texture_num;
+float texture_temp[2][ORDER_MAX*FACE_MAX];
+
+float transform_matrix[4][4];
+
+int vertex_material[ORDER_MAX][FACE_MAX];
+float vertex_normal[3][ORDER_MAX][FACE_MAX];
+float vertex_rgb[3][ORDER_MAX][FACE_MAX];
+float vertex_tex_uv[2][ORDER_MAX][FACE_MAX];
+
+/******************************************************************************/
+
+/* FUNCTION PROTOTYPES */
+
+/******************************************************************************/
+
+int main ( int argc, char **argv );
+int ase_read ( FILE *filein );
+int ase_write ( FILE *fileout );
+int byu_read ( FILE *filein );
+int byu_write ( FILE *fileout );
+int char_index_last ( char* string, char c );
+int char_pad ( int *char_index, int *null_index, char *string,
+ int STRING_MAX );
+char char_read ( FILE *filein );
+int char_write ( FILE *fileout, char c );
+int command_line ( char **argv );
+void cor3_normal_set ( void );
+void cor3_range ( void );
+void data_check ( void );
+void data_init ( void );
+int data_read ( void );
+void data_report ( void );
+int data_write ( void );
+int dxf_read ( FILE *filein );
+int dxf_write ( FILE *fileout );
+void edge_null_delete ( void );
+void face_area_set ( void );
+void face_normal_ave ( void );
+void face_null_delete ( void );
+int face_print ( int iface );
+void face_reverse_order ( void );
+int face_subset ( void );
+void face_to_line ( void );
+void face_to_vertex_material ( void );
+char *file_ext ( char *file_name );
+float float_read ( FILE *filein );
+float float_reverse_bytes ( float x );
+int float_write ( FILE *fileout, float float_val );
+int gmod_arch_check ( void );
+int gmod_read ( FILE *filein );
+float gmod_read_float ( FILE *filein );
+unsigned short gmod_read_w16 ( FILE *filein );
+unsigned long gmod_read_w32 ( FILE *filein );
+int gmod_write ( FILE *fileout );
+void gmod_write_float ( float Val, FILE *fileout );
+void gmod_write_w16 ( unsigned short Val, FILE *fileout );
+void gmod_write_w32 ( unsigned long Val, FILE *fileout );
+void hello ( void );
+void help ( void );
+int hrc_read ( FILE *filein );
+int hrc_write ( FILE *fileout );
+void init_program_data ( void );
+int interact ( void );
+int iv_read ( FILE *filein );
+int iv_write ( FILE *fileout );
+int ivec_max ( int n, int *a );
+int leqi ( char* string1, char* string2 );
+long int long_int_read ( FILE *filein );
+int long_int_write ( FILE *fileout, long int int_val );
+void news ( void );
+void node_to_vertex_material ( void );
+int obj_read ( FILE *filein );
+int obj_write ( FILE *fileout );
+int pov_write ( FILE *fileout );
+int rcol_find ( float a[][COR3_MAX], int m, int n, float r[] );
+float rgb_to_hue ( float r, float g, float b );
+short int short_int_read ( FILE *filein );
+int short_int_write ( FILE *fileout, short int int_val );
+int smf_read ( FILE *filein );
+int smf_write ( FILE *fileout );
+int stla_read ( FILE *filein );
+int stla_write ( FILE *fileout );
+int stlb_read ( FILE *filein );
+int stlb_write ( FILE *fileout );
+void tds_pre_process ( void );
+int tds_read ( FILE *filein );
+unsigned long int tds_read_ambient_section ( FILE *filein );
+unsigned long int tds_read_background_section ( FILE *filein );
+unsigned long int tds_read_boolean ( unsigned char *boolean, FILE *filein );
+unsigned long int tds_read_camera_section ( FILE *filein );
+unsigned long int tds_read_edit_section ( FILE *filein, int *views_read );
+unsigned long int tds_read_keyframe_section ( FILE *filein, int *views_read );
+unsigned long int tds_read_keyframe_objdes_section ( FILE *filein );
+unsigned long int tds_read_light_section ( FILE *filein );
+unsigned long int tds_read_u_long_int ( FILE *filein );
+int tds_read_long_name ( FILE *filein );
+unsigned long int tds_read_matdef_section ( FILE *filein );
+unsigned long int tds_read_material_section ( FILE *filein );
+int tds_read_name ( FILE *filein );
+unsigned long int tds_read_obj_section ( FILE *filein );
+unsigned long int tds_read_object_section ( FILE *filein );
+unsigned long int tds_read_tex_verts_section ( FILE *filein );
+unsigned long int tds_read_texmap_section ( FILE *filein );
+unsigned short int tds_read_u_short_int ( FILE *filein );
+unsigned long int tds_read_spot_section ( FILE *filein );
+unsigned long int tds_read_unknown_section ( FILE *filein );
+unsigned long int tds_read_view_section ( FILE *filein, int *views_read );
+unsigned long int tds_read_vp_section ( FILE *filein, int *views_read );
+int tds_write ( FILE *fileout );
+int tds_write_string ( FILE *fileout, char *string );
+int tds_write_u_short_int ( FILE *fileout,
+ unsigned short int int_val );
+int tec_write ( FILE *fileout );
+void tmat_init ( float a[4][4] );
+void tmat_mxm ( float a[4][4], float b[4][4], float c[4][4] );
+void tmat_mxp ( float a[4][4], float x[4], float y[4] );
+void tmat_mxp2 ( float a[4][4], float x[][3], float y[][3], int n );
+void tmat_mxv ( float a[4][4], float x[4], float y[4] );
+void tmat_rot_axis ( float a[4][4], float b[4][4], float angle,
+ char axis );
+void tmat_rot_vector ( float a[4][4], float b[4][4], float angle,
+ float v1, float v2, float v3 );
+void tmat_scale ( float a[4][4], float b[4][4], float sx, float sy,
+ float sz );
+void tmat_shear ( float a[4][4], float b[4][4], char *axis,
+ float s );
+void tmat_trans ( float a[4][4], float b[4][4], float x, float y,
+ float z );
+int tria_read ( FILE *filein );
+int tria_write ( FILE *fileout );
+int trib_read ( FILE *filein );
+int trib_write ( FILE *fileout );
+int txt_write ( FILE *fileout );
+int ucd_write ( FILE *fileout );
+void vertex_normal_set ( void );
+void vertex_to_face_material ( void );
+void vertex_to_node_material ( void );
+int vla_read ( FILE *filein );
+int vla_write ( FILE *fileout );
+int wrl_write ( FILE *filout );
+int xgl_write ( FILE *fileout );
+
+/******************************************************************************/
+
+int main ( int argc, char **argv )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ MAIN is the main program for converting graphics files.
+
+ Modified:
+
+ 26 May 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int result;
+/*
+ Initialize the program data.
+*/
+ init_program_data ( );
+/*
+ If there are at least two command line arguments, call COMMAND_LINE.
+ Otherwise call INTERACT and get information from the user.
+*/
+ if ( argc >= 2 ) {
+ result = command_line ( argv );
+ }
+ else {
+ result = interact ( );
+ }
+
+ return result;
+}
+/******************************************************************************/
+
+int ase_read ( FILE *filein )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ ASE_READ reads an AutoCAD ASE file.
+
+ Modified:
+
+ 22 May 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ float bval;
+ int count;
+ float gval;
+ int i;
+ int iface;
+ int ivert;
+ int iword;
+ int level;
+ char *next;
+ int nlbrack;
+ int nrbrack;
+ int cor3_num_old;
+ int face_num_old;
+ float rval;
+ float temp;
+ int width;
+ char word[LINE_MAX_LEN];
+ char word1[LINE_MAX_LEN];
+ char word2[LINE_MAX_LEN];
+ char wordm1[LINE_MAX_LEN];
+ float x;
+ float y;
+ float z;
+
+ level = 0;
+ strcpy ( level_name[0], "Top" );
+ cor3_num_old = cor3_num;
+ face_num_old = face_num;
+ nlbrack = 0;
+ nrbrack = 0;
+
+ strcpy ( word, " " );
+ strcpy ( wordm1, " " );
+/*
+ Read a line of text from the file.
+*/
+
+ for ( ;; ) {
+
+ if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
+ break;
+ }
+
+ text_num = text_num + 1;
+ next = input;
+ iword = 0;
+/*
+ Read the next word from the line.
+*/
+ for ( ;; ) {
+
+ strcpy ( wordm1, word );
+ strcpy ( word, " " );
+
+ count = sscanf ( next, "%s%n", word, &width );
+ next = next + width;
+
+ if ( count <= 0 ) {
+ break;
+ }
+
+ iword = iword + 1;
+
+ if ( iword == 1 ) {
+ strcpy ( word1, word );
+ }
+/*
+ In case the new word is a bracket, update the bracket count.
+*/
+ if ( strcmp ( word, "{" ) == 0 ) {
+
+ nlbrack = nlbrack + 1;
+ level = nlbrack - nrbrack;
+ strcpy ( level_name[level], wordm1 );
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+
+ nrbrack = nrbrack + 1;
+
+ if ( nlbrack < nrbrack ) {
+
+ printf ( "\n" );
+ printf ( "ASE_READ - Fatal error!\n" );
+ printf ( " Extraneous right bracket on line %d\n", text_num );
+ printf ( " Currently processing field:\n" );
+ printf ( "%s\n", level_name[level] );
+ return ERROR;
+ }
+
+ }
+/*
+ *3DSMAX_ASCIIEXPORT 200
+*/
+ if ( strcmp ( word1, "*3DSMAX_ASCIIEXPORT" ) == 0 ) {
+ break;
+ }
+/*
+ *COMMENT
+*/
+ else if ( strcmp ( word1, "*COMMENT" ) == 0 ) {
+ break;
+ }
+/*
+ *GEOMOBJECT
+*/
+ else if ( strcmp ( level_name[level], "*GEOMOBJECT" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+/*
+ Why don't you read and save this name?
+*/
+ else if ( strcmp ( word, "*NODE_NAME" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*NODE_TM" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*PROP_CASTSHADOW" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*PROP_MOTIONBLUR" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*PROP_RECVSHADOW" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in GEOMOBJECT, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH
+*/
+ else if ( strcmp ( level_name[level], "*MESH" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_CFACELIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_CVERTLIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_FACE_LIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_NORMALS" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_NUMCVERTEX" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_NUMCVFACES" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_NUMFACES" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_NUMTVERTEX" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_NUMTVFACES" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_NUMVERTEX" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*MESH_TFACELIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_TVERTLIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_VERTEX_LIST" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "*TIMEVALUE" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_CFACELIST
+*/
+ else if ( strcmp ( level_name[level], "*MESH_CFACELIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_CFACE" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_CFACE, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_CVERTLIST
+
+ Mesh vertex indices must be incremented by COR3_NUM_OLD before being stored
+ in the internal array.
+*/
+ else if ( strcmp ( level_name[level], "*MESH_CVERTLIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_VERTCOL" ) == 0 ) {
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+
+ i = i + cor3_num_old;
+
+ count = sscanf ( next, "%f%n", &rval, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &gval, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &bval, &width );
+ next = next + width;
+
+ if ( material_num < MATERIAL_MAX ) {
+ material_rgba[0][material_num] = rval;
+ material_rgba[1][material_num] = gval;
+ material_rgba[2][material_num] = bval;
+ material_rgba[3][material_num] = 1.0;
+ }
+
+ material_num = material_num + 1;
+ cor3_material[i] = material_num;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "\n" );
+ printf ( "ASE_READ - Warning!\n" );
+ printf ( " Bad data in MESH_CVERTLIST, line %d\n", text_num );
+ break;
+ }
+
+ }
+/*
+ *MESH_FACE_LIST
+ This coding assumes a face is always triangular or quadrilateral.
+*/
+ else if ( strcmp ( level_name[level], "*MESH_FACE_LIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_FACE" ) == 0 ) {
+
+ if ( face_num < FACE_MAX ) {
+
+ face_material[face_num] = 0;
+ face_order[face_num] = 0;
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%s%n", word2, &width );
+ next = next + width;
+ count = sscanf ( next, "%s%n", word2, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+ face[0][face_num] = i + cor3_num_old;
+ face_order[face_num] = face_order[face_num] + 1;
+
+ count = sscanf ( next, "%s%n", word2, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+ face[1][face_num] = i + cor3_num_old;
+ face_order[face_num] = face_order[face_num] + 1;
+
+ count = sscanf ( next, "%s%n", word2, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+ face[2][face_num] = i + cor3_num_old;
+ face_order[face_num] = face_order[face_num] + 1;
+
+ count = sscanf ( next, "%s%n", word2, &width );
+ next = next + width;
+
+ if ( strcmp ( word2, "D:" ) == 0 ) {
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+ face[3][face_num] = i + cor3_num_old;
+ face_order[face_num] = face_order[face_num] + 1;
+ }
+ }
+
+ face_num = face_num + 1;
+
+ break;
+
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_FACE_LIST, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_NORMALS
+*/
+ else if ( strcmp ( level_name[level], "*MESH_NORMALS" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*MESH_FACENORMAL" ) == 0 ) {
+
+ count = sscanf ( next, "%d%n", &iface, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &x, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &y, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &z, &width );
+ next = next + width;
+
+ iface = iface + face_num_old;
+ ivert = 0;
+
+ face_normal[0][iface] = x;
+ face_normal[1][iface] = y;
+ face_normal[2][iface] = z;
+
+ break;
+
+ }
+ else if ( strcmp ( word, "*MESH_VERTEXNORMAL" ) == 0 ) {
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &x, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &y, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &z, &width );
+ next = next + width;
+
+ vertex_normal[0][ivert][iface] = x;
+ vertex_normal[1][ivert][iface] = y;
+ vertex_normal[2][ivert][iface] = z;
+ ivert = ivert + 1;
+
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_NORMALS, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_TFACELIST
+*/
+ else if ( strcmp ( level_name[level], "*MESH_TFACELIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word1, "*MESH_TFACE" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_TFACE_LIST, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_TVERTLIST
+*/
+ else if ( strcmp ( level_name[level], "*MESH_TVERTLIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word1, "*MESH_TVERT" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_TVERTLIST, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *MESH_VERTEX_LIST
+*/
+ else if ( strcmp ( level_name[level], "*MESH_VERTEX_LIST" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ cor3_num_old = cor3_num;
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word1, "*MESH_VERTEX" ) == 0 ) {
+
+ count = sscanf ( next, "%d%n", &i, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &x, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &y, &width );
+ next = next + width;
+
+ count = sscanf ( next, "%f%n", &z, &width );
+ next = next + width;
+
+ i = i + cor3_num_old;
+ if ( cor3_num < i + 1 ) {
+ cor3_num = i + 1;
+ }
+
+ if ( i < COR3_MAX ) {
+
+ cor3[0][i] =
+ transform_matrix[0][0] * x
+ + transform_matrix[0][1] * y
+ + transform_matrix[0][2] * z
+ + transform_matrix[0][3];
+
+ cor3[1][i] =
+ transform_matrix[1][0] * x
+ + transform_matrix[1][1] * y
+ + transform_matrix[1][2] * z
+ + transform_matrix[1][3];
+
+ cor3[2][i] =
+ transform_matrix[2][0] * x
+ + transform_matrix[2][1] * y
+ + transform_matrix[2][2] * z
+ + transform_matrix[2][3];
+ }
+
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in MESH_VERTEX_LIST, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *NODE_TM
+
+ Each node should start out with a default transformation matrix.
+*/
+ else if ( strcmp ( level_name[level], "*NODE_TM" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+
+ tmat_init ( transform_matrix );
+
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*INHERIT_POS" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*INHERIT_ROT" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*INHERIT_SCL" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*NODE_NAME" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_POS" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROTANGLE" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROTAXIS" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROW0" ) == 0 ) {
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[0][0] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[1][0] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[2][0] = temp;
+
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROW1" ) == 0 ) {
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[0][1] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[1][1] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[2][1] = temp;
+
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROW2" ) == 0 ) {
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[0][2] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[1][2] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[2][2] = temp;
+
+ break;
+ }
+ else if ( strcmp ( word, "*TM_ROW3" ) == 0 ) {
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[0][3] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[1][3] = temp;
+
+ count = sscanf ( next, "%f%n", &temp, &width );
+ next = next + width;
+ transform_matrix[2][3] = temp;
+
+ break;
+ }
+ else if ( strcmp ( word, "*TM_SCALE" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_SCALEAXIS" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*TM_SCALEAXISANG" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in NODE_TM, line %d\n", text_num );
+ break;
+ }
+ }
+/*
+ *SCENE
+*/
+ else if ( strcmp ( level_name[level], "*SCENE" ) == 0 ) {
+
+ if ( strcmp ( word, "{" ) == 0 ) {
+ continue;
+ }
+ else if ( strcmp ( word, "}" ) == 0 ) {
+ level = nlbrack - nrbrack;
+ continue;
+ }
+ else if ( strcmp ( word, "*SCENE_AMBIENT_STATIC" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_BACKGROUND_STATIC" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_FILENAME" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_FIRSTFRAME" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_FRAMESPEED" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_LASTFRAME" ) == 0 ) {
+ break;
+ }
+ else if ( strcmp ( word, "*SCENE_TICKSPERFRAME" ) == 0 ) {
+ break;
+ }
+ else {
+ bad_num = bad_num + 1;
+ printf ( "Bad data in SCENE, line %d\n", text_num );
+ break;
+ }
+
+ }
+
+ }
+/*
+ End of loop reading words from the line.
+*/
+ }
+/*
+ End of loop reading lines from input file.
+*/
+
+ return SUCCESS;
+}
+/******************************************************************************/
+
+int ase_write ( FILE *fileout )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ ASE_WRITE writes graphics information to an AutoCAD ASE file.
+
+ Modified:
+
+ 30 September 1998
+
+ Author:
+
+ John Burkardt
+
+*/
+{
+ int i1;
+ int i2;
+ int i3;
+ int i4;
+ int iface;
+ int ivert;
+ int j;
+ int text_num;
+
+ text_num = 0;
+/*
+ Write the header.
+*/
+ fprintf ( fileout, "*3DSMAX_ASCIIEXPORT 200\n" );
+ fprintf ( fileout, "*COMMENT \"%s, created by IVCON.\"\n", fileout_name );
+ fprintf ( fileout, "*COMMENT \"Original data in %s\"\n", filein_name );
+
+ text_num = text_num + 3;
+/*
+ Write the scene block.
+*/
+ fprintf ( fileout, "*SCENE {\n" );
+ fprintf ( fileout, " *SCENE_FILENAME \"\"\n" );
+ fprintf ( fileout, " *SCENE_FIRSTFRAME 0\n" );
+ fprintf ( fileout, " *SCENE_LASTFRAME 100\n" );
+ fprintf ( fileout, " *SCENE_FRAMESPEED 30\n" );
+ fprintf ( fileout, " *SCENE_TICKSPERFRAME 160\n" );
+ fprintf ( fileout, " *SCENE_BACKGROUND_STATIC 0.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *SCENE_AMBIENT_STATIC 0.0431 0.0431 0.0431\n" );
+ fprintf ( fileout, "}\n" );
+
+ text_num = text_num + 9;
+/*
+ Begin the big geometry block.
+*/
+ fprintf ( fileout, "*GEOMOBJECT {\n" );
+ fprintf ( fileout, " *NODE_NAME \"%s\"\n", object_name );
+
+ text_num = text_num + 2;
+/*
+ Sub block NODE_TM:
+*/
+ fprintf ( fileout, " *NODE_TM {\n" );
+ fprintf ( fileout, " *NODE_NAME \"Object01\"\n" );
+ fprintf ( fileout, " *INHERIT_POS 0 0 0\n" );
+ fprintf ( fileout, " *INHERIT_ROT 0 0 0\n" );
+ fprintf ( fileout, " *INHERIT_SCL 0 0 0\n" );
+ fprintf ( fileout, " *TM_ROW0 1.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_ROW1 0.0000 1.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_ROW2 0.0000 0.0000 1.0000\n" );
+ fprintf ( fileout, " *TM_ROW3 0.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_POS 0.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_ROTAXIS 0.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_ROTANGLE 0.0000\n" );
+ fprintf ( fileout, " *TM_SCALE 1.0000 1.0000 1.0000\n" );
+ fprintf ( fileout, " *TM_SCALEAXIS 0.0000 0.0000 0.0000\n" );
+ fprintf ( fileout, " *TM_SCALEAXISANG 0.0000\n" );
+ fprintf ( fileout, " }\n" );
+
+ text_num = text_num + 16;
+/*
+ Sub block MESH:
+ Items
+*/
+ fprintf ( fileout, " *MESH {\n" );
+ fprintf ( fileout, " *TIMEVALUE 0\n" );
+ fprintf ( fileout, " *MESH_NUMVERTEX %d\n", cor3_num );
+ fprintf ( fileout, " *MESH_NUMFACES %d\n", face_num );
+
+ text_num = text_num + 4;
+/*
+ Sub sub block MESH_VERTEX_LIST
+*/
+ fprintf ( fileout, " *MESH_VERTEX_LIST {\n" );
+ text_num = text_num + 1;
+
+ for ( j = 0; j < cor3_num; j++ ) {
+ fprintf ( fileout, " *MESH_VERTEX %d %f %f %f\n", j, cor3[0][j],
+ cor3[1][j], cor3[2][j] );
+ text_num = text_num + 1;
+ }
+
+ fprintf ( fileout, " }\n" );
+ text_num = text_num + 1;
+/*
+ Sub sub block MESH_FACE_LIST
+ Items MESH_FACE
+*/
+ fprintf ( fileout, " *MESH_FACE_LIST {\n" );
+ text_num = text_num + 1;
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+
+ i1 = face[0][iface];
+ i2 = face[1][iface];
+ i3 = face[2][iface];
+
+ if ( face_order[iface] == 3 ) {
+ fprintf ( fileout, " *MESH_FACE %d: A: %d B: %d C: %d", iface, i1, i2, i3 );
+ fprintf ( fileout, " AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING *MESH_MTLID 1\n" );
+ text_num = text_num + 1;
+ }
+ else if ( face_order[iface] == 4 ) {
+ i4 = face[3][iface];
+ fprintf ( fileout, " *MESH_FACE %d: A: %d B: %d C: %d D: %d", iface, i1, i2, i3, i4 );
+ fprintf ( fileout, " AB: 1 BC: 1 CD: 1 DA: 1 *MESH_SMOOTHING *MESH_MTLID 1\n" );
+ text_num = text_num + 1;
+ }
+ }
+
+ fprintf ( fileout, " }\n" );
+ text_num = text_num + 1;
+/*
+ Item MESH_NUMTVERTEX.
+*/
+ fprintf ( fileout, " *MESH_NUMTVERTEX 0\n" );
+ text_num = text_num + 1;
+/*
+ Item NUMCVERTEX.
+*/
+ fprintf ( fileout, " *MESH_NUMCVERTEX 0\n" );
+ text_num = text_num + 1;
+/*
+ Sub block MESH_NORMALS
+ Items MESH_FACENORMAL, MESH_VERTEXNORMAL (repeated)
+*/
+ fprintf ( fileout, " *MESH_NORMALS {\n" );
+ text_num = text_num + 1;
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+
+ fprintf ( fileout, " *MESH_FACENORMAL %d %f %f %f\n",
+ iface, face_normal[0][iface], face_normal[1][iface], face_normal[2][iface] );
+ text_num = text_num + 1;
+
+ for ( ivert = 0; ivert < face_order[iface]; ivert++ ) {
+ fprintf ( fileout, " *MESH_VERTEXNORMAL %d %f %f %f\n",
+ face[ivert][iface], vertex_normal[0][ivert][iface],
+ vertex_normal[1][ivert][iface], vertex_normal[2][ivert][iface] );
+ text_num = text_num + 1;
+ }
+ }
+
+ fprintf ( fileout, " }\n" );
+ text_num = text_num + 1;
+/*
+ Close the MESH object.
+*/
+ fprintf ( fileout, " }\n" );
+/*
+ A few closing parameters.
+*/
+ fprintf ( fileout, " *PROP_MOTIONBLUR 0\n" );
+ fprintf ( fileout, " *PROP_CASTSHADOW 1\n" );
+ fprintf ( fileout, " *PROP_RECVSHADOW 1\n" );
+/*
+ Close the GEOM object.
+*/
+ fprintf ( fileout, "}\n" );
+
+ text_num = text_num + 5;
+/*
+ Report.
+*/
+ printf ( "\n" );
+ printf ( "ASE_WRITE - Wrote %d text lines;\n", text_num );
+
+ return SUCCESS;
+}
+/**********************************************************************/
+
+int byu_read ( FILE *filein )
+
+/**********************************************************************/
+
+/*
+ Purpose:
+
+ BYU_READ reads graphics data from a Movie.BYU surface geometry file.
+
+ Discussion:
+
+ A Movie.BYU surface geometry file contains 4 groups of data.
+
+ The first group of data is a single line, containing 4 integers,
+ each one left justified in 8 columns. The integers are:
+
+ PART_NUM, VERTEX_NUM, POLY_NUM, EDGE_NUM,
+
+ that is, the number of parts or objects, the number of vertices or nodes,
+ the number of polygons or faces, and the number of edges.
+
+ The second group of data is a single line, containing 2 integers,
+ each one left justified in 8 columnes. The integers are:
+
+ POLY1, POLY2,
+
+ the starting and ending polygon numbers. Presumably, this means
+ that the polygons are labeled POLY1, POLY1+1, ..., POLY2, comprising
+ a total of POLY_NUM polygons.
+
+ The third group is the X, Y and Z coordinates of all the vertices.
+ These may be written using a FORTRAN format of 6E12.5, which
+ crams two sets of (X,Y,Z) data onto each line, with each real value
+ written in an exponential format with 5 places after the decimal.
+ However, it is generally possible to write the XYZ coordinate data
+ for each vertex on a separate line.
+
+ The fourth group defines the polygons in terms of the vertex indices.
+ For each polygon, the vertices that make up the polygon are listed in
+ counterclockwise order. The last vertex listed is given with a negative
+ sign to indicate the end of the list. All the vertices for all the
+ polygons are listed one after the other, using a format that puts
+ up to 10 left-justified integers on a line, with each integer occupying
+ 8 spaces.
+
+ This code will certainly read a BYU file created by BYU_WRITE, but
+ it will not handle more general files. In particular, an object
+ can have several parts, the coordinate data can be grouped so
+ that there are 2 sets of (x,y,z) data per line, and so on.
+
+ Example:
+
+ 1 8 6 24
+ 1 6
+ 0.00000E+00 0.00000E+00 0.00000E+00
+ 1.00000E+00 0.00000E+00 0.00000E+00
+ 1.00000E+00 2.00000E+00 0.00000E+00
+ 0.00000E+00 2.00000E+00 0.00000E+00
+ 0.00000E+00 0.00000E+00 1.00000E+00
+ 1.00000E+00 0.00000E+00 1.00000E+00
+ 1.00000E+00 2.00000E+00 1.00000E+00
+ 0.00000E+00 2.00000E+00 1.00000E+00
+ 4 3 2 -1
+ 5 6 7 -8
+ 1 5 8 -4
+ 4 8 7 -3
+ 3 7 6 -2
+ 2 6 5 -1
+
+ Modified:
+
+ 24 May 2001
+
+ Author:
+
+ John Burkardt
+
+*/
+{
+ int cor3_num_new;
+ int count;
+ int edge_num;
+ int face_num_new;
+ int iface;
+ int ival;
+ int ivert;
+ int j;
+ char *next;
+ int part_num;
+ int poly1;
+ int poly2;
+ int text_num;
+ int width;
+ float x;
+ float y;
+ float z;
+
+ text_num = 0;
+
+ if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
+ return ERROR;
+ }
+ text_num = text_num + 1;
+
+ sscanf ( input, "%d %d %d %d", &part_num, &cor3_num_new, &face_num_new,
+ &edge_num );
+
+ if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
+ return ERROR;
+ }
+ text_num = text_num + 1;
+
+ sscanf ( input, "%d %d", &poly1, &poly2 );
+
+ for ( j = cor3_num; j < cor3_num + cor3_num_new; j++ ) {
+
+ if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
+ return ERROR;
+ }
+ text_num = text_num + 1;
+
+ sscanf ( input, "%f %f %f", &x, &y, &z );
+ cor3[0][j] = x;
+ cor3[1][j] = y;
+ cor3[2][j] = z;
+ }
+
+ for ( iface = face_num; iface < face_num + face_num_new; iface++ ) {
+
+ if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
+ return ERROR;
+ }
+ text_num = text_num + 1;
+
+ next = input;
+ ivert = 0;
+
+ for (;;) {
+
+ count = sscanf ( next, "%d%n", &ival, &width );
+ next = next + width;
+
+ if ( count <= 0 ) {
+ return ERROR;
+ }
+
+ if ( ival > 0 ) {
+ face[ivert][iface] = ival - 1 + cor3_num;
+ }
+ else {
+ face[ivert][iface] = - ival - 1 - cor3_num;
+ break;
+ }
+
+ ivert = ivert + 1;
+
+ }
+ face_order[iface] = ivert + 1;
+ }
+
+ cor3_num = cor3_num + cor3_num_new;
+ face_num = face_num + face_num_new;
+/*
+ Report.
+*/
+ printf ( "\n" );
+ printf ( "BYU_READ - Read %d text lines.\n", text_num );
+
+ return SUCCESS;
+}
+/**********************************************************************/
+
+int byu_write ( FILE *fileout )
+
+/**********************************************************************/
+
+/*
+ Purpose:
+
+ BYU_WRITE writes out the graphics data as a Movie.BYU surface geometry file.
+
+ Discussion:
+
+ A Movie.BYU surface geometry file contains 4 groups of data.
+
+ The first group of data is a single line, containing 4 integers,
+ each one left justified in 8 columns. The integers are:
+
+ PART_NUM, VERTEX_NUM, POLY_NUM, EDGE_NUM,
+
+ that is, the number of parts or objects, the number of vertices or nodes,
+ the number of polygons or faces, and the number of edges.
+
+ The second group of data is a single line, containing 2 integers,
+ each one left justified in 8 columnes. The integers are:
+
+ POLY1, POLY2,
+
+ the starting and ending polygon numbers. Presumably, this means
+ that the polygons are labeled POLY1, POLY1+1, ..., POLY2, comprising
+ a total of POLY_NUM polygons.
+
+ The third group is the X, Y and Z coordinates of all the vertices.
+ These may be written using a FORTRAN format of 6E12.5, which
+ crams two sets of (X,Y,Z) data onto each line, with each real value
+ written in an exponential format with 5 places after the decimal.
+ However, it is generally possible to write the XYZ coordinate data
+ for each vertex on a separate line.
+
+ The fourth group defines the polygons in terms of the vertex indices.
+ For each polygon, the vertices that make up the polygon are listed in
+ counterclockwise order. The last vertex listed is given with a negative
+ sign to indicate the end of the list. All the vertices for all the
+ polygons are listed one after the other, using a format that puts
+ up to 10 left-justified integers on a line, with each integer occupying
+ 8 spaces.
+
+ Example:
+
+ 1 8 6 24
+ 1 6
+ 0.00000E+00 0.00000E+00 0.00000E+00
+ 1.00000E+00 0.00000E+00 0.00000E+00
+ 1.00000E+00 2.00000E+00 0.00000E+00
+ 0.00000E+00 2.00000E+00 0.00000E+00
+ 0.00000E+00 0.00000E+00 1.00000E+00
+ 1.00000E+00 0.00000E+00 1.00000E+00
+ 1.00000E+00 2.00000E+00 1.00000E+00
+ 0.00000E+00 2.00000E+00 1.00000E+00
+ 4 3 2 -1
+ 5 6 7 -8
+ 1 5 8 -4
+ 4 8 7 -3
+ 3 7 6 -2
+ 2 6 5 -1
+
+ Modified:
+
+ 24 May 2001
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int edge_num;
+ int iface;
+ int ivert;
+ int j;
+ int jp;
+ int part_num;
+ int text_num;
+
+ text_num = 0;
+
+ edge_num = 0;
+ for ( iface = 0; iface < face_num; iface++ ) {
+ edge_num = edge_num + face_order[iface];
+ }
+
+ part_num = 1;
+
+ fprintf ( fileout, "%d %d %d %d\n", part_num, cor3_num, face_num, edge_num );
+ text_num = text_num + 1;
+
+ fprintf ( fileout, "1 %d\n", face_num );
+ text_num = text_num + 1;
+
+ for ( j = 0; j < cor3_num; j++ ) {
+ fprintf ( fileout, "%f %f %f\n", cor3[0][j], cor3[1][j], cor3[2][j] );
+ text_num = text_num + 1;
+ }
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+
+ for ( ivert = 0; ivert < face_order[iface]; ivert++ ) {
+
+ jp = face[ivert][iface] + 1;
+ if ( ivert == face_order[iface] - 1 ) {
+ jp = - jp;
+ }
+ fprintf ( fileout, "%d ", jp );
+ }
+ fprintf ( fileout, "\n" );
+ text_num = text_num + 1;
+ }
+/*
+ Report.
+*/
+ printf ( "\n" );
+ printf ( "BYU_WRITE - Wrote %d text lines.\n", text_num );
+
+ return SUCCESS;
+}
+/******************************************************************************/
+
+int char_index_last ( char* string, char c )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ CHAR_INDEX_LAST reports the last occurrence of a character in a string.
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int i;
+ int j;
+ int nchar;
+
+ j = -1;
+
+ nchar = strlen ( string );
+
+ for ( i = 0; i < nchar; i++ ) {
+ if ( string[i] == c ) {
+ j = i;
+ }
+ }
+
+ return j;
+
+}
+/******************************************************************************/
+
+int char_pad ( int *char_index, int *null_index, char *string,
+ int STRING_MAX )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ CHAR_PAD "pads" a character in a string with a blank on either side.
+
+ Modified:
+
+ 16 October 1998
+
+ Author:
+
+ John Burkardt
+
+ Parameters:
+
+ Input/output, int *CHAR_INDEX, the position of the character to be padded.
+ On output, this is increased by 1.
+
+ Input/output, int *NULL_INDEX, the position of the terminating NULL in
+ the string. On output, this is increased by 2.
+
+ Input/output, char STRING[STRING_MAX], the string to be manipulated.
+
+ Input, int STRING_MAX, the maximum number of characters that can be stored
+ in the string.
+
+ Output, int CHAR_PAD, is SUCCESS if the operation worked, and ERROR otherwise.
+*/
+{
+ int i;
+
+ if ( *char_index < 0 ||
+ *char_index >= *null_index ||
+ *char_index > STRING_MAX-1 ) {
+ return ERROR;
+ }
+
+ if ( (*null_index) + 2 > STRING_MAX-1 ) {
+ return ERROR;
+ }
+
+ for ( i = *null_index + 2; i > *char_index + 2; i-- ) {
+ string[i] = string[i-2];
+ }
+ string[*char_index+2] = ' ';
+ string[*char_index+1] = string[*char_index];
+ string[*char_index] = ' ';
+
+ *char_index = *char_index + 1;
+ *null_index = *null_index + 2;
+
+ return SUCCESS;
+}
+/******************************************************************************/
+
+char char_read ( FILE *filein )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ CHAR_READ reads one character from a binary file.
+
+ Modified:
+
+ 24 May 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ char c;
+
+ c = ( char ) fgetc ( filein );
+
+ return c;
+}
+/******************************************************************************/
+
+int char_write ( FILE *fileout, char c )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ CHAR_WRITE writes one character to a binary file.
+
+ Modified:
+
+ 24 May 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ fputc ( c, fileout );
+
+ return 1;
+}
+/******************************************************************************/
+
+int command_line ( char **argv )
+
+/******************************************************************************/
+
+/*
+
+ Purpose:
+
+ COMMAND_LINE carries out a command-line session of file conversion.
+
+ Discussion:
+
+ This routine is invoked when the user command is something like
+
+ ivcon filein_name fileout_name
+
+ or
+
+ ivcon -rn filein_name fileout_name
+
+ where "-rn" signals the "reverse normals" option, or
+
+ ivcon -rf filein_name fileout_name
+
+ where "-rf" signals the "reverse faces" option.
+
+ Modified:
+
+ 28 June 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int i;
+ int iarg;
+ int icor3;
+ int ierror;
+ int iface;
+ int ivert;
+ int reverse_faces;
+ int reverse_normals;
+/*
+ Initialize local data.
+*/
+ iarg = 0;
+ ierror = 0;
+ reverse_faces = FALSE;
+ reverse_normals = FALSE;
+/*
+ Initialize the graphics data.
+*/
+ data_init ( );
+/*
+ Get the -RN option, -RF option, and the input file name.
+*/
+ iarg = iarg + 1;
+ strcpy ( filein_name, argv[iarg] );
+
+ if ( leqi ( filein_name, "-RN" ) == TRUE ) {
+ reverse_normals = TRUE;
+ printf ( "\n" );
+ printf ( "COMMAND_LINE: Reverse_Normals option requested.\n" );
+ iarg = iarg + 1;
+ strcpy ( filein_name, argv[iarg] );
+ }
+
+ if ( leqi ( filein_name, "-RF" ) == TRUE ) {
+ reverse_faces = TRUE;
+ printf ( "\n" );
+ printf ( "COMMAND_LINE: Reverse_Faces option requested.\n" );
+ iarg = iarg + 1;
+ strcpy ( filein_name, argv[iarg] );
+ }
+/*
+ Read the input.
+*/
+ ierror = data_read ( );
+
+ if ( ierror == ERROR ) {
+ printf ( "\n" );
+ printf ( "COMMAND_LINE - Fatal error!\n" );
+ printf ( " Failure while reading input data.\n" );
+ return ERROR;
+ }
+/*
+ Reverse the normal vectors if requested.
+*/
+ if ( reverse_normals == TRUE ) {
+
+ for ( icor3 = 0; icor3 < cor3_num; icor3++ ) {
+ for ( i = 0; i < 3; i++ ) {
+ cor3_normal[i][icor3] = - cor3_normal[i][icor3];
+ }
+ }
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+ for ( i = 0; i < 3; i++ ) {
+ face_normal[i][iface] = - face_normal[i][iface];
+ }
+ }
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+ for ( ivert = 0; ivert < face_order[iface]; ivert++ ) {
+ for ( i = 0; i < 3; i++ ) {
+ vertex_normal[i][ivert][iface] =
+ - vertex_normal[i][ivert][iface];
+ }
+ }
+ }
+ printf ( "\n" );
+ printf ( "COMMAND_LINE - Note:\n" );
+ printf ( " Reversed node, face, and vertex normals.\n" );
+ }
+/*
+ Reverse the faces if requested.
+*/
+ if ( reverse_faces == TRUE ) {
+
+ face_reverse_order ( );
+
+ printf ( "\n" );
+ printf ( "COMMAND_LINE - Note:\n" );
+ printf ( " Reversed the face definitions.\n" );
+ }
+/*
+ Write the output file.
+*/
+ iarg = iarg + 1;
+ strcpy ( fileout_name, argv[iarg] );
+
+ ierror = data_write ( );
+
+ if ( ierror == ERROR ) {
+ printf ( "\n" );
+ printf ( "COMMAND_LINE - Fatal error!\n" );
+ printf ( " Failure while writing output data.\n" );
+ return ERROR;
+ }
+ return SUCCESS;
+}
+/******************************************************************************/
+
+void cor3_normal_set ( void )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ COR3_NORMAL_SET computes node normal vectors.
+
+ Modified:
+
+ 18 November 1998
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int icor3;
+ int iface;
+ int ivert;
+ int j;
+ float norm;
+ float temp;
+
+ for ( icor3 = 0; icor3 < cor3_num; icor3++ ) {
+ for ( j = 0; j < 3; j++ ) {
+ cor3_normal[j][icor3] = 0.0;
+ }
+ }
+/*
+ Add up the normals at all the faces to which the node belongs.
+*/
+ for ( iface = 0; iface < face_num; iface++ ) {
+
+ for ( ivert = 0; ivert < face_order[iface]; ivert++ ) {
+
+ icor3 = face[ivert][iface];
+
+ for ( j = 0; j < 3; j++ ) {
+ cor3_normal[j][icor3] = cor3_normal[j][icor3]
+ + vertex_normal[j][ivert][iface];
+ }
+ }
+ }
+/*
+ Renormalize.
+*/
+ for ( icor3 = 0; icor3 < cor3_num; icor3++ ) {
+
+ norm = 0.0;
+ for ( j = 0; j < 3; j++ ) {
+ temp = cor3_normal[j][icor3];
+ norm = norm + temp * temp;
+ }
+
+ if ( norm == 0.0 ) {
+ norm = 3.0;
+ for ( j = 0; j < 3; j++ ) {
+ cor3_normal[j][icor3] = 1.0;
+ }
+ }
+
+ norm = ( float ) sqrt ( norm );
+
+ for ( j = 0; j < 3; j++ ) {
+ cor3_normal[j][icor3] = cor3_normal[j][icor3] / norm;
+ }
+ }
+
+ return;
+}
+/******************************************************************************/
+
+void cor3_range ( void )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ COR3_RANGE computes the coordinate minima and maxima.
+
+ Modified:
+
+ 31 August 1998
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int i;
+ float xave;
+ float xmax;
+ float xmin;
+ float yave;
+ float ymax;
+ float ymin;
+ float zave;
+ float zmax;
+ float zmin;
+
+ xave = cor3[0][0];
+ xmax = cor3[0][0];
+ xmin = cor3[0][0];
+
+ yave = cor3[1][0];
+ ymax = cor3[1][0];
+ ymin = cor3[1][0];
+
+ zave = cor3[2][0];
+ zmax = cor3[2][0];
+ zmin = cor3[2][0];
+
+ for ( i = 1; i < cor3_num; i++ ) {
+
+ xave = xave + cor3[0][i];
+ if ( cor3[0][i] < xmin ) {
+ xmin = cor3[0][i];
+ }
+ if ( cor3[0][i] > xmax ) {
+ xmax = cor3[0][i];
+ }
+
+ yave = yave + cor3[1][i];
+ if ( cor3[1][i] < ymin ) {
+ ymin = cor3[1][i];
+ }
+ if ( cor3[1][i] > ymax ) {
+ ymax = cor3[1][i];
+ }
+
+ zave = zave + cor3[2][i];
+ if ( cor3[2][i] < zmin ) {
+ zmin = cor3[2][i];
+ }
+ if ( cor3[2][i] > zmax ) {
+ zmax = cor3[2][i];
+ }
+ }
+
+ xave = xave / cor3_num;
+ yave = yave / cor3_num;
+ zave = zave / cor3_num;
+
+ printf ( "\n" );
+ printf ( "COR3_RANGE - Data range:\n" );
+ printf ( "\n" );
+ printf ( " Minimum Average Maximum Range\n" );
+ printf ( "\n" );
+ printf ( "X %f %f %f %f\n", xmin, xave, xmax, xmax-xmin );
+ printf ( "Y %f %f %f %f\n", ymin, yave, ymax, ymax-ymin );
+ printf ( "Z %f %f %f %f\n", zmin, zave, zmax, zmax-zmin );
+
+}
+/******************************************************************************/
+
+void data_check ( void )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ DATA_CHECK checks the input data.
+
+ Modified:
+
+ 18 May 1999
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int iface;
+ int nfix;
+
+ if ( color_num > COLOR_MAX ) {
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Warning!\n" );
+ printf ( " The input data requires %d colors.\n", color_num );
+ printf ( " There was only room for %d\n", COLOR_MAX );
+ color_num = COLOR_MAX;
+ }
+
+ if ( cor3_num > COR3_MAX ) {
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Warning!\n" );
+ printf ( " The input data requires %d points.\n", cor3_num );
+ printf ( " There was only room for %d\n", COR3_MAX );
+ cor3_num = COR3_MAX;
+ }
+
+ if ( face_num > FACE_MAX ) {
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Warning!\n" );
+ printf ( " The input data requires %d faces.\n", face_num );
+ printf ( " There was only room for %d\n", FACE_MAX );
+ face_num = FACE_MAX;
+ }
+
+ if ( line_num > LINES_MAX ) {
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Warning!\n" );
+ printf ( " The input data requires %d line items.\n", line_num );
+ printf ( " There was only room for %d.\n", LINES_MAX );
+ line_num = LINES_MAX;
+ }
+
+ nfix = 0;
+
+ for ( iface = 0; iface < face_num; iface++ ) {
+
+ if ( face_order[iface] > ORDER_MAX ) {
+ face_order[iface] = ORDER_MAX;
+ nfix = nfix + 1;
+ }
+
+ }
+
+ if ( nfix > 0 ) {
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Warning!\n" );
+ printf ( " Corrected %d faces using more than %d vertices per face.\n",
+ nfix, ORDER_MAX );
+ }
+
+ for ( i = 0; i < material_num; i++ ) {
+ if ( strcmp ( material_name[i], "" ) == 0 ) {
+ strcpy ( material_name[i], "Material_0000" );
+ }
+ }
+
+ for ( i = 0; i < texture_num; i++ ) {
+ if ( strcmp ( texture_name[i], "" ) == 0 ) {
+ strcpy ( texture_name[i], "Texture_0000" );
+ }
+ }
+
+ printf ( "\n" );
+ printf ( "DATA_CHECK - Data checked.\n" );
+
+ return;
+}
+/******************************************************************************/
+
+void data_init ( void )
+
+/******************************************************************************/
+
+/*
+ Purpose:
+
+ DATA_INIT initializes the internal graphics data.
+
+ Modified:
+
+ 04 July 2000
+
+ Author:
+
+ John Burkardt
+*/
+{
+ int i;
+ int iface;
+ int ivert;
+ int j;
+ int k;
+
+ strcpy( anim_name, "" );
+
+ for ( i = 0; i < 3; i++ ) {
+ background_rgb[i] = 0.0;
+ }
+
+ for ( i = 0; i < 3; i++ ) {
+ for ( j = 0; j < COR3_MAX; j++ ) {
+ cor3[i][j] = 0.0;
+ }
+ }
+
+ for ( i = 0; i < COR3_MAX; i++ ) {
+ cor3_material[i] = 0;
+ }
+
+ for ( i = 0; i < 3; i++ ) {
+ for ( j = 0; j < COR3_MAX; j++ ) {
+ cor3_normal[i][j] = 0.0;
+ }
+ }
+
+ for ( j = 0; j < COR3_MAX; j++ ) {
+ cor3_tex_uv[0][j] = 0.0;
+ cor3_tex_uv[1][j] = 0.0;
+ }
+
+ for ( iface = 0; iface < FACE_MAX; iface++ ) {
+ for ( ivert = 0; ivert < ORDER_MAX; ivert++ ) {
+ face[ivert][iface] = 0;
+ }
+ }
+
+ for ( iface = 0; iface < FACE_MAX; iface++ ) {
+ face_flags[iface] = 6;
+ }
+
+ for ( iface = 0; iface < FACE_MAX; iface++ ) {
+ face_material[iface] = 0;
+ }
+
+ for ( iface = 0; iface < FACE_MAX; iface++ ) {
+ for ( i = 0; i < 3; i++ ) {
+ face_normal[i][i...
[truncated message content] |