daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [ExecuteInEditMode]
  6. public class SkinnedQuad : MonoBehaviour {
  7.  
  8.     public Transform[] bones;
  9.     SkinnedMeshRenderer smr;
  10.     private void Awake()
  11.     {
  12.         Mesh m = new Mesh();
  13.  
  14.         m.vertices = new Vector3[]
  15.         {
  16.             //몸통
  17.              new Vector3(0,-0.5f,0),        //0
  18.              new Vector3(-1f,1f,0),         //1
  19.              new Vector3(1, 1f, 0),         //2
  20.              //머리                        
  21.              new Vector3(0,1f,0),           //3
  22.              new Vector3(-0.5f,2f,0),       //4
  23.              new Vector3(0.5f,2f,0),        //5
  24.              //왼쪽 팔                      
  25.              new Vector3(1f,1f,0),          //6
  26.              new Vector3(2.5f,1.25f,0),     //7
  27.              new Vector3(2.5f,0.75f,0),     //8
  28.              new Vector3(2.5f,1f,0),        //9
  29.              new Vector3(4f,1.25f,0),       //10
  30.              new Vector3(4f,0.75f,0),       //11
  31.              //오른쪽 팔                    
  32.              new Vector3(-1f,1f,0),         //12
  33.              new Vector3(-2.5f,1.25f,0),    //13
  34.              new Vector3(-2.5f,0.75f,0),    //14
  35.              new Vector3(-2.5f,1f,0),       //15
  36.              new Vector3(-4f,1.25f,0),      //16
  37.              new Vector3(-4f,0.75f,0),      //17
  38.                                            
  39.              //골반                         //
  40.              new Vector3(0,-0.5f,0),        //18
  41.              new Vector3(-0.5f,-1.25f,0),   //19
  42.              new Vector3(0.5f,-1.25f,0),    //20
  43.                                            
  44.              //오른쪽 다리                   //
  45.              new Vector3(-0.5f,-1.25f,0),   //21
  46.              new Vector3(-0.75f,-2.75f,0),  //22
  47.              new Vector3(-0.25f,-2.75f,0),  //23
  48.                                            
  49.              new Vector3(-0.5f,-2.75f,0),   //24
  50.              new Vector3(-0.75f,-4.25f,0),  //25
  51.              new Vector3(-0.25f,-4.25f,0),  //26
  52.                                            
  53.              //왼쪽 다리                     //
  54.              new Vector3(0.5f,-1.25f,0),    //27
  55.              new Vector3(0.25f,-2.75f,0),   //28
  56.              new Vector3(0.75f,-2.75f,0),   //29
  57.                                            
  58.              new Vector3(0.5f,-2.75f,0),    //30
  59.              new Vector3(0.25f,-4.25f,0),   //31
  60.              new Vector3(0.75f,-4.25f,0)    //32
  61.                                            
  62.         };
  63.  
  64.         m.triangles = new int[]
  65.         {
  66.            0,1,2,
  67.            3,4,5,
  68.            6,7,8,
  69.            9,10,11,
  70.            12,14,13,
  71.            15,17,16,
  72.            18,20,19,
  73.            21,23,22,
  74.            24,26,25,
  75.            27,29,28,
  76.            30,32,31
  77.         };
  78.  
  79.        // m.uv = new Vector2[]
  80.        // {
  81.        //     new Vector2(0.125f,0.75f),
  82.        //     new Vector2(0.125f,0.875f),
  83.        //     new Vector2(0.25f,0.875f),
  84.        //     new Vector2(0.25f,0.75f)
  85.        // };
  86.  
  87.         m.bindposes = new Matrix4x4[]
  88.         {
  89.             bones[0].worldToLocalMatrix * transform.localToWorldMatrix,
  90.             bones[1].worldToLocalMatrix * transform.localToWorldMatrix,
  91.             bones[2].worldToLocalMatrix * transform.localToWorldMatrix,
  92.             bones[3].worldToLocalMatrix * transform.localToWorldMatrix,
  93.             bones[4].worldToLocalMatrix * transform.localToWorldMatrix,
  94.             bones[5].worldToLocalMatrix * transform.localToWorldMatrix,
  95.             bones[6].worldToLocalMatrix * transform.localToWorldMatrix,
  96.             bones[7].worldToLocalMatrix * transform.localToWorldMatrix,
  97.             bones[8].worldToLocalMatrix * transform.localToWorldMatrix
  98.         };
  99.  
  100.         m.boneWeights = new BoneWeight[]
  101.         {
  102.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  103.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  104.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  105.  
  106.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  107.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  108.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  109.  
  110.             new BoneWeight(){ boneIndex0 = 1, weight0 = 1},
  111.             new BoneWeight(){ boneIndex0 = 1, weight0 = 1},
  112.             new BoneWeight(){ boneIndex0 = 1, weight0 = 1},
  113.  
  114.             new BoneWeight(){ boneIndex0 = 2, weight0 = 1},
  115.             new BoneWeight(){ boneIndex0 = 2, weight0 = 1},
  116.             new BoneWeight(){ boneIndex0 = 2, weight0 = 1},
  117.  
  118.             new BoneWeight(){ boneIndex0 = 3, weight0 = 1},
  119.             new BoneWeight(){ boneIndex0 = 3, weight0 = 1},
  120.             new BoneWeight(){ boneIndex0 = 3, weight0 = 1},
  121.  
  122.             new BoneWeight(){ boneIndex0 = 4, weight0 = 1},
  123.             new BoneWeight(){ boneIndex0 = 4, weight0 = 1},
  124.             new BoneWeight(){ boneIndex0 = 4, weight0 = 1},
  125.  
  126.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  127.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  128.             new BoneWeight(){ boneIndex0 = 0, weight0 = 1},
  129.  
  130.  
  131.             new BoneWeight(){ boneIndex0 = 5, weight0 = 1},
  132.             new BoneWeight(){ boneIndex0 = 5, weight0 = 1},
  133.             new BoneWeight(){ boneIndex0 = 5, weight0 = 1},
  134.  
  135.             new BoneWeight(){ boneIndex0 = 6, weight0 = 1},
  136.             new BoneWeight(){ boneIndex0 = 6, weight0 = 1},
  137.             new BoneWeight(){ boneIndex0 = 6, weight0 = 1},
  138.  
  139.             new BoneWeight(){ boneIndex0 = 7, weight0 = 1},
  140.             new BoneWeight(){ boneIndex0 = 7, weight0 = 1},
  141.             new BoneWeight(){ boneIndex0 = 7, weight0 = 1},
  142.             new BoneWeight(){ boneIndex0 = 8, weight0 = 1},
  143.             new BoneWeight(){ boneIndex0 = 8, weight0 = 1},
  144.             new BoneWeight(){ boneIndex0 = 8, weight0 = 1}
  145.  
  146.         };
  147.  
  148.         smr = GetComponent<SkinnedMeshRenderer>();
  149.         smr.bones = bones;
  150.         smr.sharedMesh = m;
  151.         smr.quality = SkinQuality.Bone1;
  152.     }
  153. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top