From Julia Oritz Rojas, support for detail textures.
This commit is contained in:
parent
46c5eec0d0
commit
aca924113f
51
src/osgPlugins/flt/AttrData.h
Normal file
51
src/osgPlugins/flt/AttrData.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef __ATTR_DATA_H
|
||||
#define __ATTR_DATA_H
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Referenced>
|
||||
|
||||
// Detail Texture as defined in Creator v2.5.1 got lot's of parameters that I don't know
|
||||
// how they work, so I have implemented only the things I need, and if someone needs
|
||||
// something else it's posible to use other parameters using the new flt::AttrData class
|
||||
// Now the implemented parameters are:
|
||||
// - txDetail_m, txDetail_n : Control how new texcoord will be generated.
|
||||
// - modulateDetail : If set to true, be use scale_rgb and scale_alpha values from
|
||||
// osg::TexEnvCombine to make a lighted image.
|
||||
//
|
||||
// I implement detail texture as a new TexEnvCombine attribute in texture unit 1
|
||||
// that is added to the stateset of the geometry.
|
||||
//
|
||||
// flt::AttrData class is used to store Texture Attribute Data as defined in Creator
|
||||
// so we can pass this info to others loader object an use it where needed.
|
||||
//
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
namespace flt {
|
||||
|
||||
typedef signed long int32;
|
||||
|
||||
class AttrData : public osg::Object {
|
||||
public:
|
||||
osg::StateSet *stateset;
|
||||
|
||||
int32 useDetail; // TRUE if using next 5 integers for detail texture
|
||||
int32 txDetail_j; // J argument for TX_DETAIL
|
||||
int32 txDetail_k; // K argument for TX_DETAIL
|
||||
int32 txDetail_m; // M argument for TX_DETAIL
|
||||
int32 txDetail_n; // N argument for TX_DETAIL
|
||||
int32 txDetail_s; // Scramble argument for TX_DETAIL
|
||||
bool modulateDetail; // True if Magnification filter type is MODULATE_DETAIL
|
||||
AttrData() {};
|
||||
AttrData(const AttrData& attr,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):Object(attr,copyop) {};
|
||||
virtual osg::Object* cloneType() const { return new AttrData(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AttrData(*this,copyop); }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "AttrData"; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __ATTR_DATA_H
|
@ -2,50 +2,50 @@ TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
BoundingVolumeRecords.cpp\
|
||||
LongIDRecord.cpp\
|
||||
ColorPaletteRecord.cpp\
|
||||
MaterialPaletteRecord.cpp\
|
||||
CommentRecord.cpp\
|
||||
ObjectRecord.cpp\
|
||||
ControlRecord.cpp\
|
||||
OldVertexRecords.cpp\
|
||||
OldMaterialPaletteRecord.cpp\
|
||||
DofRecord.cpp\
|
||||
ExtensionRecord.cpp\
|
||||
ExternalRecord.cpp\
|
||||
Record.cpp\
|
||||
FaceRecord.cpp\
|
||||
LocalVertexPoolRecord.cpp\
|
||||
MeshPrimitiveRecord.cpp\
|
||||
MeshRecord.cpp\
|
||||
RecordVisitor.cpp\
|
||||
RoadRecords.cpp\
|
||||
GeoSetBuilder.cpp\
|
||||
Registry.cpp\
|
||||
FltFile.cpp\
|
||||
GroupRecord.cpp\
|
||||
SwitchRecord.cpp\
|
||||
HeaderRecord.cpp\
|
||||
TexturePaletteRecord.cpp\
|
||||
Input.cpp\
|
||||
TransformationRecords.cpp\
|
||||
InstanceRecords.cpp\
|
||||
UnknownRecord.cpp\
|
||||
LightPointRecord.cpp\
|
||||
VertexPoolRecords.cpp\
|
||||
LightSourcePaletteRecord.cpp\
|
||||
flt.cpp\
|
||||
LightSourceRecord.cpp\
|
||||
flt2osg.cpp\
|
||||
LodRecord.cpp\
|
||||
Pool.cpp\
|
||||
TextureMappingPaletteRecord.cpp\
|
||||
ReaderWriterFLT.cpp\
|
||||
ReaderWriterATTR.cpp\
|
||||
MultiTextureRecord.cpp\
|
||||
UVListRecord.cpp\
|
||||
# PointLight.cpp\
|
||||
BoundingVolumeRecords.cpp\
|
||||
LongIDRecord.cpp\
|
||||
ColorPaletteRecord.cpp\
|
||||
MaterialPaletteRecord.cpp\
|
||||
CommentRecord.cpp\
|
||||
ObjectRecord.cpp\
|
||||
ControlRecord.cpp\
|
||||
OldVertexRecords.cpp\
|
||||
OldMaterialPaletteRecord.cpp\
|
||||
DofRecord.cpp\
|
||||
ExtensionRecord.cpp\
|
||||
ExternalRecord.cpp\
|
||||
Record.cpp\
|
||||
FaceRecord.cpp\
|
||||
LocalVertexPoolRecord.cpp\
|
||||
MeshPrimitiveRecord.cpp\
|
||||
MeshRecord.cpp\
|
||||
RecordVisitor.cpp\
|
||||
RoadRecords.cpp\
|
||||
GeoSetBuilder.cpp\
|
||||
Registry.cpp\
|
||||
FltFile.cpp\
|
||||
GroupRecord.cpp\
|
||||
SwitchRecord.cpp\
|
||||
HeaderRecord.cpp\
|
||||
TexturePaletteRecord.cpp\
|
||||
Input.cpp\
|
||||
TransformationRecords.cpp\
|
||||
InstanceRecords.cpp\
|
||||
UnknownRecord.cpp\
|
||||
LightPointRecord.cpp\
|
||||
VertexPoolRecords.cpp\
|
||||
LightSourcePaletteRecord.cpp\
|
||||
flt.cpp\
|
||||
LightSourceRecord.cpp\
|
||||
flt2osg.cpp\
|
||||
LodRecord.cpp\
|
||||
Pool.cpp\
|
||||
TextureMappingPaletteRecord.cpp\
|
||||
ReaderWriterFLT.cpp\
|
||||
ReaderWriterATTR.cpp\
|
||||
MultiTextureRecord.cpp\
|
||||
UVListRecord.cpp\
|
||||
# PointLight.cpp\
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
// GeoSetBuilder.cpp
|
||||
|
||||
// Modify DynGeoSet::addToGeometry to generate texture coordinates for texture unit 1
|
||||
// that is used to detail texture
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
@ -9,6 +13,7 @@
|
||||
#include "Pool.h"
|
||||
#include "opcodes.h"
|
||||
#include "GeoSetBuilder.h"
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/LOD>
|
||||
@ -159,6 +164,24 @@ void DynGeoSet::addToGeometry(osg::Geometry* geom)
|
||||
{
|
||||
texcoords = new osg::Vec2Array(_tcoordList.begin(),_tcoordList.end());
|
||||
geom->setTexCoordArray(0,texcoords);
|
||||
|
||||
// If we got detail texture defined for this geometry, we need to setup new texcoord
|
||||
// related on base texture ones. Using txDetail_m and txDetail_n values we read in
|
||||
// ReaderWriterATTR and we got in AttrData class.
|
||||
//
|
||||
// We apply those values multiplying original texcoord.x by txDetail_m and texcoord.y
|
||||
// by txDetail_n to get detail texture repeated.
|
||||
//
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
if (_attrdata != NULL ) {
|
||||
osg::Vec2Array *texcoords2 = new osg::Vec2Array(_tcoordList.begin(),_tcoordList.end());
|
||||
for(unsigned int index=0;index<texcoords2->size();index++) {
|
||||
(*texcoords2)[index][0]=(*texcoords)[index][0]*_attrdata->txDetail_m;
|
||||
(*texcoords2)[index][1]=(*texcoords)[index][1]*_attrdata->txDetail_n;
|
||||
}
|
||||
geom->setTexCoordArray(1,texcoords2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,13 +266,13 @@ osg::Geode* GeoSetBuilder::createOsgGeoSets(osg::Geode* geode)
|
||||
itr!=_dynGeoSetList.end();
|
||||
++itr)
|
||||
{
|
||||
DynGeoSet* dgset = itr->get();
|
||||
osg::Geometry* geom = dgset->getGeometry();
|
||||
DynGeoSet* dgset = itr->get();
|
||||
osg::Geometry* geom = dgset->getGeometry();
|
||||
geode->addDrawable(geom);
|
||||
dgset->addToGeometry(geom);
|
||||
|
||||
osg::StateSet* stateset = dgset->getStateSet();
|
||||
assert( stateset == geom->getStateSet() );
|
||||
osg::StateSet* stateset = dgset->getStateSet();
|
||||
assert( stateset == geom->getStateSet() );
|
||||
}
|
||||
|
||||
osgUtil::Tesselator tesselator;
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef __FLT_GEOSETBUILDER_H
|
||||
#define __FLT_GEOSETBUILDER_H
|
||||
|
||||
// Added DynGeoSet::setDetailTextureAttrData that is used to store texture Attributes
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
@ -10,6 +13,8 @@
|
||||
#include <osg/Material>
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
@ -97,9 +102,9 @@ class DynGeoSet : public osg::Referenced
|
||||
bool operator != (const DynGeoSet& rhs) const { return compare(rhs)!=0; }
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) {
|
||||
_stateset = stateset;
|
||||
_geom->setStateSet( stateset );
|
||||
}
|
||||
_stateset = stateset;
|
||||
_geom->setStateSet( stateset );
|
||||
}
|
||||
osg::StateSet* getStateSet() { return _stateset.get(); }
|
||||
const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
||||
|
||||
@ -130,8 +135,9 @@ class DynGeoSet : public osg::Referenced
|
||||
inline const int normalListSize() const { return _normalList.size(); }
|
||||
inline const int colorListSize() const { return _colorList.size(); }
|
||||
inline const int tcoordListSize() const { return _tcoordList.size(); }
|
||||
inline void setDetailTextureAttrData(AttrData *attrdata) {_attrdata=attrdata; }
|
||||
|
||||
osg::Geometry* getGeometry() {
|
||||
osg::Geometry* getGeometry() {
|
||||
CERR << "_geom.get(): " << _geom.get()
|
||||
<< "; referenceCount: " << _geom.get()->referenceCount()<<"\n";
|
||||
return _geom.get();
|
||||
@ -163,6 +169,8 @@ class DynGeoSet : public osg::Referenced
|
||||
|
||||
osg::Geometry::AttributeBinding _texture_binding;
|
||||
TcoordList _tcoordList;
|
||||
|
||||
AttrData *_attrdata;
|
||||
};
|
||||
|
||||
|
||||
|
@ -37,12 +37,12 @@ class GroupRecord : public PrimNodeRecord
|
||||
{
|
||||
public:
|
||||
|
||||
enum FlagBit {
|
||||
FORWARD_ANIM = 0x40000000,
|
||||
SWING_ANIM = 0x20000000,
|
||||
BOUND_BOX_FOLLOW = 0x10000000,
|
||||
FREEZE_BOUND_BOX = 0x08000000,
|
||||
DEFAULT_PARENT = 0x04000000
|
||||
enum FlagBit {
|
||||
FORWARD_ANIM = 0x40000000,
|
||||
SWING_ANIM = 0x20000000,
|
||||
BOUND_BOX_FOLLOW = 0x10000000,
|
||||
FREEZE_BOUND_BOX = 0x08000000,
|
||||
DEFAULT_PARENT = 0x04000000
|
||||
};
|
||||
|
||||
GroupRecord();
|
||||
|
@ -17,10 +17,10 @@ struct STextureLayer {
|
||||
uint16 mapping;
|
||||
uint16 data;
|
||||
void endian() {
|
||||
ENDIAN( texture );
|
||||
ENDIAN( effect );
|
||||
ENDIAN( mapping );
|
||||
ENDIAN( data );
|
||||
ENDIAN( texture );
|
||||
ENDIAN( effect );
|
||||
ENDIAN( mapping );
|
||||
ENDIAN( data );
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
// Pool.cpp
|
||||
|
||||
// Modify TexturePool to store a flt::AttrData object instead of a osg::StateSet
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
@ -15,6 +18,7 @@
|
||||
#include "OldMaterialPaletteRecord.h"
|
||||
#include "Pool.h"
|
||||
#include "Registry.h"
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -109,7 +113,7 @@ ColorPool::ColorName* ColorPool::getColorName(int nIndex)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
osg::StateSet* TexturePool::getTexture(int nIndex, int fltVersion)
|
||||
flt::AttrData* TexturePool::getTexture(int nIndex, int fltVersion)
|
||||
{
|
||||
TexturePaletteMap::iterator fitr = _textureMap.find(nIndex);
|
||||
if (fitr != _textureMap.end())
|
||||
@ -126,13 +130,13 @@ osg::StateSet* TexturePool::getTexture(int nIndex, int fltVersion)
|
||||
const std::string& textureName = (*nitr).second;
|
||||
|
||||
// Valid index, find the texture
|
||||
// Get StateSet containing texture from registry pool.
|
||||
osg::StateSet* textureStateSet = Registry::instance()->getTexture(textureName);
|
||||
// Get AttrData containing texture from registry pool.
|
||||
flt::AttrData* textureAttrData = Registry::instance()->getTexture(textureName);
|
||||
|
||||
if (textureStateSet)
|
||||
if (textureAttrData)
|
||||
{
|
||||
// Add texture to local pool to be ab121le to get by index.
|
||||
addTexture(nIndex, textureStateSet);
|
||||
addTexture(nIndex, textureAttrData);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -152,29 +156,30 @@ osg::StateSet* TexturePool::getTexture(int nIndex, int fltVersion)
|
||||
sprintf(options,"FLT_VER %d",fltVersion);
|
||||
|
||||
osgDB::Registry::instance()->setOptions(new osgDB::ReaderWriter::Options(options));
|
||||
textureStateSet = dynamic_cast<osg::StateSet*>(osgDB::readObjectFile(attrName));
|
||||
textureAttrData = dynamic_cast<flt::AttrData*>(osgDB::readObjectFile(attrName));
|
||||
osgDB::Registry::instance()->setOptions(NULL); // Delete options
|
||||
|
||||
// if not found create default StateSet
|
||||
if (textureStateSet == NULL)
|
||||
// if not found create default StateSet for the AttrData
|
||||
if (textureAttrData == NULL)
|
||||
{
|
||||
textureStateSet = new osg::StateSet;
|
||||
textureAttrData = new flt::AttrData;
|
||||
textureAttrData->stateset = new osg::StateSet;
|
||||
|
||||
osg::Texture2D* osgTexture = new osg::Texture2D;
|
||||
osgTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
|
||||
osgTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
|
||||
textureStateSet->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
|
||||
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
|
||||
|
||||
osg::TexEnv* osgTexEnv = new osg::TexEnv;
|
||||
osgTexEnv->setMode(osg::TexEnv::MODULATE);
|
||||
textureStateSet->setTextureAttribute( unit, osgTexEnv );
|
||||
textureAttrData->stateset->setTextureAttribute( unit, osgTexEnv );
|
||||
}
|
||||
|
||||
osg::Texture2D *osgTexture = dynamic_cast<osg::Texture2D*>(textureStateSet->getTextureAttribute( unit, osg::StateAttribute::TEXTURE));
|
||||
osg::Texture2D *osgTexture = dynamic_cast<osg::Texture2D*>(textureAttrData->stateset->getTextureAttribute( unit, osg::StateAttribute::TEXTURE));
|
||||
if (osgTexture == NULL)
|
||||
{
|
||||
osgTexture = new osg::Texture2D;
|
||||
textureStateSet->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
|
||||
textureAttrData->stateset->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osgTexture->setImage(image.get());
|
||||
@ -182,23 +187,24 @@ osg::StateSet* TexturePool::getTexture(int nIndex, int fltVersion)
|
||||
}
|
||||
else
|
||||
{
|
||||
// invalid image file, register an empty state set
|
||||
textureStateSet = new osg::StateSet;
|
||||
// invalid image file, register an empty state set AttrData
|
||||
textureAttrData = new flt::AttrData;
|
||||
textureAttrData->stateset = new osg::StateSet;
|
||||
}
|
||||
|
||||
// Add new texture to registry pool
|
||||
// ( umm... should this have reference to the texture unit? RO. July2002)
|
||||
Registry::instance()->addTexture(textureName, textureStateSet);
|
||||
Registry::instance()->addTexture(textureName, textureAttrData);
|
||||
|
||||
// Also add to local pool to be able to get texture by index.
|
||||
// ( umm... should this have reference to the texture unit? RO. July2002)
|
||||
addTexture(nIndex, textureStateSet);
|
||||
addTexture(nIndex, textureAttrData);
|
||||
|
||||
CERR<<"Registry::instance()->addTexture("<<textureName<<", "<<textureStateSet<<")"<<std::endl;
|
||||
CERR<<"pTexturePool->addTexture("<<nIndex<<", "<<textureStateSet<<")"<<std::endl;
|
||||
CERR<<"Registry::instance()->addTexture("<<textureName<<", "<<textureAttrData<<")"<<std::endl;
|
||||
CERR<<"pTexturePool->addTexture("<<nIndex<<", "<<textureAttrData<<")"<<std::endl;
|
||||
}
|
||||
|
||||
return textureStateSet;
|
||||
return textureAttrData;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@ -214,9 +220,9 @@ std::string* TexturePool::getTextureName(int nIndex)
|
||||
}
|
||||
|
||||
|
||||
void TexturePool::addTexture(int nIndex, osg::StateSet* stateset)
|
||||
void TexturePool::addTexture(int nIndex, flt::AttrData* attrdata)
|
||||
{
|
||||
_textureMap[nIndex] = stateset;
|
||||
_textureMap[nIndex] = attrdata;
|
||||
}
|
||||
|
||||
void TexturePool::addTextureName(int nIndex, const std::string& name)
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef __FLT_POOL_H
|
||||
#define __FLT_POOL_H
|
||||
|
||||
// Modify TexturePool to store a flt::AttrData object instead of a osg::StateSet
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#include "flt.h"
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
@ -11,6 +14,8 @@
|
||||
#include <osg/Light>
|
||||
#include <osg/Group>
|
||||
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
@ -60,9 +65,9 @@ class TexturePool : public osg::Referenced
|
||||
|
||||
TexturePool() {}
|
||||
|
||||
osg::StateSet* getTexture(int nIndex, int fltVersion);
|
||||
std::string* getTextureName(int nIndex);
|
||||
void addTexture(int nIndex, osg::StateSet* stateset);
|
||||
flt::AttrData* getTexture(int nIndex, int fltVersion);
|
||||
std::string* getTextureName(int nIndex);
|
||||
void addTexture(int nIndex, flt::AttrData* attrdata);
|
||||
void addTextureName(int nIndex, const std::string& name);
|
||||
|
||||
protected :
|
||||
@ -71,7 +76,7 @@ class TexturePool : public osg::Referenced
|
||||
|
||||
private :
|
||||
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateSet> > TexturePaletteMap;
|
||||
typedef std::map<int,osg::ref_ptr<flt::AttrData> > TexturePaletteMap;
|
||||
TexturePaletteMap _textureMap;
|
||||
typedef std::map<int,std::string > TextureNameMap;
|
||||
TextureNameMap _textureNameMap;
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "AttrData.h"
|
||||
|
||||
typedef signed char int8;
|
||||
typedef unsigned char uint8;
|
||||
typedef signed short int16;
|
||||
@ -92,7 +94,6 @@ static void endian2(void* pSrc, int nSrc, void* pDst)
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
class Attr
|
||||
{
|
||||
public :
|
||||
@ -159,7 +160,7 @@ class Attr
|
||||
void init();
|
||||
void readField(std::ifstream& file, void* buf, size_t size);
|
||||
bool readAttrFile(const char* szName);
|
||||
StateSet* createOsgStateSet();
|
||||
flt::AttrData* createOsgStateSet();
|
||||
|
||||
|
||||
|
||||
@ -466,7 +467,7 @@ bool Attr::readAttrFile(const char* szName)
|
||||
int n;
|
||||
std::ifstream file;
|
||||
|
||||
file.open (szName, std::ios::in | std::ios::binary);
|
||||
file.open (szName, std::ios::in | std::ios::binary);
|
||||
|
||||
READ( texels_u );
|
||||
READ( textel_v );
|
||||
@ -527,9 +528,17 @@ bool Attr::readAttrFile(const char* szName)
|
||||
READ( lambertUpperLat );
|
||||
READ( lambertlowerLat );
|
||||
READ( reserved3 );
|
||||
|
||||
for (n=0; n<5; n++) {
|
||||
READ(spare2[n]); }
|
||||
READ( useDetail );
|
||||
|
||||
// I don't know why I get a 4 bytes displacement before reading Detail Texture parameters
|
||||
// My ATTR files have been created with Creator 2.5.1
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
int32 dummyAjust;
|
||||
READ( dummyAjust);
|
||||
|
||||
READ( useDetail );
|
||||
READ( txDetail_j );
|
||||
READ( txDetail_k );
|
||||
READ( txDetail_m );
|
||||
@ -569,11 +578,11 @@ bool Attr::readAttrFile(const char* szName)
|
||||
}
|
||||
|
||||
|
||||
StateSet* Attr::createOsgStateSet()
|
||||
{
|
||||
StateSet* osgStateSet = new StateSet;
|
||||
flt::AttrData* Attr::createOsgStateSet()
|
||||
{
|
||||
TexEnv* osgTexEnv = new TexEnv;
|
||||
Texture2D* osgTexture = new Texture2D;
|
||||
flt::AttrData* attrdata = new flt::AttrData;
|
||||
|
||||
if ((wrapMode_u != WRAP_CLAMP) && ((wrapMode_u != WRAP_REPEAT)))
|
||||
wrapMode_u = wrapMode;
|
||||
@ -707,10 +716,25 @@ StateSet* Attr::createOsgStateSet()
|
||||
// encapsulate ATTR files. Need to speak to Brede about this issue.
|
||||
// Robert Osfield, July 9th 2002.
|
||||
|
||||
osgStateSet->setTextureAttribute( 0, osgTexEnv );
|
||||
osgStateSet->setTextureAttributeAndModes( 0, osgTexture, StateAttribute::ON );
|
||||
|
||||
return osgStateSet;
|
||||
// This is now a bit diferrent. We create a new AttrData object, and StateSet object
|
||||
// is instead with attribute information needed to setup detail texutre
|
||||
//
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
attrdata->stateset = new StateSet;
|
||||
attrdata->stateset->setTextureAttribute( 0, osgTexEnv );
|
||||
attrdata->stateset->setTextureAttributeAndModes( 0, osgTexture, StateAttribute::ON );
|
||||
attrdata->useDetail = useDetail;
|
||||
attrdata->txDetail_j = txDetail_j;
|
||||
attrdata->txDetail_k = txDetail_k;
|
||||
attrdata->txDetail_m = txDetail_m;
|
||||
attrdata->txDetail_n = txDetail_n;
|
||||
attrdata->txDetail_s = txDetail_s;
|
||||
if (magFilterMode == MAG_FILTER_MODULATE_DETAIL)
|
||||
attrdata->modulateDetail = true;
|
||||
else
|
||||
attrdata->modulateDetail = false;
|
||||
|
||||
return attrdata;
|
||||
}
|
||||
|
||||
|
||||
@ -749,10 +773,12 @@ class ReaderWriterATTR : public osgDB::ReaderWriter
|
||||
return "Unable to open \""+fileName+"\"";
|
||||
}
|
||||
|
||||
StateSet* stateset = attr.createOsgStateSet();
|
||||
//StateSet* stateset = attr.createOsgStateSet();
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
flt::AttrData* attrdata = attr.createOsgStateSet();
|
||||
|
||||
notify(INFO) << "texture attribute read ok" << std::endl;
|
||||
return stateset;
|
||||
return attrdata;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -256,21 +256,21 @@ bool PrimNodeRecord::readLocalData(Input& fr)
|
||||
while (pRec && pRec->isAncillaryRecord())
|
||||
{
|
||||
addChild(pRec);
|
||||
if ( pRec->getOpcode() == 52 ) {
|
||||
CERR << "Multitexture added to " << this << "(opcode: "
|
||||
<< getOpcode() << ")\n";
|
||||
}
|
||||
if ( pRec->getOpcode() == 53 ) {
|
||||
CERR << "UV list added to " << this << "(opcode: "
|
||||
<< getOpcode() << ")\n";
|
||||
UVListRecord* mtr =
|
||||
dynamic_cast<UVListRecord*>(pRec);
|
||||
assert( mtr );
|
||||
assert( mtr->isAncillaryRecord() );
|
||||
SUVList* mt =
|
||||
reinterpret_cast<SUVList*>(mtr->getData());
|
||||
assert( mt );
|
||||
}
|
||||
if ( pRec->getOpcode() == 52 ) {
|
||||
CERR << "Multitexture added to " << this << "(opcode: "
|
||||
<< getOpcode() << ")\n";
|
||||
}
|
||||
if ( pRec->getOpcode() == 53 ) {
|
||||
CERR << "UV list added to " << this << "(opcode: "
|
||||
<< getOpcode() << ")\n";
|
||||
UVListRecord* mtr =
|
||||
dynamic_cast<UVListRecord*>(pRec);
|
||||
assert( mtr );
|
||||
assert( mtr->isAncillaryRecord() );
|
||||
SUVList* mt =
|
||||
reinterpret_cast<SUVList*>(mtr->getData());
|
||||
assert( mt );
|
||||
}
|
||||
pRec = readRecord(fr);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
;
|
||||
// Modify Registry to store a flt::AttrData object instead of a osg::StateSet
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
@ -9,6 +12,7 @@
|
||||
#include "Record.h"
|
||||
#include "Input.h"
|
||||
#include "FltFile.h"
|
||||
#include "AttrData.h"
|
||||
#include "Registry.h"
|
||||
|
||||
using namespace flt;
|
||||
@ -37,7 +41,7 @@ Record* Registry::getPrototype(const int opcode)
|
||||
return (*itr).second.get();
|
||||
}
|
||||
osg::notify( osg::INFO )
|
||||
<< "flt::Registry::getPrototype: Unkown opcode: " << opcode << "\n";
|
||||
<< "flt::Registry::getPrototype: Unkown opcode: " << opcode << "\n";
|
||||
|
||||
return NULL;
|
||||
|
||||
@ -47,14 +51,14 @@ Record* Registry::getPrototype(const int opcode)
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void Registry::addTexture(const std::string& name, osg::StateSet* texture)
|
||||
void Registry::addTexture(const std::string& name, AttrData* texture)
|
||||
{
|
||||
if (texture == NULL) return;
|
||||
_textureMap[name] = texture;
|
||||
}
|
||||
|
||||
|
||||
osg::StateSet* Registry::getTexture(const std::string name)
|
||||
AttrData* Registry::getTexture(const std::string name)
|
||||
{
|
||||
TextureMap::iterator itr = _textureMap.find(name);
|
||||
if (itr != _textureMap.end())
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Modify Registry to store a flt::AttrData object instead of a osg::StateSet
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
#ifndef __FLT_REGISTRY_H
|
||||
#define __FLT_REGISTRY_H
|
||||
|
||||
@ -10,6 +13,7 @@
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include "FltFile.h"
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -47,8 +51,10 @@ class Registry
|
||||
void addPrototype(Record* rec);
|
||||
Record* getPrototype(const int opcode);
|
||||
|
||||
void addTexture(const std::string& name, osg::StateSet* texture);
|
||||
osg::StateSet* getTexture(const std::string name);
|
||||
//void addTexture(const std::string& name, osg::StateSet* texture);
|
||||
void addTexture(const std::string& name, AttrData* texture);
|
||||
//osg::StateSet* getTexture(const std::string name);
|
||||
AttrData * getTexture(const std::string name);
|
||||
|
||||
void addFltFile(const std::string& name, FltFile* file);
|
||||
FltFile* getFltFile(const std::string& name);
|
||||
@ -60,7 +66,8 @@ class Registry
|
||||
private:
|
||||
|
||||
typedef std::map<int, osg::ref_ptr<Record> > RecordProtoMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > TextureMap;
|
||||
//typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > TextureMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<AttrData> > TextureMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<FltFile> > FltFileMap;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<Record> > RecordsForFutureDeleteList;
|
||||
|
@ -14,7 +14,7 @@ namespace flt {
|
||||
struct SVertexUV {
|
||||
float32x2 coords;
|
||||
void endian() {
|
||||
ENDIAN( coords );
|
||||
ENDIAN( coords );
|
||||
};
|
||||
};
|
||||
|
||||
@ -22,8 +22,8 @@ struct SMorphUV {
|
||||
float32x2 coords0;
|
||||
float32x2 coords100;
|
||||
void endian() {
|
||||
ENDIAN( coords0 );
|
||||
ENDIAN( coords100 );
|
||||
ENDIAN( coords0 );
|
||||
ENDIAN( coords100 );
|
||||
};
|
||||
};
|
||||
|
||||
@ -33,8 +33,8 @@ struct SUVList
|
||||
uint32 layers;
|
||||
|
||||
union {
|
||||
SVertexUV vertex[1];
|
||||
SMorphUV morph[1];
|
||||
SVertexUV vertex[1];
|
||||
SMorphUV morph[1];
|
||||
} coords;
|
||||
};
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
#endif
|
||||
|
||||
#include <osg/Notify>
|
||||
#define CERR osg::notify( osg::INFO ) << __FILE__ << ":" << __LINE__ << ": "
|
||||
#define CERR2 osg::notify( osg::NOTICE )<< __FILE__ << ":" << __LINE__ << ": "
|
||||
#define CERR osg::notify( osg::INFO ) << __FILE__ << ":" << __LINE__ << ": "
|
||||
#define CERR2 osg::notify( osg::NOTICE )<< __FILE__ << ":" << __LINE__ << ": "
|
||||
|
||||
namespace flt {
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Modify ConvertFromFLT::setTexture to create a new osg::TexEnvCombiner in texture stateset to handle
|
||||
// detail texture
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <osg/GL>
|
||||
@ -10,6 +15,7 @@
|
||||
#include <osg/StateSet>
|
||||
#include <osg/CullFace>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/TexEnvCombine>
|
||||
#include <osg/TexGen>
|
||||
#include <osg/AlphaFunc>
|
||||
#include <osg/BlendFunc>
|
||||
@ -66,6 +72,7 @@
|
||||
#include "UVListRecord.h"
|
||||
#include "LightSourceRecord.h"
|
||||
#include "LightSourcePaletteRecord.h"
|
||||
#include "AttrData.h"
|
||||
|
||||
|
||||
|
||||
@ -321,7 +328,7 @@ osg::Group* ConvertFromFLT::visitPrimaryNode(osg::Group& osgParent, PrimNodeReco
|
||||
|
||||
if( !geoSetBuilder.empty() )
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geoSetBuilder.createOsgGeoSets(geode );
|
||||
|
||||
if (geode->getNumDrawables() > 0)
|
||||
@ -1267,11 +1274,52 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet
|
||||
if (pTexturePool)
|
||||
{
|
||||
int nIndex = (int)pSFace->iTexturePattern;
|
||||
osg::StateSet *textureStateSet = pTexturePool->getTexture(nIndex,rec->getFlightVersion());
|
||||
flt::AttrData *textureAttrData = pTexturePool->getTexture(nIndex,rec->getFlightVersion());
|
||||
|
||||
osg::StateSet *textureStateSet;
|
||||
if (textureAttrData)
|
||||
textureStateSet = textureAttrData->stateset;
|
||||
else
|
||||
textureStateSet = NULL;
|
||||
|
||||
if (textureStateSet)
|
||||
{
|
||||
//We got detail texture, so we got detailTexture stateset and add a TexEnvCombine attribute
|
||||
// To add simple detail texture we just use texture unit 1 to store detail
|
||||
//As Creators help says, if Mag. Filter General is set to Modulate Detail we just
|
||||
//add the detail, but if it set to Add Detail then we got a lighter image, so we
|
||||
//use scale_rgb and scale_alpha of osg::TexEnvCombine to make this effect
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
|
||||
flt::AttrData *detailTextureAttrData;
|
||||
if (pSFace->iDetailTexturePattern != -1) {
|
||||
int nIndex2 = (int)pSFace->iDetailTexturePattern;
|
||||
detailTextureAttrData = pTexturePool->getTexture(nIndex2,rec->getFlightVersion());
|
||||
if (detailTextureAttrData && detailTextureAttrData->stateset) {
|
||||
osg::Texture2D *detTexture = dynamic_cast<osg::Texture2D*>(detailTextureAttrData->stateset->getTextureAttribute( 0, osg::StateAttribute::TEXTURE));
|
||||
textureStateSet->setTextureAttributeAndModes(1,detTexture,osg::StateAttribute::ON);
|
||||
osg::TexEnvCombine *tec1 = new osg::TexEnvCombine;
|
||||
float scale = (detailTextureAttrData->modulateDetail==0)?2.0f:4.0f;
|
||||
tec1->setScale_RGB(scale);
|
||||
tec1->setScale_Alpha(scale);
|
||||
textureStateSet->setTextureAttribute( 1, tec1,osg::StateAttribute::ON );
|
||||
}
|
||||
}
|
||||
|
||||
//Now, an ugly thing,... we have detected that in Creator we defined that a texture will we used as
|
||||
//detail texture, and we load it as it using texture unit 1,... but we also need to create texture
|
||||
//coordinates to map this detail texture, I found that texture coordinates assigment is made in
|
||||
//DynGeoSet::addToGeometry and the easy way I found to create those new coordinates is to add a method
|
||||
//to DynGeoSet class named setDetailTextureStatus that pass detail Texture AttrData class, so when
|
||||
//DynGeoSet::addToGeometry runs it reads this class and create new texture coordinates if we got a valid
|
||||
//AttrData object. I now this is not a good way to do it, and I expect someone with more osg knowledge
|
||||
//could make it in a better way.
|
||||
// Julian Ortiz, June 18th 2003.
|
||||
if (pSFace->iDetailTexturePattern != -1 && detailTextureAttrData && detailTextureAttrData->stateset)
|
||||
dgset->setDetailTextureAttrData(detailTextureAttrData);
|
||||
else
|
||||
dgset->setDetailTextureAttrData(NULL);
|
||||
|
||||
// Merge face stateset with texture stateset
|
||||
osgStateSet->merge(*textureStateSet);
|
||||
|
||||
|
@ -182,9 +182,9 @@ class ConvertFromFLT
|
||||
void setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet *osgStateSet, DynGeoSet *dgset, bool &bBlend );
|
||||
void setTransparency ( osg::StateSet *osgStateSet, bool &bBlend );
|
||||
|
||||
// multitexturing
|
||||
void addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr );
|
||||
void addUVList( DynGeoSet* dgset, UVListRecord* mtr );
|
||||
// multitexturing
|
||||
void addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr );
|
||||
void addUVList( DynGeoSet* dgset, UVListRecord* mtr );
|
||||
|
||||
typedef std::map<int,Record*> VertexPaletteOffsetMap;
|
||||
VertexPaletteOffsetMap _VertexPaletteOffsetMap;
|
||||
|
Loading…
Reference in New Issue
Block a user