Beispiel #1
0
    // Methods

    // Use this for initialization
    void Start()
    {
        // Make sure Origin anchor is set
        if (OriginAnchor == null)
        {
            OriginAnchor = this.gameObject;
        }

        // Add fitting prefab representations from inspector array to sorted dictionary for faster access speed
        foreach (RepresentationEntry entry in FittingRepresentations)
        {
            FittingRepresentationsDic.Add(entry.fittingType + ":" + entry.fittingModel, entry.representationPrefab);
        }

        if (DoSavePlacementsToFile)
        {
            // Set fitting layout save path
            if (!System.IO.Directory.Exists(PlacementInfoSaveFolderPath))
            {
                System.IO.Directory.CreateDirectory(PlacementInfoSaveFolderPath);
            }
            int savesCount = 1;
            do
            {
                placementInfoSaveFilePath = PlacementInfoSaveFolderPath + "/Layout " + savesCount + ".txt";
                savesCount++;
            } while (System.IO.File.Exists(placementInfoSaveFilePath));
        }

        // Load fitting semantics
        furnisher          = new Furnisher("FittingDatabase.xml");
        AreSemanticsLoaded = true;
    }
        private void CalculateFittingPlacements()
        {
            // Load fitting semantics from XML file
            furnisher = new Furnisher("FittingDatabase.xml");

            // Rectangular room dimensions (width, depth, height,
            // list of arrays for creating the doors (center x position, center y position,
            // door breadth in meters, axis-aligned normal direction into room, optionally height),
            // list of arrays for creating the windows (center x position, center y position,
            // window breadth in meters, axis-aligned normal direction into room, optionally height, optionally elevation above floor))
            Room testRoom = new Room(
                5f,
                4f,
                2.6f,
                new List <float[]>()
            {
                new float[] { -0.5f, 2f, 0.9f, (float)Math.PI / 2 * 3 }
            },
                new List <float[]>()
            {
                new float[] { -1.65f, -2f, 0.9f, (float)Math.PI / 2 * 1 },
                new float[] { -0.55f, -2f, 0.9f, (float)Math.PI / 2 * 1 },
                new float[] { 0.55f, -2f, 0.9f, (float)Math.PI / 2 * 1 },
                new float[] { 1.65f, -2f, 0.9f, (float)Math.PI / 2 * 1 },
            }
                );

            // List of fitting models to be placed
            List <string> fittingModelsToBePlaced = new List <string>()
            {
                "Frenhaus burlap sofa",
                "KLEA floor lamp",
                "Armaldi armchair",
                "Armaldi wooden table",
                "Armaldi wooden chair",
                "Donnerstag coffee table",
                "LuckyPanel flatscreen TV",
                "KLEA white bookcase"
            };

            // Run the fitting placer algorithm to get fitting placements
            fittingPlacements = furnisher.GeneratePlacements(testRoom, fittingModelsToBePlaced);

            // Output fitting placements
            foreach (FittingPlacement placement in fittingPlacements)
            {
                Console.WriteLine("{0}: ({1} , {2}) and {3} degrees turned. ", placement.RepresentationObject.FittingTypeId, placement.PositionX, placement.PositionY, (int)(placement.Orientation * 180 / Math.PI));
            }
        }