상속: EditorWindow
예제 #1
0
    public static void DoSplit(int maxBone, SkinnedMeshRenderer srcr)
    {
        SkinMesh src = new SkinMesh();

        src.bone = new List <Transform>(srcr.bones);
        src.mesh = srcr.sharedMesh;
        var ss = SplitSkinMesh(maxBone, src);

        if (ss.Count > 0)
        {
            srcr.sharedMesh = ss[0].mesh;
            srcr.bones      = ss[0].bone.ToArray();
        }
        for (int i = 1; i < ss.Count; i++)
        {
            GameObject newSplit = new GameObject();
            newSplit.name                    = srcr.name + "_" + i;
            newSplit.transform.parent        = srcr.transform.parent;
            newSplit.transform.localPosition = srcr.transform.localPosition;
            newSplit.transform.localScale    = srcr.transform.localScale;
            newSplit.transform.localRotation = srcr.transform.localRotation;

            var nr = newSplit.AddComponent <SkinnedMeshRenderer>();
            nr.rootBone        = srcr.rootBone;
            nr.sharedMesh      = ss[i].mesh;
            nr.bones           = ss[i].bone.ToArray();
            nr.sharedMaterials = srcr.sharedMaterials;
        }
    }
예제 #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="skinMesh">The skin mesh this triangle is part of.</param>
 /// <param name="vertex0Index">The index of the first vertex.</param>
 /// <param name="vertex1Index">The index of the second vertex.</param>
 /// <param name="vertex2Index">The index of the third vertex.</param>
 public SkinTriangle(SkinMesh skinMesh, int vertex0Index, int vertex1Index, int vertex2Index)
 {
     _skinMesh         = skinMesh;
     this.vertex0Index = vertex0Index;
     this.vertex1Index = vertex1Index;
     this.vertex2Index = vertex2Index;
 }
예제 #3
0
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <param name="skinMesh">The skin mesh this thread is part of.</param>
    /// <param name="vertex0Index">The index of the first vertex.</param>
    /// <param name="vertex1Index">The index of the second vertex.</param>
    /// <param name="visibility">The visibility.</param>
    public Thread(SkinMesh skinMesh, int vertex0Index, int vertex1Index)
    {
        _skinMesh         = skinMesh;
        this.vertex0Index = vertex0Index;
        this.vertex1Index = vertex1Index;

        UpdateModel();
    }
예제 #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="skinMesh">The skin mesh this vertex is part of.</param>
 /// <param name="vertexIndex">The index of this vertex.</param>
 /// <param name="originalPosition">The current position.</param>
 /// <param name="currentPosition">The original position.</param>
 /// <param name="uvs">The uv coordinates.</param>
 public SkinVertex(SkinMesh skinMesh, int vertexIndex, Vector3 currentPosition, Vector3 originalPosition, Vector2 uvs)
 {
     _skinMesh             = skinMesh;
     this.vertexIndex      = vertexIndex;
     this.currentPosition  = currentPosition;
     this.originalPosition = originalPosition;
     this.uvs = uvs;
 }
예제 #5
0
 /// <summary>
 /// Disposer.
 /// </summary>
 /// <param name="disposing">Indicates whether to dispose managed resources or not.</param>
 private void Dispose(bool disposing)
 {
     if (_isDisposed == false && disposing)
     {
         //Dispose managed resources.
         _skinMesh = null;
     }
     //Dispose unmanaged resources.
     _isDisposed = true;
 }
예제 #6
0
 //--------------------------------
 // A S S I G N   M A T E R I A L S
 //--------------------------------
 private void AssignMaterials(SkinMesh m, bool use_material_spec)
 {
     skinFx.ambientCol.X  = m.ambient.X;  skinFx.ambientCol.Y = m.ambient.Y;  skinFx.ambientCol.Z = m.ambient.Z;    //Vec4 to Vec3
     skinFx.emissiveCol.X = m.emissive.X; skinFx.emissiveCol.Y = m.emissive.Y; skinFx.emissiveCol.Z = m.emissive.Z; //Vec4 to Vec3
     skinFx.diffuseCol    = m.diffuse;
     if (use_material_spec)
     {
         skinFx.specularCol.X = m.specular.X;   skinFx.specularCol.Y = m.specular.Y;   skinFx.specularCol.Z = m.specular.Z;
         skinFx.specularPow   = m.shineStrength; // I think...
     }
 }
 private void SetSkinMesh()
 {
     for (int i = 0; i < BlockSize; i++)
     {
         for (int j = 0; j < BlockSize; j++)
         {
             for (int k = 0; k < BlockSize; k++)
             {
                 GameObject block    = Instantiate(skinMeshPrefab) as GameObject;
                 SkinMesh   skinMesh = block.GetComponent <SkinMesh>();
                 skinMesh.Initialize(i, j, k);
             }
         }
     }
 }
예제 #8
0
    static List <SkinMesh> SplitSkinMesh(int maxBone, SkinMesh srcMesh)
    {
        List <SkinMesh> splitMesh = new List <SkinMesh>(); //拆解的模型
        List <int>      seeks     = new List <int>();      //每个子模型的处理进度

        if (srcMesh == null || srcMesh.mesh == null)
        {
            splitMesh.Add(srcMesh);
            return(splitMesh);
        }
        Debug.Log("submesh = " + srcMesh.mesh.subMeshCount);
        for (int s = 0; s < srcMesh.mesh.subMeshCount; s++)
        {
            seeks.Add(0);
        }
        for (int loopCount = 0; loopCount < 100; loopCount++)
        {
            var m = new SkinMesh();
            FillSkinMesh(srcMesh, maxBone, seeks, m);
            splitMesh.Add(m);

            bool bexit = true;
            for (int s = 0; s < seeks.Count; s++)
            {
                if (seeks[s] < srcMesh.mesh.GetIndices(s).Length)
                {
                    bexit = false;
                    break;
                }
            }
            if (bexit)
            {
                break;
            }
        }
        for (int i = 0; i < splitMesh.Count; i++)
        {
            if (splitMesh.Count > 1)
            {
                splitMesh[i].mesh.name = srcMesh.mesh.name + "_" + i;
            }
            else
            {
                splitMesh[i].mesh.name = srcMesh.mesh.name;
            }
        }
        return(splitMesh);
    }
예제 #9
0
 /// <summary>
 /// Start is called just before any of the Update methods is called the first time.
 /// </summary>
 public void Start()
 {
     _skin = FindObjectOfType <Skin>();
     if (_skin == null)
     {
         Debug.LogWarning("Forceps could not find skin");
     }
     else
     {
         _skinMesh = _skin.skinMesh;
         if (_skinMesh == null)
         {
             Debug.LogWarning("Forceps could not find the skinmesh");
         }
     }
 }
예제 #10
0
    /// <summary>
    /// Disposer.
    /// </summary>
    /// <param name="disposing">Indicates whether to dispose managed resources or not.</param>
    private void Dispose(bool disposing)
    {
        if (_isDisposed == false && disposing)
        {
            //Dispose managed resources.
            _triangles.Clear();
            _triangles = null;

            _threads.Clear();
            _threads = null;

            _skinMesh = null;
        }
        //Dispose unmanaged resources.
        _isDisposed = true;
    }
예제 #11
0
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    public void Awake()
    {
        //Don't remove the below lines or strange behaviour will occur. The code assumes the skin always has these transform values.
        transform.position   = Vector3.zero;
        transform.rotation   = Quaternion.identity;
        transform.localScale = Vector3.one;

        _meshFilter = GetComponent <MeshFilter>();
        if (_meshFilter == null)
        {
            _meshFilter = gameObject.AddComponent <MeshFilter>();
        }

        _meshRenderer = GetComponent <MeshRenderer>();
        if (_meshRenderer == null)
        {
            _meshRenderer = gameObject.AddComponent <MeshRenderer>();
        }

        if (skinMaterial == null)
        {
            Debug.LogWarning("No skin material set!");
        }

        if (threadModelsParentTransform == null)
        {
            Debug.LogWarning("No thread models parent transform set!");
        }
        else
        {
            Thread.threadModelsParentTransform = threadModelsParentTransform;
        }

        if (threadModelPrefab == null)
        {
            Debug.LogWarning("No thread model prefab set!");
        }
        else
        {
            Thread.threadModelPrefab = threadModelPrefab;
        }

        _meshRenderer.material = skinMaterial;
        skinMesh = new SkinMesh();
        InitializeSkinMesh();
    }
예제 #12
0
 private static int TestBone(SkinMesh srcMesh, SkinMesh outMesh, List <Matrix4x4> tpose, Dictionary <int, int> boneMap, int bone)
 {
     if (bone >= 0)
     {
         if (boneMap.ContainsKey(bone) == false)//addbone
         {
             boneMap[bone] = outMesh.bone.Count;
             outMesh.bone.Add(srcMesh.bone[bone]);
             tpose.Add(srcMesh.mesh.bindposes[bone]);
         }
         return(boneMap[bone]);
     }
     else
     {
         return(-1);
     }
 }
예제 #13
0
 void Start()
 {
     skinMesh = FindObjectOfType <Skin>().skinMesh;
     cam      = GetComponent <Camera>();
 }
예제 #14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="skinMesh">The skin mesh this edge is part of.</param>
 /// <param name="vertex0Index">The index of the first vertex.</param>
 /// <param name="vertex1Index">The index of the second vertex.</param>
 public SkinEdge(SkinMesh skinMesh, int vertex0Index, int vertex1Index)
 {
     _skinMesh         = skinMesh;
     this.vertex0Index = vertex0Index;
     this.vertex1Index = vertex1Index;
 }
예제 #15
0
        protected override void LoadContent()
        {
            Error       = Content.Load <Model>("Error");
            spriteBatch = new SpriteBatch(GraphicsDevice);
            for (int i = 0; i < _3DRadSpaceGame.MAX_OBJECTS; i++)
            {
                string obj = project[i].ToString();
                switch (obj.Split(' ')[0])
                {
                case "Camera":
                {
                    Vector3 pos = new Vector3(Convert.ToSingle(obj.Split(' ')[3]), Convert.ToSingle(obj.Split(' ')[4]), Convert.ToSingle(obj.Split(' ')[5]));
                    Objects[i] = new Camera(
                        obj.Split(' ')[1],
                        Convert.ToBoolean(obj.Split(' ')[2]),
                        pos,
                        Vector3.Zero,             //Vector3.Transform(pos, Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(Convert.ToSingle(obj.Split(' ')[7])),MathHelper.ToRadians( Convert.ToSingle(obj.Split(' ')[6])), MathHelper.ToRadians(Convert.ToSingle(obj.Split(' ')[8])))),
                        MathHelper.ToRadians(Convert.ToSingle(obj.Split(' ')[9])),
                        Convert.ToSingle(obj.Split(' ')[11])
                        );
                    break;
                }

                case "SkyColor":
                {
                    Color color = new Color(Convert.ToUInt32(obj.Split(' ')[3]), Convert.ToUInt32(obj.Split(' ')[4]), Convert.ToUInt32(obj.Split(' ')[5]));
                    Objects[i] = new SkyColor(
                        obj.Split(' ')[1],
                        Convert.ToBoolean(obj.Split(' ')[2]),
                        color
                        );
                    break;
                }

                case "Skinmesh":
                {
                    Vector3 pos    = new Vector3(Convert.ToSingle(obj.Split(' ')[3]), Convert.ToSingle(obj.Split(' ')[4]), Convert.ToSingle(obj.Split(' ')[5]));
                    Vector3 rot    = new Vector3(Convert.ToSingle(obj.Split(' ')[6]), Convert.ToSingle(obj.Split(' ')[7]), Convert.ToSingle(obj.Split(' ')[8]));
                    string  res    = "";
                    int     length = obj.Split(' ').Length;
                    for (int j = 10; j < length; j++)
                    {
                        res += obj.Split(' ')[j];
                        if (j != length - 1)
                        {
                            res += " ";
                        }
                    }
                    Objects[i] = new SkinMesh(obj.Split(' ')[1],
                                              Convert.ToBoolean(obj.Split(' ')[2]),
                                              res, pos, rot);
                    break;
                }

                case "TextPrint":
                {
                    Color clr = new Color(Convert.ToInt32(obj.Split(' ')[5]),
                                          Convert.ToInt32(obj.Split(' ')[6])
                                          , Convert.ToInt32(obj.Split(' ')[7])
                                          );
                    string text = "";
                    for (int j = 8; j < obj.Split(' ').Length; j++)
                    {
                        text += obj.Split(' ')[j];
                    }
                    Vector3 loc = new Vector3(Convert.ToInt32(obj.Split(' ')[4]),
                                              Convert.ToInt32(obj.Split(' ')[5]), 0);

                    Objects[i] = new TextPrint(obj.Split(' ')[1], Convert.ToBoolean(obj.Split(' ')[2]), Content, loc, text, clr);
                    break;
                }

                case "Fog":
                {
                    Vector3 clr = new Vector3(Convert.ToInt32(obj.Split(' ')[3]),
                                              Convert.ToInt32(obj.Split(' ')[4])
                                              , Convert.ToInt32(obj.Split(' ')[5])
                                              );
                    Objects[i] = new Fog(obj.Split(' ')[1], Convert.ToBoolean(obj.Split(' ')[2])
                                         , clr, Convert.ToSingle(obj.Split(' ')[6]), Convert.ToSingle(obj.Split(' ')[7]));
                    break;
                }

                default: break;
                }
                AllObjectsInitialize();
            }
        }
예제 #16
0
    static void FillSkinMesh(SkinMesh srcMesh, int maxBone, List <int> seek, SkinMesh outMesh)
    {
        outMesh.bone = new List <Transform>();
        outMesh.mesh = new Mesh();
        Dictionary <int, int> indexmap = new Dictionary <int, int>();
        Dictionary <int, int> bonemap  = new Dictionary <int, int>();
        List <Vector3>        poses    = new List <Vector3>();
        List <Vector3>        normal   = new List <Vector3>();
        List <Vector2>        uv       = new List <Vector2>();
        List <Vector2>        uv2      = null;
        List <Vector2>        uv3      = null;
        List <Color32>        color    = null;
        List <BoneWeight>     skininfo = new List <BoneWeight>();
        List <Matrix4x4>      tpose    = new List <Matrix4x4>();

        List <List <int> > subindexs = new List <List <int> >();

        for (int s = 0; s < seek.Count; s++)
        {
            subindexs.Add(new List <int>());
        }

        //拆分逻辑
        for (int loopcount = 0; loopcount < 100000; loopcount++)//死循环,直到超出限制
        {
            bool bexit = true;
            for (int s = 0; s < seek.Count; s++)
            {
                var subindex = subindexs[s];
                var si       = srcMesh.mesh.GetIndices(s);
                if (si.Length > seek[s])//有才处理
                {
                    bexit = false;
                    for (int i = 0; i < 3; i++)//一次处理一个三角形
                    {
                        int srcindex = si[seek[s] + i];
                        if (indexmap.ContainsKey(srcindex) == false)//新顶点
                        {
                            indexmap[srcindex] = poses.Count;
                            poses.Add(srcMesh.mesh.vertices[srcindex]);
                            normal.Add(srcMesh.mesh.normals[srcindex]);
                            if (srcMesh.mesh.uv != null && srcMesh.mesh.uv.Length > 0)
                            {
                                if (uv == null)
                                {
                                    uv = new List <Vector2>();
                                }
                                uv.Add(srcMesh.mesh.uv[srcindex]);
                            }

#if UNITY4
                            if (srcMesh.mesh.uv1 != null && srcMesh.mesh.uv1.Length > 0)
                            {
                                if (uv2 == null)
                                {
                                    uv2 = new List <Vector2>();
                                }
                                uv2.Add(srcMesh.mesh.uv1[srcindex]);
                            }
                            if (srcMesh.mesh.uv2 != null && srcMesh.mesh.uv2.Length > 0)
                            {
                                if (uv3 == null)
                                {
                                    uv3 = new List <Vector2>();
                                }
                                uv3.Add(srcMesh.mesh.uv2[srcindex]);
                            }
#else
                            if (srcMesh.mesh.uv2 != null && srcMesh.mesh.uv2.Length > 0)
                            {
                                if (uv2 == null)
                                {
                                    uv2 = new List <Vector2>();
                                }
                                uv2.Add(srcMesh.mesh.uv2[srcindex]);
                            }
                            if (srcMesh.mesh.uv3 != null && srcMesh.mesh.uv3.Length > 0)
                            {
                                if (uv3 == null)
                                {
                                    uv3 = new List <Vector2>();
                                }
                                uv3.Add(srcMesh.mesh.uv3[srcindex]);
                            }
#endif

                            if (srcMesh.mesh.colors32 != null && srcMesh.mesh.colors32.Length > 0)
                            {
                                if (color == null)
                                {
                                    color = new List <Color32>();
                                }
                                color.Add(srcMesh.mesh.colors32[srcindex]);
                            }

                            BoneWeight bw = srcMesh.mesh.boneWeights[srcindex];
                            bw.boneIndex0 = TestBone(srcMesh, outMesh, tpose, bonemap, bw.boneIndex0);
                            bw.boneIndex1 = TestBone(srcMesh, outMesh, tpose, bonemap, bw.boneIndex1);
                            bw.boneIndex2 = TestBone(srcMesh, outMesh, tpose, bonemap, bw.boneIndex2);
                            bw.boneIndex3 = TestBone(srcMesh, outMesh, tpose, bonemap, bw.boneIndex3);
                            skininfo.Add(bw);
                        }
                        subindex.Add(indexmap[srcindex]);
                    }
                    seek[s] = seek[s] + 3;
                }
            }
            //加上骨骼的处理,终止条件改为骨骼数超越限制
            if (outMesh.bone.Count >= maxBone)
            {
                Debug.LogWarning("==break at:" + maxBone + "/" + outMesh.bone.Count);
                break;
            }
            else if (bexit)
            {
                Debug.LogWarning("==break for end.");
                break;
            }
        }
#if UNITY4
        outMesh.mesh.vertices = poses.ToArray();
        outMesh.mesh.normals  = normal.ToArray();
        if (uv != null)
        {
            outMesh.mesh.uv = uv.ToArray();
        }
        if (uv2 != null)
        {
            outMesh.mesh.uv1 = uv2.ToArray();
        }
        if (uv3 != null)
        {
            outMesh.mesh.uv2 = uv3.ToArray();
        }
        if (color != null)
        {
            outMesh.mesh.colors32 = color.ToArray();
        }
#else
        outMesh.mesh.SetVertices(poses);
        outMesh.mesh.SetNormals(normal);
        if (uv != null)
        {
            outMesh.mesh.SetUVs(0, uv);
        }
        if (uv2 != null)
        {
            outMesh.mesh.SetUVs(1, uv2);
        }
        if (uv3 != null)
        {
            outMesh.mesh.SetUVs(2, uv3);
        }
        if (color != null)
        {
            outMesh.mesh.SetColors(color);
        }
#endif
        outMesh.mesh.subMeshCount = subindexs.Count;
        for (int i = 0; i < subindexs.Count; i++)
        {
            outMesh.mesh.SetTriangles(subindexs[i].ToArray(), i);
        }

        outMesh.mesh.boneWeights = skininfo.ToArray();

        outMesh.mesh.bindposes = tpose.ToArray();
        Debug.LogWarning("outmest.mesh" + outMesh.mesh.vertexCount + "," + outMesh.bone.Count + "," + outMesh.mesh.bindposes.Length);
        foreach (var b in outMesh.bone)
        {
            Debug.LogWarning("bone=" + b);
        }
    }