[info-performer] pseudo loader light source - add lights to any scene!

Date view Thread view Subject view Author view

From: Dan Johnston (dan.johnston++at++nrc.ca)
Date: 07/09/2003 11:23:11


Hi pfGroup!

I created a ".light" pseudo loader so that I can add

light(s) to any Performer application that reads

multiple files (without recompiling the code!).

Feel free to use/modify/correct/enhance the source

as you like - but share the improvements!

Just turn the attached source into a loader ".so"

shared library, add the path to the library in

your run script, and add lights to your command

line. You can even use the .trans and .rot pseudo

loaders to move the light(s) around.

I don't know a lot about lighting so I'm sure you

people can improve the code. It did work for me -

i.e. it lit up a dark scene.

+++++++ Makefile to build shared library ++++++++++++

#!smake

PFROOT ?= $(ROOT)
include $(PFROOT)/usr/share/Performer/src/pfmakedefs

#-- base name of library
LIBRARY = libpflight

CXXFILES = \
        pflight.C

include $(PFROOT)/usr/share/Performer/src/pfmakerules

+++++++++++++++ End of Makefile ++++++++++++++++++++

+++++++ source of the light pseudo loader +++++++++++

/*
 * Created by;
 * Daniel F. Johnston
 * National Research Council of Canada
 * 2003-July-09
 *
 * Provide without restrictions to the Open-GL Performer
 * community in the hope that they find it useful.
 */

/*
 * pflight.C - ".light" pseudo-loader.
 *
 * To add a new light to any scene, say:
 * perfly <filename> <r>,<g>,<b>.light
 * (where r,g,b define the color of the new light source)
 * Also works with the ".trans" and ".rot" pseudo-loaders so you can

 * position the new light whereever you need it
 *
 * The rgb color numbers can have decimal points (but don't
 * use exponential notation).
 */

#include <stdio.h>
#include <Performer/pfdu.h>
 #include <Performer/pr/pfGeoMath.h>
 #include <Performer/pf/pfLightSource.h>
#ifdef __linux__
#include <limits.h>
#endif

char *strrnchr(char *s, int n, int c)
{
    char *p = NULL;
    int i;
    for (i = 0; i < n && s[i] != '\0'; ++i)
        if (s[i] == c)
            p = s+i;
    return p;
}

extern "C" pfNode *
pfdLoadFile_light(char *fileName)
{
    float red, green, blue;
    char params[PATH_MAX];

    char *lastdot = strrchr(fileName, '.');
    if (lastdot != NULL)
    {
        strncpy(params, fileName, lastdot-fileName);
        params[lastdot-fileName] = '\0';
        if (sscanf(params, "%f,%f,%f", &red, &green, &blue) != 3)
        {
            pfNotify(PFNFY_WARN, PFNFY_USAGE,
                    "pfdLoadFile_light: bad file name %s", fileName);
            return NULL;
        }
    }

    pfNotify(PFNFY_INFO, PFNFY_PRINT, "Add light (%.9g,%.9g,%.9g) to scene\n", red,green,blue);
    pfLightSource *lamp = new pfLightSource();
    PFASSERTALWAYS(lamp != NULL);

    // Create and configure light frustum
    lightFrust = new pfFrustum;
    PFASSERTALWAYS(lightFrust != NULL);
    lightFrust->makeSimple(60.0f);
    lightFrust->setNearFar(1.0f, 100.0f);

    // set light direction
    lamp->setAttr(PFLS_PROJ_FRUST, lightFrust);
    // set light source color
    lamp->setColor(PFLT_DIFFUSE, red, green, blue );
    lamp->setVal(PFLS_INTENSITY, .5f);

    return lamp;
}

+++++++++++++++ End of pflight.C +++++++++++++++++++

+++++++++++++++ Example run script +++++++++++++++++

#!/bin/tcsh

set PROGRAM = /usr/people/somename/bindirectory
setenv PFPATH $PROGRAM/data:.:/usr/share/Performer/data
# set a path for the library
if ($?LD_LIBRARY_PATH == 0) then
    setenv LD_LIBRARY_PATH /usr/people/somename/lightPseudoLoader/OPT.N32:/usr/lib32
else
    setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/people/somename/lightPseudoLoader/OPT.N32:/usr/lib32
endif
# export LD_LIBRARY_PATH

if $1 == "debug" then
    $PROGRAM/executable.debug chamber.0.lsa.10.0.scale 1,0.1,0.1.light
else
    $PROGRAM/executable $chamber.0.lsa.10.0.scale 0.6,0.6,0.6.light
endif

+++++++++++++++ End of run script ++++++++++++++++++

Enjoy!

--
      ___|__    |
      /  |  \   ||\      Daniel (Dan) Johnston
     /___|___\  || \     Dan.Johnston++at++nrc.gc.ca
    _____|____  ||  \    National Research Council of Canada, London, ON
    |    |    | ||   \   Integrated Manufacturing Technologies Institute
\___|    |    | ||____\  Tel: (519) 430-7081   Fax: (519) 430-7090
 \_o_\___|____|_|______\_    Inst: http://www.nrc.gc.ca/imti
  \                o /    These opinions are my own! Not those of NRC.
   \________________/    Virtual Reality:
                        http://www.nrc.ca/imti/vetc/home.html
 More Tall Ships - Fewer Computers!


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Jul 09 2003 - 11:25:30 PDT