/// <summary> /// Sets the given hairmesh into the given index. /// NOTE: TressFX only supports indices 0-3 (so max. 4 meshes). /// </summary> /// <param name="index"></param> /// <param name="mesh"></param> public void SetHairMesh(int index, HairMesh mesh) { if (index >= 0 && index <= 3) { this.meshes[index] = mesh; } else { throw new IndexOutOfRangeException("TressFX only supports mesh indices between including 0 and 3"); } }
/// <summary> /// Implicitly initializes the indices of this hair. /// This calculates the indices automatically /// </summary> /// <param name="lineIndices"></param> /// <param name="triangleIndices"></param> public void CreateIndices() { List <int> lineIndices = new List <int>(); List <int> triangleIndices = new List <int>(); int id = 0; // Iterate through every mesh and every strand and every vertex and generate the indices for them. for (int i = 0; i < this.meshes.Length; i++) { HairMesh currentMesh = this.meshes[i]; if (currentMesh == null) { continue; } for (int j = 0; j < currentMesh.strandCount; j++) { HairStrand currentStrand = currentMesh.strands[j]; for (int k = 0; k < currentStrand.vertices.Count - 1; k++) { HairStrandVertex currentVertex = currentStrand.vertices[k]; // Append line indices lineIndices.Add(id); lineIndices.Add(id + 1); // Append triangle indices triangleIndices.Add(2 * id); triangleIndices.Add(2 * id + 1); triangleIndices.Add(2 * id + 2); triangleIndices.Add(2 * id + 2); triangleIndices.Add(2 * id + 1); triangleIndices.Add(2 * id + 3); id++; } id++; } } // Set indices this.lineIndices = lineIndices.ToArray(); this.triangleIndices = triangleIndices.ToArray(); }
/// <summary> /// This is called in PrepareSimulationParameters(). /// It may deletes some hairs in order to avoid branching in the compute shader. /// </summary> private void BranchingAvoidance(uint threadGroupSize = 64) { // Prepare uint loadedNumStrands = (uint)this.strandCount; uint deleteStrands = loadedNumStrands % threadGroupSize; // Delete last hairs // Get last mesh HairMesh lastMesh = null; foreach (HairMesh m in this.meshes) { if (m != null) { lastMesh = m; } } for (uint i = deleteStrands; i > 0; i--) { // Remove last hair lastMesh.strands.RemoveAt(lastMesh.strands.Count - 1); } }
/// <summary> /// Sets the given hairmesh into the given index. /// NOTE: TressFX only supports indices 0-3 (so max. 4 meshes). /// </summary> /// <param name="index"></param> /// <param name="mesh"></param> public void SetHairMesh(int index, HairMesh mesh) { if (index >= 0 && index <= 3) this.meshes[index] = mesh; else throw new IndexOutOfRangeException("TressFX only supports mesh indices between including 0 and 3"); }