Exemple #1
0
int ray(int argc, char **argv) {
#else
int main(int argc, char **argv) {
#endif
    SceneHandle scene;
    unsigned int rc;
    argoptions opt;
    char * filename;
    int node, fileindex;
    rt_timerhandle parsetimer;
    size_t len;

    node = rt_initialize(&argc, &argv);

    rt_set_ui_message(my_ui_message);
    rt_set_ui_progress(my_ui_progress);

    if (node == 0) {
        printf("Tachyon Parallel/Multiprocessor Ray Tracer   Version %s   \n",
               TACHYON_VERSION_STRING);
        printf("Copyright 1994-2010,    John E. Stone <*****@*****.**> \n");
        printf("------------------------------------------------------------ \n");
    }

    if ((rc = getargs(argc, argv, &opt, node)) != 0) {
        rt_finalize();
        exit(rc);
    }

    if (opt.numfiles > 1) {
        printf("Rendering %d scene files.\n", opt.numfiles);
    }

    for (fileindex=0; fileindex<opt.numfiles; fileindex++) {
        scene = rt_newscene();

        /* process command line overrides */
        presceneoptions(&opt, scene);

        filename = opt.filenames[fileindex];

        if (opt.numfiles > 1) {
            printf("\nRendering scene file %d of %d, %s\n", fileindex+1, opt.numfiles, filename);
        }

        parsetimer=rt_timer_create();
        rt_timer_start(parsetimer);

        len = strlen(filename);

        if (len > 4 && (!strcmp(filename+len-4, ".nff") ||
                        !strcmp(filename+len-4, ".NFF"))) {
            rc = ParseNFF(filename, scene); /* must be an NFF file */
        }
        else if (len > 3 && (!strcmp(filename+len-3, ".ac") ||
                             !strcmp(filename+len-3, ".AC"))) {
            rc = ParseAC3D(filename, scene); /* Must be an AC3D file */
        }
#ifdef USELIBMGF
        else if (len > 4 && (!strcmp(filename+len-4, ".mgf") ||
                             !strcmp(filename+len-4, ".MGF"))) {
            rc = ParseMGF(filename, scene, 1); /* Must be an MGF file */
        }
#endif
        else {
            rc = readmodel(filename, scene); /* Assume its a Tachyon scene file */
        }

        rt_timer_stop(parsetimer);
        if (rc == PARSENOERR && node == 0)
            printf("Scene Parsing Time: %10.4f seconds\n", rt_timer_time(parsetimer));
        rt_timer_destroy(parsetimer);

        if (rc != PARSENOERR && node == 0) {
            switch(rc) {
            case PARSEBADFILE:
                printf("Parser failed due to nonexistent input file: %s\n", filename);
                break;
            case PARSEBADSUBFILE:
                printf("Parser failed due to nonexistent included file.\n");
                break;
            case PARSEBADSYNTAX:
                printf("Parser failed due to an input file syntax error.\n");
                break;
            case PARSEEOF:
                printf("Parser unexpectedly hit an end of file.\n");
                break;
            case PARSEALLOCERR:
                printf("Parser ran out of memory.\n");
                break;
            }
            if (fileindex+1 < opt.numfiles)
                printf("Aborting render, continuing with next scene file...\n");
            else
                printf("Aborting render.\n");

            rt_deletescene(scene); /* free the scene */
            continue;              /* process the next scene */
        }

        /* process command line overrides */
        postsceneoptions(&opt, scene);

        /* choose which rendering mode to use */
        if (opt.usecamfile == 1) {
            return animate_scene(opt, scene, node); /* fly using prerecorded data */
        }
        else if (strlen(opt.spaceball) > 0) {
            return fly_scene(opt, scene, node);     /* fly with spaceball etc */
        }
        else {
            if (opt.numfiles > 1 && opt.nosave != 1) {
                char multioutfilename[FILENAME_MAX];
                sprintf(multioutfilename, opt.outfilename, fileindex);
                rt_outputfile(scene, multioutfilename);
            }

            rt_renderscene(scene); /* Render a single frame */
        }

        rt_deletescene(scene);   /* free the scene, get ready for next one */
    }

    rt_finalize();             /* close down the rendering library and MPI */
    freeoptions(&opt);         /* free parsed command line option data */

    return 0;
}
Exemple #2
0
/*
 * main loop for creating animations by flying using a spaceball
 * or other 3-D input mechanism.
 */
static int fly_scene(argoptions opt, SceneHandle scene, int node) {
    dispHandle * dh = NULL;
    int done = 0;
    int frameno = 0;
    float fps;
    rt_timerhandle fpstimer;
    rt_timerhandle animationtimer;
    char outfilename[1];

#if defined(USESPACEBALL)
    sbHandle * bh = NULL;
#endif

    if (node == 0)
        dh = tachyon_display_create(scene);

    rt_set_ui_message(NULL);
    rt_set_ui_progress(NULL);

    if (node == 0)
        printf("Interactive Camera Flight\n");

    outfilename[0] = '\0';
    rt_outputfile(scene, outfilename);

    fpstimer=rt_timer_create();
    animationtimer=rt_timer_create();

#if defined(USESPACEBALL)
    if (node == 0) {
#if 1
        bh = tachyon_init_spaceball(scene, opt.spaceball);
#else
        if (rt_numnodes() < 2) {
            bh = tachyon_init_spaceball(scene, opt.spaceball);
        } else {
            printf("WARNING: Spaceball mode disabled when running with distributed memory");
        }
#endif
    }
#endif

    rt_timer_start(animationtimer);
    while (!done) {
        if (frameno != 0) {
            rt_timer_stop(fpstimer);
            fps = 1.0f / rt_timer_time(fpstimer);
        } else {
            fps = 0.0;
        }

        rt_timer_start(fpstimer);
        if (node == 0) {
            printf("\rRendering Frame: %9d   %10.4f FPS       ", frameno, fps);
            fflush(stdout);
        }

#if defined(USESPACEBALL)
        if (bh != NULL)
            done = tachyon_spaceball_update(bh, scene);
#endif

        rt_renderscene(scene);

        if (dh != NULL)
            tachyon_display_draw(dh);

        frameno++;
    }

    rt_timer_stop(animationtimer);
    fps = frameno / rt_timer_time(animationtimer);

    if (node == 0) {
        printf("\rCompleted animation of %d frames                            \n", frameno);
        printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n",
               rt_timer_time(animationtimer), fps);
    }
    rt_timer_destroy(fpstimer);

    if (node == 0) {
        printf("\nFinished Running Camera.\n");

        if (dh !=NULL)
            tachyon_display_delete(dh);
    }

    rt_deletescene(scene); /* free the scene */
    rt_finalize(); /* close down the rendering library and MPI */

    return 0;
}
Exemple #3
0
/*
 * main loop for creating animations by playing recorded camera fly-throughs
 */
static int animate_scene(argoptions opt, SceneHandle scene, int node) {
    char outfilename[1000];
    FILE * camfp;
    dispHandle * dh = NULL;

    if (node == 0)
        dh = tachyon_display_create(scene);

    /* if we have a camera file, then animate.. */
    if ((camfp = fopen(opt.camfilename, "r")) != NULL) {
        floatvec cv, cu, cc;
        apivector cmv, cmu, cmc;
        int frameno = 0;
        float fps;
        rt_timerhandle fpstimer;
        rt_timerhandle animationtimer;

        rt_set_ui_message(NULL);
        rt_set_ui_progress(NULL);

        if (node == 0)
            printf("Running Camera File: %s\n", opt.camfilename);

        fpstimer=rt_timer_create();
        animationtimer=rt_timer_create();

        rt_timer_start(animationtimer);

        while (!feof(camfp)) {
            fscanf(camfp, "%f %f %f  %f %f %f  %f %f %f",
                   &cv.x, &cv.y, &cv.z, &cu.x, &cu.y, &cu.z, &cc.x, &cc.y, &cc.z);

            cmv.x = cv.x;
            cmv.y = cv.y;
            cmv.z = cv.z;
            cmu.x = cu.x;
            cmu.y = cu.y;
            cmu.z = cu.z;
            cmc.x = cc.x;
            cmc.y = cc.y;
            cmc.z = cc.z;

            if (frameno != 0) {
                rt_timer_stop(fpstimer);
                fps = 1.0f / rt_timer_time(fpstimer);
            } else {
                fps = 0.0;
            }

            rt_timer_start(fpstimer);
            outfilename[0] = '\0';
            if (opt.nosave == 1) {
                if (node == 0) {
                    printf("\rRendering Frame: %9d   %10.4f FPS       ", frameno, fps);
                    fflush(stdout);
                }
            }
            else {
                sprintf(outfilename, opt.outfilename, frameno);
                if (node == 0) {
                    printf("\rRendering Frame to %s   (%10.4f FPS)       ", outfilename, fps);
                    fflush(stdout);
                }
            }

            rt_outputfile(scene, outfilename);
            rt_camera_position(scene, cmc, cmv, cmu);

            rt_renderscene(scene);

            if (dh != NULL)
                tachyon_display_draw(dh);

            frameno++;
        }
        rt_timer_stop(animationtimer);
        fps = frameno / rt_timer_time(animationtimer);
        if (node == 0) {
            printf("\rCompleted animation of %d frames                            \n", frameno);
            printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n",
                   rt_timer_time(animationtimer), fps);
        }
        rt_timer_destroy(fpstimer);
        fclose(camfp);
    } else {
        if (node == 0) {
            printf("Couldn't open camera file: %s\n", opt.camfilename);
            printf("Aborting render.\n");
        }
        rt_deletescene(scene); /* free the scene */
        rt_finalize(); /* close down the rendering library and MPI */
        return -1;
    }

    if (node == 0) {
        printf("\nFinished Running Camera.\n");

        if (dh !=NULL)
            tachyon_display_delete(dh);
    }

    rt_deletescene(scene); /* free the scene */
    rt_finalize(); /* close down the rendering library and MPI */

    return 0;
}
int main(int argc, char **argv) {
  SceneHandle scene;
  int i, j;
  apivector Ccenter, Cview, Cup;
  apivector ctr1, ctr2;
  apitexture tex1, tex2;
  void * vtx1, * vtx2;
  char fname[100];

  rt_initialize(&argc, &argv); 

  Ccenter.x=0.0; Ccenter.y=0.0; Ccenter.z=-3.0;
  Cview.x=0.0;   Cview.y=0.0;   Cview.z=1.0;
  Cup.x=0.0;     Cup.y=1.0;     Cup.z=0.0;

  ctr1.x=20.0;  ctr1.y=20.0; ctr1.z=-40.0;
  ctr2.x=-20.0; ctr2.y=20.0; ctr2.z=-40.0;
  
  tex1.col.r=1.0;
  tex1.col.g=0.5;
  tex1.col.b=0.0;
  tex1.ambient=1.0;
  tex1.opacity=1.0;
  tex2=tex1;
  tex2.col.r=0.0;
  tex2.col.b=1.0;

  initspheres();
  
 
  for (i=0; i<MAXFRAMES; i++) {  
    scene = rt_newscene();
    vtx1=rt_texture(scene, &tex1);
    vtx2=rt_texture(scene, &tex2);

    sprintf(fname,"outfile.%4.4d.tga",i);

    if (rt_mynode()==0) printf("Rendering: %s\n", fname);

    rt_outputfile(scene, fname);
    rt_resolution(scene, XRES, YRES);
    rt_verbose(scene, 0);

    rt_camera_setup(scene, 1.0, 1.0, 0, 5, Ccenter, Cview, Cup);

    movesp(); 
    drawsp(scene);

    rt_light(scene, vtx1, ctr1, 1.0);
    rt_light(scene, vtx2, ctr2, 1.0);

    rt_renderscene(scene);

    rt_deletescene(scene);

    for (j=0; j<NUMSP; j++)
      free(sp[i].voidtex);  
  }

  rt_finalize();

  return 0;
}