Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splines from .txt files
#11
[Image: idk.png]Thanks again for all your work and support! I am embarassed to admit I do not know how to import this file... it doesn't seem to be an asset unity package, or a script file.
This is what it looks like when I unzip it, and Unity doesn't seem to know what to do with it in any of the ways I tried importing it. Draging it in seems to look exactly the same as above, which I am not sure how to use, either. x _ x sorry if this is obvious, I am still a noob.

If it makes a difference, I am running unity 4.3.4f1 (free) on mac os 10.8.2 ~

Thanks again,

L
Reply
#12
Hm, this is a regular zip (7-zip) file with a regular Unitypackage in it. Once unzipped you should be able to import it.
Reply
#13
Bizzare... as you can see in the screen cap, it doesn't unzip as a Unitypackage, but a bunch of folders with files that Unity can't read?
I wonder why. I'll try a different compression agent. 7zip is windows only (i use archive utility), so I wonder if that is a thing? x ___ x
What a waste, I hope I can figure this out!

!!! Ah, it was a problem with archive utility. I downloaded stuff it expander, and that worked normally...
http://www.stuffit.com/mac-expander-download.html I guess this is good to know for mac users working with Unity, it looks like archive utility corrupts the zip.

I'll let you know how everything goes, thanks again for all your awesome work, Jake.

Yours,
L

AGH, YES IT WORKS... but not on my files. I will keep looking at this and figure it out., and post my results ~ THANK YOU : D !!!!!

<3

L
Reply
#14
Hi Lila,

changing the way the input file is readed isn't that hard, but the example should give you a good start to fine tune it.
Reply
#15
Yep, got it reading fine. : D
Just trying to make it read multiple splines now! will post results.
Thank you! this has been super helpful!
Reply
#16
Hej!
This is the script changed slightly so it doesnt error if there are unexpected charaters in the txt file (like extra returns, etc)
I am learning very slowlz but with lots of help : D

[font]using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;

[ExecuteInEditModeRequireComponent(typeof(CurvySpline))]
public class SplineFromFile : MonoBehaviour {

    public TextAsset File;

    CurvySpline mSpline;

    void Awake()
    {
        mSpline = GetComponent<CurvySpline>();
    }

    public void ReadFile()
    {
        if (mSpline && File)
        {
            mSpline.Clear();
            string[] lines = File.text.Split('\n');
            List<Vector3Points = new List<Vector3>();

            foreach (var line in lines)
            {
                string[] coords = line.Split(' ');
                //Debug.Log(coords.Length.ToString);
                if(coords.Length == 3){
                    Points.Add(new Vector3(float.Parse(coords[0]), float.Parse(coords[1]), float.Parse(coords[2])));
                }
            }

            mSpline.Add(Points.ToArray());
        }
    } 

}

YAY it works!!!

So, now since there are so many splines to make, we are trying to read them all from one file.
So far, this just reads the last entry...
Just thought I'd post the progress. We will keep working on it.
[/font]
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Collections.Generic;
  5.  
  6. [ExecuteInEditMode, RequireComponent(typeof(CurvySpline))]
  7. public class SplineFromFileAll : MonoBehaviour {
  8.  
  9. public TextAsset File;
  10.  
  11. CurvySpline mSpline;
  12. public GameObject allTracts;
  13.  
  14. void Awake()
  15. {
  16. mSpline = GetComponent<CurvySpline>();
  17. }
  18.  
  19. public void ReadFile()
  20. {
  21.  
  22. if (mSpline && File) // check for not null and file exist / readable
  23. {
  24.  
  25. mSpline.Clear();
  26. string[] linesOfFile = File.text.Split('\n');
  27. List<Vector3> splineCoords = new List<Vector3>();
  28.  
  29. List<CurvySpline> allSplines = new List<CurvySpline>();
  30.  
  31.  
  32.  
  33. var begin = true;
  34. var id = 0;
  35. string tractName = "Tract_" + id;
  36. foreach (var line in linesOfFile)
  37. {
  38.  
  39. string[] coords = line.Split('\t');
  40.  
  41. if(coords[0] == "newTrack" || coords[0] == " newTrack"){
  42.  
  43. if(begin == true){
  44. Debug.Log("first");
  45. begin = false;
  46.  
  47. }else {
  48. mSpline.Clear();
  49.  
  50. mSpline.Add(splineCoords.ToArray());
  51. allSplines.Add(mSpline);
  52. tractName = "Tract_" + id;
  53. gameObject.AddComponent(tractName) as CurvySpline;
  54.  
  55.  
  56. id++;
  57. }
  58.  
  59. splineCoords.Clear();
  60.  
  61. }else if(coords.Length == 3){
  62. splineCoords.Add(new Vector3(float.Parse(coords[0]), float.Parse(coords[1]), float.Parse(coords[2])));
  63. }
  64. }
  65. mSpline.Clear();
  66. mSpline.Add(splineCoords.ToArray());
  67. allSplines.Add(mSpline);
  68. Debug.Log("number allsplines: " + allSplines.Count);
  69. }
  70. }
  71. }

Any advice, as always, would be really awesome.

Danke,

Lila
Reply
#17
Ah, I think we have it almost figured out.
Reply
#18
(06-17-2014, 01:55 PM)'Lila' Wrote: Ah, I think we have it almost figured out.




 

Hey Lila, thanks for documenting your experience here. I helped me out while stepping thru your experience. My problem is here.  
 

 

 

 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Information New free asset: Converter For Unity Splines _Aka_ 11 28 8 hours ago
Last Post: _Aka_
  Twisting Splines ZiggZagg 6 11 05-14-2024, 04:48 PM
Last Post: _Aka_
  Help with procedural roads and splines ramiroflores 1 6 05-07-2024, 08:57 AM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_

Forum Jump: