From c3b1aaae5a09837871bb7e88e836cc534acd70c6 Mon Sep 17 00:00:00 2001 From: irei1as Date: Tue, 23 Feb 2016 17:17:54 +0100 Subject: [PATCH 1/2] New script function to edit created decals TorqueScript function to edit decals created with decalManagerAddDecal. --- Engine/source/T3D/decal/decalManager.cpp | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Engine/source/T3D/decal/decalManager.cpp b/Engine/source/T3D/decal/decalManager.cpp index 6db06a521..d733a78dd 100644 --- a/Engine/source/T3D/decal/decalManager.cpp +++ b/Engine/source/T3D/decal/decalManager.cpp @@ -1744,3 +1744,44 @@ DefineEngineFunction( decalManagerRemoveDecal, bool, ( S32 decalID ),, gDecalManager->removeDecal(inst); return true; } + +DefineEngineFunction( decalManagerEditDecal, bool, ( S32 decalID, Point3F pos, Point3F normal, F32 rotAroundNormal, F32 decalScale ),, + "Edit specified decal of the decal manager.\n" + "@param decalID ID of the decal to edit.\n" + "@param pos World position for the decal.\n" + "@param normal Decal normal vector (if the decal was a tire lying flat on a " + "surface, this is the vector pointing in the direction of the axle).\n" + "@param rotAroundNormal Angle (in radians) to rotate this decal around its normal vector.\n" + "@param decalScale Scale factor applied to the decal.\n" + "@return Returns true if successful, false if decalID not found.\n" + "" ) +{ + DecalInstance *decalInstance = gDecalManager->getDecal( decalID ); + if( !decalInstance ) + return false; + + //Internally we need Point3F tangent instead of the user friendly F32 rotAroundNormal + MatrixF mat( true ); + MathUtils::getMatrixFromUpVector( normal, &mat ); + + AngAxisF rot( normal, rotAroundNormal ); + MatrixF rotmat; + rot.setMatrix( &rotmat ); + mat.mul( rotmat ); + + Point3F tangent; + mat.getColumn( 1, &tangent ); + + //if everything is unchanged just do nothing and return "everything is ok" + if ( pos.equal(decalInstance->mPosition) && normal.equal(decalInstance->mNormal) && tangent.equal(decalInstance->mTangent) && mFabs( decalInstance->mSize - (decalInstance->mDataBlock->size * decalScale) ) < POINT_EPSILON ) return true; + + decalInstance->mPosition = pos; + decalInstance->mNormal = normal; + decalInstance->mTangent = tangent; + decalInstance->mSize = decalInstance->mDataBlock->size * decalScale; + + gDecalManager->clipDecal( decalInstance, NULL, NULL); + + gDecalManager->notifyDecalModified( decalInstance ); + return true; +} From 988bd47d5279d36b11f30c8bc815d9361b6dcd68 Mon Sep 17 00:00:00 2001 From: irei1as Date: Wed, 24 Feb 2016 09:02:07 +0100 Subject: [PATCH 2/2] Visibility change as sugested by dottools --- Engine/source/T3D/decal/decalManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/decal/decalManager.cpp b/Engine/source/T3D/decal/decalManager.cpp index d733a78dd..f992705d1 100644 --- a/Engine/source/T3D/decal/decalManager.cpp +++ b/Engine/source/T3D/decal/decalManager.cpp @@ -1773,7 +1773,11 @@ DefineEngineFunction( decalManagerEditDecal, bool, ( S32 decalID, Point3F pos, P mat.getColumn( 1, &tangent ); //if everything is unchanged just do nothing and return "everything is ok" - if ( pos.equal(decalInstance->mPosition) && normal.equal(decalInstance->mNormal) && tangent.equal(decalInstance->mTangent) && mFabs( decalInstance->mSize - (decalInstance->mDataBlock->size * decalScale) ) < POINT_EPSILON ) return true; + if ( pos.equal(decalInstance->mPosition) && + normal.equal(decalInstance->mNormal) && + tangent.equal(decalInstance->mTangent) && + mFabs( decalInstance->mSize - (decalInstance->mDataBlock->size * decalScale) ) < POINT_EPSILON ) + return true; decalInstance->mPosition = pos; decalInstance->mNormal = normal;