const std::string Clusterer::GetInfo() const { std::ostringstream os; oid_t cluster_itr; oid_t cluster_count; cluster_count = GetClusterCount(); for (cluster_itr = 0; cluster_itr < cluster_count; cluster_itr++) os << cluster_itr << " : " << GetFraction(cluster_itr) << " :: " << GetCluster(cluster_itr); return os.str(); }
void patchSkins(FbxNode* currentRoot, const std::map<std::string, FbxNode*>& animatedNodes, const std::string& prefix){ auto mesh = currentRoot->GetMesh(); if (mesh){ auto skinCount = mesh->GetDeformerCount(FbxDeformer::EDeformerType::eSkin); for (auto ix = 0; ix < skinCount; ++ix){ auto skin = (FbxSkin*) mesh->GetDeformer(ix, FbxDeformer::EDeformerType::eSkin); if (skin){ std::vector<FbxCluster*> replacements; auto clusterCount = skin->GetClusterCount(); for (auto clusterIx = 0; clusterIx < clusterCount; ++clusterIx){ auto cluster = skin->GetCluster(clusterIx); if (cluster){ auto linkNode = cluster->GetLink(); if (linkNode){ auto candidateName = prefix; candidateName.append(linkNode->GetName()); auto found = animatedNodes.find(candidateName); if (found != animatedNodes.end()){ FbxCluster* newCluster = FbxCluster::Create(currentRoot->GetScene(), ""); newCluster->SetLink(found->second); newCluster->SetLinkMode(cluster->GetLinkMode()); FbxAMatrix mat; newCluster->SetTransformAssociateModelMatrix(cluster->GetTransformAssociateModelMatrix(mat)); newCluster->SetAssociateModel(cluster->GetAssociateModel()); newCluster->SetTransformLinkMatrix(cluster->GetTransformLinkMatrix(mat)); newCluster->SetTransformMatrix(cluster->GetTransformMatrix(mat)); newCluster->SetTransformParentMatrix(cluster->GetTransformParentMatrix(mat)); auto indicesAndWeightsCount = cluster->GetControlPointIndicesCount(); for (auto ix = 0; ix < indicesAndWeightsCount; ++ix){ newCluster->AddControlPointIndex(cluster->GetControlPointIndices()[ix], cluster->GetControlPointWeights()[ix]); } replacements.push_back(newCluster); } } } } if (replacements.size() == clusterCount){ while (skin->GetClusterCount()>0){ auto oldCluster = skin->GetCluster(skin->GetClusterCount() - 1); skin->RemoveCluster(oldCluster); oldCluster->Destroy(); } for (auto c : replacements){ skin->AddCluster(c); } } else{ for (auto c : replacements){ c->Destroy(); } } } } } for (auto ix = 0; ix < currentRoot->GetChildCount(); ++ix){ patchSkins(currentRoot->GetChild(ix), animatedNodes, prefix); } }
BOOL DumpDirectory(PDRIVEINFO pDrive, ULONG ulDirCluster, PSZ pszPath) { static BYTE szLongName[512]; int iIndex; PDIRENTRY pDir; PBYTE pbCluster; PBYTE pbPath; USHORT usClusters; ULONG ulCluster; ULONG ulBytesNeeded; BYTE _huge * p; PDIRENTRY pEnd; BYTE bCheckSum, bCheck; ULONG ulClustersNeeded; ULONG ulClustersUsed; ULONG ulEntries; static BYTE szShortName[13]; if (!ulDirCluster) { printf("ERROR: Cluster for %s is 0!\n", pszPath); return TRUE; } if (ulDirCluster == pDrive->bpb.RootDirStrtClus) { PULONG pulCluster; ReadFATSector(pDrive, 0); pulCluster = (PULONG)pDrive->pbFATSector; printf("MEDIA BYTES in FAT: %8.8lX\n", *pulCluster); pulCluster = (PULONG)pDrive->pbFATSector + 1; printf("DiskStatus: %8.8lX\n", *pulCluster); // vDumpSector(pDrive->pbFATSector); } //pDrive->ulTotalDirs++; pbPath = malloc(512); usClusters = GetClusterCount(pDrive, ulDirCluster); ulTotalClusters += usClusters; if (fDetailed > 2) printf("\n\nDirectory of %s (%u clusters)\n\n", pszPath, usClusters); ulBytesNeeded = (ULONG)pDrive->bpb.SectorsPerCluster * (ULONG)pDrive->bpb.BytesPerSector * usClusters; pbCluster = calloc(usClusters, pDrive->bpb.SectorsPerCluster * pDrive->bpb.BytesPerSector); if (!pbCluster) { printf("ERROR:Not enough memory!\n"); return FALSE; } ulCluster = ulDirCluster; p = pbCluster; while (ulCluster != FAT_EOF) { ReadCluster(pDrive, ulCluster); memcpy(p, pDrive->pbCluster, pDrive->bpb.SectorsPerCluster * pDrive->bpb.BytesPerSector); ulCluster = GetNextCluster(pDrive, ulCluster); p += pDrive->bpb.SectorsPerCluster * pDrive->bpb.BytesPerSector; } memset(szLongName, 0, sizeof szLongName); pDir = (PDIRENTRY)pbCluster; pEnd = (PDIRENTRY)(pbCluster + ulBytesNeeded - sizeof (DIRENTRY)); ulEntries = 0; bCheck = 0; while (pDir <= pEnd) { if (fDetailed > 3) { ULONG ulOffset = (PBYTE)pDir - pbCluster; if (ulOffset && !(ulOffset % 4096)) printf("-------- NEXT CLUSTER ----------\n"); } if (pDir->bFileName[0] && pDir->bFileName[0] != 0xE5) { if (pDir->bAttr == FILE_LONGNAME) { if (fDetailed > 3) { printf("(longname)\n"); vDumpDirEntry(pDir); } if (strlen(szLongName) && bCheck != pDir->bReserved) { printf("A lost long filename was found: %s\n", szLongName); memset(szLongName, 0, sizeof szLongName); } bCheck = pDir->bReserved; fGetLongName(pDir, szLongName, sizeof szLongName); } else { bCheckSum = 0; for (iIndex = 0; iIndex < 11; iIndex++) { if (bCheckSum & 0x01) { bCheckSum >>=1; bCheckSum |= 0x80; } else bCheckSum >>=1; bCheckSum += pDir->bFileName[iIndex]; } if (strlen(szLongName) && bCheck != bCheckSum) { printf("The longname %s does not belong to %s\\%s\n", szLongName, pszPath, MakeName(pDir, szShortName, sizeof szShortName)); memset(szLongName, 0, sizeof szLongName); } if (fDetailed > 2) { printf("%-8.8s.%-3.3s %2.2X ", pDir->bFileName, pDir->bExtention, pDir->bAttr); if (pDir->bAttr & FILE_DIRECTORY) printf("<DIR> "); else printf("%10lu ", pDir->ulFileSize); printf("%8.8lX ", MAKEP(pDir->wClusterHigh, pDir->wCluster)); if (pDir->fEAS) printf("%2.2X ", pDir->fEAS); else printf(" "); printf("%s\n", szLongName); } if (!(pDir->bAttr & FILE_DIRECTORY)) { ulClustersNeeded = pDir->ulFileSize / pDrive->usClusterSize + (pDir->ulFileSize % pDrive->usClusterSize ? 1:0); ulClustersUsed = GetClusterCount(pDrive,(ULONG)pDir->wClusterHigh * 0x10000 + pDir->wCluster); ulTotalClusters += ulClustersUsed; if (ulClustersNeeded != ulClustersUsed) { printf("File allocation error detected for %s\\%s\n", pszPath, MakeName(pDir, szShortName, sizeof szShortName)); printf("%lu clusters needed, %lu clusters allocated\n", ulClustersNeeded, ulClustersUsed); } } memset(szLongName, 0, sizeof szLongName); } ulEntries++; }
column_map_type Clusterer::GetPartitioning(oid_t tile_count) const { PL_ASSERT(tile_count >= 1); PL_ASSERT(tile_count <= sample_column_count_); std::map<double, oid_t> frequencies; oid_t cluster_itr = START_OID; oid_t cluster_count; cluster_count = GetClusterCount(); for (cluster_itr = 0; cluster_itr < cluster_count; cluster_itr++) { auto pair = std::make_pair(GetFraction(cluster_itr), cluster_itr); frequencies.insert(pair); } std::map<oid_t, oid_t> column_to_tile_map; oid_t tile_itr = START_OID; oid_t remaining_column_count = sample_column_count_; // look for most significant cluster for (auto entry = frequencies.rbegin(); entry != frequencies.rend(); ++entry) { LOG_TRACE(" %u :: %.3lf", entry->second, entry->first); // first, check if remaining columns less than tile count if (remaining_column_count <= tile_count) { oid_t column_itr; for (column_itr = 0; column_itr < sample_column_count_; column_itr++) { if (column_to_tile_map.count(column_itr) == 0) { column_to_tile_map[column_itr] = tile_itr; tile_itr++; } } } // otherwise, get its partitioning auto config = means_[entry->second]; auto config_tile = config.GetEnabledColumns(); for (auto column : config_tile) { if (column_to_tile_map.count(column) == 0) { column_to_tile_map[column] = tile_itr; remaining_column_count--; } } // check tile itr tile_itr++; if (tile_itr >= tile_count) tile_itr--; } // check if all columns are present in partitioning PL_ASSERT(column_to_tile_map.size() == sample_column_count_); // build partitioning column_map_type partitioning; std::map<oid_t, oid_t> tile_column_count_map; for (auto entry : column_to_tile_map) { auto column_id = entry.first; auto tile_id = entry.second; // figure out how many columns in given tile auto exists = tile_column_count_map.find(tile_id); if (exists == tile_column_count_map.end()) tile_column_count_map[tile_id] = 0; else tile_column_count_map[tile_id] += 1; // create an entry for the partitioning map auto partition_entry = std::make_pair(tile_id, tile_column_count_map[tile_id]); partitioning[column_id] = partition_entry; } return partitioning; }
void FBXConverter::LoadSkin(FbxMesh* fbxMesh, std::vector<BoneConnector>& bcs, std::vector<Vertex>& vs) { vs.resize(fbxMesh->GetControlPointsCount()); auto skinCount = fbxMesh->GetDeformerCount(FbxDeformer::eSkin); for (auto skinInd = 0; skinInd < skinCount; skinInd++) { auto skin = (FbxSkin*)fbxMesh->GetDeformer(skinInd, FbxDeformer::eSkin); auto clusterCount = skin->GetClusterCount(); for (auto clusterInd = 0; clusterInd < clusterCount; clusterInd++) { auto cluster = skin->GetCluster(clusterInd); if (cluster->GetLink() == nullptr) continue; // ボーン取得 auto name = cluster->GetLink()->GetName(); FbxAMatrix m1, m2; cluster->GetTransformMatrix(m1); cluster->GetTransformLinkMatrix(m2); int32_t id = bcs.size(); BoneConnector connector; connector.Name = name; auto m2_inv = m2.Inverse(); auto m = m2_inv * m1; connector.OffsetMatrix = m; bcs.push_back(connector); auto indexCount = cluster->GetControlPointIndicesCount(); auto vindices = cluster->GetControlPointIndices(); auto vweights = cluster->GetControlPointWeights(); for (auto ind = 0; ind < indexCount; ind++) { Weight data; data.Index = id; data.Value = (float)vweights[ind]; vs[vindices[ind]].Weights.push_back(data); } } } // Calculate weight for (auto& v : vs) { if (v.Weights.size() == 0) { Weight w; w.Index = -1; w.Value = 1.0; v.Weights.push_back(w); v.Weights.push_back(Weight()); v.Weights.push_back(Weight()); v.Weights.push_back(Weight()); } else { v.Weights.push_back(Weight()); v.Weights.push_back(Weight()); v.Weights.push_back(Weight()); std::sort(v.Weights.begin(), v.Weights.end(), Weight()); float fSum = 0.0f; for (auto ind = 0; ind < 4; ind++) { fSum += v.Weights[ind].Value; } v.Weights[0].Value += 1.0f - fSum; v.Weights.resize(4); } } }