Merge branch 'master' into blender2.8

This commit is contained in:
Campbell Barton 2018-11-30 15:11:32 +11:00
commit 8f8c238659
16 changed files with 4024 additions and 42 deletions

@ -72,14 +72,14 @@ void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt);
*/
/* convenience looper over ALL driver targets for a given variable (even the unused ones) */
#define DRIVER_TARGETS_LOOPER(dvar) \
#define DRIVER_TARGETS_LOOPER_BEGIN(dvar) \
{ \
DriverTarget *dtar = &dvar->targets[0]; \
int tarIndex = 0; \
for (; tarIndex < MAX_DRIVER_TARGETS; tarIndex++, dtar++)
/* convenience looper over USED driver targets only */
#define DRIVER_TARGETS_USED_LOOPER(dvar) \
#define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar) \
{ \
DriverTarget *dtar = &dvar->targets[0]; \
int tarIndex = 0; \
@ -87,7 +87,7 @@ void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt);
/* tidy up for driver targets loopers */
#define DRIVER_TARGETS_LOOPER_END \
}
} ((void)0)
/* ---------------------- */

@ -405,13 +405,13 @@ void BKE_animdata_merge_copy(
DriverVar *dvar;
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->id == src_id) {
dtar->id = dst_id;
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}
@ -754,7 +754,7 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix
/* driver variables */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* only change the used targets, since the others will need fixing manually anyway */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
/* rename RNA path */
if (dtar->rna_path && dtar->id)
@ -769,7 +769,7 @@ static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix
}
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}

File diff suppressed because it is too large Load Diff

@ -1315,7 +1315,7 @@ static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
{
short valid_targets = 0;
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
@ -1331,7 +1331,7 @@ static short driver_check_valid_targets(ChannelDriver *driver, DriverVar *dvar)
valid_targets++;
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
return valid_targets;
}
@ -1418,7 +1418,7 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
/* SECOND PASS: get two location values */
/* NOTE: for now, these are all just worldspace */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
/* get pointer to loc values to store in */
Object *ob = (Object *)dtar_id_ensure_proxy_from(dtar->id);
@ -1489,7 +1489,7 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
copy_v3_v3(loc1, tmp_loc);
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
/* if we're still here, there should now be two targets to use,
@ -1674,13 +1674,13 @@ void driver_free_variable(ListBase *variables, DriverVar *dvar)
* currently, since there may be some lingering RNA paths from
* previous users needing freeing
*/
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
/* free RNA path if applicable */
if (dtar->rna_path)
MEM_freeN(dtar->rna_path);
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
/* remove the variable from the driver */
BLI_freelinkN(variables, dvar);
@ -1704,13 +1704,13 @@ void driver_variables_copy(ListBase *dst_vars, const ListBase *src_vars)
for (DriverVar *dvar = dst_vars->first; dvar; dvar = dvar->next) {
/* need to go over all targets so that we don't leave any dangling paths */
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
/* make a copy of target's rna path if available */
if (dtar->rna_path)
dtar->rna_path = MEM_dupallocN(dtar->rna_path);
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
@ -1730,7 +1730,7 @@ void driver_change_variable_type(DriverVar *dvar, int type)
/* make changes to the targets based on the defines for these types
* NOTE: only need to make sure the ones we're using here are valid...
*/
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
short flags = dvti->target_flags[tarIndex];
@ -1741,7 +1741,7 @@ void driver_change_variable_type(DriverVar *dvar, int type)
if ((flags & DTAR_FLAG_ID_OB_ONLY) || (dtar->idtype == 0))
dtar->idtype = ID_OB;
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
/* Validate driver name (after being renamed) */

@ -249,11 +249,11 @@ static void library_foreach_animationData(LibraryForeachIDData *data, AnimData *
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* only used targets */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
FOREACH_CALLBACK_INVOKE_ID(data, dtar->id, IDWALK_CB_NOP);
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -1528,7 +1528,7 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target)
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* all drivers */
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
if (dtar->id) {
if ((Object *)dtar->id == target)
@ -1542,7 +1542,7 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target)
}
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}

@ -2591,7 +2591,7 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
DriverVar *dvar;
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
/* only relink if still used */
if (tarIndex < dvar->num_targets)
@ -2599,7 +2599,7 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
else
dtar->id = NULL;
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
@ -2694,7 +2694,7 @@ static void direct_link_fcurves(FileData *fd, ListBase *list)
/* relink variables, targets and their paths */
link_list(fd, &driver->variables);
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
/* only relink the targets being used */
if (tarIndex < dvar->num_targets)
@ -2702,7 +2702,7 @@ static void direct_link_fcurves(FileData *fd, ListBase *list)
else
dtar->rna_path = NULL;
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
@ -9426,12 +9426,12 @@ static void expand_fcurves(FileData *fd, Main *mainvar, ListBase *list)
DriverVar *dvar;
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
// TODO: only expand those that are going to get used?
expand_doit(fd, mainvar, dtar->id);
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -378,7 +378,7 @@ static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), FCurve *fcu, void
/* Driver -> Driver Vars (for bbone_in/out) */
if (fcu->driver) {
for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_LOOPER(dvar)
DRIVER_TARGETS_LOOPER_BEGIN(dvar)
{
if (dtar->rna_path) {
dtar->rna_path = replace_bbone_easing_rnapath(dtar->rna_path);

@ -846,13 +846,13 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
/* variables */
writelist(wd, DATA, DriverVar, &driver->variables);
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->rna_path) {
writedata(wd, DATA, strlen(dtar->rna_path) + 1, dtar->rna_path);
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -956,7 +956,7 @@ void DepsgraphNodeBuilder::build_driver_variables(ID * id, FCurve *fcurve)
{
build_driver_id_property(id, fcurve->rna_path);
LISTBASE_FOREACH (DriverVar *, dvar, &fcurve->driver->variables) {
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->id == NULL) {
continue;
@ -972,7 +972,7 @@ void DepsgraphNodeBuilder::build_driver_variables(ID * id, FCurve *fcurve)
build_driver_id_property(&proxy_from->id, dtar->rna_path);
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -1469,7 +1469,7 @@ void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
/* Only used targets. */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->id == NULL) {
continue;
@ -1543,7 +1543,7 @@ void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
* is an incomplete target reference, so nothing to do here. */
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -1173,12 +1173,12 @@ static bool fcurve_has_errors(FCurve *fcu)
/* check variables for other things that need linting... */
// TODO: maybe it would be more efficient just to have a quick flag for this?
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->flag & DTAR_FLAG_INVALID)
return true;
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}

@ -166,7 +166,7 @@ static void joined_armature_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data
/* Fix driver references to invalid ID's */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* only change the used targets, since the others will need fixing manually anyway */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
/* change the ID's used... */
if (dtar->id == src_id) {
@ -199,7 +199,7 @@ static void joined_armature_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data
}
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}

@ -1904,7 +1904,7 @@ static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data)
/* Fix driver references to invalid ID's */
for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) {
/* only change the used targets, since the others will need fixing manually anyway */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
/* change the ID's used... */
if (dtar->id == src_id) {
@ -1933,7 +1933,7 @@ static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data)
}
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}

@ -831,7 +831,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* loop over all targets used here */
DRIVER_TARGETS_USED_LOOPER(dvar)
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (lastadded != dtar->id) {
// XXX this lastadded check is rather lame, and also fails quite badly...
@ -839,7 +839,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
lastadded = dtar->id;
}
}
DRIVER_TARGETS_LOOPER_END
DRIVER_TARGETS_LOOPER_END;
}
}
}

@ -0,0 +1,237 @@
/*
* ***** 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,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* 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 *****
*/
/** \file gameengine/Converter/BL_ShapeDeformer.cpp
* \ingroup bgeconv
*/
#ifdef _MSC_VER
# pragma warning (disable:4786)
#endif
#include "MEM_guardedalloc.h"
#include "BL_ShapeDeformer.h"
#include "CTR_Map.h"
#include "STR_HashedString.h"
#include "RAS_IPolygonMaterial.h"
#include "RAS_MeshObject.h"
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_action_types.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BKE_armature.h"
#include "BKE_action.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_key.h"
#include "BKE_fcurve.h"
#include "BKE_ipo.h"
#include "BKE_library.h"
#include "MT_Point3.h"
extern "C"{
#include "BKE_lattice.h"
#include "BKE_animsys.h"
}
#include "BLI_blenlib.h"
#include "BLI_math.h"
#define __NLA_DEFNORMALS
//#undef __NLA_DEFNORMALS
BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
RAS_MeshObject *mesh)
:
BL_SkinDeformer(gameobj,bmeshobj, mesh),
m_useShapeDrivers(false),
m_lastShapeUpdate(-1)
{
m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
};
/* this second constructor is needed for making a mesh deformable on the fly. */
BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj_old,
Object *bmeshobj_new,
RAS_MeshObject *mesh,
bool release_object,
bool recalc_normal,
BL_ArmatureObject* arma)
:
BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma),
m_useShapeDrivers(false),
m_lastShapeUpdate(-1)
{
m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
};
BL_ShapeDeformer::~BL_ShapeDeformer()
{
if (m_key)
{
BKE_libblock_free(G.main, m_key);
m_key = NULL;
}
};
RAS_Deformer *BL_ShapeDeformer::GetReplica()
{
BL_ShapeDeformer *result;
result = new BL_ShapeDeformer(*this);
result->ProcessReplica();
return result;
}
void BL_ShapeDeformer::ProcessReplica()
{
BL_SkinDeformer::ProcessReplica();
m_lastShapeUpdate = -1;
m_key = m_key ? BKE_key_copy(G.main, m_key) : NULL;
}
bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject* parent)
{
// Only load shape drivers if we have a key
if (GetKey() == NULL) {
m_useShapeDrivers = false;
return false;
}
// Fix drivers since BL_ArmatureObject makes copies
if (parent->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && GetKey()->adt) {
BL_ArmatureObject *arma = (BL_ArmatureObject*)parent;
FCurve *fcu;
for (fcu = (FCurve*)GetKey()->adt->drivers.first; fcu; fcu = (FCurve*)fcu->next) {
DriverVar *dvar;
for (dvar = (DriverVar*)fcu->driver->variables.first; dvar; dvar = (DriverVar*)dvar->next) {
DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
{
if (dtar->id) {
if ((Object*)dtar->id == arma->GetOrigArmatureObject())
dtar->id = (ID*)arma->GetArmatureObject();
}
}
DRIVER_TARGETS_LOOPER_END;
}
}
}
// This used to check if we had drivers from this armature,
// now we just assume we want to use shape drivers
// and let the animsys handle things.
m_useShapeDrivers = true;
return true;
}
bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
{
if (m_useShapeDrivers && PoseUpdated()) {
// We don't need an actual time, just use 0
BKE_animsys_evaluate_animdata(NULL, &GetKey()->id, GetKey()->adt, 0.f, ADT_RECALC_DRIVERS);
ForceUpdate();
m_bDynamic = true;
return true;
}
return false;
}
bool BL_ShapeDeformer::Update(void)
{
bool bShapeUpdate = false;
bool bSkinUpdate = false;
ExecuteShapeDrivers();
/* See if the object shape has changed */
if (m_lastShapeUpdate != m_gameobj->GetLastFrame()) {
/* the key coefficient have been set already, we just need to blend the keys */
Object* blendobj = m_gameobj->GetBlendObject();
/* we will blend the key directly in m_transverts array: it is used by armature as the start position */
/* m_key can be NULL in case of Modifier deformer */
if (m_key) {
WeightsArrayCache cache = {0, NULL};
float **per_keyblock_weights;
/* store verts locally */
VerifyStorage();
per_keyblock_weights = BKE_keyblock_get_per_block_weights(blendobj, m_key, &cache);
BKE_key_evaluate_relative(0, m_bmesh->totvert, m_bmesh->totvert, (char *)(float *)m_transverts,
m_key, NULL, per_keyblock_weights, 0); /* last arg is ignored */
BKE_keyblock_free_per_block_weights(m_key, per_keyblock_weights, &cache);
m_bDynamic = true;
}
// Don't release the weight array as in Blender, it will most likely be reusable on next frame
// The weight array are ultimately deleted when the skin mesh is destroyed
/* Update the current frame */
m_lastShapeUpdate=m_gameobj->GetLastFrame();
// As we have changed, the mesh, the skin deformer must update as well.
// This will force the update
BL_SkinDeformer::ForceUpdate();
bShapeUpdate = true;
}
// check for armature deform
bSkinUpdate = BL_SkinDeformer::UpdateInternal(bShapeUpdate && m_bDynamic);
// non dynamic deformer = Modifer without armature and shape keys, no need to create storage
if (!bSkinUpdate && bShapeUpdate && m_bDynamic) {
// this means that there is no armature, we still need to
// update the normal (was not done after shape key calculation)
#ifdef __NLA_DEFNORMALS
if (m_recalcNormal)
RecalcNormals();
#endif
// We also need to handle transverts now (used to be in BL_SkinDeformer::Apply())
UpdateTransverts();
bSkinUpdate = true;
}
return bSkinUpdate;
}
Key *BL_ShapeDeformer::GetKey()
{
return m_key;
}