From c67950561ef508a8e3f0ce1a7206c2b96130b1c3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 9 Mar 2002 10:52:01 +0000 Subject: [PATCH] TXP plugin changes submitted by Boris Bralo. --- src/osgPlugins/txp/trpage_compat.cpp | 283 ++++++++ src/osgPlugins/txp/trpage_compat.h | 96 +++ src/osgPlugins/txp/trpage_light.cpp | 973 +++++++++++++++++++++++++++ src/osgPlugins/txp/trpage_pparse.cpp | 210 ++++++ src/osgPlugins/txp/trpage_print.cpp | 838 +++++++++++++++++++++++ src/osgPlugins/txp/trpage_print.h | 106 +++ src/osgPlugins/txp/trpage_range.cpp | 303 +++++++++ 7 files changed, 2809 insertions(+) create mode 100644 src/osgPlugins/txp/trpage_compat.cpp create mode 100644 src/osgPlugins/txp/trpage_compat.h create mode 100644 src/osgPlugins/txp/trpage_light.cpp create mode 100644 src/osgPlugins/txp/trpage_pparse.cpp create mode 100644 src/osgPlugins/txp/trpage_print.cpp create mode 100644 src/osgPlugins/txp/trpage_print.h create mode 100644 src/osgPlugins/txp/trpage_range.cpp diff --git a/src/osgPlugins/txp/trpage_compat.cpp b/src/osgPlugins/txp/trpage_compat.cpp new file mode 100644 index 000000000..ea37b993b --- /dev/null +++ b/src/osgPlugins/txp/trpage_compat.cpp @@ -0,0 +1,283 @@ +/* ************************ + Copyright Terrain Experts Inc. + Terrain Experts Inc (TERREX) reserves all rights to this source code + unless otherwise specified in writing by the President of TERREX. + This copyright may be updated in the future, in which case that version + supercedes this one. + ------------------- + Terrex Experts Inc. + 4400 East Broadway #314 + Tucson, AZ 85711 + info@terrex.com + Tel: (520) 323-7990 + ************************ + */ + +#include +#include +#include + +/* trpage_compat.cpp + This file and the accompanying trpage_compat.h contain objects and procedures + used to maintain compatibility between versions of TerraPage. In particular, the + ability to read older versions of TerraPage and newer applications. + + */ + +#include "trpage_geom.h" +#include "trpage_read.h" +#include "trpage_compat.h" + +/* Old short Material definition from 1.0. + {secret} + */ +class trpgShortMaterial { +public: + // Full trpgMaterial definition this one is based on + int baseMat; + // Currently the only thing a short material overrides is texture + std::vector texids; +}; + +trpgMatTable1_0::trpgMatTable1_0(const trpgMatTable &inTbl) +{ + *((trpgMatTable *)this) = inTbl; +} + +bool trpgMatTable1_0::Read(trpgReadBuffer &buf) +{ + trpgMaterial mat; + trpgToken matTok; + int32 len; + bool status; + int i,j,k; + + std::vector shortTable; + std::vector baseMats; + + try { + buf.Get(numTable); + buf.Get(numMat); + if (numTable <= 0 || numMat < 0) throw 1; + + // Short material tables are always full size + shortTable.resize(numTable*numMat); + + // Look for short material table + buf.GetToken(matTok,len); + if (matTok == TRPGSHORTMATTABLE) { + int32 numTex,texId; + buf.PushLimit(len); + for (i=0;i shortMats; + shortMats.resize(numTable*numMat); + + // Iterate over the existing materials + int i; + for (i=0;i +#include +#include + +#include "trpage_geom.h" +#include "trpage_read.h" + +#if defined(_WIN32) +#define ALIGNMENT_WORKAROUND false +#else +#define ALIGNMENT_WORKAROUND true +#endif + +/****** + Lights Attribute +******/ + +trpgLightAttr::trpgLightAttr(void) +{ + Reset(); +} + +trpgLightAttr::trpgLightAttr(const trpgLightAttr &in) +{ + operator=(in); +} + +trpgLightAttr::~trpgLightAttr(void) +{ +} + + +// Setters +void trpgLightAttr::SetType( trpgLightAttr::LightType in_type ) +{ + data.type = in_type; +} +void trpgLightAttr::SetDirectionality( trpgLightAttr::LightDirectionality in_directionality ) +{ + data.directionality = in_directionality; +} +void trpgLightAttr::SetFrontColor( trpgColor in_frontColor ) +{ + data.frontColor = in_frontColor; +} +void trpgLightAttr::SetFrontIntensity( float64 in_frontIntensity ) +{ + data.frontIntensity = in_frontIntensity; +} +void trpgLightAttr::SetBackColor( trpgColor in_backColor ) +{ + data.backColor = in_backColor; +} +void trpgLightAttr::SetBackIntensity( float64 in_backIntensity ) +{ + data.backIntensity = in_backIntensity; +} +void trpgLightAttr::SetNormal( trpg3dPoint in_normal ) +{ + data.normal = in_normal; +} +void trpgLightAttr::SetSMC( int32 in_smc ) +{ + data.smc = in_smc; +} +void trpgLightAttr::SetFID( int32 in_fid ) +{ + data.fid = in_fid; +} +void trpgLightAttr::SetFlags( int32 in_flags ) +{ + data.flags = in_flags; +} +void trpgLightAttr::SetHLobeAngle( float64 in_hLobeAngle ) +{ + data.horizontalLobeAngle = in_hLobeAngle; +} +void trpgLightAttr::SetVLobeAngle( float64 in_vLobeAngle ) +{ + data.verticalLobeAngle = in_vLobeAngle; +} +void trpgLightAttr::SetLobeRollAngle( float64 in_lobeRollAngle ) +{ + data.lobeRollAngle = in_lobeRollAngle; +} +void trpgLightAttr::SetLobeFalloff( float64 in_lobeFalloff ) +{ + data.lobeFalloff = in_lobeFalloff; +} +void trpgLightAttr::SetAmbient( float64 in_ambientIntensity ) +{ + data.ambientIntensity = in_ambientIntensity; +} +void trpgLightAttr::SetQuality( trpgLightAttr::LightQuality in_quality ) +{ + data.quality = in_quality; +} +void trpgLightAttr::SetRascalSignificance( float64 in_rascalSignificance ) +{ + data.rascalSignificance = in_rascalSignificance; +} +void trpgLightAttr::SetRandomIntensity( trpgLightAttr::LightQuality in_randomIntensity ) +{ + data.randomIntensity = in_randomIntensity; +} +void trpgLightAttr::SetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& in_calligraphicAttr ) +{ + data.calligraphicAttr = in_calligraphicAttr; +} +void trpgLightAttr::SetCalligraphicDrawOrder( int32 in_drawOrder ) +{ + data.calligraphicAttr.drawOrder = in_drawOrder; +} +void trpgLightAttr::SetCalligraphicMinDefocus( float64 in_minDefocus ) +{ + data.calligraphicAttr.minDefocus = in_minDefocus; +} +void trpgLightAttr::SetCalligraphicMaxDefocus( float64 in_maxDefocus ) +{ + data.calligraphicAttr.maxDefocus = in_maxDefocus; +} +void trpgLightAttr::SetPerformerAttr( trpgLightAttr::PerformerAttr& in_performerAttr ) +{ + data.performerAttr = in_performerAttr; +} +void trpgLightAttr::SetPerformerFlags( int32 in_flags ) +{ + data.performerAttr.flags = in_flags & trpgLightAttr::trpg_PerformerMask; + data.flags |= data.performerAttr.flags; +} +void trpgLightAttr::SetPerformerMinPixelSize( float64 in_minPxSize ) +{ + data.performerAttr.minPixelSize = in_minPxSize; +} +void trpgLightAttr::SetPerformerMaxPixelSize( float64 in_maxPxSize ) +{ + data.performerAttr.maxPixelSize = in_maxPxSize; +} +void trpgLightAttr::SetPerformerActualSize( float64 in_actualSize ) +{ + data.performerAttr.actualSize = in_actualSize; +} +void trpgLightAttr::SetPerformerTpPixelSize( float64 in_tpPixelSize ) +{ + data.performerAttr.transparentPixelSize = in_tpPixelSize; +} +void trpgLightAttr::SetPerformerTpFalloffExp( float64 in_tpFalloffExp ) +{ + data.performerAttr.transparentFallofExp = in_tpFalloffExp; +} +void trpgLightAttr::SetPerformerTpScale( float64 in_tpScale ) +{ + data.performerAttr.transparentScale = in_tpScale; +} +void trpgLightAttr::SetPerformerTpClamp( float64 in_tpClamp ) +{ + data.performerAttr.transparentClamp = in_tpClamp; +} +void trpgLightAttr::SetPerformerFogScale( float64 in_fogScale ) +{ + data.performerAttr.fogScale = in_fogScale; +} +void trpgLightAttr::SetAnimationAttr( trpgLightAttr::AnimationAttr& in_animationAttr ) +{ + data.animationAttr = in_animationAttr; +} +void trpgLightAttr::SetAnimationPeriod( float64 in_period ) +{ + data.animationAttr.period = in_period; +} +void trpgLightAttr::SetAnimationPhaseDelay( float64 in_phaseDelay ) +{ + data.animationAttr.phaseDelay = in_phaseDelay; +} +void trpgLightAttr::SetAnimationTimeOn( float64 in_timeOn ) +{ + data.animationAttr.timeOn = in_timeOn; +} +void trpgLightAttr::SetAnimationVector( trpg3dPoint in_vector ) +{ + data.animationAttr.vector = in_vector; +} +void trpgLightAttr::SetAnimationFlags( int32 flags ) +{ + data.animationAttr.flags = flags & trpgLightAttr::trpg_AnimationMask; + data.flags |= data.animationAttr.flags; +} +// Getters +void trpgLightAttr::GetType( trpgLightAttr::LightType& out_type ) +{ + out_type = data.type; +} +void trpgLightAttr::GetDirectionality( trpgLightAttr::LightDirectionality& out_directionality ) +{ + out_directionality = data.directionality; +} +void trpgLightAttr::GetFrontColor( trpgColor& out_frontColor ) +{ + out_frontColor = data.frontColor; +} +void trpgLightAttr::GetFrontIntensity( float64& out_frontIntensity ) +{ + out_frontIntensity = data.frontIntensity; +} +void trpgLightAttr::GetBackColor( trpgColor& out_backColor ) +{ + out_backColor = data.backColor; +} +void trpgLightAttr::GetBackIntensity( float64& out_backIntensity ) +{ + out_backIntensity = data.backIntensity; +} +void trpgLightAttr::GetNormal( trpg3dPoint& out_normal ) +{ + out_normal = data.normal; +} +void trpgLightAttr::GetSMC( int32& out_smc ) +{ + out_smc = data.smc; +} +void trpgLightAttr::GetFID( int32& out_fid ) +{ + out_fid = data.fid; +} +void trpgLightAttr::GetFlags( int32& out_flags ) +{ + out_flags = data.flags; +} +void trpgLightAttr::GetHLobeAngle( float64& out_hLobeAngle ) +{ + out_hLobeAngle = data.horizontalLobeAngle; +} +void trpgLightAttr::GetVLobeAngle( float64& out_vLobeAngle ) +{ + out_vLobeAngle = data.verticalLobeAngle; +} +void trpgLightAttr::GetLobeRollAngle( float64& out_lobeRollAngle ) +{ + out_lobeRollAngle = data.lobeRollAngle; +} +void trpgLightAttr::GetLobeFalloff( float64& out_lobeFalloff ) +{ + out_lobeFalloff = data.lobeFalloff; +} +void trpgLightAttr::GetAmbient( float64& out_ambientIntensity ) +{ + out_ambientIntensity = data.ambientIntensity; +} +void trpgLightAttr::GetQuality( trpgLightAttr::LightQuality& out_quality ) +{ + out_quality = data.quality; +} +void trpgLightAttr::GetRascalSignificance( float64& out_rascalSignificance ) +{ + out_rascalSignificance = data.rascalSignificance; +} +void trpgLightAttr::GetRandomIntensity( trpgLightAttr::LightQuality& out_randomIntensity ) +{ + out_randomIntensity = data.randomIntensity; +} +void trpgLightAttr::GetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& out_calligraphicAttr ) +{ + out_calligraphicAttr = data.calligraphicAttr; +} +void trpgLightAttr::GetCalligraphicDrawOrder( int32& out_drawOrder ) +{ + out_drawOrder = data.calligraphicAttr.drawOrder; +} +void trpgLightAttr::GetCalligraphicMinDefocus( float64& out_minDefocus ) +{ + out_minDefocus = data.calligraphicAttr.minDefocus; +} +void trpgLightAttr::GetCalligraphicMaxDefocus( float64& out_maxDefocus ) +{ + out_maxDefocus = data.calligraphicAttr.maxDefocus; +} +void trpgLightAttr::GetPerformerAttr( trpgLightAttr::PerformerAttr& out_performerAttr ) +{ + out_performerAttr = data.performerAttr; +} +void trpgLightAttr::GetPerformerFlags( int32& out_flags ) +{ + out_flags = data.performerAttr.flags; +} +void trpgLightAttr::GetPerformerMinPixelSize( float64& out_minPxSize ) +{ + out_minPxSize = data.performerAttr.minPixelSize; +} +void trpgLightAttr::GetPerformerMaxPixelSize( float64& out_maxPxSize ) +{ + out_maxPxSize = data.performerAttr.maxPixelSize; +} +void trpgLightAttr::GetPerformerActualSize( float64& out_actualSize ) +{ + out_actualSize = data.performerAttr.actualSize; +} +void trpgLightAttr::GetPerformerTpPixelSize( float64& out_tpPixelSize ) +{ + out_tpPixelSize = data.performerAttr.transparentPixelSize; +} +void trpgLightAttr::GetPerformerTpFalloffExp( float64& out_tpFalloffExp ) +{ + out_tpFalloffExp = data.performerAttr.transparentFallofExp; +} +void trpgLightAttr::GetPerformerTpScale( float64& out_tpScale ) +{ + out_tpScale = data.performerAttr.transparentScale; +} +void trpgLightAttr::GetPerformerTpClamp( float64& out_tpClamp ) +{ + out_tpClamp = data.performerAttr.transparentClamp; +} +void trpgLightAttr::GetPerformerFogScale( float64& out_fogScale ) +{ + out_fogScale = data.performerAttr.fogScale; +} +void trpgLightAttr::GetAnimationAttr( trpgLightAttr::AnimationAttr& out_animationAttr ) +{ + out_animationAttr = data.animationAttr; +} +void trpgLightAttr::GetAnimationPeriod( float64& out_period ) +{ + out_period = data.animationAttr.period; +} +void trpgLightAttr::GetAnimationPhaseDelay( float64& out_phaseDelay ) +{ + out_phaseDelay = data.animationAttr.phaseDelay; +} +void trpgLightAttr::GetAnimationTimeOn( float64& out_timeOn ) +{ + out_timeOn = data.animationAttr.timeOn; +} +void trpgLightAttr::GetAnimationVector( trpg3dPoint& out_vector ) +{ + out_vector = data.animationAttr.vector; +} +void trpgLightAttr::GetAnimationFlags( int32& flags ) +{ + flags = data.animationAttr.flags; +} +// Writes this class to a write buffer +bool trpgLightAttr::Write(trpgWriteBuffer &buf) +{ + buf.Begin(TRPGLIGHTATTR); + + buf.Begin(TRPGLIGHTATTR_BASIC); + buf.Add((int)data.type); + buf.Add((int)data.directionality); + buf.Add(data.frontColor); + buf.Add(data.frontIntensity); + buf.Add(data.backColor); + buf.Add(data.backIntensity); + buf.Add(data.normal); + buf.Add(data.smc); + buf.Add(data.fid); + buf.Add(data.flags); + buf.Add(data.horizontalLobeAngle); + buf.Add(data.verticalLobeAngle); + buf.Add(data.lobeRollAngle); + buf.Add(data.lobeFalloff); + buf.Add(data.ambientIntensity); + buf.Add((int)data.quality); + buf.Add((int)data.randomIntensity); + buf.End(); + + buf.Begin(TRPGLIGHTATTR_RASCAL); + buf.Add(data.rascalSignificance); + buf.End(); + + buf.Begin(TRPGLIGHTATTR_CALLIGRAPHIC); + buf.Add(data.calligraphicAttr.drawOrder); + buf.Add(data.calligraphicAttr.minDefocus); + buf.Add(data.calligraphicAttr.maxDefocus); + buf.End(); + + buf.Begin(TRPGLIGHTATTR_PERFORMER); + buf.Add(data.performerAttr.actualSize); + buf.Add(data.performerAttr.fogScale); + buf.Add(data.performerAttr.minPixelSize); + buf.Add(data.performerAttr.maxPixelSize); + buf.Add(data.performerAttr.transparentClamp); + buf.Add(data.performerAttr.transparentFallofExp); + buf.Add(data.performerAttr.transparentPixelSize); + buf.Add(data.performerAttr.transparentScale); + buf.End(); + + buf.Begin(TRPGLIGHTATTR_ANIMATION); + buf.Add(data.animationAttr.period); + buf.Add(data.animationAttr.phaseDelay); + buf.Add(data.animationAttr.timeOn); + buf.Add(data.animationAttr.vector); + buf.End(); + + buf.End(); + + return true; +} + +/* LightAttr CB + Used to parse tokens for a light attribute. + */ +class lightAttrCB : public trpgr_Callback { +public: + void * Parse(trpgToken,trpgReadBuffer &); + trpgLightAttr *lightAttr; +}; +void * lightAttrCB::Parse(trpgToken tok,trpgReadBuffer &buf) +{ + int type_data; + int directionality_data; + trpgColor color_data;; + float64 float64_data; + trpg3dPoint point_data;; + int32 int32_data; + int quality_data; + + try { + switch (tok) { + case TRPGLIGHTATTR_BASIC: + buf.Get(type_data); + lightAttr->SetType((trpgLightAttr::LightType)type_data); + buf.Get(directionality_data); + lightAttr->SetDirectionality((trpgLightAttr::LightDirectionality)directionality_data); + buf.Get(color_data); + lightAttr->SetFrontColor(color_data); + buf.Get(float64_data); + lightAttr->SetFrontIntensity(float64_data); + buf.Get(color_data); + lightAttr->SetBackColor(color_data); + buf.Get(float64_data); + lightAttr->SetBackIntensity(float64_data); + buf.Get(point_data); + lightAttr->SetNormal(point_data); + buf.Get(int32_data); + lightAttr->SetSMC(int32_data); + buf.Get(int32_data); + lightAttr->SetFID(int32_data); + buf.Get(int32_data); + lightAttr->SetFlags(int32_data); + lightAttr->SetPerformerFlags(int32_data); + lightAttr->SetAnimationFlags(int32_data); + buf.Get(float64_data); + lightAttr->SetHLobeAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetVLobeAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetLobeRollAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetLobeFalloff(float64_data); + buf.Get(float64_data); + lightAttr->SetAmbient(float64_data); + buf.Get(quality_data); + lightAttr->SetQuality((trpgLightAttr::LightQuality)quality_data); + buf.Get(quality_data); + lightAttr->SetRandomIntensity((trpgLightAttr::LightQuality)quality_data); + break; + case TRPGLIGHTATTR_RASCAL: + buf.Get(float64_data); + lightAttr->SetRascalSignificance(float64_data); + break; + case TRPGLIGHTATTR_PERFORMER: + buf.Get(float64_data); + lightAttr->SetPerformerActualSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerFogScale(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerMinPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerMaxPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpClamp(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpFalloffExp(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpScale(float64_data); + break; + case TRPGLIGHTATTR_CALLIGRAPHIC: + buf.Get(int32_data); + lightAttr->SetCalligraphicDrawOrder(int32_data); + buf.Get(float64_data); + lightAttr->SetCalligraphicMinDefocus(float64_data); + buf.Get(float64_data); + lightAttr->SetCalligraphicMaxDefocus(float64_data); + break; + case TRPGLIGHTATTR_ANIMATION: + buf.Get(float64_data); + lightAttr->SetAnimationPeriod(float64_data); + buf.Get(float64_data); + lightAttr->SetAnimationPhaseDelay(float64_data); + buf.Get(float64_data); + lightAttr->SetAnimationTimeOn(float64_data); + buf.Get(point_data); + lightAttr->SetAnimationVector(point_data); + break; + default: + break; + } + } + catch (...) { + return NULL; + } + + return lightAttr; +} + +// Reads this class from a read buffer +bool trpgLightAttr::Read(trpgReadBuffer &buf) +{ + Reset(); + + trpgr_Parser parse; + lightAttrCB lightAttrCb; + + // Light attribute is just a bunch of unordered tokens. + // Interface to it with a generic parser + lightAttrCb.lightAttr = this; + parse.AddCallback(TRPGLIGHTATTR_BASIC,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_PERFORMER,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_RASCAL,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_CALLIGRAPHIC,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_ANIMATION,&lightAttrCb,false); + parse.Parse(buf); + + return isValid(); +} + +bool trpgLightAttr::isValid(void) const +{ + return true; +} + +trpgLightAttr& trpgLightAttr::operator = (const trpgLightAttr& in) +{ + data = in.data; + return *this; +} + +bool trpgLightAttr::operator == (const trpgLightAttr& in) +{ + // this doesn't work, so do it a hard way + // return memcmp( &data,&in.data,sizeof(data) ) == 0; + + if ( data.type != in.data.type ) + return false; + if ( data.directionality != in.data.directionality ) + return false; + if ( data.frontColor != in.data.frontColor ) + return false; + if ( data.frontIntensity != in.data.frontIntensity ) + return false; + if ( data.backColor != in.data.backColor ) + return false; + if ( data.backIntensity != in.data.backIntensity ) + return false; + if ( data.normal != in.data.normal ) + return false; + if ( data.smc != in.data.smc ) + return false; + if ( data.fid != in.data.fid ) + return false; + if ( data.flags != in.data.flags ) + return false; + if ( data.horizontalLobeAngle != in.data.horizontalLobeAngle ) + return false; + if ( data.verticalLobeAngle != in.data.verticalLobeAngle ) + return false; + if ( data.lobeRollAngle != in.data.lobeRollAngle ) + return false; + if ( data.lobeFalloff != in.data.lobeFalloff ) + return false; + if ( data.ambientIntensity != in.data.ambientIntensity ) + return false; + if ( data.quality != in.data.quality ) + return false; + if ( data.randomIntensity != in.data.randomIntensity ) + return false; + if ( data.rascalSignificance != in.data.rascalSignificance ) + return false; + if ( data.calligraphicAttr.drawOrder != in.data.calligraphicAttr.drawOrder ) + return false; + if ( data.calligraphicAttr.minDefocus != in.data.calligraphicAttr.minDefocus ) + return false; + if ( data.calligraphicAttr.maxDefocus != in.data.calligraphicAttr.maxDefocus ) + return false; + if ( data.performerAttr.flags != in.data.performerAttr.flags ) + return false; + if ( data.performerAttr.minPixelSize != in.data.performerAttr.minPixelSize ) + return false; + if ( data.performerAttr.maxPixelSize != in.data.performerAttr.maxPixelSize ) + return false; + if ( data.performerAttr.actualSize != in.data.performerAttr.actualSize ) + return false; + if ( data.performerAttr.transparentPixelSize != in.data.performerAttr.transparentPixelSize ) + return false; + if ( data.performerAttr.transparentFallofExp != in.data.performerAttr.transparentFallofExp ) + return false; + if ( data.performerAttr.transparentScale != in.data.performerAttr.transparentScale ) + return false; + if ( data.performerAttr.transparentClamp != in.data.performerAttr.transparentClamp ) + return false; + if ( data.performerAttr.fogScale != in.data.performerAttr.fogScale ) + return false; + if ( data.animationAttr.period != in.data.animationAttr.period ) + return false; + if ( data.animationAttr.phaseDelay != in.data.animationAttr.phaseDelay ) + return false; + if ( data.animationAttr.timeOn != in.data.animationAttr.timeOn ) + return false; + if ( data.animationAttr.vector != in.data.animationAttr.vector ) + return false; + if ( data.animationAttr.flags != in.data.animationAttr.flags ) + return false; + + return true; +} + +bool trpgLightAttr::operator != (const trpgLightAttr& in) +{ + return !operator==(in); +} + +void trpgLightAttr::Reset(void) +{ + data.type = trpg_Raster; + data.directionality = trpg_Omnidirectional; + data.frontColor = trpgColor(0,0,0); + data.frontIntensity = 0; + data.backColor = trpgColor(0,0,0); + data.backIntensity = 0; + data.normal = trpg3dPoint(0,0,1); + data.smc = 0; + data.fid = 0; + data.flags = 0; + data.horizontalLobeAngle = 0; + data.verticalLobeAngle = 0; + data.lobeRollAngle = 0; + data.lobeFalloff = 0; + data.ambientIntensity = 0; + data.quality = trpg_Low; + data.randomIntensity = trpg_Low; + data.rascalSignificance = 0; + data.calligraphicAttr.drawOrder = 0; + data.calligraphicAttr.minDefocus = 0; + data.calligraphicAttr.maxDefocus = 0; + data.performerAttr.flags = 0; + data.performerAttr.minPixelSize = 0; + data.performerAttr.maxPixelSize = 0; + data.performerAttr.actualSize = 0; + data.performerAttr.transparentPixelSize = 0; + data.performerAttr.transparentFallofExp = 0; + data.performerAttr.transparentScale = 0; + data.performerAttr.transparentClamp = 0; + data.performerAttr.fogScale = 0; + data.animationAttr.period = 0; + data.animationAttr.phaseDelay = 0; + data.animationAttr.timeOn = 0; + data.animationAttr.vector = trpg3dPoint(0,0,1); + data.animationAttr.flags = 0; +} + +/************** + Light +*/ + +trpgLight::trpgLight(void) +{ + index = -1; +} + +trpgLight::trpgLight(const trpgLight &in) +{ + operator=(in); +} + +trpgLight::~trpgLight(void) +{ + Reset(); +} + +// Set the index pointing into the Light Table +void trpgLight::SetAttrIndex(int ix) +{ + index = ix; +} + +// Add a new location this light is located at +void trpgLight::AddVertex(trpg3dPoint pt) +{ + lightPoints.push_back(pt); +} + +// Returns the number of locations, this light is located at +void trpgLight::GetNumVertices(uint32 &nvertices) const +{ + nvertices = lightPoints.size(); +} + +// Returns the location at a given index +bool trpgLight::GetVertex(uint32 ix, trpg3dPoint &pt) const +{ + if (ix < lightPoints.size() ) { + pt = lightPoints[ix]; + return true; + } + else + return false; +} + +bool trpgLight::GetVertices(trpg3dPoint *pts) const +{ + int i; + + if (!isValid()) return false; + + if (lightPoints.size() != 0) + for (i=0;i= lightList.size()) return NULL; + return &lightList[id]; +} + +bool trpgLightTable::Read(trpgReadBuffer &buf) +{ + int32 numLights; + trpgToken lightTok; + int32 len; + + try { + buf.Get(numLights); + lightList.resize(numLights); + for (unsigned int i=0;i +#include +#include + +/* trpage_pparse.cpp + This file contains classes that can parse a TerraPage + archive for the purpose of printing it out. + */ + +#include "trpage_print.h" +#include "trpage_scene.h" + +/* Set up the callbacks for the scene graph parser. + In our case this is just one read helper with + a switch statement. + */ +trpgPrintGraphParser::trpgPrintGraphParser(trpgPrintBuffer *inBuf) +{ + printBuf = inBuf; + + // Register the readers + AddCallback(TRPG_GEOMETRY,new ReadHelper(printBuf)); + AddCallback(TRPG_GROUP,new ReadHelper(printBuf)); + AddCallback(TRPG_ATTACH,new ReadHelper(printBuf)); + AddCallback(TRPG_BILLBOARD,new ReadHelper(printBuf)); + AddCallback(TRPG_LOD,new ReadHelper(printBuf)); + AddCallback(TRPG_TRANSFORM,new ReadHelper(printBuf)); + AddCallback(TRPG_MODELREF,new ReadHelper(printBuf)); + AddCallback(TRPG_LAYER,new ReadHelper(printBuf)); + AddCallback(TRPG_LIGHT,new ReadHelper(printBuf)); + AddCallback(TRPGTILEHEADER,new ReadHelper(printBuf)); +} + +/* Start Children is called when the parser hits a Push + in the read buffer. We just want to indent further when + that happens. + */ +bool trpgPrintGraphParser::StartChildren(void *) +{ + printBuf->IncreaseIndent(); + + return true; +} + + +/* End Children is called when the parser hits a Pop + in the read buffer. We just want to reduce the indent + when that happens. + */ +bool trpgPrintGraphParser::EndChildren(void *) +{ + printBuf->DecreaseIndent(); + + return true; +} + +/* Read Helper parse method sets up the correct class depending + on the token and asks it to read and print itself. + */ +void *trpgPrintGraphParser::ReadHelper::Parse(trpgToken tok,trpgReadBuffer &buf) +{ + trpgReadWriteable *obj = NULL; + + switch (tok) { + case TRPG_GEOMETRY: + obj = new trpgGeometry(); + break; + case TRPG_GROUP: + obj = new trpgGroup(); + break; + case TRPG_ATTACH: + obj = new trpgAttach(); + break; + case TRPG_BILLBOARD: + obj = new trpgBillboard(); + break; + case TRPG_LOD: + obj = new trpgLod(); + break; + case TRPG_TRANSFORM: + obj = new trpgTransform(); + break; + case TRPG_MODELREF: + obj = new trpgModelRef(); + break; + case TRPG_LAYER: + obj = new trpgLayer(); + break; + case TRPG_LIGHT: + obj = new trpgLight(); + break; + case TRPGTILEHEADER: + obj = new trpgTileHeader(); + break; + }; + + if (obj) { + if (obj->Read(buf)) + obj->Print(*pBuf); + delete obj; + } + + // Need to return non-zero. Otherwise it's interpreted as an error + return (void *)1; +} + +// The following routine is not compiled if there's no _splitpath +#ifdef _splitpath +/* This is a convenience function to print out the contents + of an entire TerraPage archive. + + There are two versions of this function. The first takes + a file name and the second an opened archive where the header + has already been read. + */ +bool trpgPrintArchive(char *filename,trpgPrintBuffer &pBuf,int flags) +{ + trpgr_Archive archive; + + // Break path apart so we can find the directory + char drive[100],dir[1024],fname[1024],ext[1024]; + _splitpath(filename,drive,dir,fname,ext); + + char rname[1024],baseDir[1024]; + sprintf(baseDir,"%s%s",drive,dir); + sprintf(rname,"%s%s",fname,ext); + + if (!*baseDir) strcpy(baseDir,"."); + archive.SetDirectory(baseDir); + if (!archive.OpenFile(rname)) { + fprintf(stdout,"Failed to open archive.\n"); + return false; + } + if (!archive.ReadHeader()) { + fprintf(stdout,"Failed to read header.\n"); + return false; + } + + bool status = trpgPrintArchive(&archive,pBuff,flags); + return status; +} +#endif + +bool trpgPrintArchive(trpgr_Archive *archive,trpgPrintBuffer &pBuf,int flags) +{ + char ls[1024]; + + if (!archive->isValid()) return false; + + pBuf.prnLine("====Header Structures===="); + + // Print out the header portion + archive->GetHeader()->Print(pBuf); + archive->GetMaterialTable()->Print(pBuf); + archive->GetTexTable()->Print(pBuf); + archive->GetModelTable()->Print(pBuf); + archive->GetTileTable()->Print(pBuf); + archive->GetLightTable()->Print(pBuf); + archive->GetRangeTable()->Print(pBuf); + pBuf.prnLine(); + + // Now do the tiles + if (!archive->isValid()) return false; + + // Parser that prints out a tile scene graph + trpgPrintGraphParser parser(&pBuf); + + pBuf.prnLine("====Tile Data===="); + int nl,x,y; + trpgMemReadBuffer buf(archive->GetEndian()); + // Iterate over the terrain lods + int numLod; + archive->GetHeader()->GetNumLods(numLod); + trpg2iPoint tileSize; + for (nl=0;nlGetHeader()->GetLodSize(nl,tileSize); + // Iterate over the tiles + for (x=tileSize.x-1;x>=0;x--) + for (y=0;yReadTile(x,y,nl,buf)) { + if (flags & TRPGPRN_BODY) { + pBuf.IncreaseIndent(); + // Parse it (also prints it + parser.Parse(buf); + pBuf.DecreaseIndent(); + } + } else + pBuf.prnLine(" Couldn't read tile."); + } + } + + return true; +} diff --git a/src/osgPlugins/txp/trpage_print.cpp b/src/osgPlugins/txp/trpage_print.cpp new file mode 100644 index 000000000..abcf2e7f6 --- /dev/null +++ b/src/osgPlugins/txp/trpage_print.cpp @@ -0,0 +1,838 @@ +/* ************************ + Copyright Terrain Experts Inc. + Terrain Experts Inc (TERREX) reserves all rights to this source code + unless otherwise specified in writing by the President of TERREX. + This copyright may be updated in the future, in which case that version + supercedes this one. + ------------------- + Terrex Experts Inc. + 4400 East Broadway #314 + Tucson, AZ 85711 + info@terrex.com + Tel: (520) 323-7990 + ************************ + */ + +#include +#include +#include + +/* trpage_print.cpp + Print out the contents of a TerraPage archive. + This module provides an example of how to access each of the classes + within a TerraPage archive. + */ + +#include "trpage_print.h" + +/* ****************************************** + Print Buffer implementation + The print buffer is a way to dump debugging data out + to a file (or console). You can make your own subclass + of trpgPrintBuffer if you have specific needs. + ****************************************** + */ + +trpgPrintBuffer::trpgPrintBuffer() +{ + curIndent = 0; + indentStr[0] = 0; +} + +// Increase the current indent +void trpgPrintBuffer::IncreaseIndent(int amount) +{ + curIndent+=amount; + updateIndent(); +} + +// Decrease the current indent +void trpgPrintBuffer::DecreaseIndent(int amount) +{ + curIndent-=amount; + curIndent = MAX(0,curIndent); + updateIndent(); +} + +// Reprint the indent string +void trpgPrintBuffer::updateIndent() +{ + int i; + for (i=0;i(this))->GetMaterialRef(j,i); + mat->Print(buf); + } + buf.DecreaseIndent(); + } + buf.DecreaseIndent(2); + + return true; +} + +/* Print out texture. + */ +bool trpgTexture::Print(trpgPrintBuffer &buf) const +{ + char ls[1024]; + + buf.prnLine("----Texture----"); + buf.IncreaseIndent(); + sprintf(ls,"mode = %d, type = %d",mode,type); buf.prnLine(ls); + sprintf(ls,"Name = %s",name); buf.prnLine(ls); + sprintf(ls,"useCount = %d",useCount); buf.prnLine(ls); + sprintf(ls,"sizeX = %d, sizeY = %d",sizeX,sizeY); buf.prnLine(ls); + sprintf(ls,"ismipmap = %d",isMipmap); buf.prnLine(ls); + sprintf(ls,"addr.file = %d, addr.offset = %d",addr.file,addr.offset); buf.prnLine(ls); + buf.DecreaseIndent(); + + buf.prnLine(); + + return true; +} + +/* Print out texture table + */ +bool trpgTexTable::Print(trpgPrintBuffer &buf) const +{ + char ls[1024]; + + buf.prnLine("----Texture Table----"); + buf.IncreaseIndent(); + for (int i=0;i (ex,ey) = (%d,%d) -> (%d,%d)",sx,sy,ex,ey); buf.prnLine(ls); + sprintf(ls,"dest (width,height) = (%d,%d)",destWidth,destHeight); buf.prnLine(ls); + sprintf(ls,"addr (file,offset) = (%d,%d)",addr.file,addr.offset); buf.prnLine(ls); + buf.DecreaseIndent(); + buf.prnLine(); + + return true; +} + +/* Light Attribute Print +*/ +bool trpgLightAttr::Print(trpgPrintBuffer &buf) const +{ + char ls[1024]; + + const char* strType[] = {"Raster","Calligraphic","RASCAL"}; + const char* strDirect[] = {"Omnidirectional","Bidirectional","Unidirectional"}; + const char* strQuality[] = {"Off","Low","Medium","High","Undefined"}; + + buf.prnLine("----Light Attribute----"); + buf.IncreaseIndent(); + sprintf(ls,"type = %s",strType[(int)(data.type)]); buf.prnLine(ls); + sprintf(ls,"directionality = %s",strDirect[(int)(data.directionality)]);buf.prnLine(ls); + sprintf(ls,"front color (RGB) = %.2lf, %.2lf, %.2lf", + data.frontColor.red, data.frontColor.green,data.frontColor.blue ); buf.prnLine(ls); + sprintf(ls,"front intensity = %.2lf", data.frontIntensity ); buf.prnLine(ls); + sprintf(ls,"back color (RGB) = %.2lf, %.2lf, %.2lf", + data.backColor.red, data.backColor.green,data.backColor.blue ); buf.prnLine(ls); + sprintf(ls,"back intensity = %.2lf", data.backIntensity ); buf.prnLine(ls); + sprintf(ls,"normal (xyz) = %.2lf,%.2lf,%.2lf", + data.normal.x,data.normal.y,data.normal.z ); buf.prnLine(ls); + sprintf(ls,"smc = %d",data.smc); buf.prnLine(ls); + sprintf(ls,"fid = %d",data.fid); buf.prnLine(ls); + sprintf(ls,"visible at DAY = %s", + (data.flags & trpgLightAttr::trpg_Day ? "yes" : "no") ); buf.prnLine(ls); + sprintf(ls,"visible at DUSK = %s", + (data.flags & trpgLightAttr::trpg_Dusk ? "yes" : "no") ); buf.prnLine(ls); + sprintf(ls,"visible at NIGHT = %s", + (data.flags & trpgLightAttr::trpg_Night ? "yes" : "no") ); buf.prnLine(ls); + sprintf(ls,"enable directionality = %s", + (data.flags & trpgLightAttr::trpg_Directional ? "yes" : "no" )); buf.prnLine(ls); + sprintf(ls,"enable back color = %s", + (data.flags & trpgLightAttr::trpg_BackColor ? "yes" : "no" )); buf.prnLine(ls); + sprintf(ls,"horizontal lobe angle = %.2lf",data.horizontalLobeAngle); buf.prnLine(ls); + sprintf(ls,"vertical lobe angle = %.2lf",data.verticalLobeAngle); buf.prnLine(ls); + sprintf(ls,"lobe roll angle = %.2lf",data.lobeRollAngle); buf.prnLine(ls); + sprintf(ls,"lobe falloff = %.2lf",data.lobeFalloff); buf.prnLine(ls); + sprintf(ls,"ambient intensity = %.2lf",data.ambientIntensity); buf.prnLine(ls); + sprintf(ls,"reflective only = %s", + (data.flags & trpgLightAttr::trpg_Reflective ? "yes" : "no") ); buf.prnLine(ls); + sprintf(ls,"quality = %s", strQuality[(int)(data.quality)]); buf.prnLine(ls); + sprintf(ls,"significance for RASCAL lights = %.2lf", + data.rascalSignificance ); buf.prnLine(ls); + sprintf(ls,"calligraphic draw order = %d", + data.calligraphicAttr.drawOrder ); buf.prnLine(ls); + sprintf(ls,"calligraphic lights maximum defocus = %f", + data.calligraphicAttr.maxDefocus ); buf.prnLine(ls); + sprintf(ls,"calligraphic lights minimum defocus = %f", + data.calligraphicAttr.minDefocus ); buf.prnLine(ls); + sprintf(ls,"randomize intensity = %s", + strQuality[(int)(data.randomIntensity)]); buf.prnLine(ls); + sprintf(ls,"performer perspective mode = %s", + (data.flags & trpgLightAttr::trpg_Perspective ? "yes" : "no" ) ); buf.prnLine(ls); + sprintf(ls,"performer fade = %s", + (data.flags & trpgLightAttr::trpg_Fade ? "yes" : "no" ) ); buf.prnLine(ls); + sprintf(ls,"performer fog punch = %s", + (data.flags & trpgLightAttr::trpg_FogPunch ? "yes" : "no" ) ); buf.prnLine(ls); + sprintf(ls,"performer range mode enable Z buffer = %s", + (data.flags & trpgLightAttr::trpg_ZBuffer ? "yes" : "no" ) ); buf.prnLine(ls); + sprintf(ls,"performer maximum pixel size = %.2lf", + data.performerAttr.maxPixelSize ); buf.prnLine(ls); + sprintf(ls,"performer minimum pixel size = %.2lf", + data.performerAttr.minPixelSize ); buf.prnLine(ls); + sprintf(ls,"performer actual size = %.2lf", + data.performerAttr.actualSize ); buf.prnLine(ls); + sprintf(ls,"performer transparent pixel size = %.2lf", + data.performerAttr.transparentPixelSize ); buf.prnLine(ls); + sprintf(ls,"performer transparent falloff exponent = %.2lf", + data.performerAttr.transparentFallofExp ); buf.prnLine(ls); + sprintf(ls,"performer transparent scale = %.2lf", + data.performerAttr.transparentScale ); buf.prnLine(ls); + sprintf(ls,"performer transparent clamp = %.2lf", + data.performerAttr.transparentClamp ); buf.prnLine(ls); + sprintf(ls,"performer fog scale = %.2lf", + data.performerAttr.fogScale ); buf.prnLine(ls); + sprintf(ls,"animation period = %.2lf",data.animationAttr.period); buf.prnLine(ls); + sprintf(ls,"animation phase delay = %.2lf", + data.animationAttr.phaseDelay ); buf.prnLine(ls); + sprintf(ls,"animation time on = %.2lf",data.animationAttr.timeOn); buf.prnLine(ls); + sprintf(ls,"animation vector (ijk) = %.2lf, %.2lf, %.2lf", + data.animationAttr.vector.x,data.animationAttr.vector.y, + data.animationAttr.vector.z); buf.prnLine(ls); + sprintf(ls,"animation - flashing = %s", + (data.flags & trpgLightAttr::trpg_Flashing ? "yes" : "no" )); buf.prnLine(ls); + sprintf(ls,"animation - rotating = %s", + (data.flags & trpgLightAttr::trpg_Rotating ? "yes" : "no" )); buf.prnLine(ls); + sprintf(ls,"animation - counter clockwise = %s", + (data.flags & trpgLightAttr::trpg_ClockWise ? "yes" : "no" )); buf.prnLine(ls); + + buf.DecreaseIndent(); + buf.prnLine(); + + return true; +} + +/* Print out light table + */ +bool trpgLightTable::Print(trpgPrintBuffer &buf) const +{ + char ls[1024]; + + buf.prnLine("----Light Table----"); + buf.IncreaseIndent(); + for (int i=0;i +#include +#include + +#include "trpage_geom.h" +#include "trpage_read.h" + +/* ******************* + Range Methods + ******************* + */ + +trpgRange::trpgRange(void) +{ + category = NULL; + subCategory = NULL; + Reset(); +} + +trpgRange::~trpgRange(void) +{ + Reset(); +} + +trpgRange::trpgRange(const trpgRange &in) +{ + *this = in; +} + +void trpgRange::Reset(void) +{ + if (category) + delete [] category; + category = NULL; + if (subCategory) + delete [] subCategory; + subCategory = NULL; + + inLod = outLod = 0.0; + priority = 0; +} + +void trpgRange::SetCategory(char *cat,char *subCat) +{ + if (category) delete [] category; + category = NULL; + if (cat) { + category = new char[strlen(cat)+1]; + strcpy(category,cat); + } + + if (subCategory) delete [] subCategory; + subCategory = NULL; + if (subCat) { + subCategory = new char[strlen(subCat)+1]; + strcpy(subCategory,subCat); + } +} + +void trpgRange::GetCategory(char *cat,int catLen,char *subCat,int subCatLen) const +{ + if (category && cat) { + strncpy(cat,category,catLen); + } else + *cat = 0; + if (subCategory && subCat) { + strncpy(subCat,subCategory,subCatLen); + } else + *subCat = 0; +} + +void trpgRange::SetLodInfo(double in,double out) +{ + inLod = in; + outLod = out; +} + +void trpgRange::GetLodInfo(double &in,double &out) const +{ + in = inLod; + out = outLod; +} + +void trpgRange::SetPriority(int prior) +{ + priority = prior; +} + +void trpgRange::GetPriority(int &prior) const +{ + prior = priority; +} + +trpgRange & trpgRange::operator = (const trpgRange &other) +{ + Reset(); + inLod = other.inLod; + outLod = other.outLod; + SetCategory(other.category,other.subCategory); + priority = other.priority; + + return *this; +} + +bool trpgRange::operator == (const trpgRange &in) const +{ + if (inLod != in.inLod || outLod != in.outLod) + return false; + if (priority != in.priority) return false; + + if (category && in.category) { + if (strcmp(category,in.category)) + return false; + } else { + if (category && !in.category || + !category && in.category) + return false; + } + + if (subCategory && in.subCategory) { + if (strcmp(subCategory,in.subCategory)) + return false; + } else { + if (subCategory && !in.subCategory || + !subCategory && in.subCategory) + return false; + } + + return true; +} + +bool trpgRange::Write(trpgWriteBuffer &buf) +{ + buf.Begin(TRPG_RANGE); + buf.Add(inLod); + buf.Add(outLod); + buf.Add(priority); + buf.Add((category ? category : "")); + buf.Add((subCategory ? subCategory : "")); + buf.End(); + + return true; +} + +bool trpgRange::Read(trpgReadBuffer &buf) +{ + char catStr[1024],subStr[1024]; + + Reset(); + valid = false; + + try { + buf.Get(inLod); + buf.Get(outLod); + buf.Get(priority); + buf.Get(catStr,1024); + buf.Get(subStr,1024); + SetCategory(catStr,subStr); + valid = true; + } + + catch (...) { + return false; + } + + return isValid(); +} + +/* *************** + Range Table methods + *************** + */ + +trpgRangeTable::trpgRangeTable(void) +{ + valid = true; +} + +trpgRangeTable::~trpgRangeTable(void) +{ + // vector cleans up itself +} + +void trpgRangeTable::Reset(void) +{ + rangeList.resize(0); + valid = true; +} + +bool trpgRangeTable::GetRange(int id,trpgRange &ret) const +{ + if (!isValid()) + return false; + + if (id < 0 || id >= rangeList.size()) + return false; + + ret = rangeList[id]; + + return true; +} + +bool trpgRangeTable::SetRange(int id,trpgRange &inRange) +{ + if (!isValid()) + return false; + + if (id < 0 || id >= rangeList.size()) + return false; + + rangeList[id] = inRange; + + return true; +} + +int trpgRangeTable::AddRange(trpgRange &range) +{ + rangeList.push_back(range); + + return rangeList.size()-1; +} + +int trpgRangeTable::FindAddRange(trpgRange &range) +{ + for (int i=0;i