RoomInteriorGenerator 1.0.2
dotnet add package RoomInteriorGenerator --version 1.0.2
NuGet\Install-Package RoomInteriorGenerator -Version 1.0.2
<PackageReference Include="RoomInteriorGenerator" Version="1.0.2" />
paket add RoomInteriorGenerator --version 1.0.2
#r "nuget: RoomInteriorGenerator, 1.0.2"
// Install RoomInteriorGenerator as a Cake Addin #addin nuget:?package=RoomInteriorGenerator&version=1.0.2 // Install RoomInteriorGenerator as a Cake Tool #tool nuget:?package=RoomInteriorGenerator&version=1.0.2
RoomInteriorGenerator
RoomInteriorGenerator is a .NET library that helps developers to create game environments. It allows you to focus only on defining different objects and hierarchical rules between them instead of an arragment algorithm.
Documentation
See the GitHub pages for the API reference and more information.
Overview
The generation process is based on several structures:
- DataTable: Lists objects and the rules between them. Consists of several "columns": object name, object variants to choose from, rules describing the behaviour of the object and the expected amount of free space around it, and possible child objects that can be placed around the parent.
- Cell: Cell defines the smallest possible unit of a room for arranging furniture. It has several basic states such as Occupied, NonOccupied or AgainstTheWall, which can be extended to give a more accurate furnishing result.
- CellGrid: Describes the available room space using cells and their positions. ngth.
- Room: Encapsulates a room using its width, height, floor number as seed for random generator, placement function and data table.
Take a look at a simple code example where we want chairs to stand around the table and couches to stand near the bottom wall. First, we'll create data table rows for all the furniture we want to use, and then create the data table itself:
let chairLeftRow =
DataTableRow("Chair", [| ObjectVariant("WhiteChair", 1, 1, 1, 1); ObjectVariant("BlackChair", 1, 1, 1, 1); ObjectVariant("OrangeChair", 1, 1, 1, 1) |], Leaf LeftTo, Option.None)
let couchRow =
DataTableRow("Couch", [| ObjectVariant("LongCouch", 3, 3, 0, 0) |], Node AgainstTheBottomWall, Option.None)
let tableRow =
DataTableRow( "Table", [| ObjectVariant("DinnerTable", 2, 2, 2, 2); ObjectVariant("OfficeTable", 2, 2, 3, 3) |], Node None, Some [| chairLeftRow; chairRightRow; chairBehindRow; chairInFrontOfRow |])
let table = DataTable([| chairLeftRow; tableRow; couchRow |])
Our placement function will replace the array values with the selected object variant name:
let arrayToChange = Array2D.init width length (fun _ _ -> "None")
let placementFunction =
fun (_: DataTable.DataTableRow<'Value>) (instance: DataTable.ObjectVariant<'Value>) cellRowIndex cellColumnIndex ->
for i in cellRowIndex - instance.FreeCellsOnTheTop .. cellRowIndex + instance.FreeCellsOnTheBottom do
for j in cellColumnIndex - instance.FreeCellsOnTheLeft .. cellColumnIndex + instance.FreeCellsOnTheRight do
arrayToChange[i, j] <- instance.Variant
let room = Room(length, width, 291, table)
room.GenerateInterior maximumAmountOfObjects placementFunction
After the visualising of the array, we have the following result, where tables are green and blue, chairs are black, white and orange and couches are red:
Unity Example
First, add the RoomInteriorGenerator package to your Unity project when you can open it in your desired script. I fill the data table in the inspector and add the current script to the new GameObject. GameObject should be in the top left corner of your room. GameObject will be the coordinate origin for all furniture placement, so make sure you set the x and z axis directions correctly. Also, all the prefabs you want to place should have (0,0,0) position and 0 degrees y-rotation (depending on your GameObject directions this may be different). Be sure to check the object's pivot point, usually it should be in the centre of your object. This will help you to get the most expected result.
The main body of my script looks like this:
private void Start()
{
var rows = dataTable.Select(row => row.ToDataTableRow()).ToArray();
var dataTableFs = new DataTable.DataTable<GameObject>(rows);
var room = new Room<GameObject>(roomLength, roomWidth, floorNumber, dataTableFs);
var tupleFunction =
FuncConvert.ToFSharpFunc<Tuple<DataTable.DataTableRow<GameObject>, DataTable.ObjectVariant<GameObject>, int, int>>(
t => PlaceObject(t.Item1, t.Item2, t.Item3, t.Item4));
var placementFunction = FuncConvert.FuncFromTupled(tupleFunction);
room.GenerateInterior(maximumAmountOfObjects, placementFunction);
}
The final result:
Take a look at the Time-Reactor-Game to see all the steps of package implementation.
Requirements
Make sure the following requirements are installed on your system:
- dotnet SDK 3.0 or higher (recommended 6.0+),
- Mono if you're on Linux or macOS or
- VSCode Dev Container.
Template
To find more building and running options take a look at the MiniScaffold template.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.1
- FSharp.Core (>= 6.0.0)
-
net6.0
- FSharp.Core (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.2 | 222 | 11/22/2023 | |
1.0.1 | 121 | 11/20/2023 | |
1.0.0 | 116 | 11/20/2023 | |
1.0.0-beta2 | 117 | 11/16/2023 | |
1.0.0-beta1 | 115 | 11/16/2023 | |
1.0.0-alpha5 | 91 | 11/15/2023 | |
1.0.0-alpha4 | 99 | 11/15/2023 | |
1.0.0-alpha3 | 103 | 11/15/2023 | |
1.0.0-alpha2 | 112 | 11/15/2023 | |
1.0.0-alpha1 | 88 | 11/13/2023 |
## [1.0.2] - 2023-11-23
[1.0.2]: https://github.com/PolinaSavelyeva/RoomInteriorGenerator/compare/v1.0.2...v1.0.2
### Added
- Add new README.md