예제 #1
0
        public override IEnumerator BeginGeneration()
        {
            var topology      = topologyInputSlot.GetAsset <Topology>();
            var vertexNormals = Vector3VertexAttribute.Create(new Vector3[topology.vertices.Count]).SetName("Vertex Normals");

            yield return(executive.GenerateConcurrently(() =>
            {
                switch (calculationMethod)
                {
                case CalculationMethod.FromSurfaceNormal:
                    VertexAttributeUtility.CalculateVertexNormalsFromSurface(topology.vertices, surfaceInputSlot.GetAsset <Surface>(), vertexPositionsInputSlot.GetAsset <IVertexAttribute <Vector3> >(), vertexNormals);
                    break;

                case CalculationMethod.FromVertexPositions:
                    VertexAttributeUtility.CalculateVertexNormalsFromVertexPositions(topology.vertices, vertexPositionsInputSlot.GetAsset <IVertexAttribute <Vector3> >(), vertexNormals);
                    break;

                case CalculationMethod.FromFacePositions:
                    VertexAttributeUtility.CalculateVertexNormalsFromFacePositions(topology.vertices, facePositionsInputSlot.GetAsset <IFaceAttribute <Vector3> >(), vertexNormals);
                    break;

                case CalculationMethod.FromFaceNormals:
                    VertexAttributeUtility.CalculateVertexNormalsFromFaceNormals(topology.vertices, faceNormalsInputSlot.GetAsset <IFaceAttribute <Vector3> >(), vertexNormals);
                    break;

                default:
                    throw new System.NotImplementedException();
                }
            }));

            vertexNormalsOutputSlot.SetAsset(vertexNormals);

            yield break;
        }
예제 #2
0
        public override IEnumerator BeginGeneration()
        {
            var surface = surfaceOutputSlot.GetAsset <SphericalSurface>();

            if (surface == null)
            {
                surface = surfaceOutputSlot.SetAsset(CreateInstance <SphericalSurface>(), false);
            }
            surface.Reset(primaryPole, equatorialPole, radius, isInverted);

            Topology topology;

            Vector3[] vertexPositions;

            switch (sphericalPolyhedron)
            {
            case SphericalPolyhedrons.Tetrahedron:
                SphericalManifoldUtility.CreateTetrahedron(surface, out topology, out vertexPositions);
                break;

            case SphericalPolyhedrons.Cube:
                SphericalManifoldUtility.CreateCube(surface, out topology, out vertexPositions);
                break;

            case SphericalPolyhedrons.Octahedron:
                SphericalManifoldUtility.CreateOctahedron(surface, out topology, out vertexPositions);
                break;

            case SphericalPolyhedrons.Dodecahedron:
                if (subdivisionDegree == 0)
                {
                    SphericalManifoldUtility.CreateDodecahedron(surface, out topology, out vertexPositions);
                }
                else
                {
                    SphericalManifoldUtility.CreateIcosahedron(surface, out topology, out vertexPositions);
                }
                break;

            case SphericalPolyhedrons.Icosahedron:
                SphericalManifoldUtility.CreateIcosahedron(surface, out topology, out vertexPositions);
                break;

            default:
                throw new System.NotImplementedException();
            }

            SphericalManifoldUtility.Subdivide(surface, topology, vertexPositions.AsVertexAttribute(), subdivisionDegree, out topology, out vertexPositions);

            var alreadyDual = sphericalPolyhedron == SphericalPolyhedrons.Dodecahedron && subdivisionDegree != 0;

            if (useDualPolyhedron != alreadyDual)
            {
                SphericalManifoldUtility.MakeDual(surface, topology, ref vertexPositions);
            }

            surfaceOutputSlot.Persist();
            topologyOutputSlot.SetAsset(topology);
            vertexPositionsOutputSlot.SetAsset(Vector3VertexAttribute.Create(vertexPositions).SetName("Vertex Positions"));

            yield break;
        }