Ejemplo n.º 1
0
        private void CreateQuadGridManifold(bool generate = true)
        {
            var surface = surfaceOutputSlot.GetAsset <RectangularQuadGrid>();

            if (surface == null || !generate && ReferenceEquals(surface, surfaceOutputSlot.persistedAsset))
            {
                surface = surfaceOutputSlot.SetAsset(CreateInstance <RectangularQuadGrid>(), false);
            }

            ResetSurface(surface, origin, Quaternion.Euler(rotation), false, size);

            if (generate)
            {
                Vector3[] vertexPositionsArray;

                var topology = surface.CreateManifold(out vertexPositionsArray);
                topologyOutputSlot.SetAsset(topology);

                surface.topology = topologyOutputSlot.GetAsset <Topology>();
                surfaceOutputSlot.Persist();

                vertexPositionsOutputSlot.SetAsset(PositionalVertexAttribute.Create(surfaceOutputSlot.GetAsset <Surface>(), vertexPositionsArray));
            }
        }
Ejemplo n.º 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;
        }