MegaVertColSelect.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Selection/Vert Color")]
  3. public class MegaVertColSelect : MegaSelectionMod
  4. {
  5. public override MegaModChannel ChannelsReq() { return MegaModChannel.Col; }
  6. public override string ModName() { return "Vert Color Select"; }
  7. public override string GetHelpURL() { return "?page_id=1305"; }
  8. public MegaChannel channel = MegaChannel.Red;
  9. float[] modselection;
  10. public float[] GetSel() { return modselection; }
  11. public float gizSize = 0.01f;
  12. public bool displayWeights = true;
  13. public float weight = 1.0f;
  14. public float threshold = 0.0f;
  15. public bool update = true;
  16. public override void GetSelection(MegaModifiers mc)
  17. {
  18. if ( ModEnabled )
  19. {
  20. if ( modselection == null || modselection.Length != mc.verts.Length )
  21. modselection = new float[mc.verts.Length];
  22. if ( update )
  23. {
  24. update = false;
  25. if ( mc.cols != null && mc.cols.Length > 0 )
  26. {
  27. int c = (int)channel;
  28. for ( int i = 0; i < mc.verts.Length; i++ )
  29. modselection[i] = ((mc.cols[i][c] - threshold) / (1.0f - threshold)) * weight;
  30. }
  31. else
  32. {
  33. for ( int i = 0; i < mc.verts.Length; i++ )
  34. modselection[i] = weight;
  35. }
  36. }
  37. mc.selection = modselection;
  38. }
  39. }
  40. }