Skip to content

Commit

Permalink
Scene regenarator following manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia committed Dec 14, 2023
1 parent cfa5a33 commit 3c49f6c
Show file tree
Hide file tree
Showing 50 changed files with 1,352 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public enum Step
private List<AssetPath> assetsToMark = new ();
private List<GltfImportSettings> gltfToWait = new ();
private Dictionary<string, string> contentTable = new ();
private Dictionary<string, string> lodContentTable = new ();
private Dictionary<string, string> gltfOriginalNames = new ();
private string logBuffer;
private int totalAssets;
Expand All @@ -100,6 +101,8 @@ public enum Step
private bool isExitForced = false;
private IABLogger log => env.logger;

private SceneLODGenerator sceneLODGenerator;

public AssetBundleConverter(Environment env, ClientSettings settings)
{
this.settings = settings;
Expand All @@ -114,6 +117,7 @@ public AssetBundleConverter(Environment env, ClientSettings settings)
finalDownloadedAssetDbPath = PathUtils.FixDirectorySeparator(Config.ASSET_BUNDLES_PATH_ROOT + Config.DASH);

log.verboseEnabled = true;
sceneLODGenerator = new SceneLODGenerator();
}

/// <summary>
Expand Down Expand Up @@ -196,6 +200,9 @@ public async Task ConvertAsync(IReadOnlyList<ContentServerUtils.MappingPair> raw
return;
}

if (settings.createSceneLOD)
await sceneLODGenerator.GenerateSceneLOD(lodContentTable);

if (settings.createAssetBundle)
{
GC.Collect();
Expand Down Expand Up @@ -942,6 +949,8 @@ private void AddAssetPathsToContentTable(List<AssetPath> assetPaths, bool useHas
string finalKey = useHash ? Utils.EnsureStartWithSlash(assetPath.hashPath) : Utils.EnsureStartWithSlash(assetPath.filePath);
finalKey = finalKey.ToLower();
contentTable[finalKey] = relativeFinalPath;

lodContentTable[assetPath.filePath] = relativeFinalPath;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class AssetBundleSceneConversionWindow : EditorWindow
private string batchModeParams = "";
private string baseUrl;
private bool placeOnScene = true;
private bool createSceneLOD = false;
private bool visualTest = false;
private bool clearDownloads = true;
private bool createAssetBundle = true;
Expand Down Expand Up @@ -85,6 +86,8 @@ private void OnGUI()

visualTest = EditorGUILayout.Toggle("Visual Test", visualTest);
placeOnScene = EditorGUILayout.Toggle("Place on Scene", placeOnScene);
createSceneLOD = EditorGUILayout.Toggle("Create Scene LOD", createSceneLOD);

createAssetBundle = EditorGUILayout.Toggle("Create Asset Bundle", createAssetBundle);
clearDownloads = EditorGUILayout.Toggle("Clear Downloads", clearDownloads);
includeShaderVariants = EditorGUILayout.Toggle("Include Shader Variants", includeShaderVariants);
Expand Down Expand Up @@ -314,6 +317,7 @@ private void SetupSettings()
includeShaderVariants = includeShaderVariants,
importGltf = importGltf,
placeOnScene = placeOnScene,
createSceneLOD = createSceneLOD,
verbose = verbose,
buildTarget = GetBuildTarget(),
BuildPipelineType = buildPipelineType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ClientSettings
public bool visualTest = true;
public bool createAssetBundle = true;
public bool placeOnScene = true;
public bool createSceneLOD = false;
public string importOnlyEntity;

public ShaderType shaderType = ShaderType.Dcl;
Expand Down
8 changes: 8 additions & 0 deletions asset-bundle-converter/Assets/AssetBundleConverter/LODs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// unset:none
using System;

namespace AssetBundleConverter.LODs.JsonParsing
{
[Serializable]
public class GLTFContainerData : ComponentData
{
public DCLGLTFMesh mesh;

public GLTFContainerData(DCLGLTFMesh mesh)
{
this.mesh = mesh;
}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace AssetBundleConverter.LODs.JsonParsing
{
[Serializable]
public class MaterialData : ComponentData
{
public DCLMaterial material;
}


}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// unset:none
using System;
using System.Collections.Generic;
using Unity.Plastic.Newtonsoft.Json;
using UnityEngine;
using Utility.Primitives;

namespace AssetBundleConverter.LODs.JsonParsing
{
[Serializable]
public class MeshRendererData : ComponentData
{
public DCLMesh mesh;
}

[JsonConverter(typeof(MeshRendererDataConverter))]
[Serializable]
public abstract class DCLMesh
{
public abstract void InstantiateMesh(Transform parent, DCLMaterial material, Dictionary<string, string> contentTable);
}



}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// unset:none
using System;
using Unity.Plastic.Newtonsoft.Json;
using Unity.Plastic.Newtonsoft.Json.Linq;

namespace AssetBundleConverter.LODs.JsonParsing
{
public class MaterialDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
(objectType == typeof(DCLMaterial));

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jsonObject = JObject.Load(reader);
DCLMaterial dclMaterial = null;
switch (jsonObject["$case"].Value<string>())
{
case MaterialConstants.PBR:
dclMaterial = new PBRMaterial();
serializer.Populate(jsonObject["pbr"].CreateReader(), dclMaterial);
break;
case MaterialConstants.Unlit:
dclMaterial = new UnlitMaterial();
serializer.Populate(jsonObject["unlit"].CreateReader(), dclMaterial);
break;
}
return dclMaterial;
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Unity.Plastic.Newtonsoft.Json;
using Unity.Plastic.Newtonsoft.Json.Linq;

namespace AssetBundleConverter.LODs.JsonParsing
{
public class MeshRendererDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
(objectType == typeof(MeshRendererData));


public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jsonObject = JObject.Load(reader);

DCLMesh dclMesh = null;
switch (jsonObject["$case"].Value<string>())
{
case MeshConstants.Box:
dclMesh = new Box();
serializer.Populate(jsonObject["box"].CreateReader(), dclMesh);
break;
case MeshConstants.Cylinder:
dclMesh = new Cylinder();
serializer.Populate(jsonObject["cylinder"].CreateReader(), dclMesh);
break;
}

return dclMesh;
}


public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// unset:none
using System;
using Unity.Plastic.Newtonsoft.Json;
using Unity.Plastic.Newtonsoft.Json.Linq;

namespace AssetBundleConverter.LODs.JsonParsing
{
public class RenderableEntityDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
(objectType == typeof(RenderableEntity));

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jsonObject = JObject.Load(reader);

RenderableEntity renderableEntity = new RenderableEntity();
renderableEntity.entityId = jsonObject["entityId"].Value<int>();
renderableEntity.componentName = jsonObject["componentName"].Value<string>();
renderableEntity.componentId = jsonObject["componentId"].Value<int>();

ComponentData componentData = null;
switch (renderableEntity.componentName)
{
case RenderableEntityConstants.Transform:
componentData = new TransformData();
break;
case RenderableEntityConstants.Material:
componentData = new MaterialData();
break;
case RenderableEntityConstants.GLTFContainer:
componentData = new GLTFContainerData(new DCLGLTFMesh(jsonObject["data"]["src"].Value<string>()));
break;
case RenderableEntityConstants.MeshRenderer:
componentData = new MeshRendererData();
break;
}

if (componentData != null)
serializer.Populate(jsonObject["data"].CreateReader(), componentData);

renderableEntity.data = componentData;

return renderableEntity;
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// unset:none
using System;
using Unity.Plastic.Newtonsoft.Json;
using Unity.Plastic.Newtonsoft.Json.Linq;

namespace AssetBundleConverter.LODs.JsonParsing
{
public class TextureDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
(objectType == typeof(Texture));

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jsonObject = JObject.Load(reader);
Texture texture = new Texture();
texture.src = jsonObject["texture"]["src"].Value<string>();
return texture;
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// unset:none
namespace AssetBundleConverter.LODs.JsonParsing
{
public class RenderableEntityConstants
{
public const string Transform = "core::Transform";
public const string Material = "core::Material";
public const string GLTFContainer = "core::GltfContainer";
public const string MeshRenderer = "core::MeshRenderer";
}

public class MeshConstants
{
public const string Box = "box";
public const string Cylinder = "cylinder";
}

public class MaterialConstants
{
public const string PBR = "pbr";
public const string Unlit = "unlit";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c49f6c

Please sign in to comment.