-
[INFO] ASE 3d- format discovery
-
totally forgot here are some usefull functions I wrote for parsing the ASE files (some very rough ones, but they worked very well for me):
1 function for finding and replacing text elements of a particular string:
Code:
function fr(txt,id,r){//fr = find and replace
var max = 1000;//security!
var pos = 0;
var done=0;
while (done<=max && pos<>-1){
pos = txt.indexOf(id);
if (pos<>-1){
done++;
var a = txt.slice(0,pos);
var b = txt.slice(pos+id.length,txt.length);
txt = a+""+r+""+b;
}else{
done++;
break;
}
}
return(txt);
}
what it does: it searches within the string variable txt for the string variable id and replaces it with the string variable r.
samples:
removing all tabs within text
Code:
var new_text = fr(my_string , "\t" , "");
remove double returns (for some reason some parts of my loaded ASE file had always a new line after a return)
Code:
var new_text = fr(my_string , "\r\n" , "\n" );
replacing weired '"' with real quotes:
[/code]var new_text = fr(my_string , """ , "\"" );[/code]
--------------------------------------------------------
1 function for getting a node- block of the text
Code:
function getNode(from,header){
var p = from.indexOf(header)
if (p<>-1){
var s1 = p+header.length;
var s2 = from.indexOf("}",s1);
var out = from.slice(s1,s2);
return({val:out,s:s2});
}else{
return("");
}
}
what it does: again from given string from it searches for the string variable header. If it finds it it returns 2 Objects, 1 with all characters following after the search string till the first curly brace "}", the other one of the position of where the curly brace character was found. So it is only usefull for single element blocks not for blocks that contain other blocks.
sample:
Code:
my_block = getNode(my_string , "*MESH_TVERTLIST {" ).val;
feel free to use them or improve them
-
supervillain
Thanks a ton for sharing... I'll be redoing the 3D resources thread... mind if I add this to the list?
-
np,- feel free to ad, I thought that goes without saying if someone posts something here.
-
Ich lerne jede Tag etwas Neues
-
-
Flash Genie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|