Igrium / mc-world-export

A mod which eases the exporting of Minecraft worlds into Blender and similar software.
GNU General Public License v3.0
102 stars 8 forks source link

How does it update meshes on a larger scale? #25

Closed Dyvinia closed 1 year ago

Dyvinia commented 1 year ago

Hi, I'm not sure exactly how/where to ask about this, but I was wondering how block updates happen on a larger scale. Basically I was curious if it could be possible to import one of those redstone noteblock creations into blender so I did a 'small scale test' by just recording myself activating a noteblock which seemed to work well

https://user-images.githubusercontent.com/13797470/213355265-dcf0e5f1-d7b9-41ca-a83f-822759fc70b3.mp4

I went ahead and tried importing an actual map (aswell as making a resource pack to show when a noteblock is activated) and noticed that sometimes blocks dont update properly and stay stuck in a block state

https://user-images.githubusercontent.com/13797470/213355496-9feb2092-6a2c-4348-83dd-c3c6b1ebbbe3.mp4

I'm mostly just wondering if its something on my end, something that could be fixed, or if it wouldn't be easy/possible to fix

edit: this is what it looks like ingame for reference (map source)

https://user-images.githubusercontent.com/13797470/213357815-467f6773-538a-441e-a376-a81be7aa9f6e.mp4

Igrium commented 1 year ago

An in-depth look at how blockstates are stored and updated can be found here, but here's a brief overview.

Unlike many exporters, my exporter doesn't export raw world meshes. Instead, it stores the actual blocks in an intermediary format I call "Vcap", which is essentially a voxel grid that stores references to various meshes representing different block types. This grid is subsequently tessellated upon import to Blender.

Whenever a block (or set of blocks) is updated, the update gets stored as a "frame" within the file. Much like a p-frame in a video file, this frame only stores the blockstates that have been updated, as well as the timestamp of the update.

In theory this should account for any amount of updates at any scale. In practice, however, I've found it a little inconsistent when it comes to larger updates. This is something I intend to improve in the future.

Does this answer your question?

(Also, your cinematography on that noteblock looks amazing!)

Dyvinia commented 1 year ago

Makes sense, i also noticed the 5 second clip was around the same file size as the 3 minutes of the megalovania theme (~1.5mb vs ~2mb) could it be some sorta compression with larger scenes? also does the inconsistency in larger scenes come from export from the game or is it from the import into blender?

(also thanks! honestly i setup the lighting/etc pretty quickly/lazily in blender and im not super satisfied with it myself, especially the sky background. also I ended up remaking the entire material system myself in blender since having it split off into multiple materials was annoying at times)

Igrium commented 1 year ago

The majority of the file size of .replay files comes from storing the world. Once the world is saved, it doesn't matter how long you spend in it. The size will remain more-or-less the same.

As for the inconsistency, I'm still trying to figure that out. My best guess is that, for some reason, Minecraft isn't triggering the client-side block update code on certain updates. But it could be Blender as well. Go to one of the frames that there's supposed to be an update and move part of the world containing the noteblocks. If there's another block mesh sitting under it, then it's Blender's fault.

Dyvinia commented 1 year ago

Go to one of the frames that there's supposed to be an update and move part of the world containing the noteblocks. If there's another block mesh sitting under it, then it's Blender's fault.

it seems that there is nothing there

https://user-images.githubusercontent.com/13797470/213498018-312a1382-52ba-4659-b99b-3a1f3e6ecdd9.mp4

Dyvinia commented 1 year ago

I don't have experience in java really, but at https://github.com/Sam54123/mc-world-export/blob/main/src/main/java/org/scaffoldeditor/worldexport/vcap/PFrame.java#L86, i noticed that it checks adjacent blocks to see if they have also received an update, which seems to explain how all the broken updates in the video are in bunches of no bigger than 3x3x3, is it possible to somehow check the adjacent blocks of said adjacent blocks? (would encasing the for (BlockPos pos : blocks) inside another for maybe work)

i don't really know much of java much less minecraft modding so what i'm saying might make little to no sense lol

Igrium commented 1 year ago

Yeah, as expected, it appears the issue is in Minecraft.

i noticed that it checks adjacent blocks to see if they have also received an update,

This isn't checking for a blockstate update. Any blocks that have been updated for whatever reason are already being iterated through. This check happens because face occlusion may have changed on blocks surrounding those which have been updated.

Encasing the whole thing in another for loop would make the entire thing run at least three times slower and it wouldn't fix the issue; only differ it. I am working on a revamped exporter though. Do you know how to build mods? If so, check out the async_world_capture branch, where in an effort to speed up the export, I may have accidentally fixed some inconsistancies.

Dyvinia commented 1 year ago

This isn't checking for a blockstate update. Any blocks that have been updated for whatever reason are already being iterated through. This check happens because face occlusion may have changed on blocks surrounding those which have been updated.

Ah that makes sense.

Do you know how to build mods? If so, check out the async_world_capture branch

I've been meaning to but I don't know how to atm, ill look more into it later today

Igrium commented 1 year ago

Real quick, what version of the mod are your running?

Dyvinia commented 1 year ago

0.6.0