af::Model OutValue::GetModelOfValue() { if(Root.IsNull()) { throw NoLabelInicialisationException("OutValue: label do not inicialised."); } TIterator TITER; Model vallr; TITER.Init(Root, false); while (TITER.More()) { Model val = (Model)TITER.Value(); QString name = val.GetName(); if(name == "Model") { return val; } TITER.Next(); } TElement e(Root); throw NoExistException("OutValue: Model Of Value do not exists.", e); return vallr; }
void ModelListTree::OnContextMenuImport(wxCommandEvent& event) { wxFileDialog dialog(this, L"Import", wxEmptyString, wxEmptyString, _T("OBJ files (*.obj*)|*.obj*"), wxFD_MULTIPLE); if (dialog.ShowModal() == wxID_OK) { Model* model = NULL; OBJParser::Parse(dialog.GetPath().wchar_str(), &model); _Assert(NULL != model); AppendItem(GetRootItem(), model->GetName(), 0, 0, New ModelTreeItemData(model)); } }
void FBXSceneInstance::InitInstance() { // Bounding Box m_BoundingBox = mScene->m_BoundingBox; // Models for(unsigned int i = 0; i < mScene->GetModelCount(); i++) { Model* srcModel = mScene->GetModel(i); m_Models.Add(srcModel->GetName(), new Model(srcModel)); } // Copy Skeleton if ( mScene->GetSkeleton() ) { Skeleton* newSkeleton = new Skeleton(); for( unsigned int x = 0; x < mScene->GetSkeleton()->GetBoneCount(); ++x ) { SkeletonBone* sourceBone = mScene->GetSkeleton()->GetSkeletonBone(x); SkeletonBone* targetBone = new SkeletonBone( sourceBone->GetName(), sourceBone->GetParentBoneIndex(), newSkeleton); newSkeleton->AddSkeletonBone( targetBone ); } newSkeleton->BuildBoneHierarchy(); for( unsigned int x = 0; x < newSkeleton->GetBoneCount(); ++x ) { SkeletonBone* sourceBone = mScene->GetSkeleton()->GetSkeletonBone(x); SkeletonBone* targetBone = newSkeleton->GetSkeletonBone(x); targetBone->SetBindPoseTransform2(sourceBone->GetBindPoseTransform2()); targetBone->SetBoneReferenceTransform2(sourceBone->GetBoneReferenceTransform2()); targetBone->m_AnimationKeyFrames = sourceBone->m_AnimationKeyFrames; targetBone->SetBoundingBoxData(sourceBone->m_AABB); } // Update My Skeleton m_pSkeleton = newSkeleton; // Update My Animation m_pAnimationController = new AnimationController(mScene->m_pAnimationController); } // Curves m_Curves = &mScene->m_Curves; }
void FBXScene::ProcessMesh(FbxNode* pNode) { FbxMesh* pFBXMesh = pNode->GetMesh(); if( !pFBXMesh ) return; if ( pFBXMesh->GetPolygonVertexCount() != pFBXMesh->GetPolygonCount() * 3 ) { FbxGeometryConverter GeometryConverter(pNode->GetFbxManager()); if( !GeometryConverter.TriangulateInPlace( pNode ) ) { return; } pFBXMesh = pNode->GetMesh(); } pFBXMesh->InitNormals(); pFBXMesh->ComputeVertexNormals(true); pFBXMesh->GenerateTangentsDataForAllUVSets(); int nVertexCount = pFBXMesh->GetControlPointsCount(); if( nVertexCount <= 0 ) return; std::vector<BoneWeights> boneWeights(nVertexCount); ProcessBoneWeights(pFBXMesh, boneWeights); Model* pModel = new Model(pNode->GetName(), m_Models.GetCount(), false); FbxVector4* aControlPoints = pFBXMesh->GetControlPoints(); for( int pi = 0; pi < pFBXMesh->GetPolygonCount(); ++pi ) // Whole for-loop takes some time too, investigate further. { // Material Material* pMaterial = NULL; for( unsigned int pvi = 0; pvi < 3; ++pvi ) { int nVertexIndex = pFBXMesh->GetPolygonVertex(pi, pvi); if( nVertexIndex < 0 || nVertexIndex >= nVertexCount ) continue; // Material if( pMaterial == NULL ) pMaterial = GetMaterialLinkedWithPolygon(pFBXMesh, 0, pi, 0, nVertexIndex); // Position FbxVector4 fbxPosition = aControlPoints[nVertexIndex]; // Normals And Tangents FbxVector4 fbxNormal, fbxTangent; fbxNormal = GetNormal(pFBXMesh, 0, pi, pvi, nVertexIndex); fbxTangent = GetTangent(pFBXMesh, 0, pi, pvi, nVertexIndex); // Add Vertex pModel->AddVertex(pMaterial, FbxVector4ToBTHFBX_VEC3(fbxPosition), FbxVector4ToBTHFBX_VEC3(fbxNormal), FbxVector4ToBTHFBX_VEC3(fbxTangent), GetTexCoord(pFBXMesh, 0, pi, pvi, nVertexIndex), boneWeights[nVertexIndex]); // Update Bounding Box UpdateBoundingBoxDataFromVertex(FbxVector4ToBTHFBX_VEC3(fbxPosition)); } } // Geometric Offset pModel->SetGeometricOffset2(GetGeometricOffset2(pNode)); // Insert Model m_Models.Add(pModel->GetName(), pModel); }
void Falcon::SetOutputs(ModelManager* allmodels, OutputManager* outputManager, std::list<int>& selected, wxWindow* parent) { //ResetStringOutputs(); // this shouldnt be used normally static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base")); logger_base.debug("Falcon Outputs Upload: Uploading to %s", (const char *)_ip.c_str()); // build a list of models on this controller std::list<Model*> models; std::list<std::string> protocolsused; std::list<Model*> warnedmodels; int maxport = 0; // Get universes based on IP std::list<Output*> outputs = outputManager->GetAllOutputs(_ip); // get outputs based on selected std::list<Output*> o2 = outputManager->GetAllOutputs(selected); // now merge them together and eleminate the duplicates outputs.merge(o2); outputs.sort(); outputs.unique(); for (auto ito = outputs.begin(); ito != outputs.end(); ++ito) { // this universe is sent to the falcon // find all the models in this range for (auto it = allmodels->begin(); it != allmodels->end(); ++it) { if (it->second->GetDisplayAs() != "ModelGroup") { int modelstart = it->second->GetNumberFromChannelString(it->second->ModelStartChannel); int modelend = modelstart + it->second->GetChanCount() - 1; if ((modelstart >= (*ito)->GetStartChannel() && modelstart <= (*ito)->GetEndChannel()) || (modelend >= (*ito)->GetStartChannel() && modelend <= (*ito)->GetEndChannel())) { //logger_base.debug("Model %s start %d end %d found on controller %s output %d start %d end %d.", // (const char *)it->first.c_str(), modelstart, modelend, // (const char *)_ip.c_str(), node, currentcontrollerstartchannel, currentcontrollerendchannel); if (!it->second->IsControllerConnectionValid()) { // only warn if we have not already warned if (std::find(warnedmodels.begin(), warnedmodels.end(), it->second) == warnedmodels.end()) { warnedmodels.push_back(it->second); logger_base.warn("Falcon Outputs Upload: Model %s on controller %s does not have its Controller Connection details completed: '%s'. Model ignored.", (const char *)it->first.c_str(), (const char *)_ip.c_str(), (const char *)it->second->GetControllerConnection().c_str()); wxMessageBox("Model " + it->first + " on controller " + _ip + " does not have its Contoller Connection details completed: '" + it->second->GetControllerConnection() + "'. Model ignored.", "Model Ignored"); } } else { // model uses channels in this universe // check we dont already have this model in our list if (std::find(models.begin(), models.end(), it->second) == models.end()) { logger_base.debug("Falcon Outputs Upload: Uploading Model %s.", (const char *)it->first.c_str()); models.push_back(it->second); if (std::find(protocolsused.begin(), protocolsused.end(), it->second->GetProtocol()) == protocolsused.end()) { protocolsused.push_back(it->second->GetProtocol()); } if (it->second->GetPort() > maxport) { maxport = it->second->GetPort(); } } } } } } } // sort the models by start channel models.sort(compare_startchannel); // get the current config before I start std::string strings = GetURL("/strings.xml"); if (strings == "") { logger_base.error("Falcon Outputs Upload: Falcon would not return strings.xml."); wxMessageBox("Error occured trying to upload to Falcon.", "Error", wxOK, parent); return; } // for each protocol for (auto protocol = protocolsused.begin(); protocol != protocolsused.end(); ++protocol) { std::string sendmessage; int count = 0; bool portdone[100]; memset(&portdone, 0x00, sizeof(portdone)); // all false // for each port ... this is the max of any port type but it should be ok for (int i = 1; i <= maxport; i++) { // find the first and last Model* first = nullptr; Model* last = nullptr; int highestend = 0; long loweststart = 999999999; for (auto model = models.begin(); model != models.end(); ++model) { if ((*model)->GetProtocol() == *protocol && (*model)->GetPort() == i) { int modelstart = (*model)->GetNumberFromChannelString((*model)->ModelStartChannel); int modelend = modelstart + (*model)->GetChanCount() - 1; if (modelstart < loweststart) { loweststart = modelstart; first = *model; } if (modelend > highestend) { highestend = modelend; last = *model; } } } if (first != nullptr) { int portstart = first->GetNumberFromChannelString(first->ModelStartChannel); int portend = last->GetNumberFromChannelString(last->ModelStartChannel) + last->GetChanCount() - 1; int numstrings = first->GetNumStrings(); bool multistringelement = (first->GetDisplayAs() == "Matrix" || first->GetDisplayAs() == "Tree" || first->GetDisplayAs() == "Circle" || first->GetDisplayAs() == "Star" || first->GetDisplayAs() == "Wreath" || first->GetDisplayAs() == "Icicles"); int channelsperstring = first->NodesPerString() * first->GetChanCountPerNode(); // upload it if (DecodeStringPortProtocol(*protocol) >= 0) { if (first == last && numstrings > 1 && multistringelement) { for (int j = 0; j < numstrings; j++) { if (portdone[i+j]) { logger_base.warn("Falcon Outputs Upload: Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i +j); wxMessageBox(wxString::Format("Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i + j)); } else { portdone[i + j] = true; count++; if (sendmessage != "") sendmessage = sendmessage + "&"; sendmessage = sendmessage + BuildStringPort(strings, i + j, DecodeStringPortProtocol(*protocol), portstart + j * channelsperstring, channelsperstring / 3, first->GetName(), parent); if (count == 40) { UploadStringPort(sendmessage, false); sendmessage = ""; count = 0; } } } } else { if (portdone[i]) { logger_base.warn("Falcon Outputs Upload: Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str() , i); wxMessageBox(wxString::Format("Attempt to upload model %s to string port %d but this string port already has a model on it.", (const char *)first->GetName().c_str(), i)); } else { portdone[i] = true; count++; if (sendmessage != "") sendmessage = sendmessage + "&"; sendmessage = sendmessage + BuildStringPort(strings, i, DecodeStringPortProtocol(*protocol), portstart, (portend - portstart + 1) / 3, first->GetName(), parent); if (count == 40) { UploadStringPort(sendmessage, false); sendmessage = ""; count = 0; } } } } else if (DecodeSerialOutputProtocol(*protocol) >= 0) { UploadSerialOutput(i, DecodeSerialOutputProtocol(*protocol), portstart, parent); } else { logger_base.warn("Falcon Outputs Upload: Controller %s protocol %s not supported by this controller.", (const char *)_ip.c_str(), (const char *)protocol->c_str()); wxMessageBox("Controller " + _ip + " protocol " + (*protocol) + " not supported by this controller.", "Protocol Ignored"); } } else { // nothing on this port ... ignore it } } UploadStringPort(sendmessage, true); } }
void Grafkit::SceneLoader::SceneLoaderHelper::Load(Archive &ar, IResourceManager * const & resman) { Persist(ar, resman); LOGGER(Log::Logger().Info("-- ASSIGN --")); // 5. material -> mesh relation LOGGER(Log::Logger().Info("Materials: %d", m_materials_to_meshes.size())); for (auto it = m_materials_to_meshes.begin(); it != m_materials_to_meshes.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Material * material = m_materials[key]; Model *model = dynamic_cast<Model *>(m_entities[val]); if (model && material) { model->SetMaterial(material); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, material->GetName().c_str(), val, model->GetName().c_str())); } } // ... // 6. entitiy -> actor relation LOGGER(Log::Logger().Info("Entities: %d", m_entities_to_actors.size())); for (auto it = m_entities_to_actors.begin(); it != m_entities_to_actors.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Entity3D *entity = m_entities[key]; Actor *actor = m_actors[val]; if (actor && entity) { actor->AddEntity(entity); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, entity->GetName().c_str()), val, actor->GetName().c_str()); } } // ... // 7. actor -> actor relation - scenegraph LOGGER(Log::Logger().Info("Actors: %d", m_actor_to_actor.size())); for (auto it = m_actor_to_actor.begin(); it != m_actor_to_actor.end(); ++it) { USHORT key = it->first; USHORT val = it->second; Actor *child = m_actors[val]; Actor *parent = m_actors[key]; if (parent && child) { parent->AddChild(child); LOGGER(Log::Logger().Info("%hu (\"%s\") -> %hu (\"%s\")", key, parent->GetName().c_str(), val, child->GetName().c_str())); } } //8, 9 animation -> actor, entity LOGGER(Log::Logger().Info("Animations: %d", m_animation_to_actor.size() + m_animation_to_entity.size())); for (auto it = m_animation_to_actor.cbegin(); it != m_animation_to_actor.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; ActorAnimation *actor_animation = dynamic_cast<ActorAnimation *>(m_Animations[key]); if (actor_animation) { Actor* actor = m_actors[value]; if (actor) { actor_animation->SetActor(ActorRef(actor)); m_scene->AddAnimation(actor_animation); LOGGER(Log::Logger().Info("Actor %hu (\"%s\") -> %hu (\"%s\")", key, actor->GetName().c_str(), value, actor_animation->GetName().c_str())); } } } for (auto it = m_animation_to_entity.cbegin(); it != m_animation_to_entity.cend(); ++it) { USHORT key = it->first; USHORT value = it->second; EntityAnimation *entity_animation = dynamic_cast<EntityAnimation*>(m_Animations[key]); if (entity_animation) { Entity3D* entity = m_entities[value]; if (entity) { entity_animation->SetEntity(Ref<Entity3D>(entity)); m_scene->AddAnimation(entity_animation); LOGGER(Log::Logger().Info("Entity %hu -> %hu", key, value)); } } } if (m_actors.empty()) throw new EX_DETAILS(SceneLoadException, "Actors are empty for some reason"); Actor * root = m_actors[0]; m_scene->Initialize(root); }