예제 #1
0
        public AdnMeshData(
            VertexLookupInt vertices,
            List <int> vertexIndices,
            NormalLookupXyz normals,
            List <int> normalIndices,
            PointInt center,
            Color color,
            double transparency,
            string id)
        {
            int n = vertexIndices.Count;

            Debug.Assert(0 == (n % 3),
                         "expected triples of 3D point vertex indices");

            Debug.Assert(normalIndices.Count == n,
                         "expected a normal for each vertex");

            FacetCount = n / 3;

            n            = vertices.Count;
            VertexCount  = n;
            VertexCoords = new int[n * 3];
            int i = 0;

            foreach (PointInt p in vertices.Keys)
            {
                VertexCoords[i++] = p.X;
                VertexCoords[i++] = p.Y;
                VertexCoords[i++] = p.Z;
            }
            VertexIndices = vertexIndices.ToArray();

            n       = normals.Count;
            Normals = new double[n * 3];
            i       = 0;
            foreach (XYZ v in normals.Keys)
            {
                Normals[i++] = v.X;
                Normals[i++] = v.Y;
                Normals[i++] = v.Z;
            }
            NormalIndices = normalIndices.ToArray();

            Center      = new int[3];
            i           = 0;
            Center[i++] = center.X;
            Center[i++] = center.Y;
            Center[i]   = center.Z;

            byte alpha = (byte)(
                (100 - transparency) * 2.55555555);

            Color = ConvertClr(
                color.Red, color.Green, color.Blue, alpha);

            Id = id;
        }
예제 #2
0
        /// <summary>
        /// Store a triangle, adding new vertices for it
        /// to our vertex lookup dictionary if needed and
        /// accumulating its volume and centroid contribution.
        /// </summary>
        void StoreTriangle(
            IList <XYZ> vertices,
            PolymeshFacet triangle,
            XYZ normal)
        {
            // Retrieve the three triangle vertices

            Transform currentTransform = CurrentTransform;

            XYZ[] p = new XYZ[] {
                currentTransform.OfPoint(vertices[triangle.V1]),
                currentTransform.OfPoint(vertices[triangle.V2]),
                currentTransform.OfPoint(vertices[triangle.V3])
            };

            // Ensure the three are ordered counter-clockwise

            //XYZ v = p[1] - p[0];
            //XYZ w = p[2] - p[0];

            //Debug.Assert( Util.IsRightHanded( v, w, normal ),
            //  "expected counter-clockwise vertex order" );

            // Centroid and volume calculation

            _centroid_volume.AddTriangle(p);

            // Store vertex, facet and normals

            for (int i = 0; i < 3; ++i)
            {
                PointInt q = new PointInt(p[i]);

                _triangles.Add(_vertices.AddVertex(q));

                _normalIndices.Add(_normals.AddNormal(
                                       currentTransform.OfVector(normal)));
            }
        }