コード例 #1
0
    private bool Initialize()
    {
        bool returnFalse = false;

        _mesheFilters = GetComponentsInChildren <MeshFilter>();
        foreach (MeshFilter meshFilter in _mesheFilters)
        {
            CurvatureFilter.DuplicateMeshVertices(meshFilter.sharedMesh);
        }
        if (_meshInfosMerged == null)
        {
            Mesh[] smoothMesh;
            GetAllSmoothMeshes(out smoothMesh, out _mapFromNew);
            _meshInfosMerged     = new MeshInfo[smoothMesh.Length];
            _meshInfosDuplicated = new MeshInfo[smoothMesh.Length];
            _curvatureDatas      = new CurvatureData[smoothMesh.Length];
            for (int i = 0; i < _mesheFilters.Length; i++)
            {
                _meshInfosMerged[i] = new MeshInfo(smoothMesh[i]);
                _curvatureDatas[i]  = new CurvatureData(smoothMesh[i].vertexCount);
            }
            returnFalse = true;
        }

        if (returnFalse)
        {
            return(false);
        }
        return(true);
    }
コード例 #2
0
 public void RotatePrincipalDirections(float angle)
 {
     // Applies to global mesh and affects all game objects
     if (!Initialize())
     {
         Debug.Log("Curvatures not computed"); return;
     }
     for (int m = 0; m < _meshInfosMerged.Length; m++)
     {
         CurvatureFilter.RotateAllDirections(ref _meshInfosMerged[m].principalDirections, _meshInfosMerged[m].approximatedNormals, angle);
         Debug.Log(CurvatureFilter.showArray(_meshInfosMerged[m].principalDirections));
     }
     ApplyPrincipalDirectios();
 }
コード例 #3
0
    public void RotateVertexColors()
    {
        //Applies only to mesh in current game object
        var meshes = GetComponentsInChildren <MeshFilter>();

        for (int i = 0; i < meshes.Length; i++)
        {
            var meshFilter = meshes[i];
            rotationCount += 1;
            List <Color> colors          = new List <Color>(meshFilter.mesh.colors);
            Vector3[]    colorsAsVectors = colors.ConvertAll(j => new Vector3(j.r, j.g, j.b)).ToArray();
            CurvatureFilter.RotateAllDirections(ref colorsAsVectors, meshFilter.mesh.normals, 90);
            meshFilter.mesh.SetColors(new List <Vector3>(colorsAsVectors).ConvertAll(j => new Color(j.x, j.y, j.z)));
        }
    }
コード例 #4
0
    public void TestCurvatureOptimization(float reliabilityRatio)
    {
        if (!Initialize() || _meshInfosMerged[0].principalDirections == null)
        {
            Debug.Log("Curvatures not computed");
            return;
        }

        for (int m = 0; m < _meshInfosMerged.Length; m++)
        {
            MeshInfo meshInfo = _meshInfosMerged[m];
            if (meshInfo.principalDirections.Length < 1)
            {
                Debug.Log("Principal directions not computed");
                return;
            }
            bool[] curvatureRatio = CurvatureFilter.GetReliability(meshInfo.curvatureRatios, reliabilityRatio);
            CurvatureFilter.TestEnergyResults(meshInfo, curvatureRatio);
        }
    }
コード例 #5
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");
    }
コード例 #6
0
    public void OptimizePrincipalDirections(float reliabilityRatio)
    {
        if (!Initialize() || _meshInfosMerged[0].principalDirections == null)
        {
            Debug.Log("Curvatures not computed");
            return;
        }

        for (int m = 0; m < _meshInfosMerged.Length; m++)
        {
            MeshInfo meshInfo = _meshInfosMerged[m];
            if (meshInfo.principalDirections.Length < 1)
            {
                Debug.Log("Principal directions not computed");
                return;
            }

            bool[] curvatureReliability = CurvatureFilter.GetReliability(meshInfo.curvatureRatios, reliabilityRatio);
            //Debug.Log(CurvatureFilter.showArray(meshInfo.principalDirections));
            meshInfo.principalDirections = CurvatureFilter.MinimizeEnergy(meshInfo, curvatureReliability);
            //Debug.Log(CurvatureFilter.showArray(meshInfo.principalDirections));
        }
        ApplyPrincipalDirectios();
    }
コード例 #7
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);
    }