Skip to content

Instantly share code, notes, and snippets.

@herronelou
Created December 5, 2021 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herronelou/7a3f7120bb6bd471c11c8531a06326da to your computer and use it in GitHub Desktop.
Save herronelou/7a3f7120bb6bd471c11c8531a06326da to your computer and use it in GitHub Desktop.
set cut_paste_input [stack 0]
version 13.0 v1
Group {
inputs 0
name Minecraft_Import
label orca.nbt
selected true
xpos 103
ypos -89
addUserKnob {20 nbtfile l NBTFile}
addUserKnob {2 file t "path to .nbt file"}
file "C:/Users/herro/AppData/Roaming/.minecraft/saves/New World/generated/minecraft/structures/orca.nbt"
addUserKnob {7 block_size l "Block Size" t "Set the block size on Import" R 0.01 10}
block_size 1
addUserKnob {22 import l Import t "Click to Import, this might create MANY cubes.\nIt is recommended to close the viewer before clicking, as Nuke sometimes crashes when rebuilding while the viewer is open." T "\"\"\"\nImport Minecraft NBT Files in Nuke.\nRequires nbt.py file to be in the nuke path, download from:\nhttps://github.com/twoolie/NBT/blob/master/nbt/nbt.py\n\"\"\"\n\nimport nuke\nimport os\nfrom nbt import NBTFile\n\nblocks_to_ignore = \['air', 'structure_block']\n# Store inputs?\ndef import_nbt(file_path):\n \"\"\" Import Minecraft NBT file \"\"\"\n node = nuke.thisNode()\n block_size = node\['block_size'].value()\n # Empty the group\n nuke.selectAll()\n nuke.nodeDelete()\n\n # Read file\n nbt_file = NBTFile(filename=file_path)\n\n # Setup inputs\n inputs = \{\}\n for index, material in enumerate(nbt_file\['palette']):\n material_name = material\['Name'].valuestr().replace('minecraft:', '', 1)\n if material_name in blocks_to_ignore:\n continue\n input_node = nuke.nodes.Input()\n input_node.setName(material_name)\n input_node.setXYpos(200*len(inputs), 0)\n inputs\[index] = input_node\n\n # Check the structure size and calculate starting point so that structure is centered in XZ\n size_x, size_y, size_z = \[int(size.valuestr()) for size in nbt_file\['size']]\n offset_x = size_x / 2.0 * block_size\n offset_z = size_z / 2.0 * block_size\n\n scene = nuke.nodes.Scene()\n scene.setXYpos(0, 200)\n\n # Build the blocks\n number_of_cubes = 0\n for block in nbt_file\['blocks']:\n index = int(block\['state'].valuestr())\n if index not in inputs:\n continue\n x, y, z = \[int(p.valuestr()) for p in block\['pos']]\n cube = nuke.nodes.Cube()\n scene.setInput(number_of_cubes, cube)\n cube\['translate'].setValue(\[(x + .5) * block_size - offset_x,\n (y + .5) * block_size,\n (z + .5) * block_size - offset_z,])\n cube\['uniform_scale'].setValue(block_size)\n cube.setXYpos(number_of_cubes * 100, 100)\n cube.setInput(0, inputs\[index])\n number_of_cubes += 1\n\n output = nuke.toNode('Output1')\n output.setXYpos(0, 300)\n output.setInput(0, scene)\n\n node\['label'].setValue(os.path.basename(file_path))\n\n\nfile_path = nuke.thisNode()\['file'].evaluate()\nif os.path.isfile(file_path):\n import_nbt(file_path)\nelse:\n nuke.critical('File Path incorrect')\n\n" +STARTLINE}
}
Output {
inputs 0
name Output1
xpos 0
ypos 300
}
end_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment