Tutorial_Generation_Navdata_FromMem.cpp

Tutorial_Generation_Navdata_FromMem.cpp
/*
* Copyright 2016 Autodesk, Inc. All rights reserved.
* Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
* or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
*/
#include "common/basesystemenv.h"
#include "common/basesystemenv.h"
namespace
{
// This tutorial illustrates how to access the NavData once it has been generated.
// The tutorial producer is identical to that provided in Tutorial_Generation_basics.
class TutorialProducer_NavData_FromMem : public Kaim::GeneratorInputProducer
{
public:
virtual KyResult Produce(const Kaim::GeneratorSector& sector, Kaim::ClientInputConsumer& inputConsumer)
{
Kaim::String sectorName(sector.GetName());
Kaim::String sector_A_Name("Sector_A");
Kaim::String sector_B_Name("Sector_B");
// Both name and GUID can be used to identify which sector the InputConsumer is requesting.
if (sectorName == sector_A_Name)
{
// When the current sector has been identified, feed the relevant data (geometry, seedpoints, tagVolumes)
// for this sector by calling the functions provided by the InputConsumer.
// In this case, add a basic triangle with a custom NavData value of "42".
Kaim::Vec3f aTriangle[3] = { Kaim::Vec3f(0.0f, 0.0f, 0.0f), Kaim::Vec3f(25.0f, 25.0f, 0.0f), Kaim::Vec3f(25.0f, 0.0f, 0.0f) };
Kaim::DynamicNavTag aNavTag;
aNavTag.m_blindDataArray.PushBack(42);
inputConsumer.ConsumeTriangle(aTriangle[0], aTriangle[1], aTriangle[2], aNavTag);
}
else if (sector.GetGuid() == Kaim::KyGuid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"))
{
// In this case, add a basic triangle with a custom NavData value of "13".
Kaim::Vec3f bTriangle[3] = { Kaim::Vec3f(25.0f, 0.0f, 0.0f), Kaim::Vec3f(25.0f, 25.0f, 0.0f), Kaim::Vec3f(50.0f, 0.0f, 0.0f) };
Kaim::DynamicNavTag bNavTag;
bNavTag.m_blindDataArray.PushBack(13);
inputConsumer.ConsumeTriangle(bTriangle[0], bTriangle[1], bTriangle[2], bNavTag);
}
return KY_SUCCESS;
}
};
class Tutorial_Generation_NavDataFromMem : public GeneratorEnv
{
public:
bool Generate_AndGetNavData()
{
// The first few steps are the same as in Tutorial_Generation_basic
// Create the producer using the class coded above.
Kaim::Ptr<TutorialProducer_NavData_FromMem> producer = *KY_NEW TutorialProducer_NavData_FromMem;
// Setup a generator using the Producer and no Glue;
// parallel processing will be disabled.
// Create it on the heap.
Kaim::Ptr<Kaim::Generator> generator = *KY_NEW(Kaim::Generator)(producer);
// Set the Directory where the navdata and clientInput files will be saved.
generator->SetOutputDirectory(RootDir().c_str(), RelativeOutputDir().c_str());
// Add sectors A and B. Keep track of the added sectors.
Kaim::GeneratorInputOutput generatorInputOutput;
Kaim::Ptr<Kaim::GeneratorSector> sectorA = *KY_NEW Kaim::GeneratorSector(Kaim::KyGuid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"), "Sector_A");
Kaim::Ptr<Kaim::GeneratorSector> sectorB = *KY_NEW Kaim::GeneratorSector(Kaim::KyGuid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"), "Sector_B");
generatorInputOutput.AddSector(sectorA);
generatorInputOutput.AddSector(sectorB);
// This stage is complete, the generator can run using the configuration established above.
if (generator->Generate(generatorInputOutput) == KY_ERROR)
return false;
// Destroy the Generator; the PathData that has been generated will remain available in
// sectorA and sectorB even after the generator has been destroyed through use of the ref-counted Ptr.
generator = nullptr;
// Retrieve the NavData from the sectors.
Kaim::Ptr<Kaim::NavData> navDataA = sectorA->GetNavData();
Kaim::Ptr<Kaim::NavData> navDataB = sectorB->GetNavData();
if (navDataA == nullptr || navDataB == nullptr)
return false;
// The NavData retrieved from the GeneratorInputOutput is
// not bound to any Database until you call the Init() method.
// NavData is added to the world at this point.
Kaim::World world;
Kaim::Database& database = *world.GetDatabase(0);
navDataA->Init(&database);
navDataB->Init(&database);
if (navDataA->AddToDatabaseImmediate() == KY_ERROR)
return false;
if (navDataB->AddToDatabaseImmediate() == KY_ERROR)
return false;
// Clean up and exit.
return true;
}
};
#define KT_TEST_ENV_CLASS Tutorial_Generation_NavDataFromMem
KT_TEST_ENV {}
KT_TUTORIAL { KT_ASSERT(KT_ENV.Generate_AndGetNavData()) }
}