Пример #1
0
        VectorArray3f restore_list3f(String valueString)
        {
            string[]      values = valueString.Split(' ');
            int           N      = values.Length / 3;
            VectorArray3f v      = new VectorArray3f(N);

            for (int i = 0; i < N; ++i)
            {
                float x = 0, y = 0, z = 0;
                float.TryParse(values[3 * i], out x);
                float.TryParse(values[3 * i + 1], out y);
                float.TryParse(values[3 * i + 2], out z);
                v.Set(i, x, y, z);
            }
            return(v);
        }
Пример #2
0
        VectorArray3f restore_list3f_binary(String valueString)
        {
            char[]        str    = valueString.ToCharArray();
            byte[]        buffer = Convert.FromBase64CharArray(str, 0, str.Length);
            int           sz     = sizeof(float);
            int           Nvals  = buffer.Length / sz;
            int           Nvecs  = Nvals / 3;
            VectorArray3f v      = new VectorArray3f(Nvecs);

            for (int i = 0; i < Nvecs; i++)
            {
                float x = BitConverter.ToSingle(buffer, (3 * i) * sz);
                float y = BitConverter.ToSingle(buffer, (3 * i + 1) * sz);
                float z = BitConverter.ToSingle(buffer, (3 * i + 2) * sz);
                v.Set(i, x, y, z);
            }
            return(v);
        }
Пример #3
0
        public virtual SimpleMesh RestoreSimpleMesh(TypedAttribSet attributes, bool bSwapRightLeft)
        {
            bool           bBinary  = true;
            TypedAttribSet meshAttr = find_struct(attributes, IOStrings.BinaryMeshStruct);

            if (meshAttr == null)
            {
                meshAttr = find_struct(attributes, IOStrings.AsciiMeshStruct);
                bBinary  = false;
            }
            if (meshAttr == null)
            {
                throw new Exception("SOFactory.RestoreSimpleMesh: Mesh ascii/binary struct not found!");
            }


            VectorArray3d v = null;
            VectorArray3i t = null;
            VectorArray3f n = null, c = null;
            VectorArray2f uv = null;

            if (bBinary)
            {
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshVertices3Binary))
                {
                    v = meshAttr[IOStrings.AMeshVertices3Binary] as VectorArray3d;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTrianglesBinary))
                {
                    t = meshAttr[IOStrings.AMeshTrianglesBinary] as VectorArray3i;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshNormals3Binary))
                {
                    n = meshAttr[IOStrings.AMeshNormals3Binary] as VectorArray3f;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshColors3Binary))
                {
                    c = meshAttr[IOStrings.AMeshColors3Binary] as VectorArray3f;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshUVs2Binary))
                {
                    uv = meshAttr[IOStrings.AMeshUVs2Binary] as VectorArray2f;
                }
            }
            else
            {
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshVertices3))
                {
                    v = meshAttr[IOStrings.AMeshVertices3] as VectorArray3d;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTriangles))
                {
                    t = meshAttr[IOStrings.AMeshTriangles] as VectorArray3i;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshNormals3))
                {
                    n = meshAttr[IOStrings.AMeshNormals3] as VectorArray3f;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshColors3))
                {
                    c = meshAttr[IOStrings.AMeshColors3] as VectorArray3f;
                }
                if (check_key_or_debug_print(meshAttr, IOStrings.AMeshUVs2))
                {
                    uv = meshAttr[IOStrings.AMeshUVs2] as VectorArray2f;
                }
            }

            if (v == null || t == null)
            {
                return(null);
            }

            if (bSwapRightLeft)
            {
                int N = v.Count;
                for (int i = 0; i < N; ++i)
                {
                    Vector3d vv = v[i];
                    v.Set(i, -vv.x, vv.y, -vv.z);
                }
                if (n != null && n.Count == N)
                {
                    for (int i = 0; i < N; ++i)
                    {
                        Vector3f nn = n[i];
                        n.Set(i, -nn.x, nn.y, -nn.z);
                    }
                }
            }

            SimpleMesh m = new SimpleMesh();

            m.Initialize(v, t, n, c, uv);
            return(m);
        }