void BL_ConvertMaterialIpos( struct Object* blenderobject, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter ) { if (blenderobject->totcol==1) { Material *mat = give_current_material(blenderobject, 1); // if there is only one material attached to the mesh then set material_index in BL_ConvertMaterialIpos to NULL // --> this makes the UpdateMaterialData function in KX_GameObject.cpp use the old hack of using SetObjectColor // because this yields a better performance as not all the vertex colors need to be edited if(mat) ConvertMaterialIpos(mat, 0, gameobj, converter); } else { for (int material_index=1; material_index <= blenderobject->totcol; material_index++) { Material *mat = give_current_material(blenderobject, material_index); STR_HashedString matname; if(mat) { matname= mat->id.name; // who is using this name? can we remove the MA here? ConvertMaterialIpos(mat, matname.hash(), gameobj, converter); } } } }
bool BL_Action::Play(const char* name, float start, float end, short priority, float blendin, short play_mode, float layer_weight, short ipo_flags, float playback_speed) { // Only start playing a new action if we're done, or if // the new action has a higher priority if (!IsDone() && priority > m_priority) return false; m_priority = priority; bAction* prev_action = m_action; KX_Scene* kxscene = m_obj->GetScene(); // First try to load the action m_action = (bAction*)kxscene->GetLogicManager()->GetActionByName(name); if (!m_action) { printf("Failed to load action: %s\n", name); m_done = true; return false; } // If we have the same settings, don't play again // This is to resolve potential issues with pulses on sensors such as the ones // reported in bug #29412. The fix is here so it works for both logic bricks and Python. // However, this may eventually lead to issues where a user wants to override an already // playing action with the same action and settings. If this becomes an issue, // then this fix may have to be re-evaluated. if (!IsDone() && m_action == prev_action && m_startframe == start && m_endframe == end && m_priority == priority && m_speed == playback_speed) return false; // First get rid of any old controllers ClearControllerList(); // Create an SG_Controller SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); // Try obcolor sg_contr = BL_CreateObColorIPO(m_action, m_obj, kxscene->GetSceneConverter()); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } // Now try materials if (m_obj->GetBlenderObject()->totcol==1) { Material *mat = give_current_material(m_obj->GetBlenderObject(), 1); if (mat) { sg_contr = BL_CreateMaterialIpo(m_action, mat, 0, m_obj, kxscene->GetSceneConverter()); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } } } else { Material *mat; STR_HashedString matname; for (int matidx = 1; matidx <= m_obj->GetBlenderObject()->totcol; ++matidx) { mat = give_current_material(m_obj->GetBlenderObject(), matidx); if (mat) { matname = mat->id.name; sg_contr = BL_CreateMaterialIpo(m_action, mat, matname.hash(), m_obj, kxscene->GetSceneConverter()); if (sg_contr) { m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } } } } // Extra controllers if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) { sg_contr = BL_CreateLampIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) { sg_contr = BL_CreateCameraIPO(m_action, m_obj, kxscene->GetSceneConverter()); m_sg_contr_list.push_back(sg_contr); m_obj->GetSGNode()->AddSGController(sg_contr); sg_contr->SetObject(m_obj->GetSGNode()); } m_ipo_flags = ipo_flags; InitIPO(); // Setup blendin shapes/poses if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; obj->GetMRDPose(&m_blendinpose); } else { BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); if (shape_deformer && shape_deformer->GetKey()) { obj->GetShape(m_blendinshape); // Now that we have the previous blend shape saved, we can clear out the key to avoid any // further interference. KeyBlock *kb; for (kb=(KeyBlock *)shape_deformer->GetKey()->block.first; kb; kb=(KeyBlock *)kb->next) kb->curval = 0.f; } } // Now that we have an action, we have something we can play m_starttime = -1.f; // We get the start time on our first update m_startframe = m_localtime = start; m_endframe = end; m_blendin = blendin; m_playmode = play_mode; m_endtime = 0.f; m_blendframe = 0.f; m_blendstart = 0.f; m_speed = playback_speed; m_layer_weight = layer_weight; m_done = false; return true; }