misode / vscode-nbt

NBT extension for VSCode
https://marketplace.visualstudio.com/items?itemName=Misodee.vscode-nbt
MIT License
166 stars 11 forks source link

3d viewer for schematic, litematic and mcstructure files #13

Closed Max-RM closed 11 months ago

Max-RM commented 3 years ago

schematic files can be opened, but they are not displayed in the 3d view

TomLewis commented 2 years ago

Bump, I came here to suggest this too!

Lukebb04 commented 2 years ago

also can you add support for construction files from Amulet this might help

magicus commented 12 months ago

Yeah, that'd like super useful!

I don't think it would be too hard. All the pieces needed to make this work is already present.

The litematica files I looked at has a Regions key, containing a map from region-name to an object with Size (x,y,z), BlockStatePalette (an array of block states, like in a region file) and finally a BlockStates array, just like the data field in a region file. That is all you need to create a Structure object to send for rendering.

I'm guessing the one big hurdle is figuring out how to map the sequence of block states onto the 3d coordinate system as given by the size, but that's a simple trial-and-error process.

I might give it a shot, if I manage to find some spare time...

misode commented 12 months ago

I'm interested in starting to implement this. If anyone has some litematic/schematic files from various versions that I could use to test, that would be very handy!

magicus commented 12 months ago

Here's a couple I recently downloaded. The slime farm is slightly more interesting, since it got two regions (most schematics only have one). For some reason, I could not attach the litematica files directly, so I had to zip them first. Chromoss_2x3x2.litematic.zip soil_swamp_slime_25k.litematic.zip

magicus commented 12 months ago

And here is the oldest one I could find, from 1.15. From a quick glance, there seem to be no (relevant) difference in format.

super_simple_tree_farm_ilmango.litematic.zip

magicus commented 12 months ago

Looking around the code and the litematica format a bit more, it seems that the storage is almost identical to structures prior to VERSION_21w43a. I think ChunkEditor.loadStructure() can be used almost straight away, with just adaptions for the size of the region, instead of the hardcoded 16x16.

misode commented 12 months ago

I've started work on this in #57

Experimental download

Known problems:

@magicus @Lukebb04 @TomLewis @Max-RM

magicus commented 12 months ago

It's looking very good! It has handled most of the files I've thrown at it, including some age-old .schematic. I found just two files which has problems. Funnily enough, both these were files I posted above. I must have a knack for finding problematic examples. ;-)

The first one is the Chromoss design I posted above. It loads and looks good, but when you look closely you see that there are missing blocks at the bottom; the bottom half of two "slices". (The construct is supposed to be fully symmetric; I double checked that the schematic itself is not broken by loading the schematic into a Minecraft world with Litematica.) Very odd. I'm guessing some kind of bug related to mapping the xyz coordinates to the block data stream.

The second is the Slime farm. I would have guessed it should be problematic since it has two different regions, but I don't even get to see a 3D view, just the error message "Cannot mix BigInt and other types, use explicit conversions" which more sounds like a type issue.

Max-RM commented 12 months ago

I've started work on this in #57

Experimental download

  • Download and extract the vscode-nbt-0.9.0-beta.1.zip
  • Run the Install from VSIX command in vscode
  • If a structure does not load or shows incorrectly, please attach it here so I can take a look!

Known problems:

  • Some .schematic files are not supported.
  • .schem files with palettes larger than 128 blocks will be broken

@magicus @Lukebb04 @TomLewis @Max-RM

ok will try it now

Max-RM commented 12 months ago

@misode I tried to open several of my schematic files, but they all opened incorrectly, none of them was displayed in 3d mode and there was just an empty window. here archive: schematic.zip

TomLewis commented 12 months ago

Just some feedback I'm super excited for previewing schematics in 3D, I'm on my phone so can't do any testing or upload any schematics yet, but I have an archive of schematics going back years, my Minecraft server is 11 years old! So hit me up for testing them when the time is ready!

Max-RM commented 12 months ago

Just some feedback I'm super excited for previewing schematics in 3D, I'm on my phone so can't do any testing or upload any schematics yet, but I have an archive of schematics going back years, my Minecraft server is 11 years old! So hit me up for testing them when the time is ready!

You're wrong. You can install Linux in proot/chroot on your phone, then install Vs code then install this NBT viewer and it will work.

https://user-images.githubusercontent.com/81485476/213984092-dd5b16ea-4a1d-4e3a-8016-a0e4267a2e7d.jpg https://youtu.be/zKLESxTTuHE?si=9wCbG11oP3ZIvK6o

magicus commented 12 months ago

@Max-RM Your MR1331 file looks odd. How did you create it? Just to check: it says Materials: "Pocket", is this created on Bedrock Edition?

Max-RM commented 12 months ago

Your MR1331 file looks odd. How did you create it? Just to check: it says , is this created on Bedrock Edition?Materials: "Pocket"

yea this machine was exported from MCBE world using Amulet Map Editor.

magicus commented 12 months ago

That's a whole different way to represent the world. Can you look at chunk/region data from bedrock in 3d?

Max-RM commented 12 months ago

That's a whole different way to represent the world. Can you look at chunk/region data from bedrock in 3d?

Yea i can via Amulet.

magicus commented 12 months ago

I meant via the vscode-nbt editor. :-) If that is not possible, then what you are requesting is substantially different from the code in #57. That is just about reading the metadata correctly so the existing code can understand the structure that is present in litematica files.

To support bedrock files, a basic handling of the way block data is stored in bedrock is needed. I had a quick look at one of your files, and it looked substantially different.

I see now that you opened the original bug report on schematic files, and that it was later merged with #32, support for litematica files, under the assumption (I'm guessing) that they were fairly similar in format. So in a way maybe this bug was kind of hijacked from you; I'm sorry if I was part in unwittingly doing that.

I'm guessing there actually exists two different NBT .schematic formats -- one used by the old Schematica Java mod, which has been superseded by Litematica. Iirc these files had a format very similar to the Litematica format.

Your .schematic files on the other hand are Bedrock data, and comes from Amulet. They seem to have a completely different format.

misode commented 12 months ago

@magicus No worries, supporting the different schematic formats can be tricky, but definitely doable and I still want to cover all of them. The extension should be able to figure out which format it is.

However support for bedrock structures is a bit more difficult since the block IDs need to be translated. That will happen another time.

There is a new version to test: vscode-nbt-0.9.0-beta.2.zip

FYI the problem with the Chromoss litematic is likely a rendering bug, to do with a buffer being too large due to complex geometry. Feel free to open a new issue for that.

If there are still schematics not rendering correctly with this version let me know! Thanks for testing!

Max-RM commented 11 months ago

@magicus No worries, supporting the different schematic formats can be tricky, but definitely doable and I still want to cover all of them. The extension should be able to figure out which format it is.

However support for bedrock structures is a bit more difficult since the block IDs need to be translated. That will happen another time.

There is a new version to test: vscode-nbt-0.9.0-beta.2.zip

  • Fixed the issue that was causing problems with the slime farm litematic
  • Added support for .schematic
  • Block entity NBT now also shows

FYI the problem with the Chromoss litematic is likely a rendering bug, to do with a buffer being too large due to complex geometry. Feel free to open a new issue for that.

If there are still schematics not rendering correctly with this version let me know! Thanks for testing!

Thx. Now it can read MCBE schematics Снимок экрана 2023-11-20 193635 Снимок экрана 2023-11-20 193743 Снимок экрана 2023-11-20 193954 but with some problems. In MR1331 it for some reason show blue terraccota in some places althought there is no such blocks: Снимок экрана 2023-11-20 194406 True variant: Снимок экрана 2023-11-20 194318 Didnt show endgateway blocks (and I think nethercore and several other exclusive MCBE blocks will be invisible): Снимок экрана 2023-11-20 194556 Some problems with glass althouht I dont think this will be easy to fix: Снимок экрана 2023-11-20 194711

Max-RM commented 11 months ago

Oh wait. Why honey block also invisible?

JR1811 commented 11 months ago

Seems like there are still some issues with WorldEdit .schem files?


Files

I used this schematic.

schem_compare_WE

misode commented 11 months ago

@Max-RM Bedrock .schematic files are only slightly working because it wrongly uses the Java numeric ID -> block state. Don't expect this to be fixed soon. Bedrock is not officially supported.

@JR1811 Thanks for your test file, I fixed that issue.

Max-RM commented 11 months ago

What about support mcstructure files?)

misode commented 11 months ago

What about support mcstructure files?

@Max-RM That should be a separate issue, I don't plan to support that in this release.

Max-RM commented 11 months ago

ok

magicus commented 11 months ago

@misode I can confirm that beta 2 can show the slime farm litematica. However, it takes like forever to load; I'm guessing it needs to create a very large volume and fill it with air to transform the two regions inside a single bounding box. An alternative would be for multi-region litematicas to have a widget where you select which region you want to view, kind of like how you select chunks when looking at .mca files. What do you think about that?

misode commented 11 months ago

@magicus Yes I had the same experience. I still need to profile why it's taking so long. Even though it is a large volume the total amount of blocks is not too crazy, so I feel like it should be a lot faster.

magicus commented 11 months ago

Actually, I was wrong. It seems that one of the regions is indeed 136 blocks tall, so the massive amount of empty space is coming from one of the regions itself, not the combination of the two.

Nevertheless, I think it would be beneficial to be able to study the regions separately.

TomLewis commented 11 months ago

image

Trying to click through some schematics, I got this on the second schameitc I clicked.

But it does seem to be working on smaller schematics, this isnt that small, but it ticks over and displays.

image

Looking forward to some speed improvements so we can quickly scan an entire directory of schematics to see whats what!

I for one would LOVE a Gallery view with a thumbnail cache.

So then we can make it scan a folder in its own time, generate a cache for thumbnails for speed of use.

Another use case, would be downloading schematics from say planet minecraft and you want to quickly find what the correct schematic is in a folder.

this is a great start!

After clicking continue on that previous message, and lots of windows messages about VSCode "waiting" and about 60 seconds, this finally loaded! So it can load larger schematics, it just nearly crashes vscode haha! image

misode commented 11 months ago

I've got a new test build: vscode-nbt-0.9.0-beta.3.zip

Details of the performance gain: for structures with a volume larger than 48^3, computing the invisible blocks is skipped. This means that the toggle invisible blocks no longer works, but that was useless for schematics anyways, since those don't have structure voids.

misode commented 11 months ago

I for one would LOVE a Gallery view with a thumbnail cache.

So then we can make it scan a folder in its own time, generate a cache for thumbnails for speed of use.

@TomLewis How would this work in practice? Where in vscode would the thumbnails be shown? Would there be a new window panel that shows this?

JR1811 commented 11 months ago

The example earlier works with the new version!

Other schematics are still problematic, tho. Here are some examples:

bridge_test.zip

small bridge segment made out of vanilla cobblestone material

grafik

ship.captains_quarters.schem.zip

rooms containing mod blocks

bridge_test

magicus commented 11 months ago

Nice! This feels much more snappy! From my point of view, this feature is close to finished.

Some UI considerations (maybe you've already thought of this):

TomLewis commented 11 months ago

I for one would LOVE a Gallery view with a thumbnail cache.

So then we can make it scan a folder in its own time, generate a cache for thumbnails for speed of use.

@TomLewis How would this work in practice? Where in vscode would the thumbnails be shown? Would there be a new window panel that shows this?

Good question! Lots of options!

Those two should cover a lot of cases then. The only way I've opened this window so far is by just clicking on schematic files through the browser panel on the left in vscode. I'm not aware of any other way to open it otherwise!

misode commented 11 months ago

New build: vscode-nbt-0.9.0-beta.5.zip

misode commented 11 months ago

@TomLewis Could you make a separate issue for the gallery suggestion?

magicus commented 11 months ago

The latest test version looks ready to release, from my PoV at least. Thank you for your effort in making this possible! (Along with the rest of this plugin/deepslate, of course!)

misode commented 11 months ago

Version 0.9.0 was just released on the VSCode Marketplace 🚀

magicus commented 11 months ago

You might want to edit the blurb at the Marketplace to mention that it can now view schematics as well.