Added osgFX::MultiTextureControl node for managing blending between
different texture layers.
This commit is contained in:
@@ -6,6 +6,7 @@ CXXFILES =\
|
||||
BumpMapping.cpp\
|
||||
Cartoon.cpp\
|
||||
Effect.cpp\
|
||||
MultiTextureControl.cpp\
|
||||
Registry.cpp\
|
||||
Scribe.cpp\
|
||||
SpecularHighlights.cpp\
|
||||
|
||||
178
src/osgFX/MultiTextureControl.cpp
Normal file
178
src/osgFX/MultiTextureControl.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/TexEnvCombine>
|
||||
|
||||
#include <osgFX/MultiTextureControl>
|
||||
|
||||
using namespace osgFX;
|
||||
|
||||
MultiTextureControl::MultiTextureControl()
|
||||
{
|
||||
}
|
||||
|
||||
MultiTextureControl::MultiTextureControl(const MultiTextureControl& copy, const osg::CopyOp& copyop):
|
||||
Group(copy,copyop),
|
||||
_textureWeightList(copy._textureWeightList)
|
||||
{
|
||||
updateStateSet();
|
||||
}
|
||||
|
||||
void MultiTextureControl::setTextureWeight(unsigned int unit, float weight)
|
||||
{
|
||||
if (unit >= _textureWeightList.size())
|
||||
{
|
||||
_textureWeightList.resize(unit+1,0.0f);
|
||||
}
|
||||
_textureWeightList[unit] = weight;
|
||||
|
||||
updateStateSet();
|
||||
}
|
||||
|
||||
void MultiTextureControl::updateStateSet()
|
||||
{
|
||||
osg::StateSet* stateset = getOrCreateStateSet();
|
||||
|
||||
stateset->clear();
|
||||
|
||||
if (_textureWeightList.size()==1)
|
||||
{
|
||||
osg::TexEnv* texenv = new osg::TexEnv(osg::TexEnv::MODULATE);
|
||||
stateset->setTextureAttribute(0, texenv);
|
||||
}
|
||||
if (_textureWeightList.size()==2)
|
||||
{
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::TEXTURE0+0);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::TEXTURE0+1);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource2_RGB(osg::TexEnvCombine::CONSTANT);
|
||||
texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
float r = _textureWeightList[0]/(_textureWeightList[0]+_textureWeightList[1]);
|
||||
texenv->setConstantColor(osg::Vec4(r,r,r,r));
|
||||
|
||||
stateset->setTextureAttribute(0, texenv);
|
||||
}
|
||||
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::MODULATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::PRIMARY_COLOR);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
stateset->setTextureAttribute(1, texenv);
|
||||
}
|
||||
}
|
||||
if (_textureWeightList.size()==3)
|
||||
{
|
||||
float b = (_textureWeightList[0]+_textureWeightList[1])/(_textureWeightList[0]+_textureWeightList[1]+_textureWeightList[2]);
|
||||
float a = _textureWeightList[0]/(_textureWeightList[0]+_textureWeightList[1]);
|
||||
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::TEXTURE0+0);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::TEXTURE0+1);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource2_RGB(osg::TexEnvCombine::CONSTANT);
|
||||
texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
texenv->setConstantColor(osg::Vec4(a,a,a,a));
|
||||
|
||||
stateset->setTextureAttribute(0, texenv);
|
||||
}
|
||||
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::TEXTURE0+2);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource2_RGB(osg::TexEnvCombine::CONSTANT);
|
||||
texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
texenv->setConstantColor(osg::Vec4(b,b,b,b));
|
||||
|
||||
stateset->setTextureAttribute(1, texenv);
|
||||
}
|
||||
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::MODULATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::PRIMARY_COLOR);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
stateset->setTextureAttribute(2, texenv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
bool firstActiveTextureUnit = true;
|
||||
for(unsigned int unit = 0;
|
||||
unit < _textureWeightList.size();
|
||||
++unit)
|
||||
{
|
||||
float r = _textureWeightList[unit];
|
||||
|
||||
if (r==0.0f)
|
||||
{
|
||||
stateset->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::OFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateset->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
||||
|
||||
if (firstActiveTextureUnit)
|
||||
{
|
||||
stateset->setTextureAttribute(unit, new osg::TexEnv);
|
||||
firstActiveTextureUnit = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
texenv->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
||||
texenv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||
texenv->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource1_RGB(osg::TexEnvCombine::TEXTURE);
|
||||
texenv->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
texenv->setSource2_RGB(osg::TexEnvCombine::CONSTANT);
|
||||
texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
texenv->setConstantColor(osg::Vec4(r,r,r,r));
|
||||
|
||||
stateset->setTextureAttribute(unit, texenv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
#include "MultiSwitch.h"
|
||||
#include "VisibilityGroup.h"
|
||||
|
||||
#include "MultiTextureControl.h"
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "ShapeDrawable.h"
|
||||
#include "Shape.h"
|
||||
@@ -952,6 +954,10 @@ osg::Node* DataInputStream::readNode()
|
||||
node = new osgSim::LightPointNode();
|
||||
((ive::LightPointNode*)(node))->read(this);
|
||||
}
|
||||
else if(nodeTypeID== IVEMULTITEXTURECONTROL){
|
||||
node = new osgFX::MultiTextureControl();
|
||||
((ive::MultiTextureControl*)(node))->read(this);
|
||||
}
|
||||
else{
|
||||
throw Exception("Unknown node identification in DataInputStream::readNode()");
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@
|
||||
#include "MultiSwitch.h"
|
||||
#include "VisibilityGroup.h"
|
||||
|
||||
#include "MultiTextureControl.h"
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "ShapeDrawable.h"
|
||||
|
||||
@@ -733,6 +735,9 @@ void DataOutputStream::writeNode(const osg::Node* node)
|
||||
else if(dynamic_cast<const osgSim::LightPointNode*>(node)){
|
||||
((ive::LightPointNode*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<const osgFX::MultiTextureControl*>(node)){
|
||||
((ive::MultiTextureControl*)(node))->write(this);
|
||||
}
|
||||
else
|
||||
throw Exception("Unknown node in Group::write()");
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ CXXFILES =\
|
||||
Material.cpp\
|
||||
MatrixTransform.cpp\
|
||||
MultiSwitch.cpp\
|
||||
MultiTextureControl.cpp\
|
||||
Node.cpp\
|
||||
Object.cpp\
|
||||
OccluderNode.cpp\
|
||||
@@ -77,7 +78,7 @@ CXXFILES =\
|
||||
VertexProgram.cpp\
|
||||
VisibilityGroup.cpp\
|
||||
|
||||
LIBS += -losgSim -losgText $(OSG_LIBS) $(OTHER_LIBS)
|
||||
LIBS += -losgFX -losgSim -losgText $(OSG_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = ive
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
|
||||
70
src/osgPlugins/ive/MultiTextureControl.cpp
Normal file
70
src/osgPlugins/ive/MultiTextureControl.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* FILE: MultiTextureControl.cpp
|
||||
*
|
||||
* DESCRIPTION: Read/Write osg::MultiTextureControl in binary format to disk.
|
||||
*
|
||||
* CREATED BY: Auto generated by iveGenerate
|
||||
* and later modified by Rune Schmidt Jensen.
|
||||
*
|
||||
* HISTORY: Created 24.3.2003
|
||||
*
|
||||
* Copyright 2003 VR-C
|
||||
**********************************************************************/
|
||||
|
||||
#include "Exception.h"
|
||||
#include "MultiTextureControl.h"
|
||||
#include "Group.h"
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void MultiTextureControl::write(DataOutputStream* out){
|
||||
// Write MultiTextureControl's identification.
|
||||
out->writeInt(IVEMULTITEXTURECONTROL);
|
||||
// If the osg class is inherited by any other class we should also write this to file.
|
||||
osg::Group* group = dynamic_cast<osg::Group*>(this);
|
||||
if(group){
|
||||
((ive::Group*)(group))->write(out);
|
||||
}
|
||||
else
|
||||
throw Exception("MultiTextureControl::write(): Could not cast this osg::MultiTextureControl to an osg::Group.");
|
||||
// Write MultiTextureControl's properties.
|
||||
|
||||
|
||||
// Write rangelist
|
||||
unsigned int size = getNumTextureWeights();
|
||||
out->writeUInt(size);
|
||||
for(unsigned int i=0;i<size;i++){
|
||||
out->writeFloat(getTextureWeight(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MultiTextureControl::read(DataInputStream* in){
|
||||
// Peek on MultiTextureControl's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVEMULTITEXTURECONTROL){
|
||||
// Read MultiTextureControl's identification.
|
||||
id = in->readInt();
|
||||
|
||||
// If the osg class is inherited by any other class we should also read this from file.
|
||||
osg::Group* group = dynamic_cast<osg::Group*>(this);
|
||||
if(group){
|
||||
((ive::Group*)(group))->read(in);
|
||||
}
|
||||
else
|
||||
throw Exception("MultiTextureControl::read(): Could not cast this osg::MultiTextureControl to an osg::Group.");
|
||||
// Read MultiTextureControl's properties
|
||||
|
||||
|
||||
// Read rangelist
|
||||
unsigned int size = in->readUInt();
|
||||
for(unsigned int i=0;i<size;i++)
|
||||
{
|
||||
float value = in->readFloat();
|
||||
setTextureWeight(i, value);
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw Exception("MultiTextureControl::read(): Expected MultiTextureControl identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/MultiTextureControl.h
Normal file
15
src/osgPlugins/ive/MultiTextureControl.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_MULTITEXTYRECONTROL
|
||||
#define IVE_MULTITEXTYRECONTROL 1
|
||||
|
||||
#include <osgFX/MultiTextureControl>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class MultiTextureControl : public osgFX::MultiTextureControl, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -96,8 +96,13 @@ namespace ive {
|
||||
#define IVELIGHTPOINTNODE 0x00100007
|
||||
#define IVEMULTISWITCH 0x00100008
|
||||
|
||||
#define IVEVISIBILITYGROUP 0x00100009
|
||||
#define IVEDIRECTIONALSECTOR 0x0010000A
|
||||
|
||||
#define IVEVISIBILITYGROUP 0x00100009
|
||||
#define IVEDIRECTIONALSECTOR 0x0010000A
|
||||
|
||||
// osgFX classes
|
||||
#define IVEMULTITEXTURECONTROL 0x01000001
|
||||
|
||||
|
||||
class ReadWrite{
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ CXXFILES =\
|
||||
IO_AnisotropicLighting.cpp\
|
||||
IO_BumpMapping.cpp\
|
||||
IO_Cartoon.cpp\
|
||||
IO_MultiTextureControl.cpp\
|
||||
IO_Scribe.cpp\
|
||||
IO_SpecularHighlights.cpp\
|
||||
IO_Effect.cpp\
|
||||
|
||||
79
src/osgPlugins/osgFX/IO_MultiTextureControl.cpp
Normal file
79
src/osgPlugins/osgFX/IO_MultiTextureControl.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <osgFX/MultiTextureControl>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
bool MultiTextureControl_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool MultiTextureControl_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
osgDB::RegisterDotOsgWrapperProxy MultiTextureControl_Proxy
|
||||
(
|
||||
new osgFX::MultiTextureControl,
|
||||
"osgFX::MultiTextureControl",
|
||||
"Object Node osgFX::MultiTextureControl Group",
|
||||
MultiTextureControl_readLocalData,
|
||||
MultiTextureControl_writeLocalData
|
||||
);
|
||||
|
||||
bool MultiTextureControl_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgFX::MultiTextureControl &mtc = static_cast<osgFX::MultiTextureControl &>(obj);
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
bool matchFirst = false;
|
||||
if ((matchFirst=fr.matchSequence("TextureWeights {")) || fr.matchSequence("TextureWeights %i {"))
|
||||
{
|
||||
|
||||
// set up coordinates.
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
if (matchFirst)
|
||||
{
|
||||
fr += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fr += 3;
|
||||
}
|
||||
|
||||
float weight=0.0f;
|
||||
unsigned int i=0;
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
if (fr[0].getFloat(weight))
|
||||
{
|
||||
mtc.setTextureWeight(i,weight);
|
||||
++fr;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
++fr;
|
||||
}
|
||||
}
|
||||
|
||||
iteratorAdvanced = true;
|
||||
++fr;
|
||||
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool MultiTextureControl_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgFX::MultiTextureControl &mtc = static_cast<const osgFX::MultiTextureControl &>(obj);
|
||||
|
||||
fw.indent() << "TextureWeights "<<mtc.getNumTextureWeights()<<" {"<< std::endl;
|
||||
fw.moveIn();
|
||||
|
||||
for(unsigned int i=0; i<mtc.getNumTextureWeights();++i)
|
||||
{
|
||||
fw.indent() << mtc.getTextureWeight(i)<<std::endl;
|
||||
}
|
||||
fw.moveOut();
|
||||
fw.indent() << "}"<< std::endl;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileNameUtils>
|
||||
|
||||
#include <osgFX/MultiTextureControl>
|
||||
|
||||
#include <osgTerrain/DataSet>
|
||||
|
||||
// GDAL includes
|
||||
@@ -2134,12 +2136,12 @@ osg::StateSet* DataSet::DestinationTile::createStateSet()
|
||||
|
||||
osg::StateSet* stateset = new osg::StateSet;
|
||||
|
||||
osg::Texture* baseTexture = 0;
|
||||
for(layerNum=0;
|
||||
layerNum<_imagery.size();
|
||||
++layerNum)
|
||||
{
|
||||
ImageData& imageData = _imagery[layerNum];
|
||||
|
||||
if (!imageData._imagery.valid() || !imageData._imagery->_image.valid()) continue;
|
||||
|
||||
osg::Image* image = imageData._imagery->_image.get();
|
||||
@@ -2156,6 +2158,9 @@ osg::StateSet* DataSet::DestinationTile::createStateSet()
|
||||
image->setFileName(imageName.c_str());
|
||||
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
|
||||
if (baseTexture==0) baseTexture=texture;
|
||||
|
||||
texture->setImage(image);
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
||||
@@ -2231,6 +2236,27 @@ osg::StateSet* DataSet::DestinationTile::createStateSet()
|
||||
}
|
||||
}
|
||||
|
||||
// now fill in any blank texture units.
|
||||
bool fillInAllTextureUnits = true;
|
||||
if (fillInAllTextureUnits && baseTexture)
|
||||
{
|
||||
for(layerNum=0;
|
||||
layerNum<_dataSet->getNumOfTextureLevels();
|
||||
++layerNum)
|
||||
{
|
||||
bool applyBaseTexture = false;
|
||||
if (layerNum>=_imagery.size()) applyBaseTexture=true;
|
||||
else
|
||||
{
|
||||
ImageData& imageData = _imagery[layerNum];
|
||||
if (!imageData._imagery.valid() ||
|
||||
!imageData._imagery->_image.valid()) applyBaseTexture=true;
|
||||
}
|
||||
if (applyBaseTexture)
|
||||
stateset->setTextureAttributeAndModes(layerNum,baseTexture,osg::StateAttribute::ON);
|
||||
}
|
||||
}
|
||||
|
||||
return stateset;
|
||||
}
|
||||
|
||||
@@ -2549,17 +2575,29 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
|
||||
geometry->setColorArray(&color);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
||||
|
||||
for(unsigned int layerNum=0;
|
||||
layerNum<_imagery.size();
|
||||
++layerNum)
|
||||
bool fillInAllTextureUnits = true;
|
||||
if (fillInAllTextureUnits)
|
||||
{
|
||||
ImageData& imageData = _imagery[layerNum];
|
||||
if (imageData._imagery.valid() && imageData._imagery->_image.valid())
|
||||
for(unsigned int layerNum=0;
|
||||
layerNum<_dataSet->getNumOfTextureLevels();
|
||||
++layerNum)
|
||||
{
|
||||
geometry->setTexCoordArray(layerNum,&t);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for(unsigned int layerNum=0;
|
||||
layerNum<_imagery.size();
|
||||
++layerNum)
|
||||
{
|
||||
ImageData& imageData = _imagery[layerNum];
|
||||
if (imageData._imagery.valid() && imageData._imagery->_image.valid())
|
||||
{
|
||||
geometry->setTexCoordArray(layerNum,&t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osg::DrawElementsUShort& drawElements = *(new osg::DrawElementsUShort(GL_TRIANGLES,2*3*(numColumns-1)*(numRows-1)));
|
||||
geometry->addPrimitiveSet(&drawElements);
|
||||
@@ -3328,6 +3366,9 @@ DataSet::DataSet()
|
||||
_useLocalTileTransform = true;
|
||||
|
||||
_decorateWithCoordinateSystemNode = true;
|
||||
_decorateWithMultiTextureControl = true;
|
||||
|
||||
_numTextureLevels = 1;
|
||||
|
||||
_writeNodeBeforeSimplification = false;
|
||||
|
||||
@@ -3708,6 +3749,19 @@ void DataSet::computeDestinationGraphFromSources(unsigned int numLevels)
|
||||
}
|
||||
}
|
||||
|
||||
// compute the number of texture layers required.
|
||||
unsigned int maxTextureUnit = 0;
|
||||
for(CompositeSource::source_iterator sitr(_sourceGraph.get());sitr.valid();++sitr)
|
||||
{
|
||||
Source* source = sitr->get();
|
||||
if (source)
|
||||
{
|
||||
if (maxTextureUnit<source->getLayer()) maxTextureUnit = source->getLayer();
|
||||
}
|
||||
}
|
||||
_numTextureLevels = maxTextureUnit+1;
|
||||
|
||||
|
||||
my_notify(osg::INFO)<<"extents = xMin()"<<extents.xMin()<<" "<<extents.xMax()<<std::endl;
|
||||
my_notify(osg::INFO)<<" yMin()"<<extents.yMin()<<" "<<extents.yMax()<<std::endl;
|
||||
|
||||
@@ -4045,6 +4099,10 @@ void DataSet::_writeRow(Row& row)
|
||||
node = decorateWithCoordinateSystemNode(node.get());
|
||||
}
|
||||
|
||||
if (_decorateWithMultiTextureControl)
|
||||
{
|
||||
node = decorateWithMultiTextureControl(node.get());
|
||||
}
|
||||
|
||||
if (!_comment.empty())
|
||||
{
|
||||
@@ -4108,6 +4166,26 @@ osg::Node* DataSet::decorateWithCoordinateSystemNode(osg::Node* subgraph)
|
||||
return csn;
|
||||
}
|
||||
|
||||
osg::Node* DataSet::decorateWithMultiTextureControl(osg::Node* subgraph)
|
||||
{
|
||||
// if only one layer exists don't need to decorate with MultiTextureControl
|
||||
if (_numTextureLevels<=1) return subgraph;
|
||||
|
||||
|
||||
// multiple layers active so use osgFX::MultiTextureControl to manage them
|
||||
osgFX::MultiTextureControl* mtc = new osgFX::MultiTextureControl;
|
||||
float r = 1.0f/(float)_numTextureLevels;
|
||||
for(unsigned int i=0;i<_numTextureLevels;++i)
|
||||
{
|
||||
mtc->setTextureWeight(i,r);
|
||||
}
|
||||
|
||||
// add the a subgraph.
|
||||
mtc->addChild(subgraph);
|
||||
|
||||
return mtc;
|
||||
}
|
||||
|
||||
|
||||
void DataSet::_buildDestination(bool writeToDisk)
|
||||
{
|
||||
@@ -4145,6 +4223,11 @@ void DataSet::_buildDestination(bool writeToDisk)
|
||||
_rootNode = decorateWithCoordinateSystemNode(_rootNode.get());
|
||||
}
|
||||
|
||||
if (_decorateWithMultiTextureControl)
|
||||
{
|
||||
_rootNode = decorateWithMultiTextureControl(_rootNode.get());
|
||||
}
|
||||
|
||||
if (!_comment.empty())
|
||||
{
|
||||
_rootNode->addDescription(_comment);
|
||||
|
||||
@@ -12,7 +12,7 @@ DEF += -DOSGTERRAIN_LIBRARY
|
||||
|
||||
INC += $(GDAL_INCLUDES)
|
||||
|
||||
LIBS += -losgDB -losgUtil -losg $(GDAL_LIBS) $(GL_LIBS) $(OTHER_LIBS)
|
||||
LIBS += -losgFX -losgDB -losgUtil -losg $(GDAL_LIBS) $(GL_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = osgTerrain
|
||||
LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)
|
||||
|
||||
Reference in New Issue
Block a user