ye.zhang Posted November 29, 2015 Share Posted November 29, 2015 Hi, My programmer is making a click function, After mouse click that the node should run 2 animations .But now it's just run the first one animation. please help us check out the code ,thank very much! here is the function code: namespace Human_PHAnim_Manage{ //give animation to character node void add_human_PHanim(Node ParentNodeName,string commonAnim1,string commonAnim2){ //log.message("human_anim \n"); ObjectMeshSkinned ParentNode_mesh; //parent name ObjectMeshSkinned phone_mesh; //phone model ObjectMeshSkinned phone1_mesh; ObjectMeshSkinned phone2_mesh; ObjectMeshSkinned phone3_mesh; ObjectMeshSkinned cp_mesh; //cp model ObjectMeshSkinned cp1_mesh; ObjectMeshSkinned cp2_mesh; ObjectMeshSkinned cp3_mesh; ObjectMeshSkinned mifi_mesh; //mifi model ObjectMeshSkinned mifi1_mesh; ObjectMeshSkinned mifi2_mesh; ObjectMeshSkinned mifi3_mesh; ObjectMeshSkinned handbag_mesh; ObjectMeshSkinned handbag1_mesh; ObjectMeshSkinned handbag2_mesh; ObjectMeshSkinned handbag3_mesh; ObjectMeshSkinned backpack_mesh; ObjectMeshSkinned backpack1_mesh; ObjectMeshSkinned backpack2_mesh; int speed=20; int isloop0=0; int isloop1=1; ParentNode_mesh=node_cast(ParentNodeName); //Node change to ObjectMeshSkinned ParentNode_mesh.setSpeed(speed); //play speed ParentNode_mesh.setLoop(isloop0); ParentNode_mesh.setNumLayers(2); ParentNode_mesh.setAnimation(0, commonAnim1); ParentNode_mesh.play(); //log.message("%f\n",ParentNode_mesh.isPlaying()); if(ParentNode_mesh.isPlaying()==0){ ParentNode_mesh.setAnimation(1, commonAnim2); ParentNode_mesh.play(); } int phone_id=ParentNodeName.findChild("phone"); if(phone_id !=-1){ Node phone_n=ParentNodeName.getChild(phone_id); phone_mesh=node_cast(phone_n); phone_mesh.setSpeed(speed); phone_mesh.setLoop(isloop0); phone_mesh.setNumLayers(2); phone_mesh.setAnimation(0, commonAnim1); phone_mesh.play(); } if(!phone_mesh.isPlaying()){ phone_mesh.setLoop(isloop1); phone_mesh.setAnimation(1, commonAnim2); phone_mesh.play(); } int phone1_id=ParentNodeName.findChild("phone1"); if(phone1_id !=-1){ Node phone1_n=ParentNodeName.getChild(phone1_id); phone1_mesh=node_cast(phone1_n); phone1_mesh.setSpeed(speed); phone1_mesh.setLoop(isloop0); phone1_mesh.setNumLayers(2); phone1_mesh.setAnimation(0, commonAnim1); phone1_mesh.play(); } if(!phone1_mesh.isPlaying()){ phone1_mesh.setLoop(isloop1); phone1_mesh.setAnimation(1, commonAnim2); phone1_mesh.play(); } int phone2_id=ParentNodeName.findChild("phone2"); if(phone2_id !=-1){ Node phone2_n=ParentNodeName.getChild(phone2_id); phone2_mesh=node_cast(phone2_n); phone2_mesh.setSpeed(speed); phone2_mesh.setLoop(isloop0); phone2_mesh.setNumLayers(2); phone2_mesh.setAnimation(0, commonAnim1); phone2_mesh.play(); } if(!phone2_mesh.isPlaying()){ phone2_mesh.setLoop(isloop1); phone2_mesh.setAnimation(1, commonAnim2); phone2_mesh.play(); } int phone3_id=ParentNodeName.findChild("phone3"); if(phone3_id !=-1){ Node phone3_n=ParentNodeName.getChild(phone3_id); phone3_mesh=node_cast(phone3_n); phone3_mesh.setSpeed(speed); phone3_mesh.setLoop(isloop0); phone3_mesh.setNumLayers(2); phone3_mesh.setAnimation(0, commonAnim1); phone3_mesh.play(); } if(!phone3_mesh.isPlaying()){ phone3_mesh.setLoop(isloop1); phone3_mesh.setAnimation(1, commonAnim2); phone3_mesh.play(); } int cp_id=ParentNodeName.findChild("cp"); if(cp_id !=-1){ Node cp_n=ParentNodeName.getChild(cp_id); cp_mesh=node_cast(cp_n); cp_mesh.setSpeed(speed); cp_mesh.setLoop(isloop0); cp_mesh.setNumLayers(2); cp_mesh.setAnimation(0, commonAnim1); cp_mesh.play(); } if(!cp_mesh.isPlaying()){ cp_mesh.setLoop(isloop1); cp_mesh.setAnimation(1, commonAnim2); cp_mesh.play(); } int cp1_id=ParentNodeName.findChild("cp1"); if(cp1_id !=-1){ Node cp1_n=ParentNodeName.getChild(cp1_id); cp1_mesh=node_cast(cp1_n); cp1_mesh.setSpeed(speed); cp1_mesh.setLoop(isloop0); cp1_mesh.setNumLayers(2); cp1_mesh.setAnimation(0, commonAnim1); cp1_mesh.play(); } if(!cp1_mesh.isPlaying()){ cp1_mesh.setLoop(isloop1); cp1_mesh.setAnimation(1, commonAnim2); cp1_mesh.play(); } int cp2_id=ParentNodeName.findChild("cp2"); if(cp2_id !=-1){ Node cp2_n=ParentNodeName.getChild(cp2_id); cp2_mesh=node_cast(cp2_n); cp2_mesh.setSpeed(speed); cp2_mesh.setLoop(isloop0); cp2_mesh.setNumLayers(2); cp2_mesh.setAnimation(0, commonAnim1); cp2_mesh.play(); } if(!cp2_mesh.isPlaying()){ cp2_mesh.setLoop(isloop1); cp2_mesh.setAnimation(1, commonAnim2); cp2_mesh.play(); } int cp3_id=ParentNodeName.findChild("cp3"); if(cp3_id !=-1){ Node cp3_n=ParentNodeName.getChild(cp3_id); cp3_mesh=node_cast(cp3_n); cp3_mesh.setSpeed(speed); cp3_mesh.setLoop(isloop0); cp3_mesh.setNumLayers(2); cp3_mesh.setAnimation(0, commonAnim1); cp3_mesh.play(); } if(!cp3_mesh.isPlaying()){ cp3_mesh.setLoop(isloop1); cp3_mesh.setAnimation(1, commonAnim2); cp3_mesh.play(); } int mifi_id=ParentNodeName.findChild("mifi"); if(mifi_id !=-1){ Node mifi_n=ParentNodeName.getChild(mifi_id); mifi_mesh=node_cast(mifi_n); mifi_mesh.setSpeed(speed); mifi_mesh.setLoop(isloop0); mifi_mesh.setNumLayers(2); mifi_mesh.setAnimation(0, commonAnim1); mifi_mesh.play(); } if(!mifi_mesh.isPlaying()){ mifi_mesh.setLoop(isloop1); mifi_mesh.setAnimation(1, commonAnim2); mifi_mesh.play(); } int mifi1_id=ParentNodeName.findChild("mifi1"); if(mifi1_id !=-1){ Node mifi1_n=ParentNodeName.getChild(mifi1_id); mifi1_mesh=node_cast(mifi1_n); mifi1_mesh.setSpeed(speed); mifi1_mesh.setLoop(isloop0); mifi1_mesh.setNumLayers(2); mifi1_mesh.setAnimation(0, commonAnim1); mifi1_mesh.play(); } if(!mifi1_mesh.isPlaying()){ mifi1_mesh.setLoop(isloop1); mifi1_mesh.setAnimation(1, commonAnim2); mifi1_mesh.play(); } int mifi2_id=ParentNodeName.findChild("mifi2"); if(mifi2_id !=-1){ Node mifi2_n=ParentNodeName.getChild(mifi2_id); mifi2_mesh=node_cast(mifi2_n); mifi2_mesh.setSpeed(speed); mifi2_mesh.setLoop(isloop0); mifi2_mesh.setNumLayers(2); mifi2_mesh.setAnimation(0, commonAnim1); mifi2_mesh.play(); } if(!mifi2_mesh.isPlaying()){ mifi2_mesh.setLoop(isloop1); mifi2_mesh.setAnimation(1, commonAnim2); mifi2_mesh.play(); } int mifi3_id=ParentNodeName.findChild("mifi3"); if(mifi3_id !=-1){ Node mifi3_n=ParentNodeName.getChild(mifi3_id); mifi3_mesh=node_cast(mifi3_n); mifi3_mesh.setSpeed(speed); mifi3_mesh.setLoop(isloop0); mifi3_mesh.setNumLayers(2); mifi3_mesh.setAnimation(0, commonAnim1); mifi3_mesh.play(); } if(!mifi3_mesh.isPlaying()){ mifi3_mesh.setLoop(isloop1); mifi3_mesh.setAnimation(1, commonAnim2); mifi3_mesh.play(); } int handbag_id=ParentNodeName.findChild("handbag"); if(handbag_id !=-1){ Node handbag_n=ParentNodeName.ge here is the call: switch(people_type){ case DOWNWOMAN_HANDBAG: // anim="metro/human/woman_handbag/animations/Woman_handbag_down_play_ph.anim"; // Human_Anim_Manage::add_human_anim(current_people,anim); //this part is one animation call witch is successfull anim1="metro/human/woman_handbag/animations/Woman_handbag_down_ph_take.anim"; anim2="metro/human/woman_handbag/animations/Woman_handbag_down_play_ph.anim"; Human_PHAnim_Manage::add_human_PHanim(current_people,anim1,anim2); break; Link to comment
honya Posted November 29, 2015 Share Posted November 29, 2015 Hi Zhang, you never set anim2, because selected mesh is always playing animation and if not, then you get NULL error. Honya Link to comment
ye.zhang Posted November 29, 2015 Author Share Posted November 29, 2015 Hi Zhang, you never set anim2, because selected mesh is always playing animation and if not, then you get NULL error. Honya Hi Honya, thanks for your reply. My English is a little poor,sorry.You mean it is no way to control a node run animations one by one ? I know animations can switch in track editor,but my project has a large number of character nodes and animations with appear random.so we can't set every situations. does it has any other ways? thanks! Link to comment
honya Posted November 29, 2015 Share Posted November 29, 2015 For understand how Unigine working with animations i recommending check Skinner samples in UnigineScript section. In your case check skinner.sequence that play first animation, when it finish it, then via skinner.switch do switch to skinner.animation that will play second animation. if your parent node is also Skinned mesh, then you can set animation only to parent and set to children that are controlled by parent for animation. About layer, function play show only animation setted to layer 0. You can add different animations to different layer, but you must do lerp or copy others layers to layer 0, if you want see other animatios too. If you want to control animations in script, then in one function set animations to the skinned mesh and in each called update function set animation time and check if first animation is already stoped and start play second animation. Link to comment
ye.zhang Posted November 29, 2015 Author Share Posted November 29, 2015 Honya: thanks for your help ! I'll try your advice! thanks again! Link to comment
Recommended Posts