Animated-Java / animated-java

A Blockbench plugin that makes complex animation a breeze in Minecraft: Java Edition.
Other
157 stars 25 forks source link

[FR] Refactor Variant JSON Structure #289

Open Dearliet opened 3 weeks ago

Dearliet commented 3 weeks ago

Proposed Changes:

  1. Extract the default variant as base_model:

    • This change eliminates the need for the is_default, as base_model now clearly defines the default state
    • base_model should not have a name field since renaming it doesn’t provide value. For example, if the base model is a pirate and a variant has the pirate without a hat, the variant should be named hatless, while the base model remains default. The base model represents the default state, while variants represent deviations. This implies that in Blockbench the default variant name should be fixed
  2. Remove models and custom_model_data field from variants:

    • Plugin developers should generate the models based on the provided texture_map and excluded_nodes with reference to the base_model
    • Plugin developers should generate custom_model_data themselves

Example of the Refactored JSON Structure:

{
   "base_model": {
      "79f0e939-8793-c578-03f7-91463de693a6": {
         "textures": {
            "0": "afba6232-5beb-cdd2-2c5f-00ccb09c6ca7",
            "1": "4c8a3125-a2ga-7fb8-fc21-e55470d610db"
         },
         "elements": [
            {
               "from": [7, 8, 7],
               "to": [9, 16, 9],
               "faces": {
                  "north": {
                     "uv": [0, 0, 2, 8],
                     "texture": "#0"
                  },
                  "east": {
                     "uv": [2, 0, 4, 8],
                     "texture": "#0"
                  },
                  "south": {
                     "uv": [4, 0, 6, 8],
                     "texture": "#0"
                  },
                  "west": {
                     "uv": [6, 0, 8, 8],
                     "texture": "#0"
                  },
                  "up": {
                     "uv": [2, 10, 0, 8],
                     "texture": "#0"
                  },
                  "down": {
                     "uv": [10, 0, 8, 2],
                     "texture": "#0"
                  }
               }
            }
         ]
      }
   },
   "variants": {
      "c21b5e0a-f496-1893-b446-b3159808f5bb": {
         "name": "New Variant",
         "uuid": "c21b5e0a-f496-1893-b446-b3159808f5bb",
         "excluded_bone_nodes": [],
         "texture_map": {
            "afba6232-5beb-cdd2-2c5f-00ccb09c6ca7": "3c7a9155-b4aa-3fd8-fb91-e58770d610da"
         }
      }
   }
}

Embedding base_model in nodes

Since base_model essentially maps data to individual bone nodes, the structure can be further simplified by embedding a model field directly within each bone node:

"79f0e939-8793-c578-03f7-91463de693a6": {
   "type": "bone",
   "name": "my_bone",
   "uuid": "79f0e939-8793-c578-03f7-91463de693a6",
   "model": {
      "textures": {
         "0": "afba6232-5beb-cdd2-2c5f-00ccb09c6ca7",
         "1": "4c8a3125-a2ga-7fb8-fc21-e55470d610db"
      },
      "elements": [
         {
            "from": [7, 8, 7],
            "to": [9, 16, 9],
            "faces": {
               "north": {
                  "uv": [0, 0, 2, 8],
                  "texture": "#0"
               },
               "east": {
                  "uv": [2, 0, 4, 8],
                  "texture": "#0"
               },
               "south": {
                  "uv": [4, 0, 6, 8],
                  "texture": "#0"
               },
               "west": {
                  "uv": [6, 0, 8, 8],
                  "texture": "#0"
               },
               "up": {
                  "uv": [2, 10, 0, 8],
                  "texture": "#0"
               },
               "down": {
                  "uv": [10, 0, 8, 2],
                  "texture": "#0"
               }
            }
         }
      ]
   }
}
Dearliet commented 2 weeks ago

When a variant texture is mapped to transparent it should be mapped to null in the exported JSON:

{
   "variants": {
      "c21b5e0a-f496-1893-b446-b3159808f5bb": {
         "name": "New Variant",
         "uuid": "c21b5e0a-f496-1893-b446-b3159808f5bb",
         "excluded_bone_nodes": [],
         "texture_map": {
            "afba6232-5beb-cdd2-2c5f-00ccb09c6ca7": null
         }
      }
   }
}
Dearliet commented 2 weeks ago

Actually, whether and how the transparent texture is represented is determined by #295