reading info from text file and loading 3d models using it

Well the title probably doesn’t make much sense, didn’t know how to “call it” :smile:
Anyways, I’ll try to explain as much as I can here.
What I’m trying to do is to “dump” a map from one game into text file, it’d basically contain 3d model id (e.g. 190), height, x and y coordinates, and face (which direction it’s facing). Then I’d dump 3d models which would be named by their id (e.g. 190.3ds).

That above is easy, now the hard part which I’m not sure whether it’d be possible to do… Now I’d want Unity to read the text file; read the model id, height, face, x and y coordinates and load that model (the models would be in .3ds format placed in one folder) in runtime.

Basically, here’s an example of the text file map dump:

//     Usage: objectId    type    face    height    objectX    objectY

obj    =    196    4    0    0    3008    3449
obj    =    196    4    0    0    3008    3452
obj    =    196    4    2    0    3010    3450
obj    =    196    4    3    0    3013    3452
obj    =    196    4    3    0    3018    3452
obj    =    196    4    0    0    3021    3450
obj    =    196    4    2    0    3023    3452
obj    =    319    22    1    0    3008    3438
obj    =    319    22    0    0    3009    3427
obj    =    319    22    0    0    3009    3438
obj    =    319    22    1    0    3012    3425
obj    =    319    22    1    0    3013    3437
obj    =    319    22    0    0    3016    3422
obj    =    319    22    0    0    3021    3440
obj    =    319    22    0    0    3022    3417
obj    =    319    22    3    0    3022    3419
obj    =    319    22    3    0    3022    3442
[ENDOFMAP]

Now let me give you an example…
I make Unity read this map dump. Ok, so the first model is 196 (in folder it is 196.3ds). Don’t mind the “type”, I won’t dump it next time because it’s not needed… Anyways, so Unity reads the text file and first model is 196, so it looks for a 3d model named 196.3ds in one folder, finds it and loads it/ adds it to the scene. Now to read other info… The face (which direction the model is facing). This could be scripted so e.g. 1 = 90 degrees, 2 = 180 degrees etc. so it would read the face info and change the rotation of that model it loaded according to the info from text file, in our case it’s 0 so it would leave it at 0.
Next comes the height, so it could simply be Transform position to Y axis. It would read the height from text file and change the Y transformation of model (Position), in our case it’s 0 so it would just change it to 0.
Now comes the coordinates. It would read the X and Z coordinates from the text file, in our case it’s X=3008 and Z=3449 and it would simply change the X and Z Transformation Position of our model to what ever is specified in the text file.

And that’s it, it’d do the same for every object specified in the text file map dump.
Not necessarily text file, I can dump it to xml or something else too, and not necessarily .3ds files for models, .obj could do just fine as well.

Sorry if I was a bit unclear, but would it be possible to do this?

Done it, thanks anyway… :wink:

I was about to answer it :slight_smile:

Well go ahead anyways, I “kind of” got it. There may be better ways :sweat_smile:

Now this is not necessary but I thought I’ll ask anyways out of curiosity… Would there be any way at all to make an editor script which adds a specified 3d model (say… obj, 3ds or any other format which Unity supports) into the scene? Say there would be a textbox and a button, you enter the path to a 3d model into the textbox, click the button and it adds that 3d model to the scene on specified coordinates or simply at (0, 0, 0). Not during runtime, but just like as if you drag dropped a 3d model from project panel to the hierarchy.

Thanks