Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
204 chris 1
/*
2
** ARToolKit object parsing function
3
**   - reads in object data from object file in Data/object_data
4
**
5
*/
6
 
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
#include <AR/ar.h>
11
#include <AR/arvrml.h>
12
#include "object.h"
13
 
14
static char *get_buff(char *buf, int n, FILE *fp)
15
{
16
    char *ret;
17
 
18
    for(;;) {
19
        ret = fgets(buf, n, fp);
20
        if (ret == NULL) return(NULL);
21
        if (buf[0] != '\n' && buf[0] != '#') return(ret); // Skip blank lines and comments.
22
    }
23
}
24
 
25
ObjectData_T *read_VRMLdata( char *name, int *objectnum )
26
{
27
    FILE          *fp;
28
    ObjectData_T  *object;
29
    char           buf[256], buf1[256];
30
    int            i;
31
 
32
        printf("Opening model file %s\n", name);
33
 
34
    if ((fp=fopen(name, "r")) == NULL) return(0);
35
 
36
    get_buff(buf, 256, fp);
37
    if (sscanf(buf, "%d", objectnum) != 1) {
38
                fclose(fp); return(0);
39
        }
40
 
41
        printf("About to load %d models.\n", *objectnum);
42
 
43
    if ((object = (ObjectData_T *)malloc(sizeof(ObjectData_T) * (*objectnum))) == NULL) exit (-1);
44
 
45
    for (i = 0; i < *objectnum; i++) {
46
 
47
        get_buff(buf, 256, fp);
48
        if (sscanf(buf, "%s %s", buf1, object[i].name) != 2) {
49
            fclose(fp); free(object); return(0);
50
        }
51
 
52
                printf("Model %d: %20s\n", i + 1, &(object[i].name[0]));
53
 
54
        if (strcmp(buf1, "VRML") == 0) {
55
            object[i].vrml_id = arVrmlLoadFile(object[i].name);
56
                        printf("VRML id - %d \n", object[i].vrml_id);
57
            if (object[i].vrml_id < 0) {
58
                fclose(fp); free(object); return(0);
59
            }
60
        } else {
61
                        object[i].vrml_id = -1;
62
                }
63
                object[i].vrml_id_orig = object[i].vrml_id;
64
                object[i].visible = 0;
65
 
66
        get_buff(buf, 256, fp);
67
        if (sscanf(buf, "%s", buf1) != 1) {
68
                        fclose(fp); free(object); return(0);
69
                }
70
 
71
        if ((object[i].id = arLoadPatt(buf1)) < 0) {
72
                        fclose(fp); free(object); return(0);
73
                }
74
 
75
        get_buff(buf, 256, fp);
76
        if (sscanf(buf, "%lf", &object[i].marker_width) != 1) {
77
                        fclose(fp); free(object); return(0);
78
                }
79
 
80
        get_buff(buf, 256, fp);
81
        if (sscanf(buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2) {
82
            fclose(fp); free(object); return(0);
83
        }
84
 
85
    }
86
 
87
    fclose(fp);
88
 
89
    return( object );
90
}