Ejemplo n.º 1
0
            public override ProBuilderMesh Build(bool preview = false)
            {
                // To keep the preview snappy, shared indexes aren't built in IcosahadreonGenerator
                var mesh = ShapeGenerator.GenerateIcosahedron(
                    EditorUtility.newShapePivotLocation,
                    s_Radius,
                    s_Subdivisions,
                    !preview);

                if (!preview)
                {
                    UVEditing.ProjectFacesBox(mesh, mesh.facesInternal);
                }

                for (int i = 0; i < mesh.facesInternal.Length; i++)
                {
                    mesh.facesInternal[i].manualUV = true;
                }

                return(mesh);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the sphere and loads all the cache information.
        /// </summary>
        void Start()
        {
            m_AudioSource = GetComponent <AudioSource>();

            if (m_AudioSource.clip == null)
            {
                missingClipWarning.SetActive(true);
            }

            // Create a new sphere.
            m_ProBuilderMesh = ShapeGenerator.GenerateIcosahedron(PivotLocation.Center, icoRadius, icoSubdivisions);

            // Assign the default material
            m_ProBuilderMesh.GetComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.defaultMaterial;

            // Shell is all the faces on the new sphere.
            var shell = m_ProBuilderMesh.faces;

            // Extrude all faces on the sphere by a small amount. The third boolean parameter
            // specifies that extrusion should treat each face as an individual, not try to group
            // all faces together.
            m_ProBuilderMesh.Extrude(shell, ExtrudeMethod.IndividualFaces, startingExtrusion);

            // ToMesh builds the mesh positions, submesh, and triangle arrays. Call after adding
            // or deleting vertices, or changing face properties.
            m_ProBuilderMesh.ToMesh();

            // Refresh builds the normals, tangents, and UVs.
            m_ProBuilderMesh.Refresh();

            m_AnimatedSelections = new ExtrudedSelection[shell.Count];

            // Populate the outsides[] cache. This is a reference to the tops of each extruded column, including
            // copies of the sharedIndices.
            for (int i = 0; i < shell.Count; ++i)
            {
                m_AnimatedSelections[i] = new ExtrudedSelection(m_ProBuilderMesh, shell[i]);
            }

            // Store copy of positions array un-modified
            m_OriginalVertexPositions = m_ProBuilderMesh.positions.ToArray();

            // displaced_vertices should mirror sphere mesh vertices.
            m_DisplacedVertexPositions = new Vector3[m_ProBuilderMesh.vertexCount];

            m_UnityMesh = m_ProBuilderMesh.GetComponent <MeshFilter>().sharedMesh;
            m_Transform = m_ProBuilderMesh.transform;

            m_FaceLength = (float)m_AnimatedSelections.Length;

            // Build the waveform ring.
            m_StartingPosition = m_Transform.position;

            waveform.positionCount = k_WaveformSampleCount;

            if (bounceWaveform)
            {
                waveform.transform.parent = m_Transform;
            }

            m_AudioSource.Play();
        }