Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,23 @@
<Material MtlFlags="524544" vertModifType="0">
<SubMaterials>
<Material Name="Block_01" MtlFlags="524416" Shader="Illum" GenMask="80000001" StringGenMask="%ALLOW_SILHOUETTE_POM%SUBSURFACE_SCATTERING" SurfaceType="mat_wood" MatTemplate="" Diffuse="0.016807377,0.12743771,0.016807377" Specular="0,0,0" Emissive="0,0,0" Opacity="1" Shininess="10" CloakAmount="0" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="textures/gettingstartedtextures/white.tif"/>
</Textures>
<PublicParams SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
<Material Name="Block_02" MtlFlags="524416" Shader="Illum" GenMask="80000001" StringGenMask="%ALLOW_SILHOUETTE_POM%SUBSURFACE_SCATTERING" SurfaceType="mat_wood" MatTemplate="" Diffuse="0.12743771,0.016807377,0.016807377" Specular="0,0,0" Emissive="0,0,0" Opacity="1" Shininess="10" CloakAmount="0" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="textures/gettingstartedtextures/white.tif"/>
</Textures>
<PublicParams SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
<Material Name="Block_03" MtlFlags="524416" Shader="Illum" GenMask="80000001" StringGenMask="%ALLOW_SILHOUETTE_POM%SUBSURFACE_SCATTERING" SurfaceType="mat_wood" MatTemplate="" Diffuse="0.016807377,0.016807377,0.12743771" Specular="0,0,0" Emissive="0,0,0" Opacity="1" Shininess="10" CloakAmount="0" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="textures/gettingstartedtextures/white.tif"/>
</Textures>
<PublicParams SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
</SubMaterials>
<PublicParams SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c02e949b50a340cb7507c14ce7b01933ed471f03d8d11f3d191f0063c85fca2e
size 33820
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7acc775dee00c5ae3be27578ca8722935b6afbaaa53348667291ad57c3f76b62
size 2948
@@ -0,0 +1,12 @@
<Material MtlFlags="557312" DccMaterialHash="0" vertModifType="0">
<SubMaterials>
<Material Name="Grass_Atlas" MtlFlags="524416" DccMaterialHash="0" Shader="Vegetation" GenMask="2400201000" StringGenMask="%DETAIL_BENDING%GRASS%TEMP_VEGETATION%VERTCOLORS" SurfaceType="mat_default" Diffuse="1,1,1,1" Specular="0,0,0,1" Opacity="1" Shininess="10" AlphaTest="0.46000001" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="objects/natural/vegetation/grass_atlas_diff.dds">
<TexMod TexMod_RotateType="0" TexMod_TexGenType="0" TexMod_bTexGenProjected="0"/>
</Texture>
</Textures>
<PublicParams bendDetailLeafAmplitude="0.2" bendDetailFrequency="1" bendDetailBranchAmplitude="-0.5" BlendTerrainCol="0" NormalViewDependency="0.5" TransmittanceColor="1,1,0.60000002" BackDiffuseMultiplier="1" BlendTerrainColDist="0.5" IndirectColor="0.25,0.25,0.25"/>
</Material>
</SubMaterials>
</Material>
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3ba56813f5d8e5c73e7d245154e130ed8fbb43dd4891fac0b9977f9383db62dd
size 2440
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:35452caba31ce0de0c53bd811e5c35e826e9b4b7c058458199ae83b0553ed8e9
size 28088
@@ -0,0 +1,13 @@
<Material MtlFlags="524544" vertModifType="0">
<SubMaterials>
<Material Name="primitives_default_001_mat" MtlFlags="524416" Shader="Illum" GenMask="80000001" StringGenMask="%ALLOW_SILHOUETTE_POM%SUBSURFACE_SCATTERING" SurfaceType="" Diffuse="1,1,1" Specular="0.5,0.5,0.5" Emissive="0,0,0" Opacity="1" Shininess="10" vertModifType="0" LayerAct="1">
<Textures>
<Texture Map="Diffuse" File="primitives_001_diff.tif"/>
</Textures>
<PublicParams SSSIndex="0" IndirectColor="0.25,0.25,0.25"/>
</Material>
<Material Name="primitives_proxy_001_mat" MtlFlags="525440" Shader="Nodraw" GenMask="0" StringGenMask="" SurfaceType="mat_nodraw" Diffuse="1,0,0" Specular="0.5,0.5,0.5" Emissive="0,0,0" Opacity="1" Shininess="10" vertModifType="0" LayerAct="1">
<Textures />
</Material>
</SubMaterials>
</Material>
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a44a5b1b222256a1904ea8da54cfb70db6cc1944b42a15a3ab0a78443e7a4252
size 812376
@@ -0,0 +1,304 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "ResourceCompilerPC_precompiled.h"
#include <AzTest/AzTest.h>
#include <AzTest/Utils.h>
#include <AzCore/IO/Path/Path.h>
#include <AzFramework/IO/LocalFileIO.h>
#include <AssetBuilderSDK/AssetBuilderSDK.h>
#include <AzCore/Component/ComponentApplication.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
#include "../CryEngine/Cry3DEngine/CGF/CGFLoader.h"
#include "StatCGFCompiler.h"
#include "MultiplatformConfig.h"
#include <QTemporaryDir>
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
AZStd::string GetTestAssetRootPath()
{
char resolvedDir[AZ_MAX_PATH_LEN];
AZ::IO::FileIOBase::GetInstance()->ResolvePath(
"@engroot@/Code/Tools/RC/ResourceCompilerPC/Tests/TestAssets/SamplesProject/",
resolvedDir, sizeof(resolvedDir));
return AZStd::string(resolvedDir);
}
// This is a dummy ResourceCompiler object overload.
// The CGF compiler is heavily dependent upon a ResourceCompiler object existing, so this overload
// just does the minimum amount of work to allow the CGF compiler to query it for default values and
// specific values needed for our test cases.
class ResourceCompilerForTesting
: public IResourceCompiler
, public IConfigKeyRegistry
{
public:
ResourceCompilerForTesting()
{
platformInfo.SetName(0, "pc");
platformInfo.bBigEndian = false;
}
virtual ~ResourceCompilerForTesting() {}
//IConfigKeyRegistry
virtual void VerifyKeyRegistration([[maybe_unused]] const char* szKey) const {}
virtual bool HasKeyRegistered([[maybe_unused]] const char* szKey) const { return false; }
//IResourceCompiler
virtual void RegisterConvertor([[maybe_unused]] const char* name, [[maybe_unused]] IConvertor* conv) {}
virtual IPakSystem* GetPakSystem() { return nullptr; }
virtual const ICfgFile* GetIniFile() const { return nullptr; }
virtual int GetPlatformCount() const { return 1; }
virtual const PlatformInfo* GetPlatformInfo([[maybe_unused]] int index) const { return &platformInfo; }
virtual int FindPlatform([[maybe_unused]] const char* name) const { return 0; }
virtual void AddInputOutputFilePair([[maybe_unused]] const char* inputFilename, [[maybe_unused]] const char* outputFilename) {}
virtual void MarkOutputFileForRemoval([[maybe_unused]] const char* sOutputFilename) {}
virtual void AddExitObserver([[maybe_unused]] IExitObserver* p) {}
virtual void RemoveExitObserver([[maybe_unused]] IExitObserver* p) {}
virtual IRCLog* GetIRCLog() { return nullptr; }
virtual int GetVerbosityLevel() const { return 0; }
virtual const SFileVersion& GetFileVersion() const { return fileVersionInfo; }
virtual const void GetGenericInfo([[maybe_unused]] char* buffer, [[maybe_unused]] size_t bufferSize, [[maybe_unused]] const char* rowSeparator) const {}
virtual void RegisterKey([[maybe_unused]] const char* key, [[maybe_unused]] const char* helptxt) {}
virtual const char* GetExePath() const { return nullptr; }
virtual const char* GetTmpPath() const { return nullptr; }
virtual const char* GetInitialCurrentDir() const { return nullptr; }
virtual XmlNodeRef LoadXml([[maybe_unused]] const char* filename) { XmlNodeRef tmp; return tmp; }
virtual XmlNodeRef CreateXml([[maybe_unused]] const char* tag) { XmlNodeRef tmp; return tmp; }
virtual bool CompileSingleFileBySingleProcess([[maybe_unused]] const char* filename) { return true; }
virtual void SetAssetWriter([[maybe_unused]] IAssetWriter* pAssetWriter) {}
virtual IAssetWriter* GetAssetWriter() const { return nullptr; }
virtual const char* GetAppRoot() const { return nullptr; }
SFileVersion fileVersionInfo;
PlatformInfo platformInfo;
MultiplatformConfig localMultiConfig;
};
class CGFBuilderTest
: public ::testing::Test
{
protected:
AZStd::string GetTemporaryDirectory()
{
QString tempPath = m_temporaryDirectory.path();
return AZStd::string(tempPath.toUtf8().constData());
}
void SetUp() override
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
AZ::AllocatorInstance<AZ::LegacyAllocator>::Create();
AZ::AllocatorInstance<CryStringAllocator>::Create();
m_app.reset(aznew AzToolsFramework::ToolsApplication());
AZ::ComponentApplication::Descriptor desc;
desc.m_useExistingAllocator = true;
m_app->Start(desc);
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
// in the unit tests.
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
AssetBuilderSDK::InitializeSerializationContext();
const AZStd::string engroot = AZ::Test::GetEngineRootPath();
AZ::IO::FileIOBase::GetInstance()->SetAlias("@engroot@", engroot.c_str());
AZ::IO::Path assetRoot(engroot);
assetRoot /= "Cache";
AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str());
m_rc = new ResourceCompilerForTesting();
m_compiler = new CStatCGFCompiler();
m_rc->localMultiConfig.init(1, 0, m_rc);
m_rc->localMultiConfig.setActivePlatform(0);
}
void TearDown() override
{
delete m_compiler;
delete m_rc;
m_compiler = nullptr;
m_rc = nullptr;
m_app->Stop();
m_app = nullptr;
AZ::AllocatorInstance<CryStringAllocator>::Destroy();
AZ::AllocatorInstance<AZ::LegacyAllocator>::Destroy();
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
}
void LoadCompileAndValidateCGF(const AZStd::string& cgfName, const AZStd::string& cgfPath, const AZStd::string& outputPath, AssetBuilderSDK::ProcessJobResponse& response);
AZStd::unique_ptr<AzToolsFramework::ToolsApplication> m_app;
QTemporaryDir m_temporaryDirectory;
CStatCGFCompiler* m_compiler = nullptr;
ResourceCompilerForTesting* m_rc = nullptr;
};
void CGFBuilderTest::LoadCompileAndValidateCGF(const AZStd::string& cgfName, const AZStd::string& cgfPath, const AZStd::string& outputPath, AssetBuilderSDK::ProcessJobResponse& response)
{
// Pass in a custom asset root to the CGF compiler because our test assets are not going through AP
AZStd::string assetRoot(GetTestAssetRootPath());
// Our test assets came from SamplesProject, so emulate that being our game project
AZStd::string gameFolder = "SamplesProject";
IConvertContext* const pCC = m_compiler->GetConvertContext();
pCC->SetMultiplatformConfig(&m_rc->localMultiConfig);
pCC->SetRC(m_rc);
pCC->SetForceRecompiling(true);
pCC->SetConvertorExtension(".cgf");
pCC->SetSourceFileNameOnly(cgfName.c_str());
pCC->SetSourceFolder(cgfPath.c_str());
pCC->SetOutputFolder(outputPath.c_str());
bool compileSuccess = m_compiler->CompileCGF(response, assetRoot, gameFolder);
EXPECT_TRUE(compileSuccess);
bool responseSuccess = m_compiler->WriteResponse(outputPath.c_str(), response, compileSuccess);
EXPECT_TRUE(responseSuccess);
}
// In this case, we load a basic CGF where the material path is just the name of the material file,
// so it is assumed that material is in the same folder as the CGF
TEST_F(CGFBuilderTest, CGF_MaterialInSameFolder)
{
AZStd::string cgfName = "cube_material_same_folder.cgf";
AZStd::string cgfPath(PathHelpers::Join(GetTestAssetRootPath().c_str(),"Objects/Primitives/"));
AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::Bus::Events::NormalizePathKeepCase, cgfPath);
AZStd::string outputPath = GetTemporaryDirectory();
AZStd::string expectedMaterialPath;
AzFramework::StringFunc::AssetDatabasePath::Join(cgfPath.c_str(), "primitives_001_mg.mtl", expectedMaterialPath);
AssetBuilderSDK::ProcessJobResponse response;
LoadCompileAndValidateCGF(cgfName, cgfPath, outputPath, response);
ASSERT_EQ(response.m_outputProducts.size(), 1);
AZStd::string productPath = response.m_outputProducts[0].m_productFileName;
EXPECT_TRUE(productPath == "cube_material_same_folder.cgf"); // Path would be relative to the AP temp directory, so just the file name itself
ASSERT_EQ(response.m_outputProducts[0].m_pathDependencies.size(), 1);
AssetBuilderSDK::ProductPathDependency& dependency = *response.m_outputProducts[0].m_pathDependencies.begin();
AZStd::string materialPath = dependency.m_dependencyPath;
EXPECT_TRUE(materialPath == expectedMaterialPath);
EXPECT_EQ(dependency.m_dependencyType, AssetBuilderSDK::ProductPathDependencyType::SourceFile);
}
// In this case, we load a basic CGF where the material path is absolute from the dev/ folder,
// for example "samplesproject/materials/test.mtl".
TEST_F(CGFBuilderTest, CGF_MaterialInDifferentFolder)
{
AZStd::string cgfName = "gs_block.cgf";
AZStd::string cgfPath(PathHelpers::Join(GetTestAssetRootPath().c_str(), "Objects/GettingStartedAssets/"));
AZStd::string outputPath = GetTemporaryDirectory();
AssetBuilderSDK::ProcessJobResponse response;
LoadCompileAndValidateCGF(cgfName, cgfPath, outputPath, response);
ASSERT_EQ(response.m_outputProducts.size(), 1);
AZStd::string productPath = response.m_outputProducts[0].m_productFileName;
EXPECT_TRUE(productPath == "gs_block.cgf"); // Path would be relative to the AP temp directory, so just the file name itself
ASSERT_EQ(response.m_outputProducts[0].m_pathDependencies.size(), 1);
AssetBuilderSDK::ProductPathDependency& dependency = *response.m_outputProducts[0].m_pathDependencies.begin();
AZStd::string materialPath = dependency.m_dependencyPath;
EXPECT_TRUE(materialPath == "materials/gettingstartedmaterials/gs_block.mtl");
EXPECT_EQ(dependency.m_dependencyType, AssetBuilderSDK::ProductPathDependencyType::ProductFile);
}
// A simple CGF with 2 lods, outputting to just 1 compiled CGF file
TEST_F(CGFBuilderTest, CGF_WithLOD_NoSplit)
{
AZStd::string cgfName = "CGF_LOD_Test.cgf";
AZStd::string cgfPath(PathHelpers::Join(GetTestAssetRootPath().c_str(), "Objects/"));
AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::Bus::Events::NormalizePathKeepCase, cgfPath);
AZStd::string outputPath = GetTemporaryDirectory();
AZStd::string expectedMaterialPath;
AzFramework::StringFunc::AssetDatabasePath::Join(cgfPath.c_str(), "Grass_Atlas_matGroup.mtl", expectedMaterialPath);
m_rc->localMultiConfig.setKeyValue(eCP_PriorityLowest, "SplitLODs", "false");
AssetBuilderSDK::ProcessJobResponse response;
LoadCompileAndValidateCGF(cgfName, cgfPath, outputPath, response);
ASSERT_EQ(response.m_outputProducts.size(), 1);
AZStd::string productPath = response.m_outputProducts[0].m_productFileName;
EXPECT_TRUE(productPath == "CGF_LOD_Test.cgf"); // Path would be relative to the AP temp directory, so just the file name itself
ASSERT_EQ(response.m_outputProducts[0].m_pathDependencies.size(), 1);
AssetBuilderSDK::ProductPathDependency& dependency = *response.m_outputProducts[0].m_pathDependencies.begin();
AZStd::string materialPath = dependency.m_dependencyPath;
EXPECT_TRUE(materialPath == expectedMaterialPath);
}
// A simple CGF with 2 lods, outputting to a unique CGF per lod
TEST_F(CGFBuilderTest, CGF_WithLOD_Split)
{
AZStd::string cgfName = "CGF_LOD_Test.cgf";
AZStd::string cgfPath(PathHelpers::Join(GetTestAssetRootPath().c_str(), "Objects/"));
AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::Bus::Events::NormalizePathKeepCase, cgfPath);
AZStd::string outputPath = GetTemporaryDirectory();
m_rc->localMultiConfig.setKeyValue(eCP_PriorityLowest, "SplitLODs", "true");
AssetBuilderSDK::ProcessJobResponse response;
LoadCompileAndValidateCGF(cgfName, cgfPath, outputPath, response);
ASSERT_EQ(response.m_outputProducts.size(), 3);
AZStd::string productPath = response.m_outputProducts[0].m_productFileName;
EXPECT_TRUE(productPath == "CGF_LOD_Test.cgf");
productPath = response.m_outputProducts[1].m_productFileName;
EXPECT_TRUE(productPath == "CGF_LOD_Test_lod1.cgf");
productPath = response.m_outputProducts[2].m_productFileName;
EXPECT_TRUE(productPath == "CGF_LOD_Test_lod2.cgf");
EXPECT_TRUE(response.m_outputProducts[0].m_pathDependencies.size() == 3);
AZStd::vector<AZStd::string> expectedDependencyPaths = {
"Grass_Atlas_matGroup.mtl",
"CGF_LOD_Test_lod1.cgf",
"CGF_LOD_Test_lod2.cgf"
};
for (AZStd::string& expectedDependency : expectedDependencyPaths)
{
const char* fileName = expectedDependency.c_str();
AzFramework::StringFunc::AssetDatabasePath::Join(cgfPath.c_str(), fileName, expectedDependency);
}
for (const AssetBuilderSDK::ProductPathDependency& dependency : response.m_outputProducts[0].m_pathDependencies)
{
ASSERT_TRUE(AZStd::find(expectedDependencyPaths.begin(), expectedDependencyPaths.end(), dependency.m_dependencyPath) != expectedDependencyPaths.end());
}
}