Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#1.1.7
- Updated gltfast to 6.16.1

#1.1.5
- Updated gltfast to 5.0.0

Expand Down
34 changes: 16 additions & 18 deletions Runtime/GLTFastWrappers/DecentralandMaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public DecentralandMaterialGenerator(string shaderName, bool preserveMaxAlpha =
/// <param name="gltfMaterial"></param>
/// <param name="gltf"></param>
/// <returns></returns>
public override Material GenerateMaterial(int materialIndex, GLTFastMaterial gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
public override Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
{
material = new Material(_shader);

SetMaterialName(materialIndex, gltfMaterial);
SetMaterialName(gltfMaterial);

if (gltfMaterial.extensions?.KHR_materials_pbrSpecularGlossiness != null)
if (gltfMaterial.Extensions?.KHR_materials_pbrSpecularGlossiness != null)
{
var specGloss = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
var specGloss = gltfMaterial.Extensions.KHR_materials_pbrSpecularGlossiness;

SetColor(specGloss.DiffuseColor.gamma);
SetSpecularColor(specGloss.SpecularColor);
Expand All @@ -56,21 +56,21 @@ public override Material GenerateMaterial(int materialIndex, GLTFastMaterial glt
// (according to extension specification)
else
{
PbrMetallicRoughness roughness = gltfMaterial.pbrMetallicRoughness;
PbrMetallicRoughnessBase roughness = gltfMaterial.PbrMetallicRoughness;

if (roughness != null)
{
SetColor(roughness.BaseColor.gamma);
SetBaseMapTexture(roughness.baseColorTexture, gltf);
SetBaseMapTexture(roughness.BaseColorTexture, gltf);
SetMetallic(roughness.metallicFactor);
SetMetallicRoughnessTexture(gltf, roughness.metallicRoughnessTexture, roughness.roughnessFactor);
SetMetallicRoughnessTexture(gltf, roughness.MetallicRoughnessTexture, roughness.roughnessFactor);
}
}

SetBumpMapTexture(gltfMaterial.normalTexture, gltf);
SetOcclusionTexture(gltfMaterial.occlusionTexture, gltf);
SetBumpMapTexture(gltfMaterial.NormalTexture, gltf);
SetOcclusionTexture(gltfMaterial.OcclusionTexture, gltf);
SetEmissiveColor(gltfMaterial.Emissive);
SetEmissiveTexture(gltfMaterial.emissiveTexture, gltf);
SetEmissiveTexture(gltfMaterial.EmissiveTexture, gltf);

SetAlphaMode(gltfMaterial.GetAlphaMode(), gltfMaterial.alphaCutoff);
SetDoubleSided(gltfMaterial.doubleSided);
Expand All @@ -79,7 +79,7 @@ public override Material GenerateMaterial(int materialIndex, GLTFastMaterial glt
}

// This step is important if we want to keep the functionality of skin and hair colouring
private void SetMaterialName(int materialIndex, GLTFastMaterial gltfMaterial)
private void SetMaterialName(MaterialBase gltfMaterial)
{
material.name = "material";

Expand All @@ -93,8 +93,6 @@ private void SetMaterialName(int materialIndex, GLTFastMaterial gltfMaterial)
if (originalName.Contains("hair"))
material.name += "_hair";
}

material.name += $"_{materialIndex}";
}

private void SetEmissiveColor(Color gltfMaterialEmissive)
Expand All @@ -107,7 +105,7 @@ private void SetEmissiveColor(Color gltfMaterialEmissive)
}
}

private void SetEmissiveTexture(TextureInfo emissiveTexture, IGltfReadable gltf)
private void SetEmissiveTexture(TextureInfoBase emissiveTexture, IGltfReadable gltf)
{
if (TrySetTexture(
emissiveTexture,
Expand All @@ -124,7 +122,7 @@ private void SetEmissiveTexture(TextureInfo emissiveTexture, IGltfReadable gltf)
}
}

private void SetOcclusionTexture(OcclusionTextureInfo occlusionTexture, IGltfReadable gltf)
private void SetOcclusionTexture(OcclusionTextureInfoBase occlusionTexture, IGltfReadable gltf)
{
if (TrySetTexture(
occlusionTexture,
Expand All @@ -141,7 +139,7 @@ private void SetOcclusionTexture(OcclusionTextureInfo occlusionTexture, IGltfRea
}
}

private void SetBumpMapTexture(NormalTextureInfo textureInfo, IGltfReadable gltf)
private void SetBumpMapTexture(NormalTextureInfoBase textureInfo, IGltfReadable gltf)
{
if (TrySetTexture(
textureInfo,
Expand All @@ -159,7 +157,7 @@ private void SetBumpMapTexture(NormalTextureInfo textureInfo, IGltfReadable gltf
}
}

private void SetMetallicRoughnessTexture(IGltfReadable gltf, TextureInfo textureInfo, float roughnessFactor)
private void SetMetallicRoughnessTexture(IGltfReadable gltf, TextureInfoBase textureInfo, float roughnessFactor)
{
if (TrySetTexture(
textureInfo,
Expand Down Expand Up @@ -204,7 +202,7 @@ private void SetSpecularMapTexture(TextureInfo textureInfo, IGltfReadable gltf)
}
}

private void SetBaseMapTexture(TextureInfo textureInfo, IGltfReadable gltf)
private void SetBaseMapTexture(TextureInfoBase textureInfo, IGltfReadable gltf)
{
TrySetTexture(
textureInfo,
Expand Down
18 changes: 9 additions & 9 deletions Runtime/GLTFastWrappers/DefaultMaterialGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using GLTFast;
using GLTFast.Materials;
using GLTFast.Schema;
using System;
using UnityEngine;
using Material = UnityEngine.Material;

namespace DCL.GLTFast.Wrappers
{
Expand All @@ -13,28 +15,26 @@ internal class DefaultMaterialGenerator : ShaderGraphMaterialGenerator
{
private const float CUSTOM_EMISSIVE_FACTOR = 5f;

public override Material GenerateMaterial(int materialIndex, global::GLTFast.Schema.Material gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
public override Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
{
Material generatedMaterial = base.GenerateMaterial(materialIndex, gltfMaterial, gltf);
Material generatedMaterial = base.GenerateMaterial(gltfMaterial, gltf, pointsSupport);

SetMaterialName(generatedMaterial, materialIndex, gltfMaterial);
SetMaterialName(generatedMaterial, gltfMaterial);

if (gltfMaterial.Emissive != Color.black) { generatedMaterial.SetColor(EmissiveFactorProperty, gltfMaterial.Emissive * CUSTOM_EMISSIVE_FACTOR); }
if (gltfMaterial.Emissive != Color.black) { generatedMaterial.SetColor(MaterialProperty.EmissiveFactor, gltfMaterial.Emissive * CUSTOM_EMISSIVE_FACTOR); }

return generatedMaterial;

// This step is important if we want to keep the functionality of skin and hair colouring
void SetMaterialName(Material material, int materialIndex, global::GLTFast.Schema.Material gltfMaterial)
void SetMaterialName(Material material, MaterialBase materialBase)
{
material.name = "material";

if (gltfMaterial.name.Contains("skin", StringComparison.InvariantCultureIgnoreCase))
if (materialBase.name.Contains("skin", StringComparison.InvariantCultureIgnoreCase))
material.name += "_skin";

if (gltfMaterial.name.Contains("hair", StringComparison.InvariantCultureIgnoreCase))
if (materialBase.name.Contains("hair", StringComparison.InvariantCultureIgnoreCase))
material.name += "_hair";

material.name += $"_{materialIndex}";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.decentraland.unity-shared-dependencies",
"version": "1.1.6",
"version": "1.1.7",
"displayName": "Decentraland.SharedDependencies",
"description": "This package contains shared dependencies between unity-renderer, aang-renderer and asset-bundle-converter repositories, this includes gltf importer wrappers, shaders and wearable utils",
"unity": "2021.3",
Expand Down