PDA

View Full Version : File reader


Mishiza
02-15-2009, 09:23 PM
Hello all!

I'm trying to do a very simple and easy to read animation importer.
I've already done a exporter (exporting in ascii).

What I'm basically trying to do is to make a script to read my file format but I'm having problems with the actual execution. the format is:

Frame Number|
ObjectName TranslateXValue TangetOutValue TangentWeightValue;
ObjectName TranslateYValue TangetOutValue TangentWeightValue;
ObjectName TranslateZValue TangetOutValue TangentWeightValue;
ObjectName RotateXValue TangetOutvalue TangentWeightValue;
@
..... etc


What I need the script to do is:
1. Reading the lines until it reaches the breaker "|", Set the frame number.
2. Reading the lines until it reaches the breaker ";", Set key based on value and from tangent based on the tangent out and tangent weight value.
3. When reaching "@" starting over.

If someone could help me out and give me an example script of how to read my files and use the variables with in to execute the code i would be eternally thankful ^^

WHW
02-16-2009, 09:54 PM
Hi Mishiza,

You may want to look at the way you store your data so it's more easily processed when you read it back in.

For example:

Frame Number = 0
Edit ObjectName TranslateXValue TangetOutValue TangentWeightValue
Edit ObjectName TranslateXValue TangetOutValue TangentWeightValue
Edit ObjectName TranslateXValue TangetOutValue TangentWeightValue
@


When you read back you check for the carriage return to seperate each line. You can use "startsWith" to check for "Frame Number", "Edit" or "@" and call the relevant procedure.

A "tokenize" with "[space]=" would provide you with the seperate elements you can operate on.

So:

string $buffer[]; clear $buffer;
$line = "Frame Number = 0";
tokenize $line " =" $buffer;

The resulting frame number would be held in $buffer[2];

$buffer[0] - "Frame"
$buffer[1] - "Number"
$buffer[2] - "0"

And you can do the same process on the object name and translations in the following lines.

Once your check does find "@", as you wanted, the procedure would start over until the end of the string has been reached.

Hope that's of help. And apologises if I've gone too basic with my explaination.

/W

edit: Forgot the $buffer in the tokenize.

CGTalk Moderation
02-16-2009, 09:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.