Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using System;
- using System.IO;
- public class UVMeshDeform : MonoBehaviour {
- Texture2D deformer;
- public Material deformermat;
- public float midway;
- Vector2[] uvdeform;
- Vector2[] uvdest;
- public GameObject destination;
- void Start()
- {
- Mesh oldmesh = GetComponent<MeshFilter>().sharedMesh;
- Mesh newmesh = Instantiate(oldmesh) as Mesh;
- Mesh destmesh = destination.GetComponent<MeshFilter>().sharedMesh;
- GetComponent<MeshFilter>().sharedMesh = newmesh;
- Vector3[] verticesold = newmesh.vertices;
- Vector3[] verticesnew = destmesh.vertices;
- uvdeform = newmesh.uv;
- deformer = new Texture2D(512,512,TextureFormat.RGBAFloat,false);
- for (int p = 0; p < uvdeform.Length; p++)
- {
- //Color pixels = deformer.GetPixelBilinear(uvdeform[p].x, uvdeform[p].y);
- //verticesold[p].x += verticesnew[p].x - verticesold[p].x;
- //verticesold[p].y += verticesnew[p].y - verticesold[p].y;
- //verticesold[p].z += verticesnew[p].z - verticesold[p].z;
- Color pixels = new Color((verticesnew[p].x - verticesold[p].x) + (midway / 255), (verticesnew[p].y - verticesold[p].y) + (midway / 255), (verticesnew[p].z - verticesold[p].z) + (midway / 255));
- deformer.SetPixel(Mathf.RoundToInt(uvdeform[p].x * deformer.width), Mathf.RoundToInt(uvdeform[p].y * deformer.height), pixels);
- verticesold[p].x += pixels.r - (midway / 255);
- verticesold[p].y += pixels.g - (midway / 255);
- verticesold[p].z += pixels.b - (midway / 255);
- //print(pixels.r);
- }
- byte[] bytes = deformer.EncodeToPNG();
- File.WriteAllBytes(Application.dataPath + "SavedScreen.png", bytes);
- newmesh.vertices = verticesold;
- newmesh.RecalculateBounds();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement