Ejemplo n.º 1
0
        /// <summary>
        /// This function will get used by importers for example if there were only strand vertex positions available.
        /// It will calculate everything inside of the HairStrand and HairStrandVertex based off the vertex positions.
        /// It also calculates the bounding sphere parameters.
        /// </summary>
        public void PrepareSimulationParameters()
        {
            this.BranchingAvoidance();
            int hairIndexCounter = 0;

            // Forward this call to all meshes
            foreach (HairMesh m in this.meshes)
            {
                if (m != null)
                {
                    m.PrepareSimulationParameters(ref hairIndexCounter);
                }
            }

            this._hairSimulationData = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new HairSimulationData object and fills it with data from this hair's hair meshes.
        /// It can get used to "easy-export" tressfx-ready data-arrays from hair objects.
        /// </summary>
        /// <returns></returns>
        private HairSimulationData CreateHairSimulationData()
        {
            // Create new hair simulation data object
            HairSimulationData data = new HairSimulationData();

            // Counter variables
            int strandTypeCounter = 0; // Maps to data.strandType. Will get incremented after every mesh iteration.
            int guideHairStrandCount = 0;
            int guideHairVertexCount = 0;
            int maxNumVerticesPerStrand = 0;

            // Start iterating through all meshes.
            foreach (HairMesh mesh in this.meshes)
            {
                if (mesh == null)
                    continue;

                // Move through every strand
                foreach (HairStrand strand in mesh.strands)
                {
                    // Set strand-level information
                    data.strandTypes.Add(strandTypeCounter);
                    data.followRootOffsets.Add(strand.followRootOffset);

                    // Get guidance hair flag
                    bool isGuide = strand.isGuidanceStrand;
                    if (isGuide)
                        guideHairStrandCount++;

                    // Vertex counter
                    int vertexCount = 0;

                    // Iterate through every vertex
                    foreach (HairStrandVertex vertex in strand.vertices)
                    {
                        // Set vertex-level information
                        data.vertices.Add(vertex.GetTressFXPosition());
                        data.tangents.Add(new Vector4(vertex.tangent, 0));
                        data.referenceVectors.Add(vertex.referenceVector);
                        data.globalRotations.Add(vertex.globalRotation);
                        data.localRotations.Add(vertex.localRotation);
                        data.thicknessCoefficients.Add(vertex.thicknessCoefficient);
                        data.restLength.Add(vertex.restLength);

                        if (isGuide)
                            guideHairVertexCount++;
                        vertexCount++;
                    }

                    // Check if we got a new highscore!
                    if (maxNumVerticesPerStrand < vertexCount)
                        maxNumVerticesPerStrand = vertexCount;
                }

                // Counter handling
                strandTypeCounter++;
            }

            // Set the counter variables
            data.guideHairStrandCount = guideHairStrandCount;
            data.guideHairVertexCount = guideHairVertexCount;
            data.maxNumVerticesPerStrand = maxNumVerticesPerStrand;

            return data;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function will get used by importers for example if there were only strand vertex positions available.
        /// It will calculate everything inside of the HairStrand and HairStrandVertex based off the vertex positions.
        /// It also calculates the bounding sphere parameters.
        /// </summary>
        public void PrepareSimulationParameters()
        {
            this.BranchingAvoidance();
            int hairIndexCounter = 0;

            // Forward this call to all meshes
            foreach (HairMesh m in this.meshes)
            {
                if (m != null)
                    m.PrepareSimulationParameters(ref hairIndexCounter);
            }

            this._hairSimulationData = null;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Explicitly initializes the simulation data.
 /// This is used in for example the tressfx binary importer.
 /// </summary>
 /// <param name="simulationData"></param>
 public void InitializeSimulationData(HairSimulationData hairSimulationData)
 {
     this._hairSimulationData = hairSimulationData;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new HairSimulationData object and fills it with data from this hair's hair meshes.
        /// It can get used to "easy-export" tressfx-ready data-arrays from hair objects.
        /// </summary>
        /// <returns></returns>
        private HairSimulationData CreateHairSimulationData()
        {
            // Create new hair simulation data object
            HairSimulationData data = new HairSimulationData();

            // Counter variables
            int strandTypeCounter       = 0; // Maps to data.strandType. Will get incremented after every mesh iteration.
            int guideHairStrandCount    = 0;
            int guideHairVertexCount    = 0;
            int maxNumVerticesPerStrand = 0;

            // Start iterating through all meshes.
            foreach (HairMesh mesh in this.meshes)
            {
                if (mesh == null)
                {
                    continue;
                }

                // Move through every strand
                foreach (HairStrand strand in mesh.strands)
                {
                    // Set strand-level information
                    data.strandTypes.Add(strandTypeCounter);
                    data.followRootOffsets.Add(strand.followRootOffset);

                    // Get guidance hair flag
                    bool isGuide = strand.isGuidanceStrand;
                    if (isGuide)
                    {
                        guideHairStrandCount++;
                    }

                    // Vertex counter
                    int vertexCount = 0;

                    // Iterate through every vertex
                    foreach (HairStrandVertex vertex in strand.vertices)
                    {
                        // Set vertex-level information
                        data.vertices.Add(vertex.GetTressFXPosition());
                        data.tangents.Add(new Vector4(vertex.tangent, 0));
                        data.referenceVectors.Add(vertex.referenceVector);
                        data.globalRotations.Add(vertex.globalRotation);
                        data.localRotations.Add(vertex.localRotation);
                        data.thicknessCoefficients.Add(vertex.thicknessCoefficient);
                        data.restLength.Add(vertex.restLength);

                        if (isGuide)
                        {
                            guideHairVertexCount++;
                        }
                        vertexCount++;
                    }

                    // Check if we got a new highscore!
                    if (maxNumVerticesPerStrand < vertexCount)
                    {
                        maxNumVerticesPerStrand = vertexCount;
                    }
                }

                // Counter handling
                strandTypeCounter++;
            }

            // Set the counter variables
            data.guideHairStrandCount    = guideHairStrandCount;
            data.guideHairVertexCount    = guideHairVertexCount;
            data.maxNumVerticesPerStrand = maxNumVerticesPerStrand;

            return(data);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Explicitly initializes the simulation data.
 /// This is used in for example the tressfx binary importer.
 /// </summary>
 /// <param name="simulationData"></param>
 public void InitializeSimulationData(HairSimulationData hairSimulationData)
 {
     this._hairSimulationData = hairSimulationData;
 }