| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 13:30:41 +00:00
										 |  |  | /** \file gameengine/Converter/BL_ShapeActionActuator.cpp
 | 
					
						
							|  |  |  |  *  \ingroup bgeconv | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | #include <cmath>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SCA_LogicManager.h"
 | 
					
						
							|  |  |  | #include "BL_ShapeActionActuator.h"
 | 
					
						
							|  |  |  | #include "BL_ShapeDeformer.h"
 | 
					
						
							|  |  |  | #include "KX_GameObject.h"
 | 
					
						
							|  |  |  | #include "STR_HashedString.h"
 | 
					
						
							|  |  |  | #include "DNA_nla_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | #include "DNA_action_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-26 20:06:16 +00:00
										 |  |  | #include "DNA_anim_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | #include "BKE_action.h"
 | 
					
						
							|  |  |  | #include "DNA_armature_types.h"
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | #include "MT_Matrix4x4.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 19:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-22 21:49:48 +00:00
										 |  |  | #include "FloatValue.h"
 | 
					
						
							| 
									
										
										
										
											2008-09-06 14:13:31 +00:00
										 |  |  | #include "PyObjectPlus.h"
 | 
					
						
							| 
									
										
										
										
											2008-09-06 02:46:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-26 20:06:16 +00:00
										 |  |  | extern "C" { | 
					
						
							|  |  |  | 	#include "BKE_animsys.h"
 | 
					
						
							| 
									
										
										
										
											2011-06-23 19:09:09 +00:00
										 |  |  | 	#include "BKE_key.h"
 | 
					
						
							|  |  |  | 	#include "RNA_access.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-26 20:06:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 19:09:09 +00:00
										 |  |  | BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj, | 
					
						
							|  |  |  | 					const STR_String& propname, | 
					
						
							|  |  |  | 					const STR_String& framepropname, | 
					
						
							|  |  |  | 					float starttime, | 
					
						
							|  |  |  | 					float endtime, | 
					
						
							|  |  |  | 					struct bAction *action, | 
					
						
							|  |  |  | 					short	playtype, | 
					
						
							|  |  |  | 					short	blendin, | 
					
						
							|  |  |  | 					short	priority, | 
					
						
							|  |  |  | 					float	stride)  | 
					
						
							|  |  |  | 	: SCA_IActuator(gameobj, KX_ACT_SHAPEACTION), | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	m_lastpos(0, 0, 0), | 
					
						
							|  |  |  | 	m_blendframe(0), | 
					
						
							|  |  |  | 	m_flag(0), | 
					
						
							|  |  |  | 	m_startframe (starttime), | 
					
						
							|  |  |  | 	m_endframe(endtime) , | 
					
						
							|  |  |  | 	m_starttime(0), | 
					
						
							|  |  |  | 	m_localtime(starttime), | 
					
						
							|  |  |  | 	m_lastUpdate(-1), | 
					
						
							|  |  |  | 	m_blendin(blendin), | 
					
						
							|  |  |  | 	m_blendstart(0), | 
					
						
							|  |  |  | 	m_stridelength(stride), | 
					
						
							|  |  |  | 	m_playtype(playtype), | 
					
						
							|  |  |  | 	m_priority(priority), | 
					
						
							|  |  |  | 	m_action(action), | 
					
						
							|  |  |  | 	m_framepropname(framepropname),	 | 
					
						
							|  |  |  | 	m_propname(propname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_idptr = new PointerRNA(); | 
					
						
							|  |  |  | 	BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent(); | 
					
						
							|  |  |  | 	BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); | 
					
						
							|  |  |  | 	RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | BL_ShapeActionActuator::~BL_ShapeActionActuator() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-23 19:09:09 +00:00
										 |  |  | 	if (m_idptr) | 
					
						
							|  |  |  | 		delete m_idptr; | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BL_ShapeActionActuator::ProcessReplica() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	SCA_IActuator::ProcessReplica(); | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	m_localtime=m_startframe; | 
					
						
							|  |  |  | 	m_lastUpdate=-1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BL_ShapeActionActuator::SetBlendTime (float newtime) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_blendframe = newtime; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CValue* BL_ShapeActionActuator::GetReplica()  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BL_ShapeActionActuator* replica = new BL_ShapeActionActuator(*this);//m_float,GetName());
 | 
					
						
							|  |  |  | 	replica->ProcessReplica(); | 
					
						
							|  |  |  | 	return replica; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool BL_ShapeActionActuator::ClampLocalTime() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_startframe < m_endframe)	{ | 
					
						
							|  |  |  | 		if (m_localtime < m_startframe) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_localtime = m_startframe; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}  | 
					
						
							|  |  |  | 		else if (m_localtime > m_endframe) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_localtime = m_endframe; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (m_localtime > m_startframe) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_localtime = m_startframe; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (m_localtime < m_endframe) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_localtime = m_endframe; | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BL_ShapeActionActuator::SetStartTime(float curtime) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float direction = m_startframe < m_endframe ? 1.0 : -1.0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!(m_flag & ACT_FLAG_REVERSE)) | 
					
						
							|  |  |  | 		m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BL_ShapeActionActuator::SetLocalTime(float curtime) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (m_endframe < m_startframe) | 
					
						
							|  |  |  | 		delta_time = -delta_time; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(m_flag & ACT_FLAG_REVERSE)) | 
					
						
							|  |  |  | 		m_localtime = m_startframe + delta_time; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		m_localtime = m_endframe - delta_time; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	vector<float>::const_iterator it; | 
					
						
							|  |  |  | 	float dstweight; | 
					
						
							|  |  |  | 	KeyBlock *kb; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	dstweight = 1.0F - srcweight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (it=m_blendshape.begin(), kb = (KeyBlock*)key->block.first;  | 
					
						
							| 
									
										
										
										
											2011-11-11 13:09:14 +00:00
										 |  |  | 	     kb && it != m_blendshape.end(); | 
					
						
							|  |  |  | 	     kb = (KeyBlock*)kb->next, it++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 		kb->curval = kb->curval * dstweight + (*it) * srcweight; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool BL_ShapeActionActuator::Update(double curtime, bool frame) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool bNegativeEvent = false; | 
					
						
							|  |  |  | 	bool bPositiveEvent = false; | 
					
						
							|  |  |  | 	bool keepgoing = true; | 
					
						
							|  |  |  | 	bool wrap = false; | 
					
						
							|  |  |  | 	bool apply=true; | 
					
						
							|  |  |  | 	int	priority; | 
					
						
							|  |  |  | 	float newweight; | 
					
						
							| 
									
										
										
										
											2008-09-16 21:11:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	curtime -= KX_KetsjiEngine::GetSuspendedDelta(); | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	// result = true if animation has to be continued, false if animation stops
 | 
					
						
							|  |  |  | 	// maybe there are events for us in the queue !
 | 
					
						
							|  |  |  | 	if (frame) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 		bNegativeEvent = m_negevent; | 
					
						
							|  |  |  | 		bPositiveEvent = m_posevent; | 
					
						
							|  |  |  | 		RemoveAllEvents(); | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (bPositiveEvent) | 
					
						
							|  |  |  | 			m_flag |= ACT_FLAG_ACTIVE; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (bNegativeEvent) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_ACTIVE)) | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			m_flag &= ~ACT_FLAG_ACTIVE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/*	This action can only be attached to a deform object */ | 
					
						
							|  |  |  | 	BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent(); | 
					
						
							|  |  |  | 	float length = m_endframe - m_startframe; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	priority = m_priority; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-01 12:20:18 +00:00
										 |  |  | 	/* Determine pre-incrementation behavior and set appropriate flags */ | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 	switch (m_playtype) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	case ACT_ACTION_MOTION: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			keepgoing=false; | 
					
						
							|  |  |  | 			apply=false; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_FROM_PROP: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			apply=false; | 
					
						
							|  |  |  | 			keepgoing=false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_LOOP_END: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bPositiveEvent) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_LOCKINPUT)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				m_flag &= ~ACT_FLAG_KEYUP; | 
					
						
							|  |  |  | 				m_flag &= ~ACT_FLAG_REVERSE; | 
					
						
							|  |  |  | 				m_flag |= ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 				m_localtime = m_startframe; | 
					
						
							|  |  |  | 				m_starttime = curtime; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			m_flag |= ACT_FLAG_KEYUP; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_LOOP_STOP: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bPositiveEvent) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_LOCKINPUT)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				m_flag &= ~ACT_FLAG_REVERSE; | 
					
						
							|  |  |  | 				m_flag &= ~ACT_FLAG_KEYUP; | 
					
						
							|  |  |  | 				m_flag |= ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 				SetStartTime(curtime); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			m_flag |= ACT_FLAG_KEYUP; | 
					
						
							|  |  |  | 			m_flag &= ~ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			keepgoing=false; | 
					
						
							|  |  |  | 			apply=false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-02-16 19:53:39 +00:00
										 |  |  | 	case ACT_ACTION_PINGPONG: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bPositiveEvent) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_LOCKINPUT)) { | 
					
						
							| 
									
										
										
										
											2011-02-16 19:53:39 +00:00
										 |  |  | 				m_flag &= ~ACT_FLAG_KEYUP; | 
					
						
							|  |  |  | 				m_localtime = m_starttime; | 
					
						
							|  |  |  | 				m_starttime = curtime; | 
					
						
							|  |  |  | 				m_flag |= ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	case ACT_ACTION_FLIPPER: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bPositiveEvent) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_LOCKINPUT)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				m_flag &= ~ACT_FLAG_REVERSE; | 
					
						
							|  |  |  | 				m_flag |= ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 				SetStartTime(curtime); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		else if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			m_flag |= ACT_FLAG_REVERSE; | 
					
						
							|  |  |  | 			m_flag &= ~ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			SetStartTime(curtime); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_PLAY: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (bPositiveEvent) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_LOCKINPUT)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				m_flag &= ~ACT_FLAG_REVERSE; | 
					
						
							|  |  |  | 				m_localtime = m_starttime; | 
					
						
							|  |  |  | 				m_starttime = curtime; | 
					
						
							|  |  |  | 				m_flag |= ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Perform increment */ | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 	if (keepgoing) { | 
					
						
							|  |  |  | 		if (m_playtype == ACT_ACTION_MOTION) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			MT_Point3	newpos; | 
					
						
							|  |  |  | 			MT_Point3	deltapos; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			newpos = obj->NodeGetWorldPosition(); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			/* Find displacement */ | 
					
						
							|  |  |  | 			deltapos = newpos-m_lastpos; | 
					
						
							|  |  |  | 			m_localtime += (length/m_stridelength) * deltapos.length(); | 
					
						
							|  |  |  | 			m_lastpos = newpos; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else{ | 
					
						
							|  |  |  | 			SetLocalTime(curtime); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Check if a wrapping response is needed */ | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 	if (length) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 		if (m_localtime < m_startframe || m_localtime > m_endframe) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			m_localtime = m_startframe + fmod(m_localtime, length); | 
					
						
							|  |  |  | 			wrap = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		m_localtime = m_startframe; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Perform post-increment tasks */ | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 	switch (m_playtype) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	case ACT_ACTION_FROM_PROP: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			CValue* propval = GetParent()->GetProperty(m_propname); | 
					
						
							|  |  |  | 			if (propval) | 
					
						
							|  |  |  | 				m_localtime = propval->GetNumber(); | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 			if (bNegativeEvent) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				keepgoing=false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_MOTION: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_LOOP_STOP: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-02-16 19:53:39 +00:00
										 |  |  | 	case ACT_ACTION_PINGPONG: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (wrap) { | 
					
						
							| 
									
										
										
										
											2011-02-16 19:53:39 +00:00
										 |  |  | 			if (!(m_flag & ACT_FLAG_REVERSE)) | 
					
						
							|  |  |  | 				m_localtime = m_endframe; | 
					
						
							|  |  |  | 			else  | 
					
						
							|  |  |  | 				m_localtime = m_startframe; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			m_flag &= ~ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			m_flag ^= ACT_FLAG_REVERSE; //flip direction
 | 
					
						
							|  |  |  | 			keepgoing = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	case ACT_ACTION_FLIPPER: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (wrap) { | 
					
						
							|  |  |  | 			if (!(m_flag & ACT_FLAG_REVERSE)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				m_localtime=m_endframe; | 
					
						
							|  |  |  | 				//keepgoing = false;
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				m_localtime=m_startframe; | 
					
						
							|  |  |  | 				keepgoing = false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_LOOP_END: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (wrap) { | 
					
						
							|  |  |  | 			if (m_flag & ACT_FLAG_KEYUP) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 				keepgoing = false; | 
					
						
							|  |  |  | 				m_localtime = m_endframe; | 
					
						
							|  |  |  | 				m_flag &= ~ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			SetStartTime(curtime); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ACT_ACTION_PLAY: | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (wrap) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 			m_localtime = m_endframe; | 
					
						
							|  |  |  | 			keepgoing = false; | 
					
						
							|  |  |  | 			m_flag &= ~ACT_FLAG_LOCKINPUT; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		keepgoing = false; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-09-22 21:49:48 +00:00
										 |  |  | 	/* Set the property if its defined */ | 
					
						
							|  |  |  | 	if (m_framepropname[0] != '\0') { | 
					
						
							|  |  |  | 		CValue* propowner = GetParent(); | 
					
						
							|  |  |  | 		CValue* oldprop = propowner->GetProperty(m_framepropname); | 
					
						
							|  |  |  | 		CValue* newval = new CFloatValue(m_localtime); | 
					
						
							|  |  |  | 		if (oldprop) { | 
					
						
							|  |  |  | 			oldprop->SetValue(newval); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			propowner->SetProperty(m_framepropname, newval); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		newval->Release(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (bNegativeEvent) | 
					
						
							|  |  |  | 		m_blendframe=0.0f; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Apply the pose if necessary*/ | 
					
						
							|  |  |  | 	if (apply) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Priority test */ | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 		if (obj->SetActiveAction(this, priority, curtime)) { | 
					
						
							| 
									
										
										
										
											2011-06-23 19:09:09 +00:00
										 |  |  | 			BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); | 
					
						
							|  |  |  | 			Key *key = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (shape_deformer) | 
					
						
							|  |  |  | 				key = shape_deformer->GetKey(); | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (!key) { | 
					
						
							|  |  |  | 				// this could happen if the mesh was changed in the middle of an action
 | 
					
						
							|  |  |  | 				// and the new mesh has no key, stop the action
 | 
					
						
							|  |  |  | 				keepgoing = false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				ListBase tchanbase= {NULL, NULL}; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 				if (m_blendin && m_blendframe==0.0f) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 					// this is the start of the blending, remember the startup shape
 | 
					
						
							|  |  |  | 					obj->GetShape(m_blendshape); | 
					
						
							|  |  |  | 					m_blendstart = curtime; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-08-26 20:06:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 19:09:09 +00:00
										 |  |  | 				KeyBlock *kb; | 
					
						
							|  |  |  | 				// We go through and clear out the keyblocks so there isn't any interference
 | 
					
						
							|  |  |  | 				// from other shape actions
 | 
					
						
							|  |  |  | 				for (kb=(KeyBlock*)key->block.first; kb; kb=(KeyBlock*)kb->next) | 
					
						
							|  |  |  | 					kb->curval = 0.f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				animsys_evaluate_action(m_idptr, m_action, NULL, m_localtime); | 
					
						
							| 
									
										
										
										
											2009-08-26 20:06:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// XXX - in 2.5 theres no way to do this. possibly not that important to support - Campbell
 | 
					
						
							| 
									
										
											  
											
												2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split, 
press SHIFT+ALT+CTRL+S for four-split. 
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
  convert from older files. Not all settings are copied over
  though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
  for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
											
										 
											2009-01-19 16:54:41 +00:00
										 |  |  | 				if (0) { // XXX !execute_ipochannels(&tchanbase)) {
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 					// no update, this is possible if action does not match the keys, stop the action
 | 
					
						
							|  |  |  | 					keepgoing = false; | 
					
						
							|  |  |  | 				}  | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					// the key have changed, apply blending if needed
 | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 					if (m_blendin && (m_blendframe<m_blendin)) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 						newweight = (m_blendframe/(float)m_blendin); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						BlendShape(key, 1.0f - newweight); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						/* Increment current blending percentage */ | 
					
						
							|  |  |  | 						m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate(); | 
					
						
							|  |  |  | 						if (m_blendframe>m_blendin) | 
					
						
							|  |  |  | 							m_blendframe = m_blendin; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					m_lastUpdate = m_localtime; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				BLI_freelistN(&tchanbase); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else{ | 
					
						
							|  |  |  | 			m_blendframe = 0.0f; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-28 05:03:24 +00:00
										 |  |  | 	if (!keepgoing) { | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | 		m_blendframe = 0.0f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return keepgoing; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
										
											2009-09-29 21:42:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | /* ------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Python functions                                                          */ | 
					
						
							|  |  |  | /* ------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Integration hooks ------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject BL_ShapeActionActuator::Type = { | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							| 
									
										
										
										
											2009-08-10 00:07:34 +00:00
										 |  |  | 	"BL_ShapeActionActuator", | 
					
						
							|  |  |  | 	sizeof(PyObjectPlus_Proxy), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	py_base_dealloc, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	py_base_repr, | 
					
						
							|  |  |  | 	0,0,0,0,0,0,0,0,0, | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | 
					
						
							|  |  |  | 	0,0,0,0,0,0,0, | 
					
						
							|  |  |  | 	Methods, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	&SCA_IActuator::Type, | 
					
						
							|  |  |  | 	0,0,0,0,0,0, | 
					
						
							|  |  |  | 	py_base_new | 
					
						
							| 
									
										
										
										
											2008-06-18 06:46:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyMethodDef BL_ShapeActionActuator::Methods[] = { | 
					
						
							|  |  |  | 	{NULL,NULL} //Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | PyAttributeDef BL_ShapeActionActuator::Attributes[] = { | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe), | 
					
						
							|  |  |  | 	KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe), | 
					
						
							|  |  |  | 	KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin), | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action), | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | 	KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority), | 
					
						
							|  |  |  | 	KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame), | 
					
						
							| 
									
										
										
										
											2012-01-16 05:27:11 +00:00
										 |  |  | 	KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_propname), | 
					
						
							|  |  |  | 	KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_framepropname), | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | 	KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime), | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType), | 
					
						
							| 
									
										
										
										
											2009-01-26 08:34:40 +00:00
										 |  |  | 	{ NULL }	//Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v); | 
					
						
							| 
									
										
										
										
											2009-06-29 02:25:54 +00:00
										 |  |  | 	return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : ""); | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BL_ShapeActionActuator* self= static_cast<BL_ShapeActionActuator*>(self_v); | 
					
						
							|  |  |  | 	/* exact copy of BL_ActionActuator's function from here down */ | 
					
						
							| 
									
										
										
										
											2009-06-29 02:25:54 +00:00
										 |  |  | 	if (!PyUnicode_Check(value)) | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action"); | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 		return PY_SET_ATTR_FAIL; | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bAction *action= NULL; | 
					
						
							| 
									
										
										
										
											2009-06-29 02:25:54 +00:00
										 |  |  | 	STR_String val = _PyUnicode_AsString(value); | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (val != "") | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); | 
					
						
							|  |  |  | 		if (action==NULL) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!"); | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 			return PY_SET_ATTR_FAIL; | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	self->SetAction(action); | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	return PY_SET_ATTR_SUCCESS; | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-29 21:42:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #endif // WITH_PYTHON
 |