FixHWSkinningSerialization.diff 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 9e187647d01b2994d8ba4eb0c925c3e4522d562a Mon Sep 17 00:00:00 2001
  2. From: MeFisto94 <[email protected]>
  3. Date: Wed, 25 May 2016 17:40:00 +0200
  4. Subject: [PATCH] Fix Hardware Skinning in 3.1 by implementing proper Array
  5. Serialization for MatParams and making the Shared Materials Check only a
  6. warning (it would pop up once each time you load the j3o and if you really
  7. use Shared Materials you have weird animations and some log spamming)
  8. ---
  9. .../java/com/jme3/animation/SkeletonControl.java | 3 +-
  10. .../src/main/java/com/jme3/material/MatParam.java | 37 ++++++++++++++++++++++
  11. 2 files changed, 39 insertions(+), 1 deletion(-)
  12. diff --git a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java b/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java
  13. index b753ad2..1d14fa6 100644
  14. --- a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java
  15. +++ b/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java
  16. @@ -255,7 +255,8 @@ public class SkeletonControl extends AbstractControl implements Cloneable, JmeCl
  17. // is operating on this material, in that case, user
  18. // is sharing materials between models which is NOT allowed
  19. // when hardware skinning used.
  20. - throw new UnsupportedOperationException(
  21. +
  22. + Logger.getLogger(SkeletonControl.class.getName()).log(Level.SEVERE,
  23. "Material instances cannot be shared when hardware skinning is used. " +
  24. "Ensure all models use unique material instances."
  25. );
  26. diff --git a/jme3-core/src/main/java/com/jme3/material/MatParam.java b/jme3-core/src/main/java/com/jme3/material/MatParam.java
  27. index 8d965e3..6c069a1 100644
  28. --- a/jme3-core/src/main/java/com/jme3/material/MatParam.java
  29. +++ b/jme3-core/src/main/java/com/jme3/material/MatParam.java
  30. @@ -309,6 +309,8 @@ When arrays can be inserted in J3M files
  31. } else if (value instanceof Boolean) {
  32. Boolean b = (Boolean) value;
  33. oc.write(b.booleanValue(), "value_bool", false);
  34. + } else if (value.getClass().isArray() && value instanceof Savable[]) {
  35. + oc.write((Savable[])value, "value_savable_array", null);
  36. }
  37. }
  38. @@ -327,6 +329,41 @@ When arrays can be inserted in J3M files
  39. case Int:
  40. value = ic.readInt("value_int", 0);
  41. break;
  42. + case Vector2Array:
  43. + Savable[] savableArray = ic.readSavableArray("value_savable_array", null);
  44. + if (savableArray != null) {
  45. + value = new Vector2f[savableArray.length];
  46. + System.arraycopy(savableArray, 0, value, 0, savableArray.length);
  47. + }
  48. + break;
  49. + case Vector3Array:
  50. + savableArray = ic.readSavableArray("value_savable_array", null);
  51. + if (savableArray != null) {
  52. + value = new Vector3f[savableArray.length];
  53. + System.arraycopy(savableArray, 0, value, 0, savableArray.length);
  54. + }
  55. + break;
  56. + case Vector4Array:
  57. + savableArray = ic.readSavableArray("value_savable_array", null);
  58. + if (savableArray != null) {
  59. + value = new Vector4f[savableArray.length];
  60. + System.arraycopy(savableArray, 0, value, 0, savableArray.length);
  61. + }
  62. + break;
  63. + case Matrix3Array:
  64. + savableArray = ic.readSavableArray("value_savable_array", null);
  65. + if (savableArray != null) {
  66. + value = new Matrix3f[savableArray.length];
  67. + System.arraycopy(savableArray, 0, value, 0, savableArray.length);
  68. + }
  69. + break;
  70. + case Matrix4Array:
  71. + savableArray = ic.readSavableArray("value_savable_array", null);
  72. + if (savableArray != null) {
  73. + value = new Matrix4f[savableArray.length];
  74. + System.arraycopy(savableArray, 0, value, 0, savableArray.length);
  75. + }
  76. + break;
  77. default:
  78. value = ic.readSavable("value_savable", null);
  79. break;
  80. --
  81. 1.8.4