colladaExtensions.cpp
Engine/source/ts/collada/colladaExtensions.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25 26#include "math/mRandom.h" 27#include "ts/collada/colladaExtensions.h" 28 29/// Check if any of the MAYA texture transform elements are animated within 30/// the interval 31bool ColladaExtension_effect::animatesTextureTransform(F32 start, F32 end) 32{ 33 return repeatU.isAnimated(start, end) || repeatV.isAnimated(start, end) || 34 offsetU.isAnimated(start, end) || offsetV.isAnimated(start, end) || 35 rotateUV.isAnimated(start, end) || noiseU.isAnimated(start, end) || 36 noiseV.isAnimated(start, end); 37} 38 39/// Apply the MAYA texture transform to the given UV coordinates 40void ColladaExtension_effect::applyTextureTransform(Point2F& uv, F32 time) 41{ 42 // This function will be called for every tvert, every frame. So cache the 43 // texture transform parameters to avoid interpolating them every call (since 44 // they are constant for all tverts for a given 't') 45 if (time != lastAnimTime) { 46 // Update texture transform 47 textureTransform.set(EulerF(0, 0, rotateUV.getValue(time))); 48 textureTransform.setPosition(Point3F( 49 offsetU.getValue(time) + noiseU.getValue(time)*gRandGen.randF(), 50 offsetV.getValue(time) + noiseV.getValue(time)*gRandGen.randF(), 51 0)); 52 textureTransform.scale(Point3F(repeatU.getValue(time), repeatV.getValue(time), 1.0f)); 53 54 lastAnimTime = time; 55 } 56 57 // Apply texture transform 58 Point3F result; 59 textureTransform.mulP(Point3F(uv.x, uv.y, 0), &result); 60 61 uv.x = result.x; 62 uv.y = result.y; 63} 64