Skip to content

Commit

Permalink
fix: Build compiler error by moving required const keyword name to a …
Browse files Browse the repository at this point in the history
…class not hidden by preprocessor directives (fixes #265)
  • Loading branch information
atteneder committed Oct 28, 2021
1 parent 93deb42 commit 933953f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Runtime/Scripts/Export/StandardMaterialExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal static bool ConvertMaterial(UnityEngine.Material uMaterial, out Materia
}
if (
uMaterial.HasProperty(k_BumpMap)
&& (uMaterial.IsKeywordEnabled( BuiltInMaterialGenerator.KW_NORMALMAP)
&& (uMaterial.IsKeywordEnabled( Materials.Constants.kwNormalMap)
|| uMaterial.IsKeywordEnabled(k_KeywordBumpMap))
)
{
Expand Down Expand Up @@ -343,8 +343,8 @@ IGltfWritable gltf
// texCoord = 0 // TODO: figure out which UV set was used
};

if (material.HasProperty(MaterialGenerator.PROP_BUMP_SCALE)) {
info.scale = material.GetFloat(MaterialGenerator.PROP_BUMP_SCALE);
if (material.HasProperty(MaterialGenerator.bumpScalePropId)) {
info.scale = material.GetFloat(MaterialGenerator.bumpMapPropId);
}

return info;
Expand Down
3 changes: 1 addition & 2 deletions Runtime/Scripts/Material/BuiltInMaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class BuiltInMaterialGenerator : MaterialGenerator {
public const string KW_ALPHATEST_ON = "_ALPHATEST_ON";
public const string KW_EMISSION = "_EMISSION";
public const string KW_METALLIC_ROUGNESS_MAP = "_METALLICGLOSSMAP";
public const string KW_NORMALMAP = "_NORMALMAP";
public const string KW_OCCLUSION = "_OCCLUSION";
public const string KW_SPEC_GLOSS_MAP = "_SPECGLOSSMAP";

Expand Down Expand Up @@ -248,7 +247,7 @@ IGltfReadable gltf
bumpMapRotationPropId,
bumpMapUVChannelPropId
)) {
material.EnableKeyword(KW_NORMALMAP);
material.EnableKeyword(Constants.kwNormalMap);
material.SetFloat(bumpScalePropId,gltfMaterial.normalTexture.scale);
}

Expand Down
26 changes: 26 additions & 0 deletions Runtime/Scripts/Material/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020-2021 Andreas Atteneder
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

namespace GLTFast.Materials {

/// <summary>
/// Contains material related constant variables that are required for both
/// import (glTF to Unity) and export (Unity to glTF) material conversions.
/// TODO: Make const var location consistent
/// </summary>
public static class Constants {
public const string kwNormalMap = "_NORMALMAP";
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Material/Constants.cs.meta

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

2 changes: 0 additions & 2 deletions Runtime/Scripts/Material/MaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ protected enum MaterialType {
public const string KW_UV_ROTATION = "_UV_ROTATION";
public const string KW_UV_CHANNEL_SELECT = "_UV_CHANNEL_SELECT";

internal const string PROP_BUMP_SCALE = "_BumpScale";

public static readonly int bumpMapPropId = Shader.PropertyToID("_BumpMap");
public static readonly int bumpMapRotationPropId = Shader.PropertyToID("_BumpMapRotation");
public static readonly int bumpMapScaleTransformPropId = Shader.PropertyToID("_BumpMap_ST");
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public override Material GenerateMaterial(Schema.Material gltfMaterial, IGltfRea
bumpMapRotationPropId,
bumpMapUVChannelPropId
)) {
// material.EnableKeyword(KW_NORMALMAP);
// material.EnableKeyword(Constants.kwNormalMap);
material.SetFloat(bumpScalePropId,gltfMaterial.normalTexture.scale);
}

Expand Down

0 comments on commit 933953f

Please sign in to comment.