colladaExtensions.cpp 2.8 KB

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