void traverse(Abc::IObject object, bool includeSelf) { if (includeSelf) { std::cout << "---------------------------------" << std::endl; std::cout << object.getFullName() << std::endl; if (Mat::IMaterial::matches(object.getHeader())) { std::cout << "(is material, local data shown)\n"; Mat::IMaterial mat(object, Abc::kWrapExisting); printMaterialSchema(mat.getSchema()); TESTING_ASSERT(object.getName() == "materialA" || object.getName() == "materialB"); } else { Mat::MaterialFlatten mafla(object); std::string name = object.getName(); std::cout << name << " " << mafla.empty() << std::endl; TESTING_ASSERT( (!mafla.empty() && (name == "geoA" || name == "geoB" || name == "geoC")) || (mafla.empty() && (name == "geometry" || name == "materials"))); if (!mafla.empty()) { std::cout << "(flattened material via has and/or assigned)\n"; printFlattenedMafla(mafla); } else { std::cout << "(neither is, has or is assigned)\n"; } } } for (size_t i = 0; i < object.getNumChildren(); ++i) { traverse(object.getChild(i), true); } }
//-***************************************************************************** void testWeirdStringScalar() { std::string archiveName = "weirdStr.abc"; Alembic::Util::string weirdStr = "Total failure"; weirdStr[5] = '\0'; Alembic::Util::wstring weirdWstr = L"Failure is always an option"; weirdWstr[5] = L'\0'; std::vector < Alembic::Util::string > weirdStrArray(3); weirdStrArray[0] = "watch"; weirdStrArray[1] = "this"; weirdStrArray[2] = "please"; weirdStrArray[2][3] = '\0'; Alembic::Util::string empty; Alembic::Util::wstring wempty; std::vector < Alembic::Util::string > allEmptyStr(3); std::vector < Alembic::Util::string > partEmptyStr(6); partEmptyStr[0] = ""; partEmptyStr[1] = ""; partEmptyStr[2] = "notEmpty!"; partEmptyStr[3] = ""; partEmptyStr[4] = "also not empty"; partEmptyStr[5] = ""; { A5::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); AbcA::CompoundPropertyWriterPtr props = archive->getProperties(); { AbcA::ScalarPropertyWriterPtr emptyWrtPtr = props->createScalarProperty("empty", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kStringPOD, 1), 0); // this should fail because of the NULL char in the string TESTING_ASSERT_THROW(emptyWrtPtr->setSample(&weirdStr), Alembic::Util::Exception); emptyWrtPtr->setSample(&empty); AbcA::ScalarPropertyWriterPtr wemptyWrtPtr = props->createScalarProperty("wempty", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kWstringPOD, 1), 0); // this should fail because of the NULL char in the string TESTING_ASSERT_THROW(wemptyWrtPtr->setSample(&weirdWstr), Alembic::Util::Exception); wemptyWrtPtr->setSample(&wempty); AbcA::ScalarPropertyWriterPtr allEmptyWrtPtr = props->createScalarProperty("allEmpty", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kStringPOD, 3), 0); // one of the strings has a NULL char in it TESTING_ASSERT_THROW( allEmptyWrtPtr->setSample(&(weirdStrArray.front())), Alembic::Util::Exception); allEmptyWrtPtr->setSample(&(allEmptyStr.front())); AbcA::ScalarPropertyWriterPtr partEmptyStrPtr = props->createScalarProperty("partEmpty", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kStringPOD, 6), 0); partEmptyStrPtr->setSample(&(partEmptyStr.front())); } } { A5::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); AbcA::CompoundPropertyReaderPtr parent = archive->getProperties(); for (size_t i = 0; i < parent->getNumProperties(); ++i) { AbcA::BasePropertyReaderPtr bp = parent->getProperty( i ); if (bp->getName() == "partEmpty") { std::vector < Alembic::Util::string > val (6); AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); TESTING_ASSERT(sp->getDataType().getExtent() == 6); sp->getSample(0, &(val.front())); TESTING_ASSERT(val == partEmptyStr); } else if (bp->getName() == "allEmpty") { std::vector < Alembic::Util::string > val (3); AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); TESTING_ASSERT(sp->getDataType().getExtent() == 3); sp->getSample(0, &(val.front())); TESTING_ASSERT(val == allEmptyStr); } else if (bp->getName() == "empty") { Alembic::Util::string val; AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); sp->getSample(0, &val); TESTING_ASSERT(val == empty); } else if (bp->getName() == "wempty") { Alembic::Util::wstring val; AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); sp->getSample(0, &val); TESTING_ASSERT(val == wempty); } else { TESTING_ASSERT(false); } } } }
//-***************************************************************************** void testRepeatedScalarData() { std::string archiveName = "repeatScalarData.abc"; { A5::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); AbcA::CompoundPropertyWriterPtr parent = archive->getProperties(); AbcA::ScalarPropertyWriterPtr swp = parent->createScalarProperty("int32", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt32POD, 3), 0); std::vector <Alembic::Util::uint32_t> ui(3); ui[0] = 0; ui[1] = 1; ui[2] = 2; std::vector <Alembic::Util::uint32_t> ui2(3); ui2[0] = 41; ui2[1] = 43; ui2[2] = 47; swp->setSample(&(ui.front())); swp->setSample(&(ui.front())); swp->setSample(&(ui2.front())); swp->setSample(&(ui.front())); swp->setSample(&(ui2.front())); swp->setSample(&(ui2.front())); swp->setSample(&(ui2.front())); swp->setSample(&(ui.front())); swp->setSample(&(ui.front())); swp->setSample(&(ui.front())); AbcA::ScalarPropertyWriterPtr swp2 = parent->createScalarProperty("float32", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kFloat32POD, 1), 0); Alembic::Util::float32_t f = 42.0; Alembic::Util::float32_t f2 = -3.0; swp2->setSample(&f); swp2->setSample(&f); swp2->setSample(&f); swp2->setSample(&f2); swp2->setSample(&f2); swp2->setSample(&f2); AbcA::ScalarPropertyWriterPtr swp3 = parent->createScalarProperty("uint16", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint16POD, 1), 0); Alembic::Util::uint16_t ui16 = 17; swp3->setSample(&ui16); swp3->setSample(&ui16); swp3->setSample(&ui16); swp3->setSample(&ui16); AbcA::ScalarPropertyWriterPtr swp4 = parent->createScalarProperty("str", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kStringPOD, 3), 0); std::vector < Alembic::Util::string > strVec(3); strVec[0] = "Please"; strVec[1] = ""; strVec[2] = "work"; std::vector < Alembic::Util::string > strVec2(3); strVec2[0] = "Whats"; strVec2[1] = "going"; strVec2[2] = "on?"; swp4->setSample(&(strVec.front())); swp4->setSample(&(strVec.front())); swp4->setSample(&(strVec2.front())); swp4->setSample(&(strVec2.front())); } { A5::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); AbcA::CompoundPropertyReaderPtr parent = archive->getProperties(); TESTING_ASSERT(parent->getNumProperties() == 4); for (size_t i = 0; i < parent->getNumProperties(); ++i) { AbcA::BasePropertyReaderPtr bp = parent->getProperty( i ); AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); switch (sp->getDataType().getPod()) { case Alembic::Util::kUint16POD: { TESTING_ASSERT( sp->getNumSamples() == 4 ); const AbcA::TimeSamplingPtr t = sp->getTimeSampling(); TESTING_ASSERT( sp->isConstant() ); Alembic::Util::uint16_t us; for ( size_t i = 0; i < sp->getNumSamples(); ++i ) { us = 0; sp->getSample( 0, &us); TESTING_ASSERT(us == 17); } } break; case Alembic::Util::kFloat32POD: { TESTING_ASSERT( sp->getNumSamples() == 6 ); TESTING_ASSERT( sp->getDataType().getExtent() == 1); TESTING_ASSERT( !sp->isConstant() ); Alembic::Util::float32_t f = 0; // make sure we can't get a non-existant sample TESTING_ASSERT_THROW(sp->getSample( 100, &f ), Alembic::Util::Exception); sp->getSample( 5, &f ); TESTING_ASSERT(f == -3.0); sp->getSample( 1, &f ); TESTING_ASSERT(f == 42.0); sp->getSample( 4, &f ); TESTING_ASSERT(f == -3.0); sp->getSample( 0, &f ); TESTING_ASSERT(f == 42.0); sp->getSample( 3, &f ); TESTING_ASSERT(f == -3.0); sp->getSample( 2, &f ); TESTING_ASSERT(f == 42.0); } break; case Alembic::Util::kInt32POD: { TESTING_ASSERT( sp->getNumSamples() == 10 ); TESTING_ASSERT( sp->getDataType().getExtent() == 3); TESTING_ASSERT( !sp->isConstant() ); std::vector< Alembic::Util::uint32_t > ui(3); // lets explicitly test each sample sp->getSample( 0, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); sp->getSample( 1, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); sp->getSample( 2, &(ui.front()) ); TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47); sp->getSample( 3, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); sp->getSample( 4, &(ui.front()) ); TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47); sp->getSample( 5, &(ui.front()) ); TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47); sp->getSample( 6, &(ui.front()) ); TESTING_ASSERT(ui[0] == 41 && ui[1] == 43 && ui[2] == 47); sp->getSample( 7, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); sp->getSample( 8, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); sp->getSample( 9, &(ui.front()) ); TESTING_ASSERT(ui[0] == 0 && ui[1] == 1 && ui[2] == 2); } break; case Alembic::Util::kStringPOD: { TESTING_ASSERT( sp->getNumSamples() == 4 ); TESTING_ASSERT( sp->getDataType().getExtent() == 3); TESTING_ASSERT( !sp->isConstant() ); std::vector< Alembic::Util::string > val(3); sp->getSample(0, &(val.front())); TESTING_ASSERT( val[0] == "Please"); TESTING_ASSERT( val[1] == ""); TESTING_ASSERT( val[2] == "work"); sp->getSample(1, &(val.front())); TESTING_ASSERT( val[0] == "Please"); TESTING_ASSERT( val[1] == ""); TESTING_ASSERT( val[2] == "work"); sp->getSample(2, &(val.front())); TESTING_ASSERT( val[0] == "Whats"); TESTING_ASSERT( val[1] == "going"); TESTING_ASSERT( val[2] == "on?"); sp->getSample(3, &(val.front())); TESTING_ASSERT( val[0] == "Whats"); TESTING_ASSERT( val[1] == "going"); TESTING_ASSERT( val[2] == "on?"); } break; default: TESTING_ASSERT(false); break; } } // for } }
//-***************************************************************************** void testReadWriteScalars() { std::string archiveName = "staticProperties.abc"; { A5::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); AbcA::CompoundPropertyWriterPtr props = archive->getProperties(); const AbcA::TimeSamplingType staticSampling; { AbcA::ScalarPropertyWriterPtr boolWrtPtr = props->createScalarProperty("bool", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kBooleanPOD, 1), 0); Alembic::Util::bool_t b = true; boolWrtPtr->setSample(&b); } { AbcA::ScalarPropertyWriterPtr ucharWrtPtr = props->createScalarProperty("uchar", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint8POD, 1), 0); Alembic::Util::uint8_t uc = 200; TESTING_ASSERT(ucharWrtPtr->getNumSamples() == 0); ucharWrtPtr->setSample(&uc); TESTING_ASSERT(ucharWrtPtr->getNumSamples() == 1); } { AbcA::ScalarPropertyWriterPtr charWrtPtr = props->createScalarProperty("char", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt8POD, 1), 0); Alembic::Util::int8_t c = -20; charWrtPtr->setSample(&c); } { AbcA::ScalarPropertyWriterPtr ushortWrtPtr = props->createScalarProperty("ushort", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint16POD, 1), 0); Alembic::Util::uint16_t us = 60000; ushortWrtPtr->setSample(&us); } { AbcA::ScalarPropertyWriterPtr shortWrtPtr = props->createScalarProperty("short", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt16POD, 1), 0); Alembic::Util::int16_t s = -20000; shortWrtPtr->setSample(&s); } { AbcA::ScalarPropertyWriterPtr uintWrtPtr = props->createScalarProperty("uint", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint32POD, 1), 0); Alembic::Util::uint32_t ui = 1000000; uintWrtPtr->setSample(&ui); } { AbcA::ScalarPropertyWriterPtr intWrtPtr = props->createScalarProperty("int", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt32POD, 1), 0); Alembic::Util::int32_t i = -1000000; intWrtPtr->setSample(&i); } { AbcA::ScalarPropertyWriterPtr ui64WrtPtr = props->createScalarProperty("uint64", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint64POD, 1), 0); Alembic::Util::uint64_t ui = 5000000000LL; ui64WrtPtr->setSample(&ui); } { AbcA::ScalarPropertyWriterPtr i64WrtPtr = props->createScalarProperty("i64", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt64POD, 1), 0); Alembic::Util::int64_t i = -5000000000LL; i64WrtPtr->setSample(&i); } { AbcA::ScalarPropertyWriterPtr halfWrtPtr = props->createScalarProperty("half", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kFloat16POD, 1), 0); Alembic::Util::float16_t h = 16.0; halfWrtPtr->setSample(&h); } { AbcA::ScalarPropertyWriterPtr floatWrtPtr = props->createScalarProperty("float", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kFloat32POD, 1), 0); Alembic::Util::float32_t f = 128.0; floatWrtPtr->setSample(&f); } { AbcA::ScalarPropertyWriterPtr doubleWrtPtr = props->createScalarProperty("double", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kFloat64POD, 1), 0); Alembic::Util::float64_t d = 32768.0; TESTING_ASSERT(doubleWrtPtr->getNumSamples() == 0); doubleWrtPtr->setSample(&d); TESTING_ASSERT(doubleWrtPtr->getNumSamples() == 1); } { AbcA::ScalarPropertyWriterPtr strWrtPtr = props->createScalarProperty("str", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kStringPOD, 1), 0); Alembic::Util::string c = "This was a triumph!"; strWrtPtr->setSample(&c); } { AbcA::ScalarPropertyWriterPtr wstrWrtPtr = props->createScalarProperty("wstr", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kWstringPOD, 1), 0); Alembic::Util::wstring c( L"Matt Lauer can suck it! \u2697" ); wstrWrtPtr->setSample(&c); } } // now we read what we've written { A5::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); AbcA::CompoundPropertyReaderPtr parent = archive->getProperties(); TESTING_ASSERT(parent->getNumProperties() == 14); for ( size_t i = 0; i < parent->getNumProperties(); ++i ) { AbcA::BasePropertyReaderPtr bp = parent->getProperty( i ); // they are all supposed to be scalar TESTING_ASSERT( bp->isScalar() ); AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); TESTING_ASSERT( sp->getNumSamples() == 1 ); TESTING_ASSERT( sp->isConstant() ); TESTING_ASSERT( sp->getParent() == parent); TESTING_ASSERT( sp->getDataType().getExtent() == 1); switch (sp->getDataType().getPod()) { case Alembic::Util::kBooleanPOD: { TESTING_ASSERT(sp->getName() == "bool"); Alembic::Util::bool_t val = false; sp->getSample(0, &val); TESTING_ASSERT(val == true); } break; case Alembic::Util::kUint8POD: { TESTING_ASSERT(sp->getName() == "uchar"); Alembic::Util::uint8_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 200); } break; case Alembic::Util::kInt8POD: { TESTING_ASSERT(sp->getName() == "char"); Alembic::Util::int8_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == -20); } break; case Alembic::Util::kUint16POD: { TESTING_ASSERT(sp->getName() == "ushort"); Alembic::Util::uint16_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 60000); } break; case Alembic::Util::kInt16POD: { TESTING_ASSERT(sp->getName() == "short"); Alembic::Util::int16_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == -20000); } break; case Alembic::Util::kUint32POD: { TESTING_ASSERT(sp->getName() == "uint"); Alembic::Util::uint32_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 1000000); } break; case Alembic::Util::kInt32POD: { TESTING_ASSERT(sp->getName() == "int"); Alembic::Util::int32_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == -1000000); } break; case Alembic::Util::kUint64POD: { TESTING_ASSERT(sp->getName() == "uint64"); Alembic::Util::uint64_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 5000000000LL); } break; case Alembic::Util::kInt64POD: { TESTING_ASSERT(sp->getName() == "i64"); Alembic::Util::int64_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == -5000000000LL); } break; case Alembic::Util::kFloat16POD: { TESTING_ASSERT(sp->getName() == "half"); Alembic::Util::float16_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 16.0); } break; case Alembic::Util::kFloat32POD: { TESTING_ASSERT(sp->getName() == "float"); Alembic::Util::float32_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 128.0); } break; case Alembic::Util::kFloat64POD: { TESTING_ASSERT(sp->getName() == "double"); Alembic::Util::float64_t val = 0; sp->getSample(0, &val); TESTING_ASSERT(val == 32768.0); } break; case Alembic::Util::kStringPOD: { TESTING_ASSERT(sp->getName() == "str"); Alembic::Util::string val; sp->getSample(0, &val); TESTING_ASSERT(val == "This was a triumph!"); } break; case Alembic::Util::kWstringPOD: { TESTING_ASSERT(sp->getName() == "wstr"); Alembic::Util::wstring val; sp->getSample(0, &val); TESTING_ASSERT(val == L"Matt Lauer can suck it! \u2697"); } break; default: TESTING_ASSERT(false); break; } } } // end of reading }
void testObjectHashes() { std::string archiveName = "objectHashTest.abc"; { AO::WriteArchive w; ABCA::ArchiveWriterPtr a = w(archiveName, ABCA::MetaData()); ABCA::ObjectWriterPtr archive = a->getTop(); ABCA::ObjectWriterPtr child; // 2 objects without any children whatsoever archive->createChild(ABCA::ObjectHeader("emptyA", ABCA::MetaData())); archive->createChild(ABCA::ObjectHeader("emptyB", ABCA::MetaData())); // 2 objects with one child object child = archive->createChild(ABCA::ObjectHeader("1ChildA", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData())); child = archive->createChild(ABCA::ObjectHeader("1ChildB", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData())); // 2 objects with one child object with a different name child = archive->createChild(ABCA::ObjectHeader("1ChildAName", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("empty", ABCA::MetaData())); child = archive->createChild(ABCA::ObjectHeader("1ChildBName", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("empty", ABCA::MetaData())); // 2 objects with one child object with different MetaData ABCA::MetaData m; m.set("Bleep", "bloop"); child = archive->createChild(ABCA::ObjectHeader("1ChildAMeta", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", m)); child = archive->createChild(ABCA::ObjectHeader("1ChildBMeta", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", m)); // 2 objects with one child object additional prop child = archive->createChild(ABCA::ObjectHeader("1ChildAProp", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData()) )->getProperties()->createCompoundProperty("child", ABCA::MetaData()); child = archive->createChild(ABCA::ObjectHeader("1ChildBProp", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData()) )->getProperties()->createCompoundProperty("child", ABCA::MetaData()); // 2 objects with one child object with additional grand child child = archive->createChild(ABCA::ObjectHeader("1ChildAChild", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData()) )->createChild(ABCA::ObjectHeader("grandchild", ABCA::MetaData())); child = archive->createChild(ABCA::ObjectHeader("1ChildBChild", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("child", ABCA::MetaData()) )->createChild(ABCA::ObjectHeader("grandchild", ABCA::MetaData())); // 2 objects with two children objects child = archive->createChild(ABCA::ObjectHeader("2ChildA", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childA", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childB", ABCA::MetaData())); child = archive->createChild(ABCA::ObjectHeader("2ChildB", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childA", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childB", ABCA::MetaData())); // 2 objects with two children objects with swapped children child = archive->createChild(ABCA::ObjectHeader("2ChildASwap", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childB", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childA", ABCA::MetaData())); child = archive->createChild(ABCA::ObjectHeader("2ChildBSwap", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childB", ABCA::MetaData())); child->createChild(ABCA::ObjectHeader("childA", ABCA::MetaData())); } { AO::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); ABCA::ObjectReaderPtr archive = a->getTop(); TESTING_ASSERT(archive->getNumChildren() == 16); // every 2 hashes should be the same for (size_t i = 0; i < archive->getNumChildren(); i += 2) { Alembic::Util::Digest dA, dB; TESTING_ASSERT(archive->getChild(i)->getChildrenHash(dA) && archive->getChild(i+1)->getChildrenHash(dB)); TESTING_ASSERT(dA == dB); } // make sure that every 2 child objects have different properties hashes for (size_t i = 0; i < archive->getNumChildren() / 2; ++i) { Alembic::Util::Digest dA; archive->getChild(i*2)->getChildrenHash(dA); for (size_t j = i + 1; j < archive->getNumChildren() / 2; ++j) { Alembic::Util::Digest dB; archive->getChild(j*2)->getChildrenHash(dB); TESTING_ASSERT(dA != dB); } } } }
void testArrayPropHashes() { std::string archiveName = "arrayHashTest.abc"; { AO::WriteArchive w; ABCA::ArchiveWriterPtr a = w(archiveName, ABCA::MetaData()); ABCA::ObjectWriterPtr archive = a->getTop(); ABCA::ObjectWriterPtr child; // add a time sampling for later use std::vector < double > timeSamps(1,-4.0); ABCA::TimeSamplingType tst(3.0); ABCA::TimeSampling ts(tst, timeSamps); a->addTimeSampling(ts); // 2 objects without any properties whatsoever archive->createChild(ABCA::ObjectHeader("emptyA", ABCA::MetaData())); archive->createChild(ABCA::ObjectHeader("emptyB", ABCA::MetaData())); // 2 objects with with the same property with no samples child = archive->createChild(ABCA::ObjectHeader( "1propA", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "1propB", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); // 2 objects with with the same property with a differnt name from above child = archive->createChild(ABCA::ObjectHeader( "1propAName", ABCA::MetaData())); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "1propBName", ABCA::MetaData())); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); // 2 objects with with the same property with a differnt MetaData ABCA::MetaData m; m.set("Bleep", "bloop"); child = archive->createChild(ABCA::ObjectHeader( "1propAMeta", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", m, ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "1propBMeta", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", m, ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); // 2 objects with with the same property with a different POD child = archive->createChild(ABCA::ObjectHeader( "1propAPod", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kFloat32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "1propBPod", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kFloat32POD, 1), 0); // 2 objects with with the same property with a different extent child = archive->createChild(ABCA::ObjectHeader( "1propAExtent", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 2), 0); child = archive->createChild(ABCA::ObjectHeader( "1propBExtent", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 2), 0); // 2 objects with with the same property with a differnt time sampling child = archive->createChild(ABCA::ObjectHeader( "1propATS", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 1); child = archive->createChild(ABCA::ObjectHeader( "1propBTS", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 1); // 2 objects with 1 sample ABCA::ArrayPropertyWriterPtr awp; std::vector <Alembic::Util::int32_t> vali(4, 0); Alembic::Util::Dimensions dims(4); ABCA::DataType i32d(Alembic::Util::kInt32POD, 1); child = archive->createChild(ABCA::ObjectHeader( "1propA1Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); child = archive->createChild(ABCA::ObjectHeader( "1propB1Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); // 2 objects with 2 samples, no repeats std::vector <Alembic::Util::int32_t> valiB(4, 1); child = archive->createChild(ABCA::ObjectHeader( "1propA2Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); child = archive->createChild(ABCA::ObjectHeader( "1propB2Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); // 2 objects with 4 samples, with repeats child = archive->createChild(ABCA::ObjectHeader( "1propA4Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); child = archive->createChild(ABCA::ObjectHeader( "1propB4Samp", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); awp->setSample(ABCA::ArraySample(&(valiB.front()), i32d, dims)); // 2 objects with 1 samplem different dimensions Alembic::Util::Dimensions dimsB; dimsB.setRank(2); dimsB[0] = 2; dimsB[1] = 2; child = archive->createChild(ABCA::ObjectHeader( "1propA1Dims", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dimsB)); child = archive->createChild(ABCA::ObjectHeader( "1propB1Dims", ABCA::MetaData())); awp = child->getProperties()->createArrayProperty("int", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); awp->setSample(ABCA::ArraySample(&(vali.front()), i32d, dimsB)); // 2 objects with with the same 2 properties with no samples child = archive->createChild(ABCA::ObjectHeader( "2propA", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "2propB", ABCA::MetaData())); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); // 2 objects with with the same 2 properties created in opposite order child = archive->createChild(ABCA::ObjectHeader( "2propASwap", ABCA::MetaData())); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "2propBSwap", ABCA::MetaData())); child->getProperties()->createArrayProperty("null", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child->getProperties()->createArrayProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); } { AO::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); ABCA::ObjectReaderPtr archive = a->getTop(); TESTING_ASSERT(archive->getNumChildren() == 26); // every 2 hashes should be the same for (size_t i = 0; i < archive->getNumChildren(); i += 2) { Alembic::Util::Digest dA, dB; TESTING_ASSERT(archive->getChild(i)->getPropertiesHash(dA) && archive->getChild(i+1)->getPropertiesHash(dB)); TESTING_ASSERT(dA == dB); } // make sure that every 2 child objects have different properties hashes for (size_t i = 0; i < archive->getNumChildren() / 2; ++i) { Alembic::Util::Digest dA; archive->getChild(i*2)->getPropertiesHash(dA); for (size_t j = i + 1; j < archive->getNumChildren() / 2; ++j) { Alembic::Util::Digest dB; archive->getChild(j*2)->getPropertiesHash(dB); TESTING_ASSERT(dA != dB); } } } }
void testCompoundPropHashes() { std::string archiveName = "compoundHashTest.abc"; { AO::WriteArchive w; ABCA::ArchiveWriterPtr a = w(archiveName, ABCA::MetaData()); ABCA::ObjectWriterPtr archive = a->getTop(); ABCA::ObjectWriterPtr child; // 2 objects without any properties whatsoever archive->createChild(ABCA::ObjectHeader("emptyA", ABCA::MetaData())); archive->createChild(ABCA::ObjectHeader("emptyB", ABCA::MetaData())); // 2 objects with with the same property with no samples child = archive->createChild(ABCA::ObjectHeader( "1propA", ABCA::MetaData())); child->getProperties()->createCompoundProperty("empty", ABCA::MetaData()); child = archive->createChild(ABCA::ObjectHeader( "1propB", ABCA::MetaData())); child->getProperties()->createCompoundProperty("empty", ABCA::MetaData()); // 2 objects with with the same property with a differnt name from above child = archive->createChild(ABCA::ObjectHeader( "1propAName", ABCA::MetaData())); child->getProperties()->createCompoundProperty("null", ABCA::MetaData()); child = archive->createChild(ABCA::ObjectHeader( "1propBName", ABCA::MetaData())); child->getProperties()->createCompoundProperty("null", ABCA::MetaData()); // 2 objects with with the same property with a different MetaData ABCA::MetaData m; m.set("Bleep", "bloop"); child = archive->createChild(ABCA::ObjectHeader( "1propAMeta", ABCA::MetaData())); child->getProperties()->createCompoundProperty("empty", m); child = archive->createChild(ABCA::ObjectHeader( "1propBMeta", ABCA::MetaData())); child->getProperties()->createCompoundProperty("empty", m); // 2 objects with compound that has a child compound child = archive->createChild(ABCA::ObjectHeader( "1propAChild", ABCA::MetaData())); child->getProperties()->createCompoundProperty("withChild", ABCA::MetaData())->createCompoundProperty("child", ABCA::MetaData()); child = archive->createChild(ABCA::ObjectHeader( "1propBChild", ABCA::MetaData())); child->getProperties()->createCompoundProperty("withChild", ABCA::MetaData())->createCompoundProperty("child", ABCA::MetaData()); // 2 objects with compound that has various children ABCA::CompoundPropertyWriterPtr childProp; child = archive->createChild(ABCA::ObjectHeader( "1propAProps", ABCA::MetaData())); childProp = child->getProperties()->createCompoundProperty("child", ABCA::MetaData()); childProp->createCompoundProperty("child", ABCA::MetaData()); childProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); child = archive->createChild(ABCA::ObjectHeader( "1propBProps", ABCA::MetaData())); childProp = child->getProperties()->createCompoundProperty("child", ABCA::MetaData()); childProp->createCompoundProperty("child", ABCA::MetaData()); childProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); // 2 objects with compound that has hierarchy ABCA::CompoundPropertyWriterPtr grandChildProp; child = archive->createChild(ABCA::ObjectHeader( "1propAHier", ABCA::MetaData())); childProp = child->getProperties()->createCompoundProperty("child", ABCA::MetaData()); grandChildProp = childProp->createCompoundProperty("child", ABCA::MetaData()); childProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); grandChildProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); grandChildProp->createCompoundProperty("child", ABCA::MetaData()); child = archive->createChild(ABCA::ObjectHeader( "1propBHier", ABCA::MetaData())); childProp = child->getProperties()->createCompoundProperty("child", ABCA::MetaData()); grandChildProp = childProp->createCompoundProperty("child", ABCA::MetaData()); childProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); grandChildProp->createScalarProperty("empty", ABCA::MetaData(), ABCA::DataType(Alembic::Util::kInt32POD, 1), 0); grandChildProp->createCompoundProperty("child", ABCA::MetaData()); } { AO::ReadArchive r; ABCA::ArchiveReaderPtr a = r( archiveName ); ABCA::ObjectReaderPtr archive = a->getTop(); TESTING_ASSERT(archive->getNumChildren() == 14); // every 2 hashes should be the same for (size_t i = 0; i < archive->getNumChildren(); i += 2) { Alembic::Util::Digest dA, dB; TESTING_ASSERT(archive->getChild(i)->getPropertiesHash(dA) && archive->getChild(i+1)->getPropertiesHash(dB)); TESTING_ASSERT(dA == dB); } // make sure that every 2 child objects have different properties hashes for (size_t i = 0; i < archive->getNumChildren() / 2; ++i) { Alembic::Util::Digest dA; archive->getChild(i*2)->getPropertiesHash(dA); for (size_t j = i + 1; j < archive->getNumChildren() / 2; ++j) { Alembic::Util::Digest dB; archive->getChild(j*2)->getPropertiesHash(dB); TESTING_ASSERT(dA != dB); } } } }
//-***************************************************************************** void testTimeSamplingScalar() { std::string archiveName = "timeSamplingScalar.abc"; { A5::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); AbcA::CompoundPropertyWriterPtr parent = archive->getProperties(); // illegal time value TESTING_ASSERT_THROW(parent->createScalarProperty("uniform", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt32POD, 1), 42), Alembic::Util::Exception); std::vector < double > timeSamps(1,-4.0); AbcA::TimeSamplingType tst(3.0); AbcA::TimeSampling ts(tst, timeSamps); uint32_t tsid = a->addTimeSampling(ts); AbcA::ScalarPropertyWriterPtr swp = parent->createScalarProperty("uniform", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt32POD, 1), tsid); Alembic::Util::int32_t i = 0; swp->setSample(&i); i+=3; swp->setSample(&i); i+=3; swp->setSample(&i); timeSamps.clear(); timeSamps.push_back(4.0); timeSamps.push_back(4.25); timeSamps.push_back(4.5); tst = AbcA::TimeSamplingType(3, 2.0); ts = AbcA::TimeSampling(tst, timeSamps); tsid = a->addTimeSampling(ts); AbcA::ScalarPropertyWriterPtr swp2 = parent->createScalarProperty("cyclic", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint32POD, 1), tsid); Alembic::Util::uint32_t ui = 0; swp2->setSample(&ui); ui++; swp2->setSample(&ui); ui++; swp2->setSample(&ui); ui++; swp2->setSample(&ui); ui++; swp2->setSample(&ui); ui++; swp2->setSample(&ui); timeSamps.clear(); timeSamps.push_back(-17.0); timeSamps.push_back(32.0); timeSamps.push_back(50.0); timeSamps.push_back(60.2); timeSamps.push_back(101.1); timeSamps.push_back(700.0); timeSamps.push_back(747.0); tst = AbcA::TimeSamplingType(AbcA::TimeSamplingType::kAcyclic); ts = AbcA::TimeSampling(tst, timeSamps); tsid = a->addTimeSampling(ts); AbcA::ScalarPropertyWriterPtr swp3 = parent->createScalarProperty("acyclic", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kUint16POD, 1), tsid); Alembic::Util::uint16_t s = 0; swp3->setSample(&s); s++; swp3->setSample(&s); s++; swp3->setSample(&s); s++; swp3->setSample(&s); s++; swp3->setSample(&s); s++; swp3->setSample(&s); s++; swp3->setSample(&s); // Setting more than what we have acyclic samples for TESTING_ASSERT_THROW(swp3->setSample(&s), Alembic::Util::Exception); AbcA::ScalarPropertyWriterPtr swp4 = parent->createScalarProperty("identity", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kInt16POD, 1), 0); Alembic::Util::int16_t ss = 35; swp4->setSample(&ss); ss = 37; swp4->setSample(&ss); ss = 1000; swp4->setSample(&ss); timeSamps.clear(); timeSamps.push_back(0.0); tst = AbcA::TimeSamplingType(1.0); ts = AbcA::TimeSampling(tst, timeSamps); tsid = a->addTimeSampling(ts); AbcA::ScalarPropertyWriterPtr swp5 = parent->createScalarProperty("defaultUniform", AbcA::MetaData(), AbcA::DataType(Alembic::Util::kFloat32POD, 1), tsid); Alembic::Util::float32_t f = 0; swp5->setSample(&f); f+=1.1; swp5->setSample(&f); f+=1.1; swp5->setSample(&f); f+=1.1; swp5->setSample(&f); } { A5::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); AbcA::CompoundPropertyReaderPtr parent = archive->getProperties(); TESTING_ASSERT(parent->getNumProperties() == 5); for ( size_t i = 0; i < parent->getNumProperties(); ++i) { AbcA::BasePropertyReaderPtr bp = parent->getProperty( i ); AbcA::ScalarPropertyReaderPtr sp = bp->asScalarPtr(); const AbcA::TimeSamplingPtr t = sp->getTimeSampling(); switch (sp->getDataType().getPod()) { case Alembic::Util::kInt16POD: { // identity TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); } break; case Alembic::Util::kUint16POD: { // acylic TESTING_ASSERT( t->getSampleTime(0) == -17.0 ); TESTING_ASSERT( sp->getNumSamples() == 7); TESTING_ASSERT( t->getTimeSamplingType().isAcyclic() ); TESTING_ASSERT( t->getSampleTime(1) == 32.0 ); TESTING_ASSERT( t->getSampleTime(2) == 50.0 ); TESTING_ASSERT( t->getSampleTime(3) == 60.2 ); TESTING_ASSERT( t->getSampleTime(4) == 101.1 ); TESTING_ASSERT( t->getSampleTime(5) == 700.0 ); TESTING_ASSERT( t->getSampleTime(6) == 747.0 ); TESTING_ASSERT_THROW( t->getSampleTime(7), Alembic::Util::Exception); } break; case Alembic::Util::kFloat32POD: { TESTING_ASSERT( sp->getNumSamples() == 4); TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); TESTING_ASSERT( t->getSampleTime(0) == 0.0 ); TESTING_ASSERT( t->getSampleTime(1) == 1.0 ); TESTING_ASSERT( t->getSampleTime(2) == 2.0 ); TESTING_ASSERT( t->getSampleTime(3) == 3.0 ); } break; case Alembic::Util::kInt32POD: { // uniform TESTING_ASSERT( sp->getNumSamples() == 3); TESTING_ASSERT( t->getTimeSamplingType().isUniform() ); TESTING_ASSERT( t->getSampleTime(0) == -4.0 ); TESTING_ASSERT( t->getSampleTime(1) == -1.0 ); TESTING_ASSERT( t->getSampleTime(2) == 2.0 ); } break; case Alembic::Util::kUint32POD: { // cyclic TESTING_ASSERT( sp->getNumSamples() == 6); TESTING_ASSERT( t->getTimeSamplingType().isCyclic() ); TESTING_ASSERT( t->getSampleTime(0) == 4.0 ); TESTING_ASSERT( t->getSampleTime(1) == 4.25 ); TESTING_ASSERT( t->getSampleTime(2) == 4.5 ); TESTING_ASSERT( t->getSampleTime(3) == 6.0 ); TESTING_ASSERT( t->getSampleTime(4) == 6.25 ); TESTING_ASSERT( t->getSampleTime(5) == 6.5 ); } break; default: TESTING_ASSERT(false); break; } } // for } }
void testScalarSamples() { std::string archiveName = "numScalarSamplesTest.abc"; AbcA::DataType dtype(Alembic::Util::kFloat32POD); float samp = 0.0f; { AO::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); AbcA::ObjectWriterPtr obj = archive->createChild( AbcA::ObjectHeader("test", AbcA::MetaData())); AbcA::CompoundPropertyWriterPtr parent = obj->getProperties(); AbcA::ScalarPropertyWriterPtr prop; AbcA::CompoundPropertyWriterPtr smallProp = parent->createCompoundProperty("small", AbcA::MetaData()); smallProp->createScalarProperty("a", AbcA::MetaData(), dtype, 0); prop = smallProp->createScalarProperty("b", AbcA::MetaData(), dtype, 0); for (std::size_t i = 0; i < 10; ++i, ++samp) { prop->setSample(&samp); } smallProp->createArrayProperty("c", AbcA::MetaData(), dtype, 0); AbcA::CompoundPropertyWriterPtr mdProp = parent->createCompoundProperty("md", AbcA::MetaData()); mdProp->createScalarProperty("a", AbcA::MetaData(), dtype, 0); prop = mdProp->createScalarProperty("b", AbcA::MetaData(), dtype, 0); for (std::size_t i = 0; i < 150; ++i, ++samp) { prop->setSample(&samp); } mdProp->createScalarProperty("c", AbcA::MetaData(), dtype, 0); AbcA::CompoundPropertyWriterPtr mdlgProp = parent->createCompoundProperty("mdlg", AbcA::MetaData()); mdlgProp->createScalarProperty("a", AbcA::MetaData(), dtype, 0); prop = mdlgProp->createScalarProperty("b", AbcA::MetaData(), dtype, 0); for (std::size_t i = 0; i < 300; ++i, ++samp) { prop->setSample(&samp); } mdlgProp->createScalarProperty("c", AbcA::MetaData(), dtype, 0); AbcA::CompoundPropertyWriterPtr lgProp = parent->createCompoundProperty("lg", AbcA::MetaData()); lgProp->createScalarProperty("a", AbcA::MetaData(), dtype, 0); prop = lgProp->createScalarProperty("b", AbcA::MetaData(), dtype, 0); for (std::size_t i = 0; i < 33000; ++i, ++samp) { prop->setSample(&samp); } lgProp->createScalarProperty("c", AbcA::MetaData(), dtype, 0); AbcA::CompoundPropertyWriterPtr insaneProp = parent->createCompoundProperty("insane", AbcA::MetaData()); insaneProp->createScalarProperty("a", AbcA::MetaData(), dtype, 0); prop = insaneProp->createScalarProperty("b", AbcA::MetaData(), dtype, 0); for (std::size_t i = 0; i < 66000; ++i, ++samp) { prop->setSample(&samp); } insaneProp->createScalarProperty("c", AbcA::MetaData(), dtype, 0); } { AO::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); AbcA::ObjectReaderPtr obj = archive->getChild(0); AbcA::CompoundPropertyReaderPtr parent = obj->getProperties(); AbcA::CompoundPropertyReaderPtr smallProp = parent->getCompoundProperty("small"); TESTING_ASSERT(smallProp->getNumProperties() == 3); TESTING_ASSERT(smallProp->getScalarProperty("b")->getNumSamples() == 10); AbcA::CompoundPropertyReaderPtr mdProp = parent->getCompoundProperty("md"); TESTING_ASSERT(mdProp->getNumProperties() == 3); TESTING_ASSERT(mdProp->getScalarProperty("b")->getNumSamples() == 150); AbcA::CompoundPropertyReaderPtr mdlgProp = parent->getCompoundProperty("mdlg"); TESTING_ASSERT(mdlgProp->getNumProperties() == 3); TESTING_ASSERT(mdlgProp->getScalarProperty("b")->getNumSamples() == 300); AbcA::CompoundPropertyReaderPtr lgProp = parent->getCompoundProperty("lg"); TESTING_ASSERT(lgProp->getNumProperties() == 3); TESTING_ASSERT(lgProp->getScalarProperty("b")->getNumSamples() == 33000); AbcA::CompoundPropertyReaderPtr insaneProp = parent->getCompoundProperty("insane"); TESTING_ASSERT(insaneProp->getNumProperties() == 3); TESTING_ASSERT(insaneProp->getScalarProperty("b")->getNumSamples() == 66000); } }
void read() { Abc::IArchive archive(Alembic::AbcCoreHDF5::ReadArchive(), "MaterialNetworkNodes.abc"); Abc::IObject materialsObject(archive.getTop(), "materials"); Mat::IMaterial matObj(materialsObject, "material1"); std::cout << "----" << std::endl; std::cout << "NODES" << std::endl; std::cout << matObj.getSchema().getNumNetworkNodes() << std::endl; TESTING_ASSERT(matObj.getSchema().getNumNetworkNodes() == 2); for (size_t i = 0, e = matObj.getSchema().getNumNetworkNodes(); i < e; ++i) { Mat::IMaterialSchema::NetworkNode node = matObj.getSchema().getNetworkNode(i); TESTING_ASSERT(node.valid()); std::cout << " ----" << std::endl; std::string target = "<undefined>"; node.getTarget(target); TESTING_ASSERT(target == "abc"); std::string nodeType = "<undefined>"; node.getNodeType(nodeType); std::cout << " NODE: " << node.getName() << ", TARGET: " << target << ", TYPE: " << nodeType << std::endl; TESTING_ASSERT((nodeType == "blinn" && node.getName() == "mainshader")|| (nodeType == "texture_read" && node.getName() == "colormap")); Abc::ICompoundProperty parameters = node.getParameters(); TESTING_ASSERT(parameters.valid()); TESTING_ASSERT(parameters.getNumProperties() == 1); if (parameters.valid()) { std::cout << " PARAMETERS:" << std::endl; TESTING_ASSERT( (node.getName() == "mainshader" && parameters.getPropertyHeader(0).getName() == "Kd") || (node.getName() == "colormap" && parameters.getPropertyHeader(0).getName() == "map_name") ); for (size_t i = 0, e = parameters.getNumProperties(); i < e; ++i) { const Abc::PropertyHeader & header = parameters.getPropertyHeader(i); std::cout << " " << header.getName() << std::endl; } } size_t numConnections = node.getNumConnections(); TESTING_ASSERT( (node.getName() == "mainshader" && numConnections == 1) || (node.getName() == "colormap" && numConnections == 0) ); if (numConnections) { std::string inputName, connectedNodeName, connectedOutputName; std::cout << " CONNNECTIONS:" << std::endl; for (size_t i = 0; i < numConnections; ++i) { if (node.getConnection(i, inputName, connectedNodeName, connectedOutputName)) { TESTING_ASSERT( inputName == "Cs" && connectedNodeName == "colormap" && connectedOutputName == "color_out" ); std::cout << " " << inputName << " -> NODE: " << connectedNodeName; if (!connectedOutputName.empty()) { std::cout << ", PORT: " << connectedOutputName; } std::cout << std::endl; } } } } std::cout << "TERMINALS" << std::endl; std::vector<std::string> targetNames; matObj.getSchema().getNetworkTerminalTargetNames(targetNames); TESTING_ASSERT(targetNames.size() == 1); for (std::vector<std::string>::iterator I = targetNames.begin(); I != targetNames.end(); ++I) { const std::string & targetName = (*I); std::cout << " TARGET: " << targetName << std::endl; std::vector<std::string> shaderTypeNames; matObj.getSchema().getNetworkTerminalShaderTypesForTarget( targetName, shaderTypeNames); for (std::vector<std::string>::iterator I = shaderTypeNames.begin(); I != shaderTypeNames.end(); ++I) { const std::string & shaderType = (*I); std::cout << " SHADERTYPE: " << shaderType; std::string connectedNodeName = "<undefined>"; std::string connectedOutputName = "<undefined>"; if (matObj.getSchema().getNetworkTerminal( targetName, shaderType, connectedNodeName, connectedOutputName)) { TESTING_ASSERT(targetName == "abc" && shaderType == "surface" && connectedNodeName == "mainshader" && connectedOutputName == "out"); std::cout << ", NODE: " << connectedNodeName; if (!connectedOutputName.empty()) { std::cout << ", PORT: " << connectedOutputName; } } std::cout << std::endl; } } std::vector<std::string> mappingNames; matObj.getSchema().getNetworkInterfaceParameterMappingNames(mappingNames); std::cout << "INTERFACE MAPPINGS" << std::endl; TESTING_ASSERT(mappingNames.size() == 1); for (std::vector<std::string>::iterator I = mappingNames.begin(); I != mappingNames.end(); ++I) { std::string mapToNodeName; std::string mapToParamName; if (matObj.getSchema().getNetworkInterfaceParameterMapping( (*I), mapToNodeName, mapToParamName)) { TESTING_ASSERT(mapToNodeName == "colormap" && mapToParamName == "map_name"); std::cout << " PARAM NAME: " << (*I) << ", MAPTONODE: " << mapToNodeName << ", MAPTOPARAMNAME: " << mapToParamName; std::cout << std::endl; } } std::cerr << "\n\n\nFROM FLATTENED MATERIAL" << std::endl; Mat::MaterialFlatten mafla(matObj); printFlattenedMafla(mafla); }
void read() { Abc::IArchive archive(Alembic::AbcCoreHDF5::ReadArchive(), "HasAMaterial.abc"); Abc::IObject an_object(archive.getTop(), "an_object"); if (const Abc::PropertyHeader * header = an_object.getProperties().getPropertyHeader(".byanyothername")) { TESTING_ASSERT(Mat::OMaterialSchema::matches(*header)); if (Mat::OMaterialSchema::matches(*header)) { std::cout << ".byanyothername yes.\n"; Mat::IMaterialSchema mat(an_object.getProperties(), ".byanyothername"); printMaterialSchema(mat); } else { std::cout << ".byanyothername no.\n"; } } if (const Abc::PropertyHeader * header = an_object.getProperties().getPropertyHeader("butnotbythisone")) { TESTING_ASSERT( !Mat::OMaterialSchema::matches(*header) ); if (Mat::OMaterialSchema::matches(*header)) { std::cout << "butnotbythisone yes.\n"; } else { std::cout << "butnotbythisone no.\n"; } } if (const Abc::PropertyHeader * header = an_object.getProperties().getPropertyHeader(".material")) { TESTING_ASSERT(!Mat::OMaterialSchema::matches(*header)); if (Mat::OMaterialSchema::matches(*header)) { std::cout << "manually built .material yes.\n"; } else { std::cout << "manually built .material no.\n"; } } std::cout << "-----------\n"; Abc::IObject anotherObj(archive.getTop(), "another_object"); std::string assignmentPath; if (Mat::getMaterialAssignmentPath(anotherObj, assignmentPath)) { std::cout << "another_object assignment path: " << assignmentPath; std::cout << std::endl; } TESTING_ASSERT(assignmentPath == "/some/material"); Mat::IMaterialSchema hasMat; TESTING_ASSERT(Mat::hasMaterial(anotherObj, hasMat)); if (Mat::hasMaterial(anotherObj, hasMat)) { std::cout << "another_object has local material: " << std::endl; printMaterialSchema(hasMat); } }
//-***************************************************************************** void testObjects() { std::string archiveName = "objectTest.abc"; { A5::WriteArchive w; AbcA::ArchiveWriterPtr a = w(archiveName, AbcA::MetaData()); AbcA::ObjectWriterPtr archive = a->getTop(); TESTING_ASSERT(archive->getName() == "ABC"); TESTING_ASSERT(archive->getFullName() == "/"); AbcA::ObjectWriterPtr child1 = archive->createChild( AbcA::ObjectHeader("wow", AbcA::MetaData())); TESTING_ASSERT(child1->getName() == "wow"); TESTING_ASSERT(child1->getFullName() == "/wow"); AbcA::ObjectWriterPtr child2 = archive->createChild( AbcA::ObjectHeader("bar", AbcA::MetaData())); TESTING_ASSERT(child2->getName() == "bar"); TESTING_ASSERT(child2->getFullName() == "/bar"); AbcA::ObjectWriterPtr child3 = archive->createChild( AbcA::ObjectHeader("foo", AbcA::MetaData())); TESTING_ASSERT(child3->getName() == "foo"); TESTING_ASSERT(child3->getFullName() == "/foo"); TESTING_ASSERT(archive->getNumChildren() == 3); TESTING_ASSERT(child1->getNumChildren() == 0); AbcA::ObjectWriterPtr gchild = child1->createChild( AbcA::ObjectHeader("food", AbcA::MetaData())); TESTING_ASSERT(child1->getNumChildren() == 1); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "food"); TESTING_ASSERT(gchild->getFullName() == "/wow/food"); gchild = child2->createChild( AbcA::ObjectHeader("hat", AbcA::MetaData())); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "hat"); TESTING_ASSERT(gchild->getFullName() == "/bar/hat"); TESTING_ASSERT_THROW(child2->createChild( AbcA::ObjectHeader("hat", AbcA::MetaData())), Alembic::Util::Exception); TESTING_ASSERT_THROW(child2->createChild( AbcA::ObjectHeader("slashy/", AbcA::MetaData())), Alembic::Util::Exception); TESTING_ASSERT_THROW(child2->createChild( AbcA::ObjectHeader("sla/shy", AbcA::MetaData())), Alembic::Util::Exception); TESTING_ASSERT_THROW(child2->createChild( AbcA::ObjectHeader("/slashy", AbcA::MetaData())), Alembic::Util::Exception); TESTING_ASSERT_THROW(child2->createChild( AbcA::ObjectHeader("", AbcA::MetaData())), Alembic::Util::Exception); gchild = child2->createChild( AbcA::ObjectHeader("bowling", AbcA::MetaData())); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "bowling"); TESTING_ASSERT(gchild->getFullName() == "/bar/bowling"); TESTING_ASSERT(child2->getNumChildren() == 2); gchild = child3->createChild( AbcA::ObjectHeader("hamburger", AbcA::MetaData())); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "hamburger"); TESTING_ASSERT(gchild->getFullName() == "/foo/hamburger"); gchild = child3->createChild( AbcA::ObjectHeader("burrito", AbcA::MetaData())); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "burrito"); TESTING_ASSERT(gchild->getFullName() == "/foo/burrito"); gchild = child3->createChild( AbcA::ObjectHeader("pizza", AbcA::MetaData())); TESTING_ASSERT(child3->getNumChildren() == 3); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "pizza"); TESTING_ASSERT(gchild->getFullName() == "/foo/pizza"); } { A5::ReadArchive r; AbcA::ArchiveReaderPtr a = r( archiveName ); AbcA::ObjectReaderPtr archive = a->getTop(); TESTING_ASSERT(archive->getNumChildren() == 3); TESTING_ASSERT(archive->getName() == "ABC"); TESTING_ASSERT(archive->getFullName() == "/"); AbcA::ObjectReaderPtr child = archive->getChild(0); TESTING_ASSERT(child->getName() == "wow"); TESTING_ASSERT(child->getFullName() == "/wow"); TESTING_ASSERT(child->getNumChildren() == 1); AbcA::ObjectReaderPtr gchild = child->getChild(0); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "food"); TESTING_ASSERT(gchild->getFullName() == "/wow/food"); child = archive->getChild(1); TESTING_ASSERT(child->getName() == "bar"); TESTING_ASSERT(child->getFullName() == "/bar"); TESTING_ASSERT(child->getNumChildren() == 2); gchild = child->getChild(0); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "hat"); TESTING_ASSERT(gchild->getFullName() == "/bar/hat"); gchild = child->getChild(1); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "bowling"); TESTING_ASSERT(gchild->getFullName() == "/bar/bowling"); child = archive->getChild(2); TESTING_ASSERT(child->getName() == "foo"); TESTING_ASSERT(child->getFullName() == "/foo"); TESTING_ASSERT(child->getNumChildren() == 3); gchild = child->getChild(0); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "hamburger"); TESTING_ASSERT(gchild->getFullName() == "/foo/hamburger"); gchild = child->getChild(1); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getName() == "burrito"); TESTING_ASSERT(gchild->getFullName() == "/foo/burrito"); gchild = child->getChild(2); TESTING_ASSERT(gchild->getNumChildren() == 0); TESTING_ASSERT(gchild->getFullName() == "/foo/pizza"); TESTING_ASSERT(gchild->getName() == "pizza"); A5::ReadArchive r2; AbcA::ArchiveReaderPtr a2 = r2( archiveName ); AbcA::ObjectReaderPtr archive2 = a2->getTop(); AbcA::ObjectReaderPtr child2 = archive->getChild(0); AbcA::ObjectReaderPtr gchild2 = child2->getChild(0); TESTING_ASSERT(gchild2->getNumChildren() == 0); TESTING_ASSERT(gchild2->getName() == "food"); TESTING_ASSERT(gchild2->getFullName() == "/wow/food"); } }