コード例 #1
0
 public static int FindNextFaceIndex(Polyhedra mesh, int nodeIndex, int faceIndex)
 {
     var node = mesh.nodes[nodeIndex];
     var face = mesh.faces[faceIndex];
     var nodeFaceIndex = face.n.IndexOf(nodeIndex);
     var edge = mesh.edges[face.e[(nodeFaceIndex + 2) % 3]];
     return GetEdgeOppositeFaceIndex(edge, faceIndex);
 }
コード例 #2
0
    private Polyhedra GeneratePlanetPolyhedra()
    {
        var mesh = Utils.GenerateSubdividedIcosahedron(this.subdivisionLevel);

        mesh.planet = this;
        var totalDistortion     = Math.Ceiling(mesh.edges.Count * this.distortionLevel);
        var remainingIterations = 6;
        int i;

        while (remainingIterations > 0)
        {
            var iterationDistortion = (int)Math.Floor(totalDistortion / remainingIterations);
            totalDistortion -= iterationDistortion;
            mesh.DistortMesh(iterationDistortion, globalRandom);
            mesh.RelaxMesh(0.5f);
            --remainingIterations;
        }

        //var initialIntervalIteration = action.intervalIteration;

        var averageNodeRadius = Math.Sqrt(4 * Math.PI / mesh.nodes.Count);
        var minShiftDelta     = averageNodeRadius / 50000 * mesh.nodes.Count;
        var maxShiftDelta     = averageNodeRadius / 50 * mesh.nodes.Count;

        float priorShift, shiftDelta;
        var   currentShift = mesh.RelaxMesh(0.5f);

        do
        {
            priorShift   = currentShift;
            currentShift = mesh.RelaxMesh(0.5f);
            shiftDelta   = Math.Abs(currentShift - priorShift);
        } while (shiftDelta >= minShiftDelta /* && action.intervalIteration - initialIntervalIteration < 300*/);

        for (i = 0; i < mesh.faces.Count; ++i)
        {
            var face = mesh.faces[i];
            var p0   = mesh.nodes[face.n[0]].p;
            var p1   = mesh.nodes[face.n[1]].p;
            var p2   = mesh.nodes[face.n[2]].p;
            face.centroid = Utils.CalculateFaceCentroid(p0, p1, p2).normalized;
        }

        for (i = 0; i < mesh.nodes.Count; ++i)
        {
            var node      = mesh.nodes[i];
            var faceIndex = node.f[0];
            for (var j = 1; j < node.f.Count - 1; ++j)
            {
                faceIndex = Utils.FindNextFaceIndex(mesh, i, faceIndex);
                var k = node.f.IndexOf(faceIndex);
                node.f[k] = node.f[j];
                node.f[j] = faceIndex;
            }
        }
        this.surface = mesh;
        return(mesh);
    }
コード例 #3
0
ファイル: MeshSelector.cs プロジェクト: Xallt/WavePropagation
    public void Start()
    {
        Dropdown dropdown = GetComponent <Dropdown>();

        dropdown.ClearOptions();
        dropdown.AddOptions(meshes.Select(p => p.name).ToList());
        Polyhedra poly = GameObject.Find("Polyhedra").GetComponent <Polyhedra>();

        dropdown.onValueChanged.AddListener(value => poly.SetMesh(meshes[value].mesh));
    }
コード例 #4
0
 public void Generate()
 {
     this.globalRandom = new Random(randomSeed);
     this.surface = GeneratePlanetPolyhedra();
     this.surface.GeneratePlanetTopology();
     this.surface.topology.GeneratePlanetPartition();
     this.GeneratePlanetTectonicPlates();
     this.GeneratePlanetElevation();
     //DrawTectonicPlates(6000f);
     this.GeneratePlanetMesh(false);
 }
コード例 #5
0
 public void Generate()
 {
     this.globalRandom = new Random(randomSeed);
     this.surface      = GeneratePlanetPolyhedra();
     this.surface.GeneratePlanetTopology();
     this.surface.topology.GeneratePlanetPartition();
     this.GeneratePlanetTectonicPlates();
     this.GeneratePlanetElevation();
     //DrawTectonicPlates(6000f);
     this.GeneratePlanetMesh(false);
 }
コード例 #6
0
    private Polyhedra GeneratePlanetPolyhedra()
    {
        var mesh = Utils.GenerateSubdividedIcosahedron(this.subdivisionLevel);
        mesh.planet = this;
        var totalDistortion = Math.Ceiling(mesh.edges.Count * this.distortionLevel);
        var remainingIterations = 6;
        int i;
        while (remainingIterations > 0)
        {
            var iterationDistortion = (int)Math.Floor(totalDistortion / remainingIterations);
            totalDistortion -= iterationDistortion;
            mesh.DistortMesh(iterationDistortion, globalRandom);
            mesh.RelaxMesh(0.5f);
            --remainingIterations;
        }

        //var initialIntervalIteration = action.intervalIteration;

        var averageNodeRadius = Math.Sqrt(4 * Math.PI / mesh.nodes.Count);
        var minShiftDelta = averageNodeRadius / 50000 * mesh.nodes.Count;
        var maxShiftDelta = averageNodeRadius / 50 * mesh.nodes.Count;

        float priorShift, shiftDelta;
        var currentShift = mesh.RelaxMesh(0.5f);

        do
        {
            priorShift = currentShift;
            currentShift = mesh.RelaxMesh(0.5f);
            shiftDelta = Math.Abs(currentShift - priorShift);
        } while (shiftDelta >= minShiftDelta /* && action.intervalIteration - initialIntervalIteration < 300*/);

        for (i = 0; i < mesh.faces.Count; ++i)
        {
            var face = mesh.faces[i];
            var p0 = mesh.nodes[face.n[0]].p;
            var p1 = mesh.nodes[face.n[1]].p;
            var p2 = mesh.nodes[face.n[2]].p;
            face.centroid = Utils.CalculateFaceCentroid(p0, p1, p2).normalized;
        }

        for (i = 0; i < mesh.nodes.Count; ++i)
        {
            var node = mesh.nodes[i];
            var faceIndex = node.f[0];
            for (var j = 1; j < node.f.Count - 1; ++j)
            {
                faceIndex = Utils.FindNextFaceIndex(mesh, i, faceIndex);
                var k = node.f.IndexOf(faceIndex);
                node.f[k] = node.f[j];
                node.f[j] = faceIndex;
            }
        }
        this.surface = mesh;
        return mesh;
    }
コード例 #7
0
 public static int FindNextFaceIndex(Polyhedra mesh, int nodeIndex, int faceIndex)
 {
     var node = mesh.nodes[nodeIndex];
     var face = mesh.faces[faceIndex];
     var nodeFaceIndex = face.n.IndexOf(nodeIndex);
     var edge = mesh.edges[face.e[(nodeFaceIndex + 2) % 3]];
     return GetEdgeOppositeFaceIndex(edge, faceIndex);
 }
コード例 #8
0
 private void Awake()
 {
     polyhedra = GetComponent <Polyhedra>();
     vertexHighlightSpheres = new Dictionary <int, GameObject>();
     simulationController   = GameObject.Find("App").GetComponent <SimulationController>();
 }
コード例 #9
0
 public void Awake()
 {
     polyhedra = GameObject.Find("Polyhedra").GetComponent <Polyhedra>();
 }