The anatomy of a delta file: does it need to be as large as it is?

Because checkCollisions didn’t work so well with every mesh in my scene, I opted to wrap the problematic ones with invisible cube meshes and use those instead.

To do that, I used the Inspector, or more specifically, its handy feature for recording and exporting delta files. I spawned the required number of cubes from the code, then went into the Inspector and painstakingly repositioned and resized them (and hid them and enabled checkCollisions). Once that was done, I downloaded the delta file and applied it:

private CreateColliders() {
  // For more complex meshes, it's better to wrap them manually
  // in a cube collider.
  const colliderRoot = new TransformNode("colliders", this.scene);

  for (let i = 0; i < 25; i++) {
    const box = MeshBuilder.CreateBox(`collider_box_test${i}`, {
      width: 1,
      height: 1,
    });
    box.setParent(colliderRoot);
  }

  // This was added after the delta file was created in the Inspector.
  const delta = JSON.parse(mallCollidersDelta);
  SceneRecorder.ApplyDelta(delta, this.scene);

  // For the simpler ones, enable collisions on them automatically.
  for (let mesh of this.scene.meshes) {
    if (COLLISION_MESHES.includes(mesh.name) || mesh.name == "door store")
      mesh.checkCollisions = true;
  }
}

This works. However, the generated delta file is massive: once formatted, it takes up over 500 lines. That seems like a lot for 15-30 cubes. I took a look, and indeed, it contains everything from my cameras, to my materials, multi-materials, etc.

{
  "cameras": [
    {
      "rotation": [-0.1001121247834017, 3.14355046134856, 0],
      "position": [0.35, 1.481, 56.8],
      "maxZ": 15000,
      "__state": { "id": "universal_camera" }
    },
    {
      "ellipsoid": [0.3, 0.7, 0.3],
      "checkCollisions": true,
      "applyGravity": true,
      "rotation": [-0.1001121247834017, 3.14355046134856, 0],
      "position": [0.35, 1.481, 56.8],
      "maxZ": 15000,
      "cameraRigMode": 0,
      "name": "universal_camera",
      "id": "universal_camera",
      "type": "UniversalCamera",
      "__state": { "id": "universal_camera" }
    },
    {
      "rotation": [-0.1001121247834017, 3.14355046134856, 0],
      "position": [0.35, 1.481, 56.8],
      "maxZ": 15000,
      "name": "universal_camera",
      "id": "universal_camera",
      "type": "UniversalCamera",
      "__state": { "id": "universal_camera" }
    }
  ],
  "materials": [
    {
      "useSpecularOverAlpha": true,
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "useSpecularOverAlpha": true,
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "useSpecularOverAlpha": true,
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "alpha": 1,
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "emissive": [0, 0, 0],
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "alpha": 1,
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "maxSimultaneousLights": 4,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "alpha": 1,
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "customType": "BABYLON.PBRMaterial",
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "emissive": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    },
    {
      "ambient": [0, 0, 0],
      "disableLighting": true,
      "twoSidedLighting": true,
      "id": "skyBox",
      "name": "skyBox",
      "backFaceCulling": false,
      "__state": { "id": "skyBox" }
    }
  ],
  "multiMaterials": [
    {
      "name": "Material #396",
      "id": "5540373e-e13c-4b1a-8f23-394f84354917",
      "__state": { "id": "5540373e-e13c-4b1a-8f23-394f84354917" }
    },
    {
      "name": "Material #396",
      "id": "5540373e-e13c-4b1a-8f23-394f84354917",
      "materials": [
        "b4198795-49e2-497f-b80a-1ecaae9a49bb",
        "28ff8910-881a-4389-b81c-0dfd3b2330b4"
      ],
      "__state": { "id": "5540373e-e13c-4b1a-8f23-394f84354917" }
    },
    {
      "name": "Material #396",
      "id": "5540373e-e13c-4b1a-8f23-394f84354917",
      "materials": [
        "b4198795-49e2-497f-b80a-1ecaae9a49bb",
        "28ff8910-881a-4389-b81c-0dfd3b2330b4"
      ],
      "__state": { "id": "5540373e-e13c-4b1a-8f23-394f84354917" }
    }
  ],
  "transformNodes": [
    {
      "position": [30, 0, 85],
      "scaling": [2, 2, 2],
      "name": "environment_model",
      "id": "environment_model",
      "__state": { "id": "environment_model" }
    }
  ],
  "meshes": [
    {
      "position": [39.8, 2.5, -8.87],
      "scaling": [58, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test0" }
    },
    {
      "position": [39.8, 2.5, 7.557],
      "scaling": [58, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test1" }
    },
    {
      "position": [-41.067, 0.409, -0.628],
      "scaling": [4, 1, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test2" }
    },
    {
      "position": [0.4208763539791107, 0.40122804045677185, -37.224],
      "scaling": [1, 1, 4],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test3" }
    },
    {
      "position": [
        0.41796523332595825, 0.40043574571609497, -45.741493225097656
      ],
      "scaling": [1, 1, 4],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test4" }
    },
    {
      "position": [69.373, 2.5, -0.65828537940979],
      "scaling": [1, 5, 17],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test5" }
    },
    {
      "position": [-68.28800964355469, 2.5, -0.6856837868690491],
      "scaling": [1, 5, 15],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test6" }
    },
    {
      "position": [0, 2.5, 63.9782829284668],
      "scaling": [15, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test7" }
    },
    {
      "position": [0.554198145866394, 2.5, -64.49107360839844],
      "scaling": [15, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test8" }
    },
    {
      "position": [0.6123590469360352, 0.9582553505897522, -0.6577818989753723],
      "rotation": [0, 0.785398156308485, 0],
      "scaling": [9.200000213440973, 2, 9.200000213440973],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test9" }
    },
    {
      "position": [-39.50033187866211, 2.5, -8.869999885559082],
      "scaling": [60, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test10" }
    },
    {
      "position": [-39.10319519042969, 2.5, 7.557000160217285],
      "scaling": [58, 5, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test11" }
    },
    {
      "position": [7.283, 2.5, 37.538],
      "scaling": [1, 5, 53],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test12" }
    },
    {
      "position": [-6.176000118255615, 2.5, 37.538],
      "scaling": [1, 5, 52],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test13" }
    },
    {
      "position": [7.283, 2.5, -38.366],
      "scaling": [1, 5, 52],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test14" }
    },
    {
      "position": [-6.176000118255615, 2.5, -38.366],
      "scaling": [1, 5, 52.5],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test15" }
    },
    {
      "position": [-8.231, 2.5, 9.646653175354004],
      "rotation": [0, 0.7853981439639591, 0],
      "scaling": [0.999999982885729, 5, 6.2999999849031685],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test16" }
    },
    {
      "position": [9.139408111572266, 2.5, -10.722980499267578],
      "rotation": [0, 0.785398156308485, 0],
      "scaling": [0.999999982885729, 5, 5.699999809725588],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test17" }
    },
    {
      "position": [9.125628471374512, 2.5, 9.35754108428955],
      "rotation": [0, 0.7928117710287251, 0],
      "scaling": [5.64, 5, 0.9999998995619691],
      "checkCollisions": true,
      "__state": { "id": "collider_box_test18" }
    },
    {
      "position": [-7.980129241943359, 2.5, -10.563694953918457],
      "rotation": [0, 0.7714355311311498, 0],
      "scaling": [5.530000058505466, 5, 1.0000000577398893],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test19" }
    },
    {
      "position": [40.677, 0.4090000092983246, -0.1725575029850006],
      "scaling": [4, 1, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test20" }
    },
    {
      "position": [49.25578308105469, 0.4013468325138092, -0.17464542388916016],
      "scaling": [4, 1, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test21" }
    },
    {
      "position": [0.6950069069862366, 0.40078896284103394, 32.436],
      "scaling": [1, 1, 4],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test22" }
    },
    {
      "position": [0.687580406665802, 0.40305960178375244, 40.92949295043945],
      "scaling": [1, 1, 4],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test23" }
    },
    {
      "position": [-32.576, 0.40457624197006226, -0.6409369707107544],
      "scaling": [4, 1, 1],
      "visibility": 0,
      "checkCollisions": true,
      "__state": { "id": "collider_box_test24" }
    },
    {
      "position": [0, 0.39349600021435605, 0],
      "__state": { "id": "torusTeleportation" }
    },
    {
      "instances": [
        {
          "name": "Box230",
          "id": "3ea20fcc-0981-4159-985a-cb9b50d8a51d",
          "isEnabled": true,
          "isVisible": true,
          "isPickable": false,
          "checkCollisions": false,
          "position": [0, -1.49, 0],
          "scaling": [1, 1, 1],
          "parentId": "c45c690f-0fd8-45fc-b436-97e4a80bd937",
          "rotationQuaternion": [0, 0, 0, 1],
          "animations": [],
          "ranges": []
        },
        {
          "name": "Box296",
          "id": "4b4bb50a-0d0c-491b-99ed-ecc25b8d7322",
          "isEnabled": true,
          "isVisible": true,
          "isPickable": false,
          "checkCollisions": false,
          "position": [
            9.2482004276917e-8, -1.4900000095367432, -0.012250441126525402
          ],
          "scaling": [1, 1, 1],
          "parentId": "69dcad66-3917-4062-a632-31edebe3f92a",
          "rotationQuaternion": [0, -9.002270229176851e-14, 0, 1],
          "animations": [],
          "ranges": []
        },
        {
          "name": "Box263",
          "id": "a704ccd9-248b-4003-9807-d995a2bf8504",
          "isEnabled": true,
          "isVisible": true,
          "isPickable": false,
          "checkCollisions": false,
          "position": [0, -1.49, 0],
          "scaling": [1, 1, 1],
          "parentId": "5cb7cf84-5056-4257-9eb6-00b722910635",
          "rotationQuaternion": [0, 0, 0, 1],
          "animations": [],
          "ranges": []
        }
      ],
      "__state": { "id": "2417b790-b762-455a-936e-50cf8f6774ec" }
    },
    {
      "position": [-10.912723541259766, 0, -36.88462448120117],
      "__state": { "id": "769667f2-640e-498b-9fd5-9edd8662ffe7" }
    }
  ]
}

Indeed, it seems like it contains data for the entire scene. Unfortunately, it also overrides the transform of the camera—which I used to fly around in the scene to see where to put the cube colliders—so I removed that section from the file. It appears to work fine regardless, raising the question: does it need to describe the whole scene?

If not, is it safe to remove all the unnecessary data (i.e. everything but the transforms of the collider cubes)? And, do I need to keep the code that initially spawns those cubes, or does the delta file make that redundant?

It is safe to remove the unnecessary data if you know that your setup will cover it. So it is up to you:) you can either remove the redundant data or remove your init code :wink:

1 Like