Example #1
0
int main(int argc, char *argv[])
{
    int err = 0;
    int frames = 0;
    time_t start = 0;
    time_t stop = 0;

    EON_Light *light;
    EON_Obj *model;
    EON_Mat *material;
    EON_Cam *camera;
    EON_Rend *rend;
    EON_Frame *frame;
    EONx_Console *console;
    EONViewer view;

    view.logger = CX_log_open_console(CX_LOG_MARK, stderr);

    opts_Defaults(&view.opts);
    err = opts_Parse(&view.opts, argc, argv);
    if (err) {
        return opts_ErrCode(err);
    }

    CX_log_trace(view.logger, CX_LOG_INFO, EXE,
                 "Shading mode: %s",
                 shade_ModeToStr(view.opts.shade));
    CX_log_trace(view.logger, CX_LOG_INFO, EXE,
                 "Frame Size: %ix%i",
                 view.opts.width, view.opts.height);
    CX_log_trace(view.logger, CX_LOG_INFO, EXE,
                 "Model rotation: X=%f Y=%f Z=%f",
                 view.opts.rx, view.opts.ry, view.opts.rz);

    EONx_ConsoleStartup("Eon3D Model Viewer", NULL);

    material = EON_MatCreate(); 
    material->ShadeType = view.opts.shade;

    material->Ambient.R = 200;
    material->Ambient.G = 200;
    material->Ambient.B = 200;

    EON_MatInit(material);
    EON_MatInfo(material, view.logger);

    console = EONx_ConsoleCreate(view.opts.width, view.opts.height, 90);

    EONx_ConsoleBindEventKey(console, 's', onkey_Screenshot, &view); // XXX
    EONx_ConsoleBindEventKey(console, 'q', onkey_Quit, &view); // XXX

    model = EONx_ReadPLYObj(view.opts.filename, material);
    EON_ObjInfo(model, view.logger);

    frame = EONx_ConsoleGetFrame(console);
    camera = EONx_ConsoleGetCamera(console);
    camera->Pos.Z = -view.opts.distance;

    light = EON_LightNew(EON_LIGHT_VECTOR, 0.0, 0.0, 0.0, 1.0, 1.0);

    rend = EON_RendCreate(camera);

    start = time(NULL);
    while (!EONx_ConsoleNextEvent(console)) {
        model->Xa += view.opts.rx;
        model->Ya += view.opts.ry;
        model->Za += view.opts.rz;
        EONx_ConsoleClearFrame(console);
        EON_RenderBegin(rend);
        EON_RenderLight(rend, light);
        EON_RenderObj(rend, model);
        EON_RenderEnd(rend, frame);
        EONx_ConsoleShowFrame(console);
        frames++;
    }
    stop = time(NULL);

    CX_log_trace(view.logger, CX_LOG_INFO, EXE,
                 "%i frames in %f seconds: %.3f FPS\n",
                 frames, (double)stop-(double)start,
                 (double)frames/((double)stop-(double)start));

    return EONx_ConsoleShutdown();
}
Example #2
0
int main(int argc, char *argv[])
{
    const char *filename;
    int frames = 0;
    int framenum = 100000;
    time_t start = 0, stop = 0;
    // Our variables
    EON_Light *TheLight;   // Our light
    EON_Mesh *TheModel;      // Our cube object
    EON_Mat *ModelMat;      // The material for the cube
    EON_Cam *TheCamera;
    EON_Rend *TheRend;
    EON_Frame *TheFrame;
    NullConsole *TheConsole;
    double distance = 50;
    int ch = -1;
    int verbose = 1;
    CX_LogContext *Logger = CX_log_open_console(CX_LOG_MARK, stderr);

    while (1) {
        ch = getopt(argc, argv, "d:n:v:h?");
        if (ch == -1) {
            break;
        }

        switch (ch) {
          case 'd':
            distance = atof(optarg);
            break;
          case 'n':
            framenum = atoi(optarg);
            break;
          case 'v':
            verbose = atoi(optarg);
            break;
          case '?': /* fallthrough */
          case 'h': /* fallthrough */
          default:
            usage();
            return 0;
        }
    }

    /* XXX: watch out here */
    argc -= optind;
    argv += optind;

    if (argc != 1) {
        usage();
        return 1;
    }
    filename = argv[0];

    if (verbose) {
        CX_log_trace(Logger, CX_LOG_INFO, EXE,
                     "settings> rendering model = %s",
                     filename);
        CX_log_trace(Logger, CX_LOG_INFO, EXE,
                     "settings> frame limit     = %i",
                     framenum);
    }

    ModelMat = EON_MatCreate(); 
    ModelMat->ShadeType = EON_SHADE_FLAT;

    ModelMat->Ambient.R = 216;
    ModelMat->Ambient.G = 216;
    ModelMat->Ambient.B = 216;

    EON_MatInit(ModelMat);
    EON_MatInfo(ModelMat, Logger);

    TheConsole = NullConsoleCreate(800, // Screen width
                                   600 // Screen height
                                   );

    TheModel = EONx_ReadPLYMesh(filename, ModelMat);
    if (TheModel == NULL) {
        CX_log_trace(Logger, CX_LOG_ERROR, EXE,
                     "failed to load model '%s', aborting",
                     filename);
        return 1;
    }

    EON_MeshInfo(TheModel, Logger);

    TheFrame = TheConsole->fb;
    TheCamera = TheConsole->cam;
    TheCamera->Pos.Z = -distance; // Back the camera up from the origin

    TheLight = EON_LightNew(EON_LIGHT_VECTOR, // vector light
                            0.0, 0.0, 0.0, // rotation angles
                            1.0, // intensity
                            1.0); // falloff, not used for vector lights

    TheRend = EON_RendCreate(TheCamera);

    start = time(NULL);
    while (frames < framenum) {
        // Rotate by 1 degree on each axis
        TheModel->Rotation.X += 1.0;
        TheModel->Rotation.Y += 1.0;
        TheModel->Rotation.Z += 1.0;
        NullConsoleClearFrame(TheConsole);
        EON_RenderBegin(TheRend);           // Start rendering with the camera
        EON_RenderLight(TheRend, TheLight); // Render our light
        EON_RenderMesh(TheRend, TheModel);   // Render our object
        EON_RenderEnd(TheRend, TheFrame);   // Finish rendering
        frames++;
    }
    stop = time(NULL);

    CX_log_trace(Logger, CX_LOG_INFO, EXE,
                 "%i frames in %f seconds: %.3f FPS",
                 frames, (double)stop-(double)start,
                 (double)frames/((double)stop-(double)start));

    return CX_log_close(Logger);
}