Author Topic: Perl script regquest. Two actually.  (Read 1747 times)

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
Perl script regquest. Two actually.
« on: June 17, 2011, 01:57:29 am »


               NOT NWN script request, but perl scripts.

I need two different perl scripts.

1) A script to read all .mdl files in a given folder, and change any object that has a specific texture assigned to have a new alpha value of .8 instead of whatever it is currently set at.  I need this to change the water visibility in an entire tileset to less than 1.
  --  Key 1 - texture name
  --  Key 2 - change alpha to 0.8

2) A second script, to read all .mdl files, and remove any object that has a specific texture assigned to it.
  --  key 1 - texture name
  --  key 2 - remove that entire object from the mdl file.

Both need to recursively check through the entire mdl for any objects that meet the criteria and then perform the action on that object/mdl file.  Some tiles will have multiple objects with the given texture, most will not.
               
               

               


                     Modifié par Bannor Bloodfist, 17 juin 2011 - 12:58 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #1 on: June 18, 2011, 05:19:04 pm »


               Just so you know, I looked into the possibility of using leto for this, since it's very perl-like. I lack the experience to do it, however, and I don't actually know perl, so I'm not going to be able to help. Think of this as a free bump. '<img'>

Funky
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #2 on: June 18, 2011, 06:37:54 pm »


               You can do it via my nwnx_files plugin. It can read the file line by line and you can controll it inside nwscript.
               
               

               
            

Legacy_Calvinthesneak

  • Hero Member
  • *****
  • Posts: 1159
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #3 on: June 18, 2011, 07:07:24 pm »


               Bannor I use a program called Useful File Utilities.  It has a REGEX like type interface, and you can use it to do batch replacement in thousands of ascii mdl files.

I used it to massively convert robes from one phenotype to another.  I'm not sure enough of tile formatting to know if this will do what you want entirely, but it is quite capable.  I've done a little PERL scripting but I'm not very good with it, just a few labs in school.  I'm pretty sure I listed useful file utilities in the Custom content section of the forums in the stick of tools.
               
               

               
            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #4 on: June 19, 2011, 01:03:06 am »


               Thanks for the suggestions,

1) a single line replacement won't work, so useful file utils is out completely.  You have to compare sections of the file, first search for the key texturename, then backtrack inside that entire node/object to find the alpha setting to adjust it, and write that change back.  A full alpha replacement on every instance in the tile will break every other object in the tile as they all need the alpha to be set at 1.0 instead of the 0.8  (BY the by, I use useful file utils for batch processing on lots of things, but it can only handle ALL instances on a given search, and I would have to sit there and approve / disapprove each find.  I am talking roughly 500 tiles, possibly more, I don't have a direct count, that each has as many as 20 separate instances of an alpha setting on any objects, as in walls, ground, trees, branches, bushes, etc... the list is very long)

2) I don't think nwnx will help at all as it is primarily an interface for nwscript, and I need to be able to import, modify, then export the changed mdl files. and I would almost bet that it can't handle anything much more complicated than line by line, which has the same issue as useful file utils has, no way to skip stuff it doesn't need, and only change specific objects inside the mdl, not the entire mdl.

I am not a scripter by trade, I can only (slighlty) modify existing stuff.  It's been over 20 years since I used my C++ education, and I can't remember how to even open/read a file much less process it to be able to change the data.  

Thanks for the bumps guys, I may just have to manually do this.

What I need is the ability to find nodes that have sub-sections that match the criteria.

A typical tile object (node) would be something like this:

node trimesh plane588
  parent tctl0_h02_02
  ambient 1 1 1
  diffuse 1 1 1
  specular 0 0 0
  shininess 1
  rotatetexture 1
  bitmap tctl0_grass02
  orientation 0 0 0 0
  alpha 1
  scale 1
  selfillumcolor 0 0 0
  position 0 0 2.0
  verts 25
    -5 -2.5000000 0
---continues many more lines down in file ---
endnode
and that is not the entire node, but to explain, I would have to check the node for the bimap reference, then go down 2 lines to change the alpha setting ONLY if that node's bitmap matched the search criteria.

on the second program, basically the same sort of thing, find the node that has a specific bitmap assigned, and delete the entire node and all associated lines below it until the Next node starts.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #5 on: June 19, 2011, 02:00:59 am »


               This pattern should work if you use my nwnx_files plugin and finish the script via nwscript:

string sAll, sLine, sTemp, sTexture;
file mdl = "path that starts from NWN root";
int bNewNode,bErase;
string sLine = read line(mdl);
 while(sLine != "")
 {
  if(5 chars from left == "node ")
  {
  sAll+= sTemp;
  bNewNode = TRUE;
  sTemp = sLine;
  }
  else if(7 chars from left == "endnode")
  {
  bNewNode = FALSE;
   if(!bErase)
   {
   sAll+= sTemp;
   }
  bErase = FALSE;
  }
  else if(bNewNode)
  {
   if(6chars from left == "aplha ")
   {
    if(sTexture == "something")
    {
    sLine = "alpha 1";
    }
   }
   else if(7chars from left == "bitmap ")
   {
   sTexture = rest chars from right;
    if(sTexture == "something")
    {
    bErase = TRUE;
    }
   }
  sTemp+= sLine;
  }
  else
  {
  sAll+= sLine;
  }
 }


This algorhytm should work for perl as well but i dont know name of the functions/dont have perl installed etc. So if I would want it I would use my plugin. LINK: http://nwvault.ign.c....Detail&id=1383
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #6 on: June 19, 2011, 02:40:34 am »


               My problem is that I have never really looked at the .mdl file format.  I took a quick look today just to discover that it was not something I could do quickly. 
One of the thing that can compicate the matter is that at this point we do not know if all of your .mdl files are in ASCII or Bianary or both .
The solution of cource will be simpler if we know that all of the files are at least the same format.
Changing the alpha sounds stright forward in a ASCII file. I have not looked at the bianary format that close yet. 
The second script for the removal of the object, I currently do not know  enough about  file format to even guess at.  


I also do not know perl.   Anything I did would most likely be a command line utility, If I  found the time to do it. And with my current poor computer language skills could take me awhile. 

Shadows option for the alpha fix sounds good if all of you files are currently in ASCII format.  
               
               

               
            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #7 on: June 19, 2011, 03:04:23 am »


               ShaDoOoW that looks a bit like the basics required, but you say you need nwscript to actually finish it, and how would I run it in the firstplace?

Lightfoot8, any mdl file I work on is ascii.  Each node in that file begins with the word node and ends with the word endnode.

Basically, for that second script, you need to handle ALL the data between node/endnode objects as single objects, then search within for the criteria (in this case a specific texture name) and if it matches, remove everything between node/endnode for that object, including the node/endnode keywords.  Of course, leaving the rest of the tile alone.

My hope for these scripts, is something that could be changed at will for different texture names and used on many different tilesets as needed and as changed by the texture (bitmap) name.

The reason I wanted them as two separate scripts is so that I can process groups of tiles performing one or the other task, but not both at same time.  Having them separate, makes it easier to handle that way.

Currently, this tileset has 900+ tiles, and will likely end up somewhere around 950, to 1000 depending on how many new groups get created.  Obviously, not something I want to handle inside 3ds one tile at a time.  

Not every mdl will match the search criteria, so those should just be left alone which is simple enough I assume.

As I said, I am NOT a scripter, best I would ever really be able to accomplish would be slight modifications of a given script.  To change the criteria changed, or the criteria searched for etc...
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #8 on: June 19, 2011, 03:14:45 am »


               

Bannor Bloodfist wrote...

ShaDoOoW that looks a bit like the basics required, but you say you need nwscript to actually finish it, and how would I run it in the firstplace?

|You add this script when finished (now its only pattern) into module OnLoad event and then you run it as a server via NWNX (+you need my plugin in NWN root).

I might finish that script tomorrow and prepare you such working module if you wait.
               
               

               
            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #9 on: June 19, 2011, 04:39:21 am »


               

ShaDoOoW wrote...

Bannor Bloodfist wrote...

ShaDoOoW that looks a bit like the basics required, but you say you need nwscript to actually finish it, and how would I run it in the firstplace?

|You add this script when finished (now its only pattern) into module OnLoad event and then you run it as a server via NWNX (+you need my plugin in NWN root).

I might finish that script tomorrow and prepare you such working module if you wait.


And you will be able to write out the tile mdls with nwscript?  Or are you talking of a in memory or inside the actual module option here?
               
               

               


                     Modifié par Bannor Bloodfist, 19 juin 2011 - 03:39 .
                     
                  


            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #10 on: June 19, 2011, 10:23:20 am »


               I usually write Python scripts to do mass mdl/set modifications. Contact me via IM or IRC - I'll need a few mdls to test it on.
               
               

               


                     Modifié par virusman, 19 juin 2011 - 09:30 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #11 on: June 19, 2011, 06:33:05 pm »


               

Bannor Bloodfist wrote...

ShaDoOoW wrote...

Bannor Bloodfist wrote...

ShaDoOoW that looks a bit like the basics required, but you say you need nwscript to actually finish it, and how would I run it in the firstplace?

|You add this script when finished (now its only pattern) into module OnLoad event and then you run it as a server via NWNX (+you need my plugin in NWN root).

I might finish that script tomorrow and prepare you such working module if you wait.


And you will be able to write out the tile mdls with nwscript?

Yes, ill try to prepare demo module within few hours.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #12 on: June 19, 2011, 09:38:16 pm »


               

ShaDoOoW wrote...

Yes, ill try to prepare demo module within few hours.

Hmm its not so easy... My plugin failed. First I had to make TMI workaround with delay as the normal mdl file has 5k+ lines and nwn cant hendle it. Second my nwnx_files cant handle writing 5k+ lines string into file so far. I think I can fix this but not in short terms so your best chance is virusman now.

Also the script to do it was in the end (cos those TMI workarounds) so complex that it would not be useable for non-scripter anymore...'<img'>

EDIT: So I got it working, I workarounded the issue above via simply writing only max 1000chars at once in loop.

LINK for demo: http://social.biowar...t_file_id=10158

Extract into NWN root and run the mdl_change module in nwserver but dont forget to run it via NWNX. You can see debug informations in logs.0/nwserverlog1.txt and it takes quite a long time for each file to be proceeded.

The demo changes one mdl file inside mdltest folder, c_nymph.mdl, the file c_nymph.mdx is backup file for compare/retest.

So far it replaces verts line to verts 666 if the bitmap is 72_nymph and it removes whole node if the bitmap is 71_nymph. If you would want to change any line above the bitmap, the script would have to be rewritten. The actual script is in module called sh_mdlchange.
               
               

               


                     Modifié par ShaDoOoW, 19 juin 2011 - 09:11 .
                     
                  


            

Legacy_Bannor Bloodfist

  • Hero Member
  • *****
  • Posts: 1578
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #13 on: June 20, 2011, 01:57:53 am »


               Well, three problems... actually more, but three critical ones.

One, I would need to be able to specify the bitmap searched for.

Two, I need to fix the Alpha (as originally requested) and change it to 0.8 Not VERTS to 666 I have no idea why you went to changing verts, that is very dangerous.

Three, I need TWO separate scripts, each with different bitmap search, I mean, why change the alpha (or verts in your case) then delete the entire node anyway?  Again, I need to be able to specify the bitmaps on call, or easily within the script.

Four, I need it to process an entire folder full of .mdl files.  Either a folder I can specify or one that can be specified within the script.  In this particular case, I am talking something on the order of 950 tiles that need to be processed, half of which will require at least one of the two scripts to fix the issues in them. 

I don't really think this is going to work for me, it will require me to install NWNX, then run the game as server, and run your nwnx plugins etc, all to perform something much simpler to perform outside of NWN.

I do appreciate your effort to make something happen for me, after all, you and I learned a bit more on what can be accomplished within nwscript, and nwnx.
               
               

               


                     Modifié par Bannor Bloodfist, 20 juin 2011 - 12:59 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Perl script regquest. Two actually.
« Reply #14 on: June 20, 2011, 12:01:06 pm »


               

Bannor Bloodfist wrote...

Well, three problems... actually more, but three critical ones.

One, I would need to be able to specify the bitmap searched for.

Two, I need to fix the Alpha (as originally requested) and change it to 0.8 Not VERTS to 666 I have no idea why you went to changing verts, that is very dangerous.

Three, I need TWO separate scripts, each with different bitmap search, I mean, why change the alpha (or verts in your case) then delete the entire node anyway?  Again, I need to be able to specify the bitmaps on call, or easily within the script.

Four, I need it to process an entire folder full of .mdl files.  Either a folder I can specify or one that can be specified within the script.  In this particular case, I am talking something on the order of 950 tiles that need to be processed, half of which will require at least one of the two scripts to fix the issues in them. 

I don't really think this is going to work for me, it will require me to install NWNX, then run the game as server, and run your nwnx plugins etc, all to perform something much simpler to perform outside of NWN.

I do appreciate your effort to make something happen for me, after all, you and I learned a bit more on what can be accomplished within nwscript, and nwnx.

1) You said you can work it out and change what you need. I just took first decompiled mdl i found and there wasnt apha, so its just a test.

2) To change it to alpha is simple, just change verts in script to alpha.

3) No that didnt happened. My script does both, it changes the verts/apha if it encounters bitmap 1 and erase whole node if it encounters bitmap 2.

4) The script will process all mdl files in that folder, I just had only one testing file.

5) Whats so hard on this it takes only three seconds, if you dont have NWNX I can add it into package, then you just run NWNX.exe, that run nwserver and then you choose mdl_changer module and load it. Thats all.

I would really appreciate if you tried it as it took three hours to make it. If you are not able to change bitmap you need to search then tell me exact values you want to search and what you want adjust and how, its now very simple to change.