Exemple #1
0
        // append "disc" verts/tris between vEnd1 and vEnd2
        protected void append_2d_disc_segment(int iCenter, int iEnd1, int iEnd2, int nSteps, bool bCycle, ref int vtx_counter, ref int tri_counter, int groupid = -1, double force_r = 0)
        {
            Vector3D c  = vertices[iCenter];
            Vector3D e0 = vertices[iEnd1];
            Vector3D e1 = vertices[iEnd2];
            Vector3D v0 = (e0 - c);
            double   r0 = v0.Normalize();

            if (force_r > 0)
            {
                r0 = force_r;
            }
            double   tStart = Math.Atan2(v0.z, v0.x);
            Vector3D v1     = (e1 - c);
            double   r1     = v1.Normalize();

            if (force_r > 0)
            {
                r1 = force_r;
            }
            double tEnd = Math.Atan2(v1.z, v1.x);

            // fix angles to handle sign. **THIS ONLY WORKS IF WE ARE GOING CCW!!**
            if (tStart < 0)
            {
                tStart += math.MathUtil.TwoPI;
            }
            if (tEnd < 0)
            {
                tEnd += math.MathUtil.TwoPI;
            }
            if (tEnd < tStart)
            {
                tEnd += math.MathUtil.TwoPI;
            }

            int iPrev = iEnd1;

            for (int i = 0; i < nSteps; ++i)
            {
                double   t     = (double)(i + 1) / (double)(nSteps + 1);
                double   angle = (1 - t) * tStart + (t) * tEnd;
                Vector3D pos   = c + new Vector3D(r0 * Math.Cos(angle), 0, r1 * Math.Sin(angle));
                vertices.Set(vtx_counter, pos.x, pos.y, pos.z);
                if (groupid >= 0)
                {
                    groups[tri_counter] = groupid;
                }
                triangles.Set(tri_counter++, iCenter, iPrev, vtx_counter, bCycle);
                iPrev = vtx_counter++;
            }
            if (groupid >= 0)
            {
                groups[tri_counter] = groupid;
            }
            triangles.Set(tri_counter++, iCenter, iPrev, iEnd2, bCycle);
        }
Exemple #2
0
        VectorArray3d restore_list3d(String valueString)
        {
            string[]      values = valueString.Split(' ');
            int           N      = values.Length / 3;
            VectorArray3d v      = new VectorArray3d(N);

            for (int i = 0; i < N; ++i)
            {
                double x = 0, y = 0, z = 0;
                double.TryParse(values[3 * i], out x);
                double.TryParse(values[3 * i + 1], out y);
                double.TryParse(values[3 * i + 2], out z);
                v.Set(i, x, y, z);
            }
            return(v);
        }
Exemple #3
0
        VectorArray3d restore_list3d_binary(String valueString)
        {
            char[]        str    = valueString.ToCharArray();
            byte[]        buffer = Convert.FromBase64CharArray(str, 0, str.Length);
            int           sz     = sizeof(double);
            int           Nvals  = buffer.Length / sz;
            int           Nvecs  = Nvals / 3;
            VectorArray3d v      = new VectorArray3d(Nvecs);

            for (int i = 0; i < Nvecs; i++)
            {
                double x = BitConverter.ToDouble(buffer, (3 * i) * sz);
                double y = BitConverter.ToDouble(buffer, (3 * i + 1) * sz);
                double z = BitConverter.ToDouble(buffer, (3 * i + 2) * sz);
                v.Set(i, x, y, z);
            }
            return(v);
        }
Exemple #4
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);
        }