private void ReadVoxel(JSONObject voxelObject, VoxelArray voxelArray, List <Material> materials, List <Substance> substances) { if (voxelObject["at"] == null) { return; } Vector3 position = ReadVector3(voxelObject["at"].AsArray); Voxel voxel = null; if (!editor) { // slightly faster -- doesn't add to octree voxel = voxelArray.InstantiateVoxel(position); } else { voxel = voxelArray.VoxelAt(position, true); } if (voxelObject["s"] != null) { voxel.substance = substances[voxelObject["s"].AsInt]; } if (voxelObject["f"] != null) { foreach (JSONNode faceNode in voxelObject["f"].AsArray) { JSONObject faceObject = faceNode.AsObject; if (fileWriterVersion == 0) { // faces were oriented differently. Get voxel for each face int faceI = faceObject["i"].AsInt; voxel = voxelArray.VoxelAt(position + Voxel.DirectionForFaceI(faceI), true); } ReadFace(faceObject, voxel, materials); } } if (voxelObject["e"] != null) { foreach (JSONNode edgeNode in voxelObject["e"].AsArray) { ReadEdge(edgeNode.AsObject, voxel); } } voxel.UpdateVoxel(); }
private void ReadVoxel(MessagePackObject voxelObj, VoxelArray voxelArray, List <Material> materials, List <Material> overlays, List <Substance> substances) { var voxelList = voxelObj.AsList(); if (voxelList.Count == 0) { return; } Vector3 position = ReadVector3(voxelList[0]); Voxel voxel = null; if (!editor) { // slightly faster -- doesn't add to octree voxel = voxelArray.InstantiateVoxel(position); } else { voxel = voxelArray.VoxelAt(position, true); } if (voxelList.Count >= 2) { foreach (var faceObj in voxelList[1].AsList()) { ReadFace(faceObj, voxel, materials, overlays); } } if (voxelList.Count >= 3 && voxelList[2].AsInt32() != -1) { voxel.substance = substances[voxelList[2].AsInt32()]; } if (voxelList.Count >= 4) { foreach (var edgeObj in voxelList[3].AsList()) { ReadEdge(edgeObj, voxel); } } voxel.UpdateVoxel(); }
private void ReadVoxel(MessagePackObject voxelObj, VoxelArray voxelArray, List <Material> materials, List <Material> overlays, List <Substance> substances) { var voxelList = voxelObj.AsList(); if (voxelList.Count == 0) { return; } Vector3Int position = ReadVector3Int(voxelList[0]); Voxel voxel = null; voxel = voxelArray.VoxelAt(position, true); if (voxelList.Count >= 2) { foreach (var faceObj in voxelList[1].AsList()) { VoxelFace face = ReadFace(faceObj, out int faceI, materials, overlays); if (faceI != -1) { voxel.faces[faceI] = face; } } } if (voxelList.Count >= 3 && voxelList[2].AsInt32() != -1) { voxel.substance = substances[voxelList[2].AsInt32()]; } if (voxelList.Count >= 4) { foreach (var edgeObj in voxelList[3].AsList()) { ReadEdge(edgeObj, voxel); } } voxel.UpdateVoxel(); }