Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [ExecuteInEditMode]
- public class SkinnedQuad : MonoBehaviour
- {
- public Transform[] bones;
- SkinnedMeshRenderer smr;
- private void Awake()
- {
- Mesh m = new Mesh(); // mesh 생성
- m.vertices = new Vector3[]
- {
- new Vector2(-1,-3),
- new Vector2(0,-1),
- new Vector2(1,-3),
- new Vector2(0,0),
- new Vector2(-1,1),
- new Vector2(1,1),
- new Vector2(0,-1),
- new Vector2(-1,0),
- new Vector2(1,0),
- //leftshoulder
- new Vector2(-1.5f, -2.5f),
- new Vector2(-1.5f, -1.5f),
- new Vector2(-0.5f ,-2),
- //left arm
- new Vector2(-2, -2),
- new Vector2(-1.5f, -1.75f),
- new Vector2(-1.5f, -2.25f),
- //rightsoulder
- new Vector2(0.5f, -2),
- new Vector2(1.5f, -1.5f),
- new Vector2(1.5f ,-2.5f),
- //right arm
- new Vector2(1.5f ,-2.25f),
- new Vector2(1.5f, -1.75f),
- new Vector2(2, -2),
- //left knee
- new Vector2(-1, -4),
- new Vector2(-0.5f, -3),
- new Vector2(0 ,-4),
- //left leg
- new Vector2(-0.5f, -4.5f),
- new Vector2(-0.75f, -4),
- new Vector2(-0.25f ,-4),
- //right knee
- new Vector2(0, -4),
- new Vector2(0.5f, -3),
- new Vector2(1 ,-4),
- //right leg
- new Vector2(0.5f, -4.5f),
- new Vector2(0.25f, -4),
- new Vector2(0.75f ,-4),
- };
- m.triangles = new int[]
- {
- 0, 1, 2,
- 3, 4, 5,
- 6, 7, 8,
- 9, 10, 11,
- 12, 13, 14,
- 15, 16, 17,
- 18, 19, 20,
- 21, 22, 23,
- 24, 25, 26,
- 27, 28, 29,
- 30, 31, 32
- };
- m.uv = new Vector2[]
- {
- new Vector2(0.3125f, 0.5f),
- new Vector2(0.3125f, 0.6875f),
- new Vector2(0.4375f, 0.6875f),
- new Vector2(0.125f, 0.75f),
- new Vector2(0.125f, 0.875f),
- new Vector2(0.25f, 0.875f),
- new Vector2(0.25f, 0.75f),
- new Vector2(0.25f, 0.875f),
- new Vector2(0.375f, 0.875f),
- new Vector2(0.5625f, 0.0f),
- new Vector2(0.5625f, 0.1875f),
- new Vector2(0.625f, 0.1875f),
- new Vector2(0.625f, 0.0f),
- new Vector2(0.625f, 0.1875f),
- new Vector2(0.6875f, 0.1875f),
- new Vector2(0.6875f, 0.5f),
- new Vector2(0.6875f, 0.6875f),
- new Vector2(0.75f, 0.6875f),
- new Vector2(0.75f, 0.5f),
- new Vector2(0.75f, 0.6875f),
- new Vector2(0.8125f, 0.6875f),
- new Vector2(0.3125f, 0.0f),
- new Vector2(0.3125f, 0.1875f),
- new Vector2(0.3125f, 0.1875f),
- new Vector2(0.375f, 0.0f),
- new Vector2(0.375f, 0.1875f),
- new Vector2(0.4375f, 0.1875f),
- new Vector2(0.0625f, 0.5f),
- new Vector2(0.0625f, 0.6875f),
- new Vector2(0.125f, 0.6875f),
- new Vector2(0.125f, 0.5f),
- new Vector2(0.125f, 0.6875f),
- new Vector2(0.1875f, 0.6875f),
- };
- m.bindposes = new Matrix4x4[]
- {
- bones[0].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[1].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[2].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[3].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[4].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[5].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[6].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[7].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[8].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[9].worldToLocalMatrix * transform.localToWorldMatrix,
- bones[10].worldToLocalMatrix * transform.localToWorldMatrix
- };
- m.boneWeights = new BoneWeight[]
- {
- new BoneWeight() { boneIndex0 = 0, weight0 = 1},
- new BoneWeight() { boneIndex0 = 0, weight0 = 1},
- new BoneWeight() { boneIndex0 = 0, weight0 = 1},
- new BoneWeight() { boneIndex0 = 1, weight0 = 1},
- new BoneWeight() { boneIndex0 = 1, weight0 = 1},
- new BoneWeight() { boneIndex0 = 1, weight0 = 1},
- new BoneWeight() { boneIndex0 = 2, weight0 = 1},
- new BoneWeight() { boneIndex0 = 2, weight0 = 1},
- new BoneWeight() { boneIndex0 = 2, weight0 = 1},
- new BoneWeight() { boneIndex0 = 3, weight0 = 1},
- new BoneWeight() { boneIndex0 = 3, weight0 = 0.7f},
- new BoneWeight() { boneIndex0 = 3, weight0 = 1},
- new BoneWeight() { boneIndex0 = 4, weight0 = 0.5f},
- new BoneWeight() { boneIndex0 = 4, weight0 = 1f},
- new BoneWeight() { boneIndex0 = 4, weight0 = 1f},
- new BoneWeight() { boneIndex0 = 5, weight0 = 1},
- new BoneWeight() { boneIndex0 = 5, weight0 = 0.7f},
- new BoneWeight() { boneIndex0 = 5, weight0 = 1},
- new BoneWeight() { boneIndex0 = 6, weight0 = 0.5f},
- new BoneWeight() { boneIndex0 = 6, weight0 = 1},
- new BoneWeight() { boneIndex0 = 6, weight0 = 1},
- new BoneWeight() { boneIndex0 = 7, weight0 = 1},
- new BoneWeight() { boneIndex0 = 7, weight0 = 1},
- new BoneWeight() { boneIndex0 = 7, weight0 = 1},
- new BoneWeight() { boneIndex0 = 8, weight0 = 0.5f}, //발가락
- new BoneWeight() { boneIndex0 = 8, weight0 = 1},
- new BoneWeight() { boneIndex0 = 8, weight0 = 1},
- new BoneWeight() { boneIndex0 = 9, weight0 = 1},
- new BoneWeight() { boneIndex0 = 9, weight0 = 1},
- new BoneWeight() { boneIndex0 = 9, weight0 = 1},
- new BoneWeight() { boneIndex0 = 10, weight0 = 0.5f}, // 발가락
- new BoneWeight() { boneIndex0 = 10, weight0 = 1},
- new BoneWeight() { boneIndex0 = 10, weight0 = 1},
- };
- smr = GetComponent<SkinnedMeshRenderer>();
- smr.bones = bones;
- smr.sharedMesh = m;
- smr.quality = SkinQuality.Bone2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement