RawModelProcessor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #region License
  2. // Copyright 2015-2016 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using Microsoft.Xna.Framework.Content.Pipeline;
  17. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  19. namespace nkast.Aether.Content.Pipeline
  20. {
  21. [ContentProcessor(DisplayName = "RawModelProcessor - Aether")]
  22. class RawModelProcessor : ModelProcessor
  23. {
  24. public override ModelContent Process(NodeContent input, ContentProcessorContext context)
  25. {
  26. ModelContent model = base.Process(input, context);
  27. foreach(ModelMeshContent mesh in model.Meshes)
  28. foreach(ModelMeshPartContent part in mesh.MeshParts)
  29. Proccess(part);
  30. return model;
  31. }
  32. private void Proccess(ModelMeshPartContent part)
  33. {
  34. byte[] vertexData = part.VertexBuffer.VertexData;
  35. object indexData;
  36. int indexSize = part.IndexBuffer.Count;
  37. if (part.VertexBuffer.VertexData.Length < short.MaxValue)
  38. {
  39. short[] indexData16 = new short[indexSize];
  40. for (int i = 0; i < indexSize; i++)
  41. indexData16[i] = (short)part.IndexBuffer[i];
  42. indexData = indexData16;
  43. }
  44. else
  45. {
  46. int[] indexData32 = new int[indexSize];
  47. part.IndexBuffer.CopyTo(indexData32, 0);
  48. indexData = indexData32;
  49. }
  50. object[] tag;
  51. tag = new object[] { vertexData, indexData };
  52. part.Tag = tag;
  53. }
  54. }
  55. }