Advertisement
soulassassin547

NIF - tweak NIF shaders for use in mass mesh processing (LE)

Jun 30th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. {
  2. Zilav
  3. modifed by SA547 for Oldrim meshes only - armor/clothing mod development
  4. Set emission, textureclamp, and glossiness values
  5. }
  6. unit NifBatchShaderTweak;
  7.  
  8. const
  9. sPath = 'h:\tmp-dev'; // path to folders with nifs to update
  10. fEmissionMult = 1;
  11. fTextureClamp = 3;
  12. fGlossiness = 20;
  13.  
  14. function Initialize: Integer;
  15. var
  16. TDirectory: TDirectory; // to access member functions
  17. i, j: integer;
  18. files: TStringDynArray;
  19. f: string;
  20. bChanged: Boolean;
  21. nif: TwbNifFile;
  22. shaders: TList;
  23. b: TwbNifBlock;
  24. begin
  25. nif := TwbNifFile.Create;
  26. shaders := TList.Create;
  27. try
  28. // get all *.nif files from this directory and subdirectories
  29. files := TDirectory.GetFiles(sPath, '*.nif', soAllDirectories);
  30.  
  31. // process each file
  32. for i := 0 to Pred(Length(files)) do begin
  33. f := files[i];
  34. nif.LoadFromFile(f);
  35. bChanged := False;
  36.  
  37. // get all shaders
  38. nif.BlocksByType('BSLightingShaderProperty', False, shaders);
  39.  
  40. // update
  41. for j := 0 to Pred(shaders.Count) do begin
  42. b := TwbNifBlock(shaders[j]);
  43. if (b.NativeValues['Emissive Multiple'] <> fEmissionMult) or (b.NativeValues['Texture Clamp Mode'] <> fTextureClamp) or (b.NativeValues['Glossiness'] <> fGlossiness) then
  44. begin
  45. b.NativeValues['Emissive Multiple'] := fEmissionMult;
  46. b.NativeValues['Texture Clamp Mode'] := fTextureClamp;
  47. b.NativeValues['Glossiness'] := fGlossiness;
  48. bChanged := True;
  49. end;
  50. end;
  51.  
  52. // save if nif has changed
  53. if bChanged then
  54. begin
  55. nif.SaveToFile(f);
  56. AddMessage('Updated: ' + f);
  57. end;
  58.  
  59. shaders.Clear;
  60. end;
  61.  
  62. finally
  63. nif.Free;
  64. shaders.Free;
  65. end;
  66.  
  67. Result := 1;
  68. end;
  69.  
  70. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement