Fixes mapping of imposter images to be packed as part of the shape asset, and fixes paths to be formatted more sanely.

This commit is contained in:
JeffR 2021-12-10 00:01:26 -06:00
parent bd876e427a
commit a8b3d874a1
7 changed files with 186 additions and 7 deletions

View file

@ -86,6 +86,8 @@ TSLastDetail::TSLastDetail( TSShape *shape,
mCenter = mShape->center;
mCachePath = cachePath;
mDiffusePath = mCachePath + "_imposter.dds";
mNormalPath = mCachePath + "_imposter_normals.dds";
mMaterial = NULL;
mMatInstance = NULL;
@ -94,6 +96,38 @@ TSLastDetail::TSLastDetail( TSShape *shape,
smLastDetails.push_back( this );
}
TSLastDetail::TSLastDetail(TSShape* shape,
const String& cachePath,
const String& diffusePath,
const String& normalPath,
U32 numEquatorSteps,
U32 numPolarSteps,
F32 polarAngle,
bool includePoles,
S32 dl, S32 dim)
{
mNumEquatorSteps = getMax(numEquatorSteps, (U32)1);
mNumPolarSteps = numPolarSteps;
mPolarAngle = polarAngle;
mIncludePoles = includePoles;
mShape = shape;
mDl = dl;
mDim = getMax(dim, (S32)32);
mRadius = mShape->mRadius;
mCenter = mShape->center;
mCachePath = cachePath;
mDiffusePath = diffusePath;
mNormalPath = normalPath;
mMaterial = NULL;
mMatInstance = NULL;
// Store this in the static list.
smLastDetails.push_back(this);
}
TSLastDetail::~TSLastDetail()
{
SAFE_DELETE( mMatInstance );
@ -189,7 +223,8 @@ void TSLastDetail::update( bool forceUpdate )
// Do we need to update the imposter?
const String diffuseMapPath = _getDiffuseMapPath();
if ( forceUpdate ||
bool isFile = Platform::isFile(diffuseMapPath.c_str());
if ( forceUpdate || !Platform::isFile(diffuseMapPath.c_str()) ||
Platform::compareModifiedTimes( diffuseMapPath, shapeFile ) <= 0 )
_update();
@ -218,8 +253,9 @@ void TSLastDetail::update( bool forceUpdate )
// Setup the material for this imposter.
mMaterial = MATMGR->allocateAndRegister( String::EmptyString );
mMaterial->mAutoGenerated = true;
mMaterial->_setDiffuseMap(diffuseMapPath,0);
mMaterial->_setNormalMap(_getNormalMapPath(), 0);
mMaterial->setDiffuseMapFile(diffuseMapPath, 0);
mMaterial->setNormalMapFile(_getNormalMapPath(), 0);
mMaterial->mImposterLimits.set( (mNumPolarSteps * 2) + 1, mNumEquatorSteps, mPolarAngle, mIncludePoles );
mMaterial->mTranslucent = true;
mMaterial->mTranslucentBlendOp = Material::None;
@ -466,8 +502,8 @@ void TSLastDetail::_update()
// Should we dump the images?
if ( Con::getBoolVariable( "$TSLastDetail::dumpImposters", false ) )
{
String imposterPath = mCachePath + ".imposter.png";
String normalsPath = mCachePath + ".imposter_normals.png";
String imposterPath = _getDiffuseMapPath();
String normalsPath = _getNormalMapPath();
FileStream stream;
if ( stream.open( imposterPath, Torque::FS::File::Write ) )