From 5408a5eade590fb4604197e6395c874bcc7ca7d0 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 24 Oct 2017 19:15:54 -0500 Subject: [PATCH 1/2] allows arbitrary material name string replacement, rather than forcing folks to start with base. ie: an entry of skin = "blue; area=fire"; would replace base_area_grid with blue_fire_grid as the used material --- Engine/source/ts/tsShapeInstance.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Engine/source/ts/tsShapeInstance.cpp b/Engine/source/ts/tsShapeInstance.cpp index 98d6b39ea..7010371bc 100644 --- a/Engine/source/ts/tsShapeInstance.cpp +++ b/Engine/source/ts/tsShapeInstance.cpp @@ -307,12 +307,9 @@ void TSShapeInstance::reSkin( String newBaseName, String oldBaseName ) { // Try changing base const String &pName = materialNames[i]; - if ( pName.compare( oldBaseName, oldBaseNameLength, String::NoCase ) == 0 ) - { - String newName( pName ); - newName.replace( 0, oldBaseNameLength, newBaseName ); - pMatList->renameMaterial( i, newName ); - } + String newName( pName ); + newName.replace( oldBaseName, newBaseName ); + pMatList->renameMaterial( i, newName ); } // Initialize the material instances From 00798992811349ebdba4a210633e847bc08a0bf7 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Sun, 12 Nov 2017 23:58:34 -0600 Subject: [PATCH 2/2] new method: TSShapeInstance::resetMaterialList(). Sets all object-instance mapto values back to initial state. reskin now does so to avoid having to track origional values independently. (so say, if you've already got skin1 plugged in to one, and nothing in to another, no need to set skin1=skin2 on the first and skin2 or base=skin2 on the second to swap both on over to skin2). also by request, went ahead and killed case sensitivity for mapto string replacement when reskinning. --- Engine/source/T3D/player.cpp | 1 + Engine/source/T3D/shapeBase.cpp | 1 + Engine/source/T3D/tsStatic.cpp | 1 + Engine/source/ts/tsShapeInstance.cpp | 10 ++++++++-- Engine/source/ts/tsShapeInstance.h | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Engine/source/T3D/player.cpp b/Engine/source/T3D/player.cpp index 15b57046a..7f537d65d 100644 --- a/Engine/source/T3D/player.cpp +++ b/Engine/source/T3D/player.cpp @@ -1953,6 +1953,7 @@ void Player::reSkin() { if ( isGhost() && mShapeInstance && mSkinNameHandle.isValidString() ) { + mShapeInstance->resetMaterialList(); Vector skins; String(mSkinNameHandle.getString()).split( ";", skins ); diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index 5f71a7eb9..19ada8ce2 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -3689,6 +3689,7 @@ void ShapeBase::reSkin() { if ( isGhost() && mShapeInstance && mSkinNameHandle.isValidString() ) { + mShapeInstance->resetMaterialList(); Vector skins; String(mSkinNameHandle.getString()).split( ";", skins ); diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index b2f33f44a..67e210f34 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -534,6 +534,7 @@ void TSStatic::reSkin() { if ( isGhost() && mShapeInstance && mSkinNameHandle.isValidString() ) { + mShapeInstance->resetMaterialList(); Vector skins; String(mSkinNameHandle.getString()).split( ";", skins ); diff --git a/Engine/source/ts/tsShapeInstance.cpp b/Engine/source/ts/tsShapeInstance.cpp index 7010371bc..53167f1cf 100644 --- a/Engine/source/ts/tsShapeInstance.cpp +++ b/Engine/source/ts/tsShapeInstance.cpp @@ -307,8 +307,8 @@ void TSShapeInstance::reSkin( String newBaseName, String oldBaseName ) { // Try changing base const String &pName = materialNames[i]; - String newName( pName ); - newName.replace( oldBaseName, newBaseName ); + String newName( String::ToLower(pName) ); + newName.replace( String::ToLower(oldBaseName), String::ToLower(newBaseName) ); pMatList->renameMaterial( i, newName ); } @@ -316,6 +316,12 @@ void TSShapeInstance::reSkin( String newBaseName, String oldBaseName ) initMaterialList(); } +void TSShapeInstance::resetMaterialList() +{ + TSMaterialList* oMatlist = mShape->materialList; + setMaterialList(oMatlist); +} + //------------------------------------------------------------------------------------- // Render & detail selection //------------------------------------------------------------------------------------- diff --git a/Engine/source/ts/tsShapeInstance.h b/Engine/source/ts/tsShapeInstance.h index c483c8792..627eb63ce 100644 --- a/Engine/source/ts/tsShapeInstance.h +++ b/Engine/source/ts/tsShapeInstance.h @@ -377,7 +377,7 @@ protected: } void reSkin( String newBaseName, String oldBaseName = String::EmptyString ); - + void resetMaterialList(); enum { MaskNodeRotation = 0x01,