コード例 #1
0
        public Model3DGroup GetModel()
        {
            var mainModel = new Model3DGroup();

            if (PackageHeight > 0 && PackageWidth > 0 && PackageLength > 0 && PaletteWidth > 0 && PaletteLength > 0)
            {
                FloorMap floorMap       = new FloorMap(PackageWidth, PackageLength, PaletteWidth, PaletteLength);
                FloorMap floorTurnedMap = new FloorMap(PackageWidth, PackageLength, PaletteWidth, PaletteLength, true);

                for (int i = 0; i < Levels; i++)
                {
                    mainModel.Children.Add(FloorGenerator(floorMap, PackageGenerator(), i));
                    TranslateTransform3D translate = new TranslateTransform3D();
                    translate = (TranslateTransform3D)mainModel.Children[i].Transform;
                    mainModel.Children[i].Transform = new TranslateTransform3D(new Vector3D(translate.OffsetX, translate.OffsetY + PackageHeight * 2 * i + i * 0.01, translate.OffsetZ));

                    if (++i >= Levels)
                    {
                        break;
                    }
                    mainModel.Children.Add(FloorGenerator(floorTurnedMap, PackageGenerator(), i));
                    TranslateTransform3D turnedFloorTranslate = new TranslateTransform3D();
                    turnedFloorTranslate            = (TranslateTransform3D)mainModel.Children[i].Transform;
                    mainModel.Children[i].Transform = new TranslateTransform3D(new Vector3D(turnedFloorTranslate.OffsetX, turnedFloorTranslate.OffsetY + PackageHeight * 2 * i + i * 0.01, turnedFloorTranslate.OffsetZ));
                }

                ThrowUpRainbow(mainModel);
            }
            return(mainModel);
        }
コード例 #2
0
        private Model3DGroup FloorGenerator(FloorMap floorMap, GeometryModel3D model, int whichLevel)
        {
            Model3DGroup floor = new Model3DGroup();

            foreach (MapNode mapNode in floorMap.Map)
            {
                GeometryModel3D geometryModel = new GeometryModel3D();
                geometryModel = model.Clone();
                RotateTransform3D rotation       = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90));
                Transform3DGroup  transformation = new Transform3DGroup();

                if (mapNode.IsTurned)
                {
                    transformation.Children.Add(rotation);
                }

                TranslateTransform3D translation = new TranslateTransform3D(new Vector3D(mapNode.PosX, PackageHeight, -mapNode.PosY));
                transformation.Children.Add(translation);
                geometryModel.Transform = transformation;

                floor.Children.Add(geometryModel);
            }

            double min_X, max_X, min_Z, max_Z;

            min_X = min_Z = double.MaxValue;
            max_X = max_Z = double.MinValue;

            PackagesPerFloor = floor.Children.Count;
            for (int i = 0; i < PackagesPerFloor; i++)
            {
                GeometryModel3D geometryModel = new GeometryModel3D();
                geometryModel = (GeometryModel3D)floor.Children[i];

                Transform3DGroup     transformGroup = (Transform3DGroup)geometryModel.Transform;
                TranslateTransform3D translation    = (TranslateTransform3D)transformGroup.Children[transformGroup.Children.Count - 1];

                double minCandidateX, maxCandidateX, minCandidateZ, maxCandidateZ;

                if (transformGroup.Children.Count > 1)
                {
                    minCandidateX = translation.OffsetX - PackageLength;
                    maxCandidateX = translation.OffsetX + PackageLength;
                    minCandidateZ = translation.OffsetZ - PackageWidth;
                    maxCandidateZ = translation.OffsetZ + PackageWidth;
                }
                else
                {
                    minCandidateX = translation.OffsetX - PackageWidth;
                    maxCandidateX = translation.OffsetX + PackageWidth;
                    minCandidateZ = translation.OffsetZ - PackageLength;
                    maxCandidateZ = translation.OffsetZ + PackageLength;
                }

                if (min_X > minCandidateX)
                {
                    min_X = minCandidateX;
                }

                if (max_X < maxCandidateX)
                {
                    max_X = maxCandidateX;
                }

                if (min_Z > minCandidateZ)
                {
                    min_Z = minCandidateZ;
                }

                if (max_Z < maxCandidateZ)
                {
                    max_Z = maxCandidateZ;
                }

                Model3DGroup modelGroup = new Model3DGroup();
                modelGroup.Children.Add(geometryModel);
                Model3DGroup signsAll = new Model3DGroup();
                modelGroup.Children.Add(signsAll);
                signsAll.Transform = transformGroup;
                bool turned = transformGroup.Children.Count < 2 ? true : false;
                for (int k = 0; k < 5; k++)
                {
                    int numberToDisplay = whichLevel * floor.Children.Count + i + 1;
                    signsAll.Children.Add(new GeometryModel3D());
                    if (k == 0)
                    {
                        signsAll.Children[k] = SignUp(numberToDisplay);
                        upSignShortcut.Add((GeometryModel3D)signsAll.Children[k]);
                    }
                    if (k == 1)
                    {
                        signsAll.Children[k] = SignFront(numberToDisplay);
                    }
                    if (k == 2)
                    {
                        signsAll.Children[k] = SignBack(numberToDisplay);
                    }
                    if (k == 3)
                    {
                        signsAll.Children[k] = SignRight(numberToDisplay);
                    }
                    if (k == 4)
                    {
                        signsAll.Children[k] = SignLeft(numberToDisplay);
                    }
                }
                floor.Children[i] = modelGroup;
            }

            floor.Transform = new TranslateTransform3D(new Vector3D(-(max_X - (max_X - min_X) / 2), 0, -(max_Z - (max_Z - min_Z) / 2)));
            return(floor);
        }