Aller au contenu

Photo

Perl script regquest. Two actually.


  • Veuillez vous connecter pour répondre
39 réponses à ce sujet

#1
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
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 .


#2
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
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. :P

Funky

#3
Shadooow

Shadooow
  • Members
  • 4 468 messages
You can do it via my nwnx_files plugin. It can read the file line by line and you can controll it inside nwscript.

#4
Calvinthesneak

Calvinthesneak
  • Members
  • 656 messages
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.

#5
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
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.

#6
Shadooow

Shadooow
  • Members
  • 4 468 messages
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

#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.  

#8
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
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...

#9
Shadooow

Shadooow
  • Members
  • 4 468 messages

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.

#10
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages

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 .


#11
virusman

virusman
  • Members
  • 282 messages
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 .


#12
Shadooow

Shadooow
  • Members
  • 4 468 messages

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.

#13
Shadooow

Shadooow
  • Members
  • 4 468 messages

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...:(

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 .


#14
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
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 .


#15
Shadooow

Shadooow
  • Members
  • 4 468 messages

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.

#16
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
well, dm client feedback in nwn sucks, no way to tell if the damned thing is actually running the script or not.

I changed the texture names as needed. loaded it up via nwnx2, then logged in as dmclient. then enabled debug mode, ran command "dm_runscript sh_mdlchange" without quotes, get message success, but no files are written anywhere.

If, as you say, this thing takes a long time on a single mdl file, it won't help me anyway, as I have over 950 mdl files to process so this will likely tie up the computer for a very long time.

Don't take me wrong ShaDoW, I do appreciate you trying to help out.

#17
Shadooow

Shadooow
  • Members
  • 4 468 messages

Bannor Bloodfist wrote...

well, dm client feedback in nwn sucks, no way to tell if the damned thing is actually running the script or not.

I changed the texture names as needed. loaded it up via nwnx2, then logged in as dmclient. then enabled debug mode, ran command "dm_runscript sh_mdlchange" without quotes, get message success, but no files are written anywhere.

If, as you say, this thing takes a long time on a single mdl file, it won't help me anyway, as I have over 950 mdl files to process so this will likely tie up the computer for a very long time.

Don't take me wrong ShaDoW, I do appreciate you trying to help out.

The script will start automatically when you load module and thats why all debugging informantions are written into logs.0/nwserverlog1.txt as I already said. (I did it this way as its fastest for testing, logging in as PC/DM and then do something is quite slow. So check that log file first.

Its was approximately 30sec for 5k lines model file.

#18
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
well, the logs are full, with the statement that the file is not in ascii format. They are, all of them. So your test is failing, you need to search for #MAXMODEL ASCII but not by specific line location. It could be anywhere in the first 5 or six lines. Anything with a $ is a comment line, so just finding that text anywhere in the mdl will work.

Since the sh_mdlchange is searching for #MAXMODEL ASCII in line one only, all files fail. So no actual processing is occurring.

#19
Shadooow

Shadooow
  • Members
  • 4 468 messages

Bannor Bloodfist wrote...

well, the logs are full, with the statement that the file is not in ascii format. They are, all of them. So your test is failing, you need to search for #MAXMODEL ASCII but not by specific line location. It could be anywhere in the first 5 or six lines. Anything with a $ is a comment line, so just finding that text anywhere in the mdl will work.

Since the sh_mdlchange is searching for #MAXMODEL ASCII in line one only, all files fail. So no actual processing is occurring.

I see, didnt know that. The best would be if you upload all those files what do you want to replace and I modify the script and run it...

#20
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
I sent you a PM asking for an email addy.

#21
Borden Haelven

Borden Haelven
  • Members
  • 403 messages
Might be a silly suggestion but:-

Try using a regular mass text replacer to find and replace

bitmap tctl0_grass02
orientation 0 0 0 0
alpha 1

including carraige returns

with:-

bitmap tctl0_grass02
orientation 0 0 0 0
alpha 0.8

Might be worth a try...

#22
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages
Won't work, too many variations in the tiles, for example the bit map name is 7-9 lines below the alpha line, and the rest of the lines in-between can be different. The export routines in 3dsmax, export by order of creation or change while working on the tile. So, if someone adjusted something else in between, the orientation can be above, OR below the bitmap line, The "center" location is almost always different depending on size and position of water plane etc...

I truly wish it was otherwise or I never would have asked for a set of scripts to help with this.

#23
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
@ Bannor Bloodfist: What OS are you useing?

#24
Bannor Bloodfist

Bannor Bloodfist
  • Members
  • 924 messages

Lightfoot8 wrote...

@ Bannor Bloodfist: What OS are you useing?


XP SP3.

#25
Baragg

Baragg
  • Members
  • 271 messages
You fellas are on a level way over my head.