diff --git a/NeutrinoJSONTest.ipynb b/NeutrinoJSONTest.ipynb index b119107..d684d22 100644 --- a/NeutrinoJSONTest.ipynb +++ b/NeutrinoJSONTest.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 28, + "execution_count": 7, "source": [ "import json\r\n", "\r\n", @@ -20,7 +20,8 @@ " \"assets\": {}\r\n", " },\r\n", " \"internal\": {\r\n", - " \"max_key\": 0\r\n", + " \"max_object_key\": 0,\r\n", + " \"max_cache_key\": 0\r\n", " }\r\n", " }\r\n", "\r\n", @@ -39,13 +40,23 @@ " with open(filename, \"w\") as outfile:\r\n", " json.dump(clean_data, outfile, indent = 4)\r\n", "\r\n", - "# get a new indexed object key and increment the scene's max key\r\n", - "def add_key(data):\r\n", + "# get a new indexed object key and track it\r\n", + "def object_key(data):\r\n", " # get the indexed key\r\n", - " key = hex(data[\"internal\"][\"max_key\"] + 1)\r\n", + " key = hex(data[\"internal\"][\"max_object_key\"] + 1)\r\n", "\r\n", " # index the max key\r\n", - " data[\"internal\"][\"max_key\"] += 1\r\n", + " data[\"internal\"][\"max_object_key\"] += 1\r\n", + "\r\n", + " return key\r\n", + "\r\n", + "# get a new indexed cache key and track it\r\n", + "def cache_key(data):\r\n", + " # get the indexed key\r\n", + " key = hex(data[\"internal\"][\"max_cache_key\"] + 1)\r\n", + "\r\n", + " # index the max key\r\n", + " data[\"internal\"][\"max_cache_key\"] += 1\r\n", "\r\n", " return key\r\n", "\r\n", @@ -57,7 +68,7 @@ " }\r\n", " \r\n", " # add the asset to the graph\r\n", - " data[\"graph\"][\"assets\"][add_key(data)] = (\"asset\", asset_data)\r\n", + " data[\"graph\"][\"assets\"][object_key(data)] = (\"asset\", asset_data)\r\n", "\r\n", "# add an object to the scene\r\n", "def spawn_object(data, name, asset):\r\n", @@ -73,14 +84,14 @@ " object_data[\"asset\"] = f\"*{key}\"\r\n", "\r\n", " # add the object to the scene\r\n", - " data[\"graph\"][\"scene\"][add_key(data)] = (\"object\", object_data)" + " data[\"graph\"][\"scene\"][object_key(data)] = (\"object\", object_data)" ], "outputs": [], "metadata": {} }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 8, "source": [ "# cache the scene\r\n", "def cache_scene(data):\r\n", @@ -120,7 +131,7 @@ "\r\n", " # create hash objects for each repeated value\r\n", " for key, value in hash_cache.items():\r\n", - " cache_pointer = f\"#{add_key(data)}\"\r\n", + " cache_pointer = cache_key(data)\r\n", " data[\"cache\"][cache_pointer] = value[\"value\"]\r\n", " hash_cache[key][\"pointer\"] = cache_pointer\r\n", "\r\n", @@ -134,14 +145,14 @@ "\r\n", " # if this value is cached, replace it with its cache pointer\r\n", " if value_hash in hash_cache:\r\n", - " objects[object_key][1][value_key] = hash_cache[value_hash][\"pointer\"]" + " objects[object_key][1][value_key] = \"#\" + hash_cache[value_hash][\"pointer\"]" ], "outputs": [], "metadata": {} }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 9, "source": [ "# just returns a random string\r\n", "import random\r\n", diff --git a/NeutrinoTestScene.json b/NeutrinoTestScene.json index d884c1a..d85de6d 100644 --- a/NeutrinoTestScene.json +++ b/NeutrinoTestScene.json @@ -20,10 +20,10 @@ { "name": [ "name", - "MN7SY1DZ" + "NO94Z37B" ], "asset": "*0x1", - "trans": "#0x9" + "trans": "#0x1" } ], "0x5": [ @@ -31,10 +31,10 @@ { "name": [ "name", - "JIZTJG2T" + "NC302YU1" ], - "asset": "*0x3", - "trans": "#0x9" + "asset": "*0x2", + "trans": "#0x1" } ], "0x6": [ @@ -42,10 +42,10 @@ { "name": [ "name", - "78LMETC7" + "GW5625SS" ], - "asset": "*0x2", - "trans": "#0x9" + "asset": "*0x3", + "trans": "#0x1" } ], "0x7": [ @@ -53,10 +53,10 @@ { "name": [ "name", - "4PEMWVMY" + "THUUN5IN" ], "asset": "*0x3", - "trans": "#0x9" + "trans": "#0x1" } ], "0x8": [ @@ -64,10 +64,10 @@ { "name": [ "name", - "N553FJRY" + "JT5FVYOW" ], - "asset": "*0x1", - "trans": "#0x9" + "asset": "*0x2", + "trans": "#0x1" } ] }, @@ -77,9 +77,9 @@ { "name": [ "name", - "ONQSQMWX" + "3QDJ22P1" ], - "file": "#0xa" + "file": "#0x2" } ], "0x2": [ @@ -87,9 +87,9 @@ { "name": [ "name", - "GTIRGEOQ" + "49ITSLZI" ], - "file": "#0xa" + "file": "#0x2" } ], "0x3": [ @@ -97,15 +97,15 @@ { "name": [ "name", - "DA6GXN8J" + "O6YSH0DS" ], - "file": "#0xa" + "file": "#0x2" } ] } }, "cache": { - "#0x9": [ + "0x1": [ "trans", [ [ @@ -125,7 +125,7 @@ ] ] ], - "#0xa": [ + "0x2": [ "path", "Assets/TestAsset.obj" ]