void Init(QuadFace parent, int resolution, float scale, Vector3 normal, Vector3 left, Vector3 forward)
    {
        this.parent     = parent;
        this.scale      = scale;
        this.position   = normal;
        this.resolution = resolution;
        this.left       = left;
        this.forward    = forward;

        faceTree = null;

        gameObject = new GameObject("CubePlane_" + scale + "_" + scale + "_" + position.ToString());
        gameObject.SetActive(true);
        position               -= left * (scale / 2);
        position               -= forward * (scale / 2);
        mesh                    = new Mesh();
        _material               = new Material(Shader.Find("Standard"));
        meshFilter              = gameObject.AddComponent <MeshFilter>();
        meshRenderer            = gameObject.AddComponent <MeshRenderer>();
        meshCollider            = gameObject.AddComponent <MeshCollider>();
        meshCollider.sharedMesh = null;
        if (parent != null)
        {
            gameObject.transform.parent = parent.gameObject.transform;
        }
        RenderFace();
    }
Пример #2
0
        public OBJFile(FileStream stream)
        {
            this.vertices      = new List <VertexPosition>();
            this.triangleFaces = new List <TriangleFace>();
            this.quadFaces     = new List <QuadFace>();
            StreamReader reader = new StreamReader(stream);
            string       text   = reader.ReadToEnd();

            text = text.Replace("\r", "");
            text = text.Replace('.', ',');
            string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in lines)
            {
                string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                //if (words[0] == "v")
                //{
                //    float x = float.Parse(words[1]);
                //    float y = float.Parse(words[2]);
                //    float z = float.Parse(words[3]);
                //    VertexPosition coord = new VertexPosition(x, y, z);
                //    this.vertices.Add(coord);
                //}
                switch (words[0])
                {
                case "v":
                    float          x     = float.Parse(words[1]);
                    float          y     = float.Parse(words[2]);
                    float          z     = float.Parse(words[3]);
                    VertexPosition coord = new VertexPosition(x, y, z);
                    this.vertices.Add(coord);
                    break;

                case "f":
                    if (words.Length == 5)
                    {
                        int      a4    = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                        int      b4    = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                        int      c4    = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                        int      d4    = int.Parse(words[4].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                        QuadFace face4 = new QuadFace(a4, b4, c4, d4);
                        this.quadFaces.Add(face4);
                        break;
                    }
                    int          a    = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    int          b    = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    int          c    = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    TriangleFace face = new TriangleFace(a, b, c);
                    this.triangleFaces.Add(face);
                    break;
                }
            }
            this.mesh               = new MeshBase();
            this.mesh.QuadFaces     = this.quadFaces;
            this.mesh.TriangleFaces = this.triangleFaces;
            this.mesh.Vertices      = this.vertices;
            string[] path = stream.Name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            this.mesh.Name = HeadFile.ReplaceExtention(path[path.Length - 1], "");
        }
Пример #3
0
 public OBJFile(FileStream stream)
 {
     this.vertices = new List<VertexPosition>();
     this.triangleFaces = new List<TriangleFace>();
     this.quadFaces = new List<QuadFace>();
     StreamReader reader = new StreamReader(stream);
     string text = reader.ReadToEnd();
     text = text.Replace("\r", "");
     text = text.Replace('.', ',');
     string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string line in lines)
     {
         string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
         //if (words[0] == "v")
         //{
         //    float x = float.Parse(words[1]);
         //    float y = float.Parse(words[2]);
         //    float z = float.Parse(words[3]);
         //    VertexPosition coord = new VertexPosition(x, y, z);
         //    this.vertices.Add(coord);
         //}
         switch (words[0])
         {
             case "v":
                 float x = float.Parse(words[1]);
                 float y = float.Parse(words[2]);
                 float z = float.Parse(words[3]);
                 VertexPosition coord = new VertexPosition(x, y, z);
                 this.vertices.Add(coord);
                 break;
             case "f":
                 if (words.Length == 5)
                 {
                     int a4 = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int b4 = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int c4 = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int d4 = int.Parse(words[4].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     QuadFace face4 = new QuadFace(a4, b4, c4, d4);
                     this.quadFaces.Add(face4);
                     break;
                 }      
                 int a = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 int b = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 int c = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 TriangleFace face = new TriangleFace(a, b, c);
                 this.triangleFaces.Add(face);
                 break;
         }
     }
     this.mesh = new MeshBase();
     this.mesh.QuadFaces = this.quadFaces;
     this.mesh.TriangleFaces = this.triangleFaces;
     this.mesh.Vertices = this.vertices;
     string[] path =  stream.Name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
     this.mesh.Name = HeadFile.ReplaceExtention(path[path.Length - 1],"");
 }
Пример #4
0
    private void AddFace(QuadFaceType type, float size, GameObject player, int startingSubdivisions, float[] subdivisionDistances, QuadTriangleCache cache)
    {
        string faceName = type.ToString();
        var    empty    = new GameObject(faceName);

        empty.transform.parent   = gameObject.transform;
        empty.layer              = gameObject.layer;
        empty.transform.position = transform.position;
        empty.transform.rotation = transform.rotation;

        switch (type)
        {
        case QuadFaceType.YPosTop:
            empty.transform.Rotate(Vector3.left, 90);
            empty.transform.Rotate(Vector3.up, 180);
            break;

        case QuadFaceType.YNegBottom:
            empty.transform.Rotate(Vector3.right, 90);
            empty.transform.Rotate(Vector3.up, 180);
            break;

        case QuadFaceType.XNegLeft:
            empty.transform.Rotate(Vector3.up, 90);
            break;

        case QuadFaceType.XPosRight:
            empty.transform.Rotate(Vector3.down, 90);
            break;

        case QuadFaceType.ZPosFront:
            empty.transform.Rotate(Vector3.up, 180);
            break;
        }
        empty.transform.Translate(Vector3.back * (size / 2));

        QuadFace face = empty.AddComponent <QuadFace>();

        face.Root                     = this;
        face.FaceType                 = type;
        face.Size                     = size;
        face.Player                   = player;
        face.Subdivisions             = startingSubdivisions;
        face.SubdivisionDistances     = subdivisionDistances;
        face.TriangleCache            = cache;
        face.StartingNoiseFrequency   = StartingNoiseFrequency;
        face.StartingNoiseAmplitude   = StartingNoiseAmplitude;
        face.SmoothNegativeElevations = SmoothNegativeElevations;
        face.Active                   = true;
        face.Initialise();

        _faces[(int)type] = face;
    }
 private void GetActiveFaces(QuadFace face, ref List <QuadFace> active)
 {
     if (face.faceTree == null)
     {
         active.Add(face);
     }
     else
     {
         for (int f = 0; f < face.faceTree.Length; f++)
         {
             GetActiveFaces(face.faceTree[f], ref active);
         }
     }
 }
 public QuadFace(QuadFace parent, int resolution, float scale, Vector3 normal, Vector3 left, Vector3 forward)
 {
     Init(parent, resolution, scale, normal, left, forward);
 }