D2R Preset Map Editor in Unity

We will open up modding section ones the remaster of original Diablo 2 game is released. Until then we open up a section to discuss the upcoming title.
User avatar
pairofdocs
Posts: 7
Joined: Sat Feb 20, 2021 5:11 pm
United States of America

D2R Preset Map Editor in Unity

Post by pairofdocs » Tue Aug 24, 2021 4:21 pm

Credits: Shalzuth's D2RStudio which this tool is based on and Norbyte's LSLib

With these unity scripts editing D2R preset environments is possible: https://github.com/pairofdocs/Unity-D2R-Scene-Editor

Requirements: Instructions:
  1. Create a new 3D project in Unity (this example project is named "D2R-docktown")
  2. Download the Unity-D2R-Scene-Editor repository, unzip and place its contents into your unity project Assets folder (e.g. ...Unity Projects/D2R-docktown/Assets/Scripts , Resources, libs, ...)
  3. Open the project in Unity and select the Main Camera object in the Scene. Then in the Inspector window on the right hand side add a component script Scripts/SaveJson.cs. (This is done only once per project)
  4. Save your Unity Scene with ctrl+s. Set your D2R data paths in SaveJson.cs and save the script (see Config section below)
  5. Click the blue "Play" button above the Scene window to load a json preset in the project folder (e.g. docktown3.json). Click "Pause" and move/rotate/scale objects in the Scene
  6. To add objects to the Scene click "Pause" to unpause and then click the "Add" button on the left of the Scene and specify the path of the model to add. Once objects have been added click "Pause" to go back to Scene editing
  7. When finished editing click "Pause" once again to unpause and then click "Save" on the left of the Scene to save your changes to the preset json file
  8. Place your edited preset json into your D2R/Data/hd/env/preset location and launch D2R with -direct -txt
Config D2R Data paths:
Lines 16 and 17 in Scripts/SaveJson.cs should be configured for your preset path and D2R data path

Code: Select all

    public string preset = "docktown3.json";              // Change this to be the json preset that is edited
    public static string d2rDataPath = "D:/D2R/";         // Change this to where your D2R data is extracted (casc storage)

Video Clip: https://streamable.com/xbxe7i

Screenshots:
Unity scene - act1 town south
Image
In-game act1 town south (*preset model saving has been fixed. Models behind the chest stash and the campfire will be saved correctly in the current version of the editor and will appear in-game)
Image

Happy Moddin'

Donie Brasko
Posts: 2
Joined: Tue Sep 28, 2021 1:54 pm
Ukraine

Re: D2R Preset Map Editor in Unity

Post by Donie Brasko » Sat Oct 16, 2021 5:23 pm

Can't make it work. Unity shows:
Assets\Scripts\SaveJson.cs(17,43): error CS1009: Unrecognized escape sequence
Assets\Scripts\SaveJson.cs(17,49): error CS1009: Unrecognized escape sequence

Adding "@" to this string: public static string d2rDataPath = @"F:\Games\D2R"; results in more errors :(

mapron
Posts: 1
Joined: Tue Sep 28, 2021 2:19 am
Russia

Re: D2R Preset Map Editor in Unity

Post by mapron » Wed Oct 20, 2021 4:36 pm

Maybe you should use normal slashes instead of backslashes? change to F:/Games/D2R ?

User avatar
pairofdocs
Posts: 7
Joined: Sat Feb 20, 2021 5:11 pm
United States of America

Re: D2R Preset Map Editor in Unity

Post by pairofdocs » Thu Oct 21, 2021 5:56 am

Donie Brasko wrote:
Sat Oct 16, 2021 5:23 pm
Can't make it work. Unity shows:
Assets\Scripts\SaveJson.cs(17,43): error CS1009: Unrecognized escape sequence
Assets\Scripts\SaveJson.cs(17,49): error CS1009: Unrecognized escape sequence

Adding "@" to this string: public static string d2rDataPath = @"F:\Games\D2R"; results in more errors :(
on line 17, try

public static string d2rDataPath = "F:/Games/D2R/";

like mapron has

Donie Brasko
Posts: 2
Joined: Tue Sep 28, 2021 1:54 pm
Ukraine

Re: D2R Preset Map Editor in Unity

Post by Donie Brasko » Sun Oct 24, 2021 7:59 pm

pairofdocs wrote:
Thu Oct 21, 2021 5:56 am

on line 17, try

public static string d2rDataPath = "F:/Games/D2R/";

like mapron has
I used this "\" type of quotes because I got only two errors with them. When I did not change path at all or use "F:/Games/D2R/"; - I'm receiving this 6 errors:

Assets\Scripts\SaveJson.cs(9,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(10,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(7,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(8,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(20,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(21,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)

User avatar
MilesTeg
Posts: 36
Joined: Sun Jul 18, 2021 6:42 am
Germany

Re: D2R Preset Map Editor in Unity

Post by MilesTeg » Sat Nov 13, 2021 9:39 pm

Donie Brasko wrote:
Sun Oct 24, 2021 7:59 pm
Assets\Scripts\SaveJson.cs(9,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(10,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(7,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(8,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(20,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(21,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
I had exactly the same errors. Now I've found the official link for the required package (took me quite a while :lol: ): https://assetstore.unity.com/packages/t ... nity-11347.
I tried this method with another project and it actually kept the JObject error for me...

Alternatively what worked (without any errors!) for me:
https://github.com/needle-mirror/com.un ... nsoft-json
- get latest stable release (2.0.2) (get zipfile (not tar.gz) & extract*)
- in unity project: window - package manager - + (install from disk); open package.json.

*be sure to store it somewhere permanently, it somehow still needs the files after installation. I got an error once I move the files :roll:

edit: added some details
Last edited by MilesTeg on Sun Nov 14, 2021 1:52 pm, edited 2 times in total.

User avatar
Spectrum
Posts: 69
Joined: Mon May 12, 2003 12:40 pm
Location: Denmark
Denmark

Re: D2R Preset Map Editor in Unity

Post by Spectrum » Sun Nov 14, 2021 1:15 pm

Nice! Thanks for sharing!

If you move objects around like this (like the cart in the linked video), does it affect visuals only or does it also affect collision - i.e., can characters walk through the cart?

User avatar
MilesTeg
Posts: 36
Joined: Sun Jul 18, 2021 6:42 am
Germany

Re: D2R Preset Map Editor in Unity

Post by MilesTeg » Sun Nov 14, 2021 3:00 pm

Spectrum wrote:
Sun Nov 14, 2021 1:15 pm
If you move objects around like this (like the cart in the linked video), does it affect visuals only or does it also affect collision - i.e., can characters walk through the cart?
Haven't tried it myself, but afaik legacy ds1 controls collision. I added a house to the rogue camp (via DS1Edit) and although nothing is visible in HD collision worked for both legacy and HD. But I saw some physics data in the json, maybe there's a way :?:

btw: I just realized default grid in unity matches tylegrid from DS1Edit, nice :)

https://imgur.com/8Yj23M2

edit: data/hd/env/model/tests/test_cube_02.model scaled up by factor 2 seems to be the size of a DS1-Edit-subgridsquare (=object mode = 1/5 of tilegrid). Very handy thing for testing/measuring.
Last edited by MilesTeg on Thu Nov 18, 2021 3:30 pm, edited 1 time in total.

User avatar
marhawkman
Retired staff
Angel
Posts: 698
Joined: Thu May 13, 2004 2:21 am
Location: CO

Re: D2R Preset Map Editor in Unity

Post by marhawkman » Sun Nov 14, 2021 8:04 pm

yeah I was gonna say, I've actually never done D2 map modding, but I was interested in it and looked into it back when I was doing modding. D2 uses tileset based maps and the contents of the tile determine collision. to my understanding, it's like a checkerboard, turned 45°, where some tiles are flat and some tiles not. this looks like a tool for re-arranging the non-flat tiles.
Currently working on making an Andariel Player character.
Status of my Mod: Assimilated

User avatar
MilesTeg
Posts: 36
Joined: Sun Jul 18, 2021 6:42 am
Germany

Re: D2R Preset Map Editor in Unity

Post by MilesTeg » Sat Nov 20, 2021 2:45 pm

just some more notes & expierience from a Unity noob:

Save often. At the beginning make backups (e.g. zip) of your projects folder. This way you can easily revert back to the point before everything went haywire.

recommended (from pairofdocs github):
- First 30min about Unity's essential controls, layout, panels and terminology. It also has helpful timestamps :)

Texture Problems

If your objects show up in a strange, glossy/metallic way (maybe only half visible) or maybe not everything shows up in Unity there might be problems regarding textures.

First solution: Make sure your textures settings are active. Via the SaveJson.cs file (in line 19 set loadTextures from false back to true) then start your Unity Editor: (out of Rendering mode) select "Main Camera" and in the inspector under "Save Json (Script)" make sure the checkbox "Load Textures" is enabled. If there is no such option the project isn't installed correctly (if there are errors in your console-tab(bottom) maybe take a look at my post from above).
Also make sure
- you have correctly added your D2R directory in the SaveJson.cs file
- your hd-directory is extracted from D2R casc storage...

If you want to edit without any textures (more performance/ less RAM usage) do it the other way around (loadTextures to false/ checkbox off) and disable the glossy/metallic effect by outcommenting. At line 46 in YourProjectFolder\Assets\Scripts\ MeshLoader.cs add // :

Code: Select all

....
45  meshRenderer.material.EnableKeyword("_NORMALMAP");
46  // meshRenderer.material.EnableKeyword("_METALLICGLOSSMAP");
47  if (loadTextures == true) {
....
Objects are invisible but worked before

After I did some bigger edits in the json files outside of Unity, the map appeared in gameview, but all objects were invisible in "Scene":

First make sure you haven't disabled the any layer view:
- at the topright open the "Layer" dropdown menu
- Make sure only the eye at "nothing" is striked out.
otherwise...

Caches

If you ran out of ideas you can clean the caches:
- the general cache: From menu "Edit" - "Preferences" select "GI Cache" and click "Clean Cache"

- your projects cache (if unsure make a backup the dir first):
In short: don't (!) delete your Assets, ProjectSettings and the Packages folders. All the rest you can delete and Unity will recreate/recompile them when you open the project again.
source & much more info: https://stackoverflow.com/a/56267992/17336886

User avatar
pairofdocs
Posts: 7
Joined: Sat Feb 20, 2021 5:11 pm
United States of America

Re: D2R Preset Map Editor in Unity

Post by pairofdocs » Sun Nov 21, 2021 6:07 pm

Spectrum wrote:
Sun Nov 14, 2021 1:15 pm
Nice! Thanks for sharing!

If you move objects around like this (like the cart in the linked video), does it affect visuals only or does it also affect collision - i.e., can characters walk through the cart?
The 3d models that are added with Unity are just visual in-game. If they are placed in act1's open space, the player model will just run through them, no collision detection is done.

User avatar
pairofdocs
Posts: 7
Joined: Sat Feb 20, 2021 5:11 pm
United States of America

Re: D2R Preset Map Editor in Unity

Post by pairofdocs » Sun Nov 21, 2021 6:10 pm

Donie Brasko wrote:
Sun Oct 24, 2021 7:59 pm
pairofdocs wrote:
Thu Oct 21, 2021 5:56 am

on line 17, try

public static string d2rDataPath = "F:/Games/D2R/";

like mapron has
I used this "\" type of quotes because I got only two errors with them. When I did not change path at all or use "F:/Games/D2R/"; - I'm receiving this 6 errors:

Assets\Scripts\SaveJson.cs(9,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(10,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(7,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\TextureLoader.cs(8,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(20,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\SaveJson.cs(21,12): error CS0246: The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)

MilesTeg is right, that looks like the Newtonsoft Json package is needed
https://d2mods.info/forum/posting.php?m ... 7&p=502341

I updated the Readme on github to help trouble shoot that https://github.com/pairofdocs/Unity-D2R ... leshooting

d2joannadark
Posts: 1
Joined: Sun Dec 19, 2021 2:46 am
Canada

Re: D2R Preset Map Editor in Unity

Post by d2joannadark » Sun Dec 19, 2021 3:23 am

So i gave er a try, it definitely has potential, but i think its having issues. Upon installing, it ran docktown with no problems what so ever. But after changing the .json to wstone01.json... it loads up missing alot of stuff, half of baals walk ramp just isn't there, and, without making any changes, and just saving the file, in game, the very same stuff that was 'missing' is now gone too. And, lastly, upon loading and running that area in unity... a mass tonne of errors are produced, all of which point to a single line, regarding the terrain.model

Code: Select all

                    catch (Exception e) {
                        Destroy(GameObject.Find(entname));
                        if (!strArr[strArr.Length-1].Contains("terrain.model")) {
                            Debug.LogException(e, this);
                        }
                    }
Huge potential, but pretty buggy atm me thinks.

For reference,

faizanmazhar00
Posts: 5
Joined: Thu Feb 17, 2022 6:52 am

Re: D2R Preset Map Editor in Unity

Post by faizanmazhar00 » Thu Feb 17, 2022 6:57 am

pairofdocs wrote:
Tue Aug 24, 2021 4:21 pm
Credits: Shalzuth's D2RStudio which this tool is based on and Norbyte's LSLib

With these unity scripts editing D2R preset environments is possible: https://github.com/pairofdocs/Unity-D2R-Scene-Editor

Requirements: Instructions:
  1. Create a new 3D project in Unity (this example project is named "D2R-docktown")
  2. Download the Unity-D2R-Scene-Editor repository, unzip and place its contents into your unity project Assets folder (e.g. ...Unity Projects/D2R-docktown/Assets/Scripts , Resources, libs, ...)
  3. Open the project in Unity and select the Main Camera object in the Scene. Then in the Inspector window on the right hand side add a component script Scripts/SaveJson.cs. (This is done only once per project)
  4. Save your Unity Scene with ctrl+s. Set your D2R data paths in SaveJson.cs and save the script (see Config section below)
  5. Click the blue "Play" button above the Scene window to load a json preset in the project folder (e.g. docktown3.json). Click "Pause" and move/rotate/scale objects in the Scene
  6. To add objects to the Scene click "Pause" to unpause and then click the "Add" button on the left of the Scene and specify the path of the model to add. Once objects have been added click "Pause" to go back to Scene editing
  7. When finished editing click "Pause" once again to unpause and then click "Save" on the left of the Scene to save your changes to the preset json file
  8. Place your edited preset json into your D2R/Data/hd/env/preset location and launch D2R with -direct -txt
Config D2R Data paths:
Lines 16 and 17 in Scripts/SaveJson.cs should be configured for your preset path and D2R data path

Code: Select all

    public string preset = "docktown3.json";              // Change this to be the json preset that is edited
    public static string d2rDataPath = "D:/D2R/";         // Change this to where your D2R data is extracted (casc storage)

Video Clip: https://streamable.com/xbxe7i

Screenshots:
Unity scene - act1 town south
Image
In-game act1 town south (*preset model saving has been fixed. Models behind the chest stash and the campfire will be saved correctly in the current version of the editor and will appear in-game)
Image

Happy Moddin'
Thanks

Return to “Diablo II Resurrected Discussion”