Пример #1
0
    public void ApplyPrincipalDirectios(bool align = true)
    {
        for (int m = 0; m < _mesheFilters.Length; m++)
        {
            Mesh      mesh       = _mesheFilters[m].sharedMesh;
            Vector3[] newVectors = new Vector3[mesh.vertices.Length];
            Vector3[,] allNewVectors = new Vector3[mesh.vertices.Length, 4];
            Vector3[] smoothedNormals = new Vector3[mesh.normals.Length];

            int displacement = 0;
            for (int i = 0; i < _meshInfosMerged[m].principalDirections.Length; i++)
            {
                for (int j = 0; j < _mapFromNew[m][i].Count; j++)
                {
                    displacement += j;
                    newVectors[_mapFromNew[m][i][j]] = _meshInfosMerged[m].principalDirections[i];
                    for (int k = 0; k < 4; k++)
                    {
                        allNewVectors[_mapFromNew[m][i][j], k] = _meshInfosMerged[m].AllPrincipalDirections[i, k];
                    }
                    smoothedNormals[_mapFromNew[m][i][j]] = _meshInfosMerged[m].approximatedNormals[i];
                }
            }

            mesh.normals = smoothedNormals;
            MeshInfo newMeshInfo = new MeshInfo(mesh);
            newMeshInfo.principalDirections    = newVectors;
            newMeshInfo.AllPrincipalDirections = allNewVectors;
            newMeshInfo.approximatedNormals    = smoothedNormals;

            if (align)
            {
                CurvatureFilter.AlignDirections(newMeshInfo, false);
            }
            StoreMeshInfoInFile(newMeshInfo, storedName);
            _meshInfosDuplicated[m] = newMeshInfo;
            newVectors  = newMeshInfo.GetaDirection(0);
            mesh.colors = Array.ConvertAll(newVectors, j => new Color(j.x, j.y, j.z, 1));
        }
        Debug.Log("Applied principal directions as colors");
    }
Пример #2
0
    private MeshInfo rebuildMeshInfo(MeshInfo baseInfo, StoredCurvature newCurvatureInfo)
    {
        Debug.Log(CurvatureFilter.showArray(baseInfo.GetaDirection(0)));
        Debug.Log(CurvatureFilter.showArray(newCurvatureInfo.principalDirections0));
        if (baseInfo.vertexCount == newCurvatureInfo.vertexPositions.Length)
        {
            Debug.Log(baseInfo.vertexCount.ToString() + ", " +
                      newCurvatureInfo.principalDirections0.Length.ToString());
            for (int i = 0; i < baseInfo.vertexCount; i++)
            {
                baseInfo.AllPrincipalDirections[i, 0] = newCurvatureInfo.principalDirections0[i];
                baseInfo.AllPrincipalDirections[i, 1] = newCurvatureInfo.principalDirections1[i];
                baseInfo.AllPrincipalDirections[i, 2] = newCurvatureInfo.principalDirections2[i];
                baseInfo.AllPrincipalDirections[i, 3] = newCurvatureInfo.principalDirections3[i];
            }
        }
        else
        {
            Debug.Log("Vertex count did not match, could not load data. " +
                      baseInfo.vertexCount.ToString() + " x " + newCurvatureInfo.vertexPositions.Length.ToString());
        }

        return(baseInfo);
    }