Hi, My project requires me to have three modes of a floor plan.
Build, Design and Explore.
The 'Build' and 'Design' are similar to the 'FloorMapEditor' and 'HomeDesigner' respectively . But currently the data between these modes can not be shared between each of the scenes , for example you can create a floorplan in editor and load it in the designer, that works fine, you can then make changes like wall color floor color etc. But if you save it now it saves itself as a completely different "internal" plan of sorts.
So what I mean to ask you is that , could there be a way to keep all the data (external and internal) in one json file which can be saved and loaded as per the modes chosen ?
Also (I think this might be a bit impractical but still asking) Can we configure things in a way by which we can have a single scene where we can switch between the modes ?
Saving and Loading between modes
bigknockdown Right now everything is separated into two plugins, that's why we have 2 json project files. But yes that would make sense to merge them. As for the scenes, same thing I needed to have them separated because of the modular approach, now you can certainly merge both into one scene. But when you go from "Build" to "Design", you would have to toggle a lot of gameobjects to get the same result as just switching to another scene, so I'm not sure it would be a good idea. You can transit data from one scene to another using static variables. so the transitions could be seamless. I will put on my todo list to try to merge both json files for now. Thanks!
Hi Anthony,
I have a question regarding the loading function. Lets say we have 4 'vector3' saved somewhere, these are similar to the 'world' point of the Control Point of your system. What would be the best way to 'load' these points using your system to be able to create a room ?
bigknockdown Hi!
Look at the function called "BuildRoom()" I think this is what you want:
`
GameObject inst = Instantiate(proceduralRoomPrefab, roomsContainer);
ProceduralRoom proc = inst.GetComponent<ProceduralRoom>();
...
proc.Generate(worldPosList);`
worldPosList is a list of vector3. You can copy that code where you need and adapt it.
- Edited
Anthony
Hi,
Thanks this works nicely , one more related question even though I am able to create the room based on this approach how do I create a UI Item of Room associated with it along with the room ?
I also tried to create the Control Points for this room as well as I want it to be edited and saved as the normally created ones, but I am unable to do so. Can you please guide me for this ?
bigknockdown The approach to create something in the editor is a bit different, you can look at the deserialization methods like FloorMapSerializer->DeserializeFloorMapUI(), or UIFloorMapMenu->OnDuplicateUIItem()
Here is the basic general approach:
UIFloorMapMenu floorMapMenu = GameObject.FindObjectOfType<UIFloorMapMenu>();
DataModel.FloorMapItem item = new FloorMapItem();
item.type = DataModel.FloorMapItemType.Room.ToString();
item.normalizedPositions = YOUR LIST OF POINTS ON THE GRID(NORMALIZED)
floorMapMenu.CreateNewUIItem(item, item.type);
the points need to be normalized here, You can use Grid->GetNormalizedPosition(p); if you need to convert a world position to a normalized position on the grid.
Hope that helps!
Hi Anthony,
While saving and loading (in editor mode) I have noticed some difference in the points position. What I mean is when I save a simple room , a 4 wall room with perfect 90 degree angles.
But when I load the same design I have noticed that the normalised position is saved and loaded correctly from the json , but while converting normalised to world pos, for two out of four points , there seems to be difference of at least 0.2-0.5 units.
Can this be because of the Grid space I am using ?
the space I am using is (0.05,1, 0.05)
I have not modified original saving system in any way until now. Can you give me a hit as to how to sort this ?
bigknockdown Hi! Are you doing the load & save in the same scene with the same grid ? Or are you saving in FloorMap and loading in HomeDesigner or so?
I am saving and loading in the Editor scene , using the same grid at both times.
bigknockdown That's very strange, can you send me your json file to try it out on my side ? Thanks
Anthony I have sent you the json file via email with a couple of screenshots. Please let me know if you require any further information from my side.
what I see from your json file is that these numbers were supposed to be the same or close, but they are not. Which means the issue was during the saving time
- Edited
when serializing, the normalized positions are not calculated, they were cached. So if the cached value is not the actuel position, the save get corrupted.
In ControlPointsController.cs replace GetNormalizedPositionList() like this:
public List<Vector3> GetNormalizedPositionList()
{
List<Vector3> list = new List<Vector3>();
list = GetPointsList().Select(s => (Vector3)s.GetNormalizedPostion(grid)).ToList();
return list;
}
And add this function inside ControlPoint.cs
public Vector3 GetNormalizedPostion(Grid grid)
{
return grid.GetNormalizedPosition(transform.position);
}
The position will always be recalculated at save time.
By the way, I see that there is a small bug, when you click to create the control point, it gets moved/dragged, so it's no longer the snapped control point that was found when moving the mouse before clicking. to fix, remove the DragPoint() call line 304 of ControlPointsController:
else if ((cp == null || cp == ghostPoint) && IsDrawing)
{
cp = CreateControlPointBasedOnGhost();
//DragPoint(cp);
}
I know its very late, but still wanted to thank you for your suggestion , it worked like a charm.
Thanks