Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-entity-id-to-remote-folder-path
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Oct 3, 2024
2 parents 27d5408 + 8aca86c commit 0650046
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH

# Change this value ONLY if we have done breaking changes for every material, doing so is VERY costly
ENV AB_VERSION=v13
ENV AB_VERSION_WINDOWS=v22
ENV AB_VERSION_MAC=v22
ENV AB_VERSION_WINDOWS=v24
ENV AB_VERSION_MAC=v24

# NODE_ENV is used to configure some runtime options, like JSON logger
ENV NODE_ENV=production
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private async Task ProcessAllGltfs()

string directory = Path.GetDirectoryName(relativePath);

if (textures.Count > 0) { textures = ExtractEmbedTexturesFromGltf(textures, directory); }
if (textures.Count > 0) { textures = ExtractEmbedTexturesFromGltf(textures, gltfImport, directory); }

embedExtractTextureTime.Stop();

Expand Down Expand Up @@ -729,10 +729,30 @@ private static void RefreshAssetsWithNoLogs()
Debug.unityLogger.logEnabled = true;
}

private List<Texture2D> ExtractEmbedTexturesFromGltf(List<Texture2D> textures, string folderName)


private List<Texture2D> ExtractEmbedTexturesFromGltf(List<Texture2D> textures, IGltfImport gltfImport, string folderName)
{
var newTextures = new List<Texture2D>();

TextureTypeManager textTypeMan = new TextureTypeManager();

for (var t = 0; t < gltfImport.MaterialCount; t++)
{

var originalMaterial = gltfImport.GetMaterial(t);
var textureProperties = originalMaterial.GetTexturePropertyNameIDs();
var texturePropertiesNames = originalMaterial.GetTexturePropertyNames();

for (int i = 0; i < textureProperties.Count(); i++)
{
int propertyId = textureProperties[i];
Texture currentTexture = originalMaterial.GetTexture(propertyId);
if (currentTexture)
textTypeMan.AddTextureType(currentTexture.name, TextureInfoExtensions.GetTextureTypeFromString(texturePropertiesNames[i]));
}
}

if (textures.Count > 0)
{
var texturesRoot = $"{folderName}/Textures/";
Expand Down Expand Up @@ -788,12 +808,14 @@ private List<Texture2D> ExtractEmbedTexturesFromGltf(List<Texture2D> textures, s
}
else
{
TextureInfo texInfo = textTypeMan.GetTextureInfo(tex.name);

RenderTexture tmp = RenderTexture.GetTemporary(
tex.width,
tex.height,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Default);
texInfo.HasAnyType(TextureType.BumpMap) ? RenderTextureFormat.RGHalf : RenderTextureFormat.Default,
texInfo.HasAnyType( TextureType.BumpMap | TextureType.MetallicGlossMap | TextureType.OcclusionMap | TextureType.ParallaxMap | TextureType.SpecGlossMap) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default );

Graphics.Blit(tex, tmp);
RenderTexture previous = RenderTexture.active;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using UnityEngine;
using System.Collections.Generic;

[System.Flags]
public enum TextureType
{
None = 0,
MainTex = 1 << 0,
BaseMap = 1 << 1,
BumpMap = 1 << 2,
MetallicGlossMap = 1 << 3,
ParallaxMap = 1 << 4,
OcclusionMap = 1 << 5,
EmissionMap = 1 << 6,
SpecGlossMap = 1 << 7
}

public struct TextureInfo
{
public string Name;
public TextureType Types;

public TextureInfo(string name)
{
Name = name;
Types = TextureType.None;
}
}

public static class TextureInfoExtensions
{
public static TextureType GetTextureTypeFromString(string input)
{
switch (input)
{
case "_MainTex" :
return TextureType.MainTex;
case "_BaseMap" :
return TextureType.BaseMap;
case "_BumpMap" :
return TextureType.BumpMap;
case "_MetallicGlossMap" :
return TextureType.MetallicGlossMap;
case "_ParallaxMap" :
return TextureType.ParallaxMap;
case "_OcclusionMap" :
return TextureType.OcclusionMap;
case "_EmissionMap" :
return TextureType.EmissionMap;
case "_SpecGlossMap" :
return TextureType.SpecGlossMap;
default :
return TextureType.None;
}
}



public static TextureInfo AddType(this TextureInfo info, TextureType type)
{
info.Types |= type;
return info;
}

public static TextureInfo RemoveType(this TextureInfo info, TextureType type)
{
info.Types &= ~type;
return info;
}

public static bool HasType(this TextureInfo info, TextureType type)
{
return (info.Types & type) != 0;
}

public static bool HasAnyType(this TextureInfo info, TextureType types)
{
return (info.Types & types) != 0;
}

public static bool HasAllTypes(this TextureInfo info, TextureType types)
{
return (info.Types & types) == types;
}

public static string GetTypesString(this TextureInfo info)
{
return $"{info.Name}: {info.Types}";
}
}

public class TextureTypeManager : MonoBehaviour
{
private Dictionary<string, TextureInfo> textureInfos = new Dictionary<string, TextureInfo>();

public void AddTextureType(string textureName, TextureType type)
{
if (!textureInfos.TryGetValue(textureName, out TextureInfo info))
{
info = new TextureInfo(textureName);
}
textureInfos[textureName] = info.AddType(type);
}

public TextureInfo GetTextureInfo(string textureName)
{
return textureInfos.TryGetValue(textureName, out TextureInfo info) ? info : new TextureInfo(textureName);
}

public bool HasTextureType(string textureName, TextureType type)
{
return textureInfos.TryGetValue(textureName, out TextureInfo info) && info.HasType(type);
}
}

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

Submodule unity-shared-dependencies updated 30 files
+33 −33 Runtime/Shaders/SceneRendering/Scene.shader
+0 −78 Runtime/Shaders/SceneRendering/SceneVariantsManuallyAdded.shadervariants
+0 −8 Runtime/Shaders/SceneRendering/SceneVariantsManuallyAdded.shadervariants.meta
+32 −4 Runtime/Shaders/SceneRendering/Scene_Clustering.hlsl
+4 −4 Runtime/Shaders/SceneRendering/Scene_Debugging3D.hlsl
+24 −24 Runtime/Shaders/SceneRendering/Scene_DepthNormalsPass.hlsl
+17 −17 Runtime/Shaders/SceneRendering/Scene_ForwardPass.hlsl
+13 −11 Runtime/Shaders/SceneRendering/Scene_Input.hlsl
+2 −2 Runtime/Shaders/SceneRendering/Scene_ShaderVariablesFunctions.hlsl
+8 −8 Runtime/Shaders/SceneRendering/Scene_SurfaceInput.hlsl
+30 −30 Runtime/Shaders/SceneRendering/TexArray/Scene_TexArray.shader
+3 −0 Runtime/Shaders/Unlit.meta
+55 −0 Runtime/Shaders/Unlit/DepthOnlyPass.hlsl
+3 −0 Runtime/Shaders/Unlit/DepthOnlyPass.hlsl.meta
+219 −0 Runtime/Shaders/Unlit/Input.hlsl
+3 −0 Runtime/Shaders/Unlit/Input.hlsl.meta
+19 −0 Runtime/Shaders/Unlit/SurfaceData.hlsl
+3 −0 Runtime/Shaders/Unlit/SurfaceData.hlsl.meta
+64 −0 Runtime/Shaders/Unlit/SurfaceInput.hlsl
+3 −0 Runtime/Shaders/Unlit/SurfaceInput.hlsl.meta
+27 −0 Runtime/Shaders/Unlit/Unlit.hlsl
+3 −0 Runtime/Shaders/Unlit/Unlit.hlsl.meta
+178 −0 Runtime/Shaders/Unlit/Unlit.shader
+3 −0 Runtime/Shaders/Unlit/Unlit.shader.meta
+84 −0 Runtime/Shaders/Unlit/UnlitDepthNormalsPass.hlsl
+3 −0 Runtime/Shaders/Unlit/UnlitDepthNormalsPass.hlsl.meta
+170 −0 Runtime/Shaders/Unlit/UnlitForwardPass.hlsl
+3 −0 Runtime/Shaders/Unlit/UnlitForwardPass.hlsl.meta
+45 −0 Runtime/Shaders/Unlit/UnlitInput.hlsl
+3 −0 Runtime/Shaders/Unlit/UnlitInput.hlsl.meta

0 comments on commit 0650046

Please sign in to comment.