cwisbg

PopulateFromTexture

Nov 21st, 2018
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. from pymel.core import *
  2. #grass plane
  3. Plane = ls("pPlane1")[0]
  4. PlaneScale = Plane.getScale()
  5. #scale of grass object
  6. PlaneWidth = PlaneScale[0]
  7. PlaneHeight = PlaneScale[2]
  8. # get pixles from texture
  9. CellWidth = getAttr(Plane.getShape().listConnections()[1].subdivisionsWidth)
  10. CellHeight = getAttr(Plane.getShape().listConnections()[1].subdivisionsHeight)
  11.  
  12.  
  13.  
  14.  
  15.  
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using UnityEngine;
  19.  
  20. public class MakeTexture : MonoBehaviour {
  21.  
  22. public Color StartColor;
  23. public Color EndColor;
  24. public int TextueWidth = 16;
  25. public int TextureHeight = 16;
  26. //public Color[] StartColorList;
  27. private Texture2D texture;
  28. private Color[] mapPixels;
  29. private int mapPixelLength;
  30. private float Timer = 0;
  31. public int Offseter = 0;
  32.  
  33.  
  34. void LoopThroughPixles()
  35. {
  36.  
  37. for (var ix = 0; ix < mapPixelLength; ix++)
  38. {
  39. for (var iy = 0; iy < mapPixelLength; iy++)
  40. {
  41. texture.SetPixel(ix, iy, EndColor);
  42. }
  43. }
  44. texture.Apply(false);
  45. }
  46.  
  47. void Start () {
  48. texture = new Texture2D(TextueWidth, TextureHeight);
  49. texture.filterMode = 0;
  50. GetComponent<Renderer>().material.mainTexture = texture;
  51. mapPixels = texture.GetPixels();
  52. mapPixelLength = mapPixels.Length;
  53. for (var ix = 0; ix < mapPixelLength; ix++)
  54. {
  55. for (var iy = 0; iy < mapPixelLength; iy++)
  56. {
  57. texture.SetPixel(ix, iy, StartColor);
  58. }
  59. }
  60. texture.Apply(false);
  61.  
  62. }
  63.  
  64. void Update()
  65. {
  66.  
  67.  
  68. LoopThroughPixles();
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment