當前位置: 首頁>>代碼示例>>C#>>正文


C# Autodesk.ComputeNormal方法代碼示例

本文整理匯總了C#中Autodesk.ComputeNormal方法的典型用法代碼示例。如果您正苦於以下問題:C# Autodesk.ComputeNormal方法的具體用法?C# Autodesk.ComputeNormal怎麽用?C# Autodesk.ComputeNormal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Autodesk的用法示例。


在下文中一共展示了Autodesk.ComputeNormal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TriangulateFace

        public void TriangulateFace(Autodesk.Revit.DB.Face vFace, Transform instTransform)
        {
            try
            {
                //setup utility class
                LuxExporter.UnitConverter Converter = new UnitConverter();

                //process face
                Mesh vMesh = vFace.Triangulate();

                //check if we have a quad mesh (4 edges to a face)
                if (vMesh.Vertices.Count == 4)
                {
                    //increase face counter
                    iNumberOfFaces++;

                    //found quad
                    Data.NumberOfVerticesinFace = 4;
                    //loop through all vertices and add
                    foreach (XYZ ii in vMesh.Vertices)
                    {
                        XYZ point = ii;
                        XYZ transformedPoint;

                        //transform geometry (only required in nested families / or elements like baluster
                        if (instTransform == null)
                        {
                            transformedPoint = point;
                        }
                        else
                        {
                            transformedPoint = instTransform.OfPoint(point);
                        }

                        //get the normal
                        XYZ NormalAtPoint;

                        IntersectionResult IntResult= vFace.Project(ii);

                        if (IntResult != null)
                        {
                            UV UVatPoint = IntResult.UVPoint;
                            NormalAtPoint = new XYZ(vFace.ComputeNormal(UVatPoint).X, vFace.ComputeNormal(UVatPoint).Y, vFace.ComputeNormal(UVatPoint).Z);
                        }
                        else
                        {
                            //this needs fixing!!!
                            NormalAtPoint = new XYZ(0, 0, 0);
                        }

                        //convert to meter
                        transformedPoint = Converter.ConvertPointCoordToMeter(transformedPoint);
                        //NormalAtPoint = Converter.ConvertPointCoordToMeter(NormalAtPoint);

                        //add to ply class
                        Data.AddVertice(transformedPoint,NormalAtPoint);

                    }

                }
                else
                {
                    // set pointer
                    Data.NumberOfVerticesinFace = 3;

                    //export all triangles in face
                    for (int i = 0; i < vMesh.NumTriangles; i++)
                    {
                        //increase face counter
                        iNumberOfFaces++;

                        MeshTriangle objTriangular = vMesh.get_Triangle(i);

                        for (int iPointsCounter = 0; iPointsCounter < 3; iPointsCounter++)
                        {
                            XYZ point = objTriangular.get_Vertex(iPointsCounter);
                            XYZ transformedPoint;
                            //transform geometry (only required in nested families / or elements like baluster
                            if (instTransform == null)
                            {
                                transformedPoint = point;
                            }
                            else
                            {
                                transformedPoint = instTransform.OfPoint(point);
                            }

                            XYZ NormalAtPoint;

                            //get the normal
                            IntersectionResult IntResult = vFace.Project(point);
                            if (IntResult!=null)
                            {
                                UV UVatPoint = IntResult.UVPoint;
                                NormalAtPoint = new XYZ(vFace.ComputeNormal(UVatPoint).X,vFace.ComputeNormal(UVatPoint).Y,vFace.ComputeNormal(UVatPoint).Z);
                            }
                            else
                            {
                                //this needs fixing
                                NormalAtPoint = new XYZ(0, 0, 0);
//.........這裏部分代碼省略.........
開發者ID:jchristel,項目名稱:LuxExporter,代碼行數:101,代碼來源:PLY_By_Material.cs

示例2: ExtractSurface

        public static Surface ExtractSurface(Autodesk.Revit.DB.RevolvedFace face, IEnumerable<PolyCurve> edgeLoops)
        {
            var crv = face.Curve.ToProtoType(false);

            var axis = face.Axis.ToVector(false);
            var o = face.Origin.ToVector(false);
            var x = face.get_Radius(0).ToVector(false);
            var y = face.get_Radius(1).ToVector(false);

            // Note: The profile curve is represented in the coordinate system of the revolve
            //       so we need to transform it into the global coordinate system
            var revolveCs = CoordinateSystem.Identity();
            var globalCs = CoordinateSystem.ByOriginVectors(o.AsPoint(), x, y);

            var crvTrf = (Autodesk.DesignScript.Geometry.Curve)crv.Transform(revolveCs, globalCs);

            var srf =
                Surface.ByRevolve(crvTrf, o.AsPoint(), axis.Normalized(), 0, 360)
                    .FlipNormalDirection();

            var ptOnSrf = srf.PointAtParameter(0.5, 0.5);
            var projRes = face.Project(ptOnSrf.ToXyz());

            if (projRes == null) return srf;

            var uvOnFace = projRes.UVPoint;

            var normOnFace = face.ComputeNormal(uvOnFace).ToVector();
            var normOnSrf = srf.NormalAtParameter(0.5, 0.5);

            // if the normal is reversed, reverse the surface
            if (normOnFace.Dot(normOnSrf) < 0) return srf.FlipNormalDirection();

            return srf;

        }
開發者ID:RobertiF,項目名稱:Dynamo,代碼行數:36,代碼來源:SurfaceExtractor.cs


注:本文中的Autodesk.ComputeNormal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。