コード例 #1
0
        private void CreateBSplineSurface()
        {
            var viewModel = BezierSurfaceCreationViewModel.ShowDialog();

            if (viewModel == null)
            {
                return;
            }

            BSplineSurfaceWorldObject surface;

            if (viewModel.CylindricalFold)
            {
                surface = BSplineSurfaceWorldObject.CreateCylindrical(viewModel.SegmentsX, viewModel.SegmentsY,
                                                                      viewModel.Radius, viewModel.Height);
            }
            else
            {
                surface = BSplineSurfaceWorldObject.CreateFlatGrid(viewModel.SegmentsX, viewModel.SegmentsY, viewModel.PlaneWidth, viewModel.PlaneHeight);
            }

            surface.Name = "BSpline surface";

            _scene.SmartEditTarget?.RegisterNewObject(surface);
            _scene.AttachObject(surface);
        }
コード例 #2
0
        private WorldObject MakeImportableObject(
            string objectTypeName,
            string objectName)
        {
            objectTypeName = objectTypeName.Trim();
            objectName     = objectName.Trim();

            if (objectTypeName == "BEZIERCURVE")
            {
                var beziercurve = new BezierC0WorldObject
                {
                    Name  = objectName,
                    Shape = new BezierCurveC0()
                };

                var refPointsCount = ReadInt();
                for (var i = 0; i < refPointsCount; ++i)
                {
                    beziercurve.AttachObject(GetMarkerPoint(ReadInt()));
                }

                return(beziercurve);
            }

            if (objectTypeName == "BSPLINECURVE")
            {
                var bsplinecurve = new BezierC2WorldObject
                {
                    Name  = objectName,
                    Shape = new BezierCurveC2()
                };

                var refPointsCount = ReadInt();
                for (var i = 0; i < refPointsCount; ++i)
                {
                    bsplinecurve.AttachObject(GetMarkerPoint(ReadInt()));
                }

                return(bsplinecurve);
            }

            if (objectTypeName == "INTERP")
            {
                var interpolat = new InterpolatingBSplineObject
                {
                    Name  = objectName,
                    Shape = new BezierCurveC2()
                };

                var refPointsCount = ReadInt();
                for (var i = 0; i < refPointsCount; ++i)
                {
                    interpolat.AttachObject(GetMarkerPoint(ReadInt()));
                }

                return(interpolat);
            }

            if (objectTypeName == "BEZIERSURF" ||
                objectTypeName == "BSPLINESURF")
            {
                var controlPointsV   = ReadInt();
                var controlPointsU   = ReadInt();
                var folded           = GetTextSegment()[0] == 'C';
                var correctDirection = GetTextSegment()[0] == 'H';

                var dataRows    = controlPointsU;
                var dataColumns = controlPointsV;

                Func <int, int, Tuple <int, int> > mapper;
                if (correctDirection)
                {
                    mapper = (i, j) => new Tuple <int, int>(i, j);
                }
                else
                {
                    throw new ArgumentException("Only H option is supported");
                }

                var data = new SharedPoint3D[dataRows, dataColumns];

                for (var row = 0; row < controlPointsU; ++row)
                {
                    for (var column = 0; column < controlPointsV; ++column)
                    {
                        var id     = ReadInt();
                        var point  = _referencePoints[id];
                        var mapped = mapper(row, column);
                        data[mapped.Item1, mapped.Item2] = point;
                    }
                }

                WorldObject surf;
                if (objectTypeName == "BEZIERSURF")
                {
                    var bezierSurf = new BezierSurfaceWorldObject
                    {
                        Name  = objectName,
                        Shape = new BezierPatchGroup(),
                    };

                    bezierSurf.BuildFromExternalData(data, folded);
                    surf = bezierSurf;
                }
                else
                {
                    var bsplineSurf = new BSplineSurfaceWorldObject
                    {
                        Name  = objectName,
                        Shape = new BSplinePatchGroup(),
                    };

                    bsplineSurf.BuildFromExternalData(data, folded);
                    surf = bsplineSurf;
                }

                return(surf);
            }

            return(null);
        }