Пример #1
0
    /// <summary>
    /// Make outline gameObject varied from the staticMesh or skinnedMesh. thre reason make a new gameobject is simply
    /// it is much easier to adjust parameters.
    /// </summary>
    /// <param name="newMat"></param>
    /// <param name="partName"></param>
    /// <param name="outGo"></param>
    void MakeOutlineGameObjectForSkinnedMesh(ref Material newMat, string partName, ref Mesh averagedMesh, out GameObject outGo)
    {
        var go = new GameObject(partName + "_Outline");

        go.transform.SetParent(transform);

        // If mesh is rigged.
        if (null != GetComponent <SkinnedMeshRenderer>())
        {
            go.AddComponent <SkinnedMeshRenderer>();
            if (false == IsNormalAveraged)
            {
                averagedMesh = Instantiate(GetComponent <SkinnedMeshRenderer>().sharedMesh);
                Dbg.Log($"Vertices Count of {averagedMesh.name} is {averagedMesh.vertexCount}.");
                SmoothingGroupExtension.MeshNormalAverage(ref averagedMesh);
                IsNormalAveraged = true;
            }
            go.GetComponent <SkinnedMeshRenderer>().sharedMesh = averagedMesh;
            go.GetComponent <SkinnedMeshRenderer>().material   = newMat;
        }
        go.transform.localPosition = transform.position;
        go.transform.localRotation = transform.rotation;
        go.transform.localScale    = transform.localScale;
        outGo = go;
    }
Пример #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="newMat"></param>
    /// <param name="partName"></param>
    /// <param name="outGo"></param>
    void MakeOutlineGameObjectForStaticMesh(ref Material newMat, string partName, ref Mesh averagedMesh, out GameObject outGo)
    {
        var go = new GameObject(partName + "_Outline");

        go.transform.SetParent(transform);

        if (null != GetComponent <MeshFilter>())
        {
            go.AddComponent <MeshFilter>();
            go.AddComponent <MeshRenderer>();
            if (false == IsNormalAveraged)
            {
                averagedMesh = Instantiate(GetComponent <MeshFilter>().sharedMesh);
                SmoothingGroupExtension.MeshNormalAverage(ref averagedMesh);
                IsNormalAveraged = true;
            }
            go.GetComponent <MeshFilter>().sharedMesh = averagedMesh;
            go.GetComponent <MeshRenderer>().material = newMat;
        }
        go.transform.localPosition = transform.position;
        go.transform.localRotation = transform.rotation;
        go.transform.localScale    = transform.localScale;
        outGo = go;
    }