Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Plate : MonoBehaviour {
- Mesh mesh;
- Vector3[] verticles;
- public float size_x = 0.05f;
- public float size_y = 0.05f;
- public float height_metall = 0.005f;
- public float width_incision = 10.0f;
- public int count = 4;
- //ФИЗИКА
- float[,] h;
- float[,]Q;
- // Use this for initialization
- void Start () {
- mesh = GetComponent<MeshFilter>().mesh;
- h = new float[count,count];
- Q = new float[count, count];
- //region Отрисовка пластины сварного соединения
- //создаем вершины
- verticles = new Vector3[count*count];
- int n = 0;
- for (int i = 0; i < count; i++) {
- for (int j = 0; j < count; j++) {
- verticles [n] = new Vector3 (i*size_x/(count-1),0,j*size_y/(count-1));
- n++;
- }
- }
- //создаем полигоны (треугольники)
- int[] tri = new int[(count-1)*(count-1)*6];
- n = 0;
- for (int i = 0; i < count-2; i++) {
- for (int j = 0; j < count-2; j++) {
- tri[n] = (i*count)+j;
- tri[n+1] = (i*count)+j+1;
- tri[n+2] = (i*count)+j+count+1;
- tri[n+3] = (i*count)+j;
- tri[n+4] = (i*count)+j+count+1;
- tri[n+5] = (i*count)+j+count;
- n+=6;
- }
- }
- //Устанавливаем нормали
- Vector3[] normals = new Vector3[count*count];
- for (int i = 0; i < count; i++) {
- normals [i] = -Vector3.up;
- }
- //endregion
- //Делаем разрез стыка металлов
- for (int i = (count - 1) / 2 * count; i < (count - 1) / 2 * count + count - 1; i++)
- {
- verticles[i] -= new Vector3(0, width_incision * height_metall, 0);
- }
- mesh.vertices = verticles;
- mesh.triangles = tri;
- mesh.normals = normals;
- mesh.RecalculateNormals();
- mesh.RecalculateBounds();
- //Добавляем коллайдер для пластины
- transform.gameObject.AddComponent<MeshCollider>(); //Добавим компонент MeshCollider
- transform.GetComponent<MeshCollider> ().convex = true; //Установим convex в истину
- transform.GetComponent<MeshCollider> ().sharedMesh = mesh; //Применим на mesh наш сгенерированный меш.
- }
- // Update is called once per frame
- void Update () {
- mesh.vertices = verticles;
- mesh.RecalculateNormals();
- mesh.RecalculateBounds();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement