예제 #1
0
        private static void ValidateData(File_Data file)
        {
            var padding = Enumerable.Repeat((byte)0xFF, 100).ToArray();
            var buffer  = file.ZibFile != null?file.ZibFile.LoadBuffer() : file.File.LoadBuffer();

            var paddedBuffer = new byte[buffer.Length + padding.Length];

            Buffer.BlockCopy(padding, 0, paddedBuffer, 0, padding.Length);
            Buffer.BlockCopy(buffer, 0, paddedBuffer, padding.Length, buffer.Length);

            using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                    bw.Write(padding);

                    file.Save(bw);
                    var buffer2 = ms.ToArray();
                    if (file.FileType == File_Types.Dfymoo)
                    {
                        Debug.Assert(Encoding.ASCII.GetString(paddedBuffer).TrimEnd('\r', '\n') ==
                                     Encoding.ASCII.GetString(buffer2).TrimEnd('\r', '\n'));
                    }
                    else
                    {
                        for (var i = 0; i < paddedBuffer.Length; i++)
                        {
                            Debug.Assert(paddedBuffer[i] == buffer2[i]);
                        }
                        Debug.Assert(paddedBuffer.SequenceEqual(buffer2));
                    }
                }
        }
예제 #2
0
    //Construct 3D object to be able to render it in Unity
    private GameObject create3DObject(File_Data fileData)
    {
        GameObject face3D = new GameObject("face3D");

        face3D.AddComponent <MeshRenderer>();
        face3D.AddComponent <MeshFilter>();
        face3D.GetComponent <MeshRenderer>().materials = new List <Material>()
        {
            Resources.Load("Materials/Default_Material", typeof(Material)) as Material
        }.ToArray();
        face3D.GetComponent <MeshFilter>().mesh           = new Mesh();
        face3D.GetComponent <MeshFilter>().mesh.vertices  = fileData.Points.ToArray();
        face3D.GetComponent <MeshFilter>().mesh.uv        = fileData.Texture_Points.ToArray();
        face3D.GetComponent <MeshFilter>().mesh.triangles = fileData.Points_Index.ToArray();
        float max   = fileData.Points.Select(S => S.z).Max();
        float min   = fileData.Points.Select(S => S.z).Min();
        float depth = Math.Abs(max - min) * 1f;

        Color[] colors = new Color[fileData.Points.ToArray().Length];

        for (int i = 0; i < fileData.Points.ToArray().Length; i++)
        {
            colors[i] = Color.Lerp(Color.black, Color.white, Math.Abs((fileData.Points[i].z - min) / depth));
        }

        // assign the array of colors to the Mesh.
        face3D.GetComponent <MeshFilter>().mesh.colors = colors;

        face3D.GetComponent <MeshFilter>().mesh.RecalculateNormals();

        return(face3D);
    }
예제 #3
0
    // Start is called before the first frame update
    void Start()
    {
        //Open .wrl File
        string path = EditorUtility.OpenFilePanel("Select .wrl File", "", "wrl");

        if (path.Length != 0)
        {
            //Read File
            var dataLines = System.IO.File.ReadAllLines(path);

            //Parse and split file data (keep each line as string)
            var fileDataLines = splitData(dataLines);

            //Parse and Convert Data
            File_Data fileData = new File_Data();
            fileData.Points               = getParsedDataToVector3(fileDataLines.Points);
            fileData.Points_Index         = getParsedDataToListInt(fileDataLines.Points_Index);
            fileData.Texture_Points       = getParsedDataToVector2(fileDataLines.Texture_Points);
            fileData.Texture_Points_Index = getParsedDataToListInt(fileDataLines.Texture_Points_Index);

            //Construct 3D Face Object
            var constructed3DFace = create3DObject(fileData);

            //Add 3D object to the Unity Scene
            constructed3DFace.transform.SetParent(this.transform);

            //Take Screenshot of the Scene
            ScreenCapture.CaptureScreenshot(path.Replace(".wrl", ".png"), 10);
        }
    }
예제 #4
0
파일: JSONIO.cs 프로젝트: nyanzebra/JSON
            public void read(string file_name)
            {
                StreamReader stream_reader = new StreamReader(file_name);

                while (!stream_reader.EndOfStream)
                {
                    string line = stream_reader.ReadLine();
                    if (line.IndexOf(Input.HASH) == Input.NOT_FOUND)
                    {
                        if (!line.Equals(""))
                        {
                            File_Data.Add(line.Trim(Input.TAB, Input.NEW_LINE, Input.CARRIAGE_RETURN));
                        }
                    }
                }
                try {
                    stream_reader.Dispose();
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }