/// <summary> /// Returns the implementation of the hair format. /// </summary> /// <param name="format"></param> /// <returns></returns> public static IHairFormat GetFormatImplementation(this HairFormat format) { switch (format) { case HairFormat.ASE: return(new AseFormat()); case HairFormat.TFXB: return(new TFXBFormat()); case HairFormat.OBJ: return(new WavefrontObjFormat()); default: throw new FormatException("Format unknown!"); // This should never happen if the library is unmodified } }
/// <summary> /// Loads / imports hair from the given file with given format. /// </summary> /// <param name="format"></param> /// <param name="path"></param> public static Hair Import(HairFormat format, string path, HairImportSettings importSettings = null) { if (importSettings == null) { importSettings = HairImportSettings.standard; } // Get hair format impl IHairFormat formatImpl = format.GetFormatImplementation(); // Create new hair object Hair hair = new Hair(); // Open the binary reader BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)); // Import the hair data HairMesh[] hairMeshes = null; try { hairMeshes = formatImpl.Import(reader, path, hair, importSettings); } finally { reader.Close(); } reader.Close(); // Validity check if (hairMeshes.Length > 4) { throw new IndexOutOfRangeException("TressFX only supports up to 4 hair meshes, the file you tried to import had " + hairMeshes.Length); } // Set all meshes for (int i = 0; i < hairMeshes.Length; i++) { hair.SetHairMesh(i, hairMeshes[i]); } hair.CreateBoundingSphere(); // We're done :> return(hair); }
/// <summary> /// Loads / imports hair from the given file with given format. /// </summary> /// <param name="format"></param> /// <param name="path"></param> public static Hair Import(HairFormat format, string path, HairImportSettings importSettings = null) { if (importSettings == null) importSettings = HairImportSettings.standard; // Get hair format impl IHairFormat formatImpl = format.GetFormatImplementation(); // Create new hair object Hair hair = new Hair(); // Open the binary reader BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)); // Import the hair data HairMesh[] hairMeshes = null; try { hairMeshes = formatImpl.Import(reader, path, hair, importSettings); } finally { reader.Close(); } reader.Close(); // Validity check if (hairMeshes.Length > 4) throw new IndexOutOfRangeException("TressFX only supports up to 4 hair meshes, the file you tried to import had " + hairMeshes.Length); // Set all meshes for (int i = 0; i < hairMeshes.Length; i++) hair.SetHairMesh(i, hairMeshes[i]); // We're done :> return hair; }
/// <summary> /// Exports this hair to the given file format output. /// </summary> public void Export(HairFormat format, string path) { IHairFormat formatImpl = format.GetFormatImplementation(); this.Export(formatImpl, path); }