Beispiel #1
0
 public static Vec4[] SetVectors(Vector4[] vecs)
 {
     Vec4[] _vecs = new Vec4[vecs.Length];
     for (int i = 0; i < _vecs.Length; i++)
     {
         _vecs[i] = vecs[i];
     }
     return(_vecs);
 }
Beispiel #2
0
        public SkinnedMeshRenderer GetSkinnedMesh(Dictionary <string, Transform> bones, SkinnedMeshRenderer skin)
        {
            Mesh _mesh = new Mesh();

            _mesh.vertices    = Vec3.GetVectors(vertices);
            _mesh.normals     = Vec3.GetVectors(normals);
            _mesh.tangents    = Vec4.GetVectors(tangents);
            _mesh.uv          = Vec2.GetVectors(uv);
            _mesh.boneWeights = BoneWeight_.GetBoneWeights(boneWeights);
            _mesh.bindposes   = Matrix4x4_.GetMatrix4x4s(bindposes);
            _mesh.triangles   = triangles;
            _mesh.RecalculateBounds();
            skin.sharedMesh = _mesh;

            Texture2D tex = new Texture2D(0, 0);

            if (texture != null)
            {
                tex.LoadImage(texture);
            }
            else
            {
                tex = null;
            }
            skin.material.mainTexture = tex;
            skin.material.color       = color;

            skin.name          = name;
            skin.rootBone.name = rootBoneName;
            List <Transform> _bones = new List <Transform>();

            for (int i = 0; i < bonesName.Length; i++)
            {
                string _name = bonesName[i];
                if (bones.ContainsKey(_name))
                {
                    _bones.Add(bones[_name]);
                }
                else
                {
                    AvatarDebug.Log("bones name is null!");
                }
            }
            skin.bones = _bones.ToArray();
            return(skin);
        }
Beispiel #3
0
        public SkinnedInfo(SkinnedMeshRenderer skin)
        {
            Mesh _mesh = skin.sharedMesh;

            vertices    = Vec3.SetVectors(_mesh.vertices);
            normals     = Vec3.SetVectors(_mesh.normals);
            tangents    = Vec4.SetVectors(_mesh.tangents);
            uv          = Vec2.SetVectors(_mesh.uv);
            boneWeights = BoneWeight_.SetBoneWeights(_mesh.boneWeights);
            bindposes   = Matrix4x4_.SetMatrix4x4s(_mesh.bindposes);
            triangles   = _mesh.triangles;
            _mesh.RecalculateBounds();
            skin.sharedMesh = _mesh;

            color        = skin.material.color;
            name         = skin.name;
            rootBoneName = skin.rootBone.name;
            bonesName    = new string[skin.bones.Length];
            for (int i = 0; i < bonesName.Length; i++)
            {
                bonesName[i] = skin.bones[i].name;
            }
            Texture2D matTex = (Texture2D)skin.material.mainTexture;

            if (matTex)
            {
                Texture2D tex = new Texture2D(matTex.width, matTex.height);
                try
                {
                    tex.SetPixels(matTex.GetPixels());
                    tex.Apply();
                    texture = tex.EncodeToPNG();
                }
                catch
                {
                    texture = null;
                    AvatarDebug.Log("mainTexture is not read/write!");
                }
            }
            else
            {
                texture = null;
                AvatarDebug.Log("mainTexture is null!");
            }
        }