bool Sample_MeshLod::loadConfig() { mLodConfig.advanced = LodConfig::Advanced(); mLodConfig.strategy = PixelCountLodStrategy::getSingletonPtr(); mLodConfig.levels.clear(); mLodConfig.advanced.profile.clear(); // The mesh should already be set. assert(mLodConfig.mesh.get()); String filename(mLodConfig.mesh->getName()); filename += ".lodconfig"; LodConfigSerializer lcs; lcs.importLodConfig(&mLodConfig, filename); mLodLevelList->clearItems(); for(size_t i = 0; i < mLodConfig.levels.size(); i++){ mLodLevelList->addItem(StringConverter::toString(mLodConfig.levels[i].distance) + "px"); } mProfileList->clearItems(); for(size_t i = 0; i < mLodConfig.advanced.profile.size(); i++){ mProfileList->addItem(StringConverter::toString(mLodConfig.advanced.profile[i].src)); } mUseVertexNormals->setChecked(mLodConfig.advanced.useVertexNormals, false); mOutsideWeightSlider->setValue(std::sqrt(mLodConfig.advanced.outsideWeight), false); mOutsideWalkAngle->setValue(mLodConfig.advanced.outsideWalkAngle, false); return true; }
void Sample_MeshLod::saveConfig() { String filename(mLodConfig.mesh->getName()); filename += ".lodconfig"; LodConfigSerializer lcs; lcs.exportLodConfig(mLodConfig, filename); }
//-------------------------------------------------------------------------- void MeshLodTests::testLodConfigSerializer() { UnitTestSuite::getSingletonPtr()->startTestMethod(__FUNCTION__); LodConfig config, config2; setTestLodConfig(config); addProfile(config); LodConfigSerializer serializer; serializer.exportLodConfig(config, "testLodConfigSerializer.lodconfig"); serializer.importLodConfig(&config2, "testLodConfigSerializer.lodconfig"); CPPUNIT_ASSERT(config.mesh->getHandle() == config2.mesh->getHandle()); CPPUNIT_ASSERT(config.strategy == config2.strategy); CPPUNIT_ASSERT(config.advanced.outsideWalkAngle == config.advanced.outsideWalkAngle); CPPUNIT_ASSERT(config.advanced.outsideWeight == config.advanced.outsideWeight); CPPUNIT_ASSERT(config.advanced.useBackgroundQueue == config.advanced.useBackgroundQueue); CPPUNIT_ASSERT(config.advanced.useCompression == config.advanced.useCompression); CPPUNIT_ASSERT(config.advanced.useVertexNormals == config.advanced.useVertexNormals); { // Compare profiles LodProfile& p1 = config.advanced.profile; LodProfile& p2 = config2.advanced.profile; bool isProfileSameSize = (p1.size() == p2.size()); CPPUNIT_ASSERT(isProfileSameSize); if (isProfileSameSize) { for (size_t i = 0; i < p1.size(); i++) { CPPUNIT_ASSERT(p1[i].src == p2[i].src); CPPUNIT_ASSERT(p1[i].dst == p2[i].dst); CPPUNIT_ASSERT(isEqual(p1[i].cost, p2[i].cost)); } } } { // Compare Lod Levels LodConfig::LodLevelList& l1 = config.levels; LodConfig::LodLevelList& l2 = config2.levels; bool isLevelsSameSize = (l1.size() == l2.size()); CPPUNIT_ASSERT(isLevelsSameSize); if (isLevelsSameSize) { for (size_t i = 0; i < l1.size(); i++) { CPPUNIT_ASSERT(l1[i].distance == l2[i].distance); CPPUNIT_ASSERT(l1[i].manualMeshName == l2[i].manualMeshName); CPPUNIT_ASSERT(l1[i].reductionMethod == l2[i].reductionMethod); CPPUNIT_ASSERT(isEqual(l1[i].reductionValue, l2[i].reductionValue)); } } } }
//-------------------------------------------------------------------------- TEST_F(MeshLodTests,LodConfigSerializer) { LodConfig config, config2; setTestLodConfig(config); addProfile(config); LodConfigSerializer serializer; serializer.exportLodConfig(config, "testLodConfigSerializer.lodconfig"); serializer.importLodConfig(&config2, "testLodConfigSerializer.lodconfig"); EXPECT_EQ(config.mesh->getHandle(), config2.mesh->getHandle()); EXPECT_EQ(config.strategy, config2.strategy); EXPECT_EQ(config.advanced.outsideWalkAngle, config.advanced.outsideWalkAngle); EXPECT_EQ(config.advanced.outsideWeight, config.advanced.outsideWeight); EXPECT_EQ(config.advanced.useBackgroundQueue, config.advanced.useBackgroundQueue); EXPECT_EQ(config.advanced.useCompression, config.advanced.useCompression); EXPECT_EQ(config.advanced.useVertexNormals, config.advanced.useVertexNormals); { // Compare profiles LodProfile& p1 = config.advanced.profile; LodProfile& p2 = config2.advanced.profile; ASSERT_EQ(p1.size(), p2.size()); for (size_t i = 0; i < p1.size(); i++) { EXPECT_EQ(p1[i].src, p2[i].src); EXPECT_EQ(p1[i].dst, p2[i].dst); EXPECT_FLOAT_EQ(p1[i].cost, p2[i].cost); } } { // Compare Lod Levels LodConfig::LodLevelList& l1 = config.levels; LodConfig::LodLevelList& l2 = config2.levels; ASSERT_EQ(l1.size(), l2.size()); for (size_t i = 0; i < l1.size(); i++) { EXPECT_EQ(l1[i].distance , l2[i].distance); EXPECT_EQ(l1[i].manualMeshName, l2[i].manualMeshName); EXPECT_EQ(l1[i].reductionMethod, l2[i].reductionMethod); EXPECT_FLOAT_EQ(l1[i].reductionValue, l2[i].reductionValue); } } }