From Daniel Sjolie, support for light source.
This commit is contained in:
@@ -65,6 +65,9 @@ FltFile::FltFile(
|
||||
setMaterialPool( new MaterialPool );
|
||||
}
|
||||
|
||||
// no support for external light palettes
|
||||
setLightPool( new LightPool );
|
||||
|
||||
// instances are always internally defined
|
||||
setInstancePool( new InstancePool );
|
||||
}
|
||||
|
||||
@@ -32,11 +32,13 @@ class FltFile : public osg::Referenced
|
||||
|
||||
ColorPool* getColorPool() { return _colorPool.get(); }
|
||||
TexturePool* getTexturePool() { return _texturePool.get(); }
|
||||
LightPool* getLightPool() { return _lightPool.get(); }
|
||||
MaterialPool* getMaterialPool() { return _materialPool.get(); }
|
||||
InstancePool* getInstancePool() { return _instancePool.get(); }
|
||||
|
||||
void setColorPool(ColorPool* colorPool) { _colorPool = colorPool; }
|
||||
void setTexturePool(TexturePool* texturePool) { _texturePool = texturePool; }
|
||||
void setLightPool(LightPool* lightPool){ _lightPool = lightPool; }
|
||||
void setMaterialPool(MaterialPool* materialPool){ _materialPool = materialPool; }
|
||||
void setInstancePool(InstancePool* instancePool){ _instancePool = instancePool; }
|
||||
|
||||
@@ -70,6 +72,7 @@ class FltFile : public osg::Referenced
|
||||
|
||||
osg::ref_ptr<ColorPool> _colorPool;
|
||||
osg::ref_ptr<TexturePool> _texturePool;
|
||||
osg::ref_ptr<LightPool> _lightPool;
|
||||
osg::ref_ptr<MaterialPool> _materialPool;
|
||||
osg::ref_ptr<InstancePool> _instancePool;
|
||||
};
|
||||
|
||||
@@ -28,4 +28,28 @@ LightSourcePaletteRecord::~LightSourcePaletteRecord()
|
||||
// virtual
|
||||
void LightSourcePaletteRecord::endian()
|
||||
{
|
||||
SLightSourcePalette *pSLightSourcePalette = (SLightSourcePalette*)getData();
|
||||
|
||||
ENDIAN( pSLightSourcePalette->diReserved_1 );
|
||||
ENDIAN( pSLightSourcePalette->diIndex );
|
||||
ENDIAN( pSLightSourcePalette->diReserved_2 );
|
||||
ENDIAN( pSLightSourcePalette->sfAmbientRGBA[0] );
|
||||
ENDIAN( pSLightSourcePalette->sfAmbientRGBA[1] );
|
||||
ENDIAN( pSLightSourcePalette->sfAmbientRGBA[2] );
|
||||
ENDIAN( pSLightSourcePalette->sfAmbientRGBA[3] );
|
||||
ENDIAN( pSLightSourcePalette->sfDiffuseRGBA[0] );
|
||||
ENDIAN( pSLightSourcePalette->sfDiffuseRGBA[1] );
|
||||
ENDIAN( pSLightSourcePalette->sfDiffuseRGBA[2] );
|
||||
ENDIAN( pSLightSourcePalette->sfDiffuseRGBA[3] );
|
||||
ENDIAN( pSLightSourcePalette->sfSpecularRGBA[0] );
|
||||
ENDIAN( pSLightSourcePalette->sfSpecularRGBA[1] );
|
||||
ENDIAN( pSLightSourcePalette->sfSpecularRGBA[2] );
|
||||
ENDIAN( pSLightSourcePalette->sfSpecularRGBA[3] );
|
||||
ENDIAN( pSLightSourcePalette->sfDropoff );
|
||||
ENDIAN( pSLightSourcePalette->sfCutoff );
|
||||
ENDIAN( pSLightSourcePalette->sfYaw );
|
||||
ENDIAN( pSLightSourcePalette->sfPitch );
|
||||
ENDIAN( pSLightSourcePalette->sfConstantAttuenation );
|
||||
ENDIAN( pSLightSourcePalette->sfLinearAttuenation );
|
||||
ENDIAN( pSLightSourcePalette->sfQuadraticAttuenation );
|
||||
}
|
||||
|
||||
@@ -227,6 +227,22 @@ void TexturePool::addTextureName(int nIndex, const std::string& name)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
osg::Light* LightPool::getLight(int nIndex)
|
||||
{
|
||||
if (nIndex < 0) return NULL;
|
||||
LightPaletteMap::iterator fitr = _lightMap.find(nIndex);
|
||||
if (fitr != _lightMap.end())
|
||||
return (*fitr).second.get();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void LightPool::addLight(int nIndex, osg::Light* light)
|
||||
{
|
||||
_lightMap[nIndex] = light;
|
||||
}
|
||||
|
||||
MaterialPool::PoolMaterial* MaterialPool::getMaterial(int nIndex)
|
||||
{
|
||||
if (nIndex < 0) return NULL;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Material>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Light>
|
||||
#include <osg/Group>
|
||||
|
||||
#include <string>
|
||||
@@ -78,6 +79,27 @@ class TexturePool : public osg::Referenced
|
||||
|
||||
|
||||
|
||||
class LightPool : public osg::Referenced
|
||||
{
|
||||
public :
|
||||
|
||||
LightPool() {}
|
||||
|
||||
osg::Light* getLight(int nIndex );
|
||||
void addLight(int nIndex, osg::Light* light);
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~LightPool() {}
|
||||
|
||||
private :
|
||||
|
||||
typedef std::map<int,osg::ref_ptr<osg::Light> > LightPaletteMap;
|
||||
LightPaletteMap _lightMap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MaterialPool : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/Image>
|
||||
#include <osg/Notify>
|
||||
|
||||
@@ -63,6 +64,8 @@
|
||||
#include "LocalVertexPoolRecord.h"
|
||||
#include "MultiTextureRecord.h"
|
||||
#include "UVListRecord.h"
|
||||
#include "LightSourceRecord.h"
|
||||
#include "LightSourcePaletteRecord.h"
|
||||
|
||||
|
||||
|
||||
@@ -180,6 +183,10 @@ osg::Group* ConvertFromFLT::visitAncillary(osg::Group& osgParent, osg::Group& os
|
||||
visitColorPalette(osgPrimary, (ColorPaletteRecord*)child);
|
||||
break;
|
||||
|
||||
case LIGHT_SOURCE_PALETTE_OP:
|
||||
visitLightSourcePalette(osgPrimary, (LightSourcePaletteRecord*)child);
|
||||
break;
|
||||
|
||||
case MATERIAL_PALETTE_OP:
|
||||
visitMaterialPalette(osgPrimary, (MaterialPaletteRecord*)child);
|
||||
break;
|
||||
@@ -266,6 +273,9 @@ osg::Group* ConvertFromFLT::visitPrimaryNode(osg::Group& osgParent, PrimNodeReco
|
||||
case GROUP_OP:
|
||||
osgPrim = visitGroup(osgParent, (GroupRecord*)child);
|
||||
break;
|
||||
case LIGHT_SOURCE_OP:
|
||||
osgPrim = visitLightSource(osgParent, (LightSourceRecord*)child);
|
||||
break;
|
||||
case LOD_OP:
|
||||
osgPrim = visitLOD(osgParent, (LodRecord*)child);
|
||||
break;
|
||||
@@ -469,6 +479,33 @@ void ConvertFromFLT::visitColorPalette(osg::Group& , ColorPaletteRecord* rec)
|
||||
}
|
||||
}
|
||||
|
||||
/*osgParent*/
|
||||
void ConvertFromFLT::visitLightSourcePalette(osg::Group& , LightSourcePaletteRecord* rec)
|
||||
{
|
||||
|
||||
SLightSourcePalette* pLight = (SLightSourcePalette*)rec->getData();
|
||||
|
||||
osg::Light* light = new osg::Light();
|
||||
|
||||
light->setAmbient( osg::Vec4(
|
||||
pLight->sfAmbientRGBA[0], pLight->sfAmbientRGBA[1],
|
||||
pLight->sfAmbientRGBA[2], pLight->sfAmbientRGBA[3] ) );
|
||||
light->setDiffuse( osg::Vec4(
|
||||
pLight->sfDiffuseRGBA[0], pLight->sfDiffuseRGBA[1],
|
||||
pLight->sfDiffuseRGBA[2], pLight->sfDiffuseRGBA[3] ) );
|
||||
light->setSpecular( osg::Vec4(
|
||||
pLight->sfSpecularRGBA[0], pLight->sfSpecularRGBA[1],
|
||||
pLight->sfSpecularRGBA[2], pLight->sfSpecularRGBA[3] ) );
|
||||
light->setConstantAttenuation( pLight->sfConstantAttuenation );
|
||||
light->setLinearAttenuation( pLight->sfLinearAttuenation );
|
||||
light->setQuadraticAttenuation( pLight->sfQuadraticAttuenation );
|
||||
//light->setSpotExponent( pLight->sfDropoff );
|
||||
//light->setSpotCutoff( pLight->sfCutoff );
|
||||
|
||||
LightPool* pLightPool = rec->getFltFile()->getLightPool();
|
||||
pLightPool->addLight( pLight->diIndex, light );
|
||||
}
|
||||
|
||||
/*osgParent*/
|
||||
void ConvertFromFLT::visitMaterialPalette(osg::Group&, MaterialPaletteRecord* rec)
|
||||
{
|
||||
@@ -623,6 +660,49 @@ osg::Group* ConvertFromFLT::visitGroup(osg::Group& osgParent, GroupRecord* rec)
|
||||
}
|
||||
}
|
||||
|
||||
osg::Group* ConvertFromFLT::visitLightSource(osg::Group& osgParent, LightSourceRecord* rec)
|
||||
{
|
||||
|
||||
static int lightnum = 0;
|
||||
|
||||
LightPool* pLightPool = rec->getFltFile()->getLightPool();
|
||||
SLightSource* pLSource = (SLightSource*) rec->getData();
|
||||
|
||||
/*
|
||||
if ( !(pLSource->dwFlags & 1) ) { // enabled
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
osg::LightSource* lightSource = new osg::LightSource();
|
||||
|
||||
osg::Light* pLight = pLightPool->getLight( pLSource->diIndex );
|
||||
osg::Light* light = new osg::Light( *pLight );
|
||||
|
||||
light->setPosition( osg::Vec4(
|
||||
pLSource->Coord.x(), pLSource->Coord.y(),
|
||||
pLSource->Coord.z(), 1 ) );
|
||||
light->setLightNum( lightnum );
|
||||
|
||||
lightSource->setLight( light );
|
||||
lightSource->setLocalStateSetModes( osg::StateAttribute::ON );
|
||||
osg::Node* node = &osgParent;
|
||||
if ( 1 ) { //pLSource->dwFlags & 2 ) { // global
|
||||
while ( !node->getParents().empty() ) {
|
||||
node = *(node->getParents().begin());
|
||||
}
|
||||
}
|
||||
lightSource->setStateSetModes( *(node->getOrCreateStateSet()),
|
||||
osg::StateAttribute::ON );
|
||||
|
||||
lightnum++;
|
||||
|
||||
osgParent.addChild( lightSource );
|
||||
visitPrimaryNode(*lightSource, rec);
|
||||
|
||||
return lightSource;
|
||||
}
|
||||
|
||||
osg::Group* ConvertFromFLT::visitRoadConstruction(osg::Group& osgParent, GroupRecord* rec)
|
||||
{
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
@@ -55,6 +55,8 @@ class InstanceDefinitionRecord;
|
||||
class InstanceReferenceRecord;
|
||||
class MultiTextureRecord;
|
||||
class UVListRecord;
|
||||
class LightSourceRecord;
|
||||
class LightSourcePaletteRecord;
|
||||
struct SFace;
|
||||
|
||||
//class GeoSetBuilder;
|
||||
@@ -124,6 +126,7 @@ class ConvertFromFLT
|
||||
|
||||
// Palette records
|
||||
void visitColorPalette(osg::Group& osgParent, ColorPaletteRecord* rec);
|
||||
void visitLightSourcePalette(osg::Group& osgParent, LightSourcePaletteRecord* rec);
|
||||
void visitMaterialPalette(osg::Group& osgParent, MaterialPaletteRecord* rec);
|
||||
void visitOldMaterialPalette(osg::Group& osgParent, OldMaterialPaletteRecord* rec);
|
||||
void visitTexturePalette(osg::Group& osgParent, TexturePaletteRecord* rec);
|
||||
@@ -136,6 +139,7 @@ class ConvertFromFLT
|
||||
// Primary records
|
||||
osg::Group* visitHeader(HeaderRecord* rec);
|
||||
osg::Group* visitGroup(osg::Group& osgParent, GroupRecord* rec);
|
||||
osg::Group* visitLightSource(osg::Group& osgParent, LightSourceRecord* rec);
|
||||
osg::Group* visitRoadConstruction(osg::Group& osgParent, GroupRecord* rec);
|
||||
osg::Group* visitLOD(osg::Group& osgParent, LodRecord* rec);
|
||||
osg::Group* visitOldLOD(osg::Group& osgParent, OldLodRecord* rec);
|
||||
|
||||
Reference in New Issue
Block a user