Esempio n. 1
0
 internal ObjObjectUnsafe(ref ObjObjectCore core)
 {
     _core = core;
     core  = default;
 }
Esempio n. 2
0
        private static bool TryParseFLine(ReadOnlySpan <byte> str, ref ObjObjectCore core)
        {
            // <pos_i>/<uv_i>/<normal_i> <pos_i>/<uv_i>/<normal_i> <pos_i>/<uv_i>/<normal_i> ...

            FaceData v0;
            FaceData v1;
            FaceData v2;

            var splits = str.Split((byte)' ', StringSplitOptions.RemoveEmptyEntries);

            using (var e = splits.GetEnumerator()) {
                int pos;
                int?uv;
                int?normal;

                if (e.MoveNext() == false)
                {
                    return(false);
                }
                if (TryParseFace(e.Current, out pos, out uv, out normal) == false)
                {
                    return(false);
                }
                v0 = new(pos, uv, normal);

                if (e.MoveNext() == false)
                {
                    return(false);
                }
                if (TryParseFace(e.Current, out pos, out uv, out normal) == false)
                {
                    return(false);
                }
                v1 = new(pos, uv, normal);

                if (e.MoveNext() == false)
                {
                    return(false);
                }
                if (TryParseFace(e.Current, out pos, out uv, out normal) == false)
                {
                    return(false);
                }
                v2 = new(pos, uv, normal);

                if (TryAdd(ref core, v0, v1, v2) == false)
                {
                    return(false);
                }
                while (e.MoveNext())
                {
                    v1 = v2;
                    if (TryParseFace(e.Current, out pos, out uv, out normal) == false)
                    {
                        return(false);
                    }
                    v2 = new(pos, uv, normal);
                    if (TryAdd(ref core, v0, v1, v2) == false)
                    {
                        return(false);
                    }
                }
            }
            return(true);
Esempio n. 3
0
 static bool TryAdd(ref ObjObjectCore core, in FaceData v0, in FaceData v1, in FaceData v2)
Esempio n. 4
0
        private static bool TryParsePrivate(ReadOnlySpan <byte> text, out ObjObjectCore obj)
        {
            ObjObjectCore core = default;

            try {
                core = new ObjObjectCore();
                var lines = text.Lines();
                foreach (Utf8Reader lineReader in lines)
                {
                    if (lineReader.MoveIfMatch((byte)'#'))
                    {
                        continue;
                    }
                    else if (lineReader.MoveIfMatch((byte)'v', (byte)' '))
                    {
                        if (TryParseVector3(lineReader.Current, out var pos) == false)
                        {
                            goto FAILURE;
                        }
                        core.Positions.Add(pos);
                    }
                    else if (lineReader.MoveIfMatch((byte)'v', (byte)'t', (byte)' '))
                    {
                        if (TryParseVector2(lineReader.Current, out var uv) == false)
                        {
                            goto FAILURE;
                        }
                        core.UVs.Add(uv);
                    }
                    else if (lineReader.MoveIfMatch((byte)'v', (byte)'n', (byte)' '))
                    {
                        if (TryParseVector3(lineReader.Current, out var normal) == false)
                        {
                            goto FAILURE;
                        }
                        core.Normals.Add(normal);
                    }
                    else if (lineReader.MoveIfMatch((byte)'f', (byte)' '))
                    {
                        if (TryParseFLine(lineReader.Current, ref core) == false)
                        {
                            goto FAILURE;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                obj = core;
                return(true);

FAILURE:
                obj = default;
                return(false);
            }
            catch {
                core.Dispose();
                obj = default;
                return(false);
            }
        }