// calculate normal on vertices and deal with boarder condition.
        private void calculateVertexNormals()
        {
            vertexNormals = iSpringMesh.ComputeVertexNormals();

            foreach (Edge edge in iSpringMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    continue;
                }
                // Gene Added
                if (iSpringMesh.Vertices[edge.FirstVertexIndex].Position.Z > 0.65 &&
                    iSpringMesh.Vertices[edge.SecondVertexIndex].Position.Z > 0.65)
                {
                    continue;
                }

                Vector3d vertexNormal = vertexNormals[edge.FirstVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.FirstVertexIndex] = vertexNormal;

                vertexNormal   = vertexNormals[edge.SecondVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.SecondVertexIndex] = vertexNormal;
            }
            // here is to get all vertex normal and utilize them
        }
Example #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.GetData <SpringMesh>("Spring Mesh", ref iSpringMesh);
            DA.GetData <double>("Min. Thickness", ref iMinThickness);
            DA.GetData <double>("Max. Thickness", ref iMaxThickness);
            DA.GetData <double>("Tangent Scale", ref iTangentScale);
            DA.GetData <bool>("Allow PolySrf", ref iPolySrf);


            // =========================================================================================================

            List <Vector3d> vertexNormals = iSpringMesh.ComputeVertexNormals();

            foreach (Edge edge in iSpringMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    continue;
                }

                // Gene Added
                if (iSpringMesh.Vertices[edge.FirstVertexIndex].Position.Z > 0.65 &&
                    iSpringMesh.Vertices[edge.SecondVertexIndex].Position.Z > 0.65)
                {
                    continue;
                }

                Vector3d vertexNormal = vertexNormals[edge.FirstVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.FirstVertexIndex] = vertexNormal;

                vertexNormal   = vertexNormals[edge.SecondVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.SecondVertexIndex] = vertexNormal;
            }


            // =========================================================================================================


            bottomCps = new List <Point3d>();
            topCps    = new List <Point3d>();


            for (int i = 0; i < iSpringMesh.Vertices.Count; i++)
            {
                Point3d vertexPosition = iSpringMesh.Vertices[i].Position;
                double  k         = vertexPosition.Z * 0.125;
                double  thickness = k * iMinThickness + (0.5 - k) * iMaxThickness;

                bottomCps.Add(vertexPosition - thickness * vertexNormals[i]);
                topCps.Add(vertexPosition + thickness * vertexNormals[i]);
            }


            // =========================================================================================================


            foreach (Triangle triangle in iSpringMesh.Triangles)
            {
                createStripe(triangle.FirstVertexIndex, triangle.SecondVertexIndex, triangle.ThirdVertexIndex);
                createStripe(triangle.SecondVertexIndex, triangle.ThirdVertexIndex, triangle.FirstVertexIndex);
                createStripe(triangle.ThirdVertexIndex, triangle.FirstVertexIndex, triangle.SecondVertexIndex);
            }


            DA.SetDataList(1, oDebugBreps1);
            DA.SetDataList(2, oDebugBreps2);
            //DA.SetDataList(2, oDebugCurves1);
            //DA.SetDataList(3, oDebugPoints1);
        }
Example #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (!menuItemValue_Standard && !menuItemValue_StructuralAnalysis && !menuItemValue_ExtendedSurfaces)
            {
                return;
            }

            oStripes = new List <Brep>();
            oStructuralInteriorStripes = new List <Brep>();
            oStructuralExteriorStripes = new List <Brep>();

            DA.GetData <SpringMesh>("Spring Mesh", ref iSpringMesh);
            DA.GetData <double>("Min. Thickness", ref iMinThickness);
            DA.GetData <double>("Max. Thickness", ref iMaxThickness);
            DA.GetData <double>("Tangent Scale", ref iTangentScale);


            // =========================================================================================================

            List <Vector3d> vertexNormals = iSpringMesh.ComputeVertexNormals();

            foreach (Edge edge in iSpringMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    continue;
                }

                Vector3d vertexNormal = vertexNormals[edge.FirstVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.FirstVertexIndex] = vertexNormal;

                vertexNormal   = vertexNormals[edge.SecondVertexIndex];
                vertexNormal.Z = 0.0;
                vertexNormal.Unitize();
                vertexNormals[edge.SecondVertexIndex] = vertexNormal;
            }


            // =========================================================================================================


            bottomCps = new List <Point3d>();
            topCps    = new List <Point3d>();


            for (int i = 0; i < iSpringMesh.Vertices.Count; i++)
            {
                Point3d vertexPosition = iSpringMesh.Vertices[i].Position;
                double  k         = vertexPosition.Z * 0.125;
                double  thickness = k * iMinThickness + (0.5 - k) * iMaxThickness;

                bottomCps.Add(vertexPosition - thickness * vertexNormals[i]);
                topCps.Add(vertexPosition + thickness * vertexNormals[i]);
            }


            // =========================================================================================================


            foreach (Triangle triangle in iSpringMesh.Triangles)
            {
                createStripe(triangle.FirstVertexIndex, triangle.SecondVertexIndex, triangle.ThirdVertexIndex);
                createStripe(triangle.SecondVertexIndex, triangle.ThirdVertexIndex, triangle.FirstVertexIndex);
                createStripe(triangle.ThirdVertexIndex, triangle.FirstVertexIndex, triangle.SecondVertexIndex);
                if (menuItemValue_StructuralAnalysis)
                {
                    createSharedTriangles(triangle.FirstVertexIndex, triangle.SecondVertexIndex, triangle.ThirdVertexIndex);
                }
            }


            // =========================================================================================================


            oInfo += "Triloop Segments: " + iSpringMesh.Triangles.Count;
            oInfo += "\nWood Stripes: " + iSpringMesh.Triangles.Count * 3;


            double totalArea = 0.0;

            if (menuItemValue_Standard)
            {
                foreach (Brep brep in oStripes)
                {
                    totalArea += brep.GetArea();
                }
            }
            else if (menuItemValue_StructuralAnalysis)
            {
                foreach (Brep brep in oStructuralInteriorStripes)
                {
                    totalArea += brep.GetArea();
                }
                foreach (Brep brep in oStructuralInteriorStripes)
                {
                    totalArea += brep.GetArea();
                }
            }
            oInfo += "\nTotal (Wood) Area: " + totalArea.ToString();


            // =========================================================================================================


            DA.SetData(0, oInfo);
            DA.SetDataList(1, oDebugCurves1);
            DA.SetDataList(2, oDebugCurves2);
            DA.SetDataList(6, oStripes);
            DA.SetDataList(7, oStructuralInteriorStripes);
            DA.SetDataList(8, oStructuralExteriorStripes);
        }