Exemplo n.º 1
0
        public MeshBinder(Autodesk.Dynamo.MeshToolkit.Mesh mesh, Color color)
        {
            dynamoMesh        = false;
            StartingPositions = mesh.Vertices().ToTriples().ToArray();
            Color             = color;

            faceIndices = mesh.VertexIndicesByTri();
            int faceCount = faceIndices.Count / 3;

            faces = new IndexGroup[faceCount];

            for (int i = 0; i < faceCount; i++)
            {
                faces[i] = IndexGroup.ByIndices(
                    (uint)faceIndices[i * 3],
                    (uint)faceIndices[i * 3 + 1],
                    (uint)faceIndices[i * 3 + 2]);
            }

            meshIndices = new IntCollection();

            foreach (IndexGroup face in faces)
            {
                meshIndices.Add((int)face.A);
                meshIndices.Add((int)face.B);
                meshIndices.Add((int)face.C);
            }
        }
Exemplo n.º 2
0
        public TexturedMeshBinder(Autodesk.Dynamo.MeshToolkit.Mesh mesh, Color color, string textureFileName, Vector2Collection textureCoordinates)
        {
            StartingPositions = mesh.Vertices().ToTriples().ToArray();
            Color             = color;

            try { diffuseMap = new BitmapImage(new Uri(textureFileName)); }
            catch (FileNotFoundException) { throw new Exception("Could not locate the texture file"); }

            this.textureCoordinates = textureCoordinates;

            faceIndices = mesh.VertexIndicesByTri();
            int faceCount = faceIndices.Count / 3;

            faces = new IndexGroup[faceCount];

            for (int i = 0; i < faceCount; i++)
            {
                faces[i] = IndexGroup.ByIndices(
                    (uint)faceIndices[i * 3],
                    (uint)faceIndices[i * 3 + 1],
                    (uint)faceIndices[i * 3 + 2]);
            }

            meshFaceIndices = new IntCollection();

            foreach (IndexGroup face in faces)
            {
                meshFaceIndices.Add((int)face.A);
                meshFaceIndices.Add((int)face.B);
                meshFaceIndices.Add((int)face.C);
            }
        }
Exemplo n.º 3
0
 internal SphereTree(MeshToolkit mesh)
 {
     this._mesh            = mesh;
     this.vertices         = _mesh.Vertices();
     this.vertexIndexByTri = List.Chop <int>(_mesh.VertexIndicesByTri(), 3);
     CreateSphereNodes();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Returns the BoundingBox of a MeshToolkit Mesh
 /// </summary>
 /// <param name="mesh">MeshToolkit Mesh</param>
 /// <returns name="BoundingBox">Mesh's BoundingBox</returns>
 public static DS.BoundingBox BoundingBox(MT.Mesh mesh)
 {
     IEnumerable<double> x = mesh.Vertices().Select(pt => pt.X);
     IEnumerable<double> y = mesh.Vertices().Select(pt => pt.Y);
     IEnumerable<double> z = mesh.Vertices().Select(pt => pt.Z);
     return DS.BoundingBox.ByCorners(
         DS.Point.ByCoordinates(x.Min(), y.Min(), z.Min()),
         DS.Point.ByCoordinates(x.Max(), y.Max(), z.Max())
     );
 }
Exemplo n.º 5
0
        public static IList <SphereNode> SphereNodesByMesh(MeshToolkit mesh)
        {
            List <Point>      vertices     = mesh.Vertices();
            List <int>        vertexIndex  = mesh.VertexIndicesByTri();
            var               setOfIndexes = Core.List.Chop <int>(vertexIndex, 3);
            List <SphereNode> sphereNodes  = new List <SphereNode>();

            foreach (var ind in setOfIndexes)
            {
                sphereNodes.Add(SphereNode.ByThreePoints(vertices[ind[0]], vertices[ind[1]], vertices[ind[2]]));
            }

            return(sphereNodes);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a Dynamo Mesh by converting a MeshToolkit Mesh
        /// </summary>
        /// <param name="meshToolkit">MeshToolkit Mesh</param>
        /// <returns name = "mesh">Dynamo Mesh</returns>
        public static DS.Mesh ByMeshToolkit(MT.Mesh meshToolkit)
        {
            List <DS.Point> vertices     = meshToolkit.Vertices();
            List <int>      vertexIndex  = meshToolkit.VertexIndicesByTri();
            var             setOfIndexes = vertexIndex
                                           .Select((x, i) => new { Index = i, Value = x })
                                           .GroupBy(x => x.Index / 3)
                                           .Select(x => x.Select(v => v.Value).ToList())
                                           .ToList();
            List <DS.IndexGroup> indexGroups = new List <DS.IndexGroup>();

            foreach (var ind in setOfIndexes)
            {
                indexGroups.Add(DS.IndexGroup.ByIndices((uint)ind[0], (uint)ind[1], (uint)ind[2]));
            }

            return(DS.Mesh.ByPointsFaceIndices(vertices, indexGroups));
        }
Exemplo n.º 7
0
 public MeshBinder(Autodesk.Dynamo.MeshToolkit.Mesh mesh)
     : this(mesh, DynaShapeDisplay.DefaultMeshFaceColor)
 {
 }
Exemplo n.º 8
0
 public TexturedMeshBinder(Autodesk.Dynamo.MeshToolkit.Mesh mesh, string textureFileName, Vector2Collection textureCoordinates)
     : this(mesh, DynaShapeDisplay.DefaultMeshFaceColor, textureFileName, textureCoordinates)
 {
 }
Exemplo n.º 9
0
 public static SphereTree ByMesh(MeshToolkit meshToolkit)
 {
     return(new SphereTree(meshToolkit));
 }
Exemplo n.º 10
0
        public static Dictionary <string, object> ByToolkitMeshAndColor(mt.Mesh mesh, Color[] color)
        {
            var m = new SpectaclesMesh(mesh);

            var g = new SpectaclesGeometry
            {
                uuid = Guid.NewGuid().ToString(),
                type = "Geometry"
            };

            var data = new SpectaclesGeometryData
            {
                vertices      = new List <double>(),
                faces         = new List <int>(),
                normals       = new List <double>(),
                uvs           = new List <double>(),
                scale         = 1,
                visible       = true,
                castShadow    = true,
                receiveShadow = false,
                doubleSided   = true
            };

            //populate data object properties


            //populate vertices
            foreach (var v in mesh.Vertices())
            {
                data.vertices.Add(Math.Round(v.X * -1.0, 5));
                data.vertices.Add(Math.Round(v.Z, 5));
                data.vertices.Add(Math.Round(v.Y, 5));
            }

            //populate faces
            for (var i = 0; i < mesh.VertexIndicesByTri().Count; i += 3)
            {
                data.faces.Add(0);

                data.faces.Add(mesh.VertexIndicesByTri()[i]);
                data.faces.Add(mesh.VertexIndicesByTri()[i + 1]);
                data.faces.Add(mesh.VertexIndicesByTri()[i + 2]);
            }

            //this will display the mesh
            //var displayMesh = mt.Display.MeshDisplay.ByMeshColor(mesh, color);


            //TO DO:
            //populate vertex colors

            var alpha = color[0].Alpha;
            var red   = color[0].Red.ToString("X2");
            var green = color[0].Green.ToString("X2");
            var blue  = color[0].Blue.ToString("X2");

            var mat = new SpectaclesMaterial
            {
                uuid        = Guid.NewGuid().ToString(),
                type        = "MeshBasicMaterial",
                color       = $"0x{red}{green}{blue}",
                side        = 2,
                opacity     = 1.0,
                transparent = true
            };

            //TO DO: user data
            //populate userData objects

            g.data = data;

            return(new Dictionary <string, object>
            {
                { "SpectaclesGeometry", g },
                { "SpectaclesMaterial", mat },
                { "originalMesh", m }
            });
        }
Exemplo n.º 11
0
 private SpectaclesMesh(mt.Mesh mesh)
 {
     _mesh = mesh;
 }