[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19813] branches/blender2.5/blender/source /blender: Drivers - Rotational Difference

Joshua Leung aligorith at gmail.com
Mon Apr 20 12:45:30 CEST 2009


Revision: 19813
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19813
Author:   aligorith
Date:     2009-04-20 12:45:25 +0200 (Mon, 20 Apr 2009)

Log Message:
-----------
Drivers - Rotational Difference

Restored the code to get this working. I haven't tested this to verify it, but it 'should' work...


Also, deleted old gpencil.c file in editors, since it was causing compiling errors. 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c

Removed Paths:
-------------
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-04-20 10:20:18 UTC (rev 19812)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c	2009-04-20 10:45:25 UTC (rev 19813)
@@ -709,6 +709,41 @@
 	return value;
 }
 
+/* Get two PoseChannels from the targets of the given Driver */
+static void driver_get_target_pchans2 (ChannelDriver *driver, bPoseChannel **pchan1, bPoseChannel **pchan2)
+{
+	DriverTarget *dtar;
+	short i = 0;
+	
+	/* before doing anything */
+	*pchan1= NULL;
+	*pchan2= NULL;
+	
+	/* only take the first two targets */
+	for (dtar= driver->targets.first; (dtar) && (i < 2); dtar=dtar->next, i++) {
+		PointerRNA id_ptr, ptr;
+		PropertyRNA *prop;
+		
+		/* get RNA-pointer for the ID-block given in target */
+		if (dtar->id)
+			RNA_id_pointer_create(dtar->id, &id_ptr);
+		else
+			continue;
+		
+		/* resolve path so that we have pointer to the right posechannel */
+		if (RNA_path_resolve(&id_ptr, dtar->rna_path, &ptr, &prop)) {
+			/* is pointer valid (i.e. pointing to an actual posechannel */
+			if ((ptr.type == &RNA_PoseChannel) && (ptr.data)) {
+				/* first or second target? */
+				if (i)
+					*pchan1= ptr.data;
+				else
+					*pchan2= ptr.data;
+			}
+		}
+	}
+}
+
 /* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime"
  *	- "evaltime" is the frame at which F-Curve is being evaluated
  * 	- has to return a float value 
@@ -746,7 +781,8 @@
 				return (value / (float)tot);
 			}
 		}
-
+			break;
+		
 		case DRIVER_TYPE_PYTHON: /* expression */
 		{
 #ifndef DISABLE_PYTHON
@@ -766,11 +802,30 @@
 			break;
 
 		
-		case DRIVER_TYPE_ROTDIFF: /* difference of rotations of 2 bones (should be in same armature) */
+		case DRIVER_TYPE_ROTDIFF: /* difference of rotations of 2 bones (should ideally be in same armature) */
 		{
-			/*
+			bPoseChannel *pchan, *pchan2;
 			float q1[4], q2[4], quat[4], angle;
 			
+			/* get pose channels, and check if we've got two */
+			driver_get_target_pchans2(driver, &pchan, &pchan2);
+			if (ELEM(NULL, pchan, pchan2)) {
+				/* disable this driver, since it doesn't work correctly... */
+				driver->flag |= DRIVER_FLAG_INVALID;
+				
+				/* check what the error was */
+				if ((pchan == NULL) && (pchan2 == NULL))
+					printf("Driver Evaluation Error: Rotational difference failed - first 2 targets invalid \n");
+				else if (pchan == NULL)
+					printf("Driver Evaluation Error: Rotational difference failed - first target not valid PoseChannel \n");
+				else if (pchan2 == NULL)
+					printf("Driver Evaluation Error: Rotational difference failed - second target not valid PoseChannel \n");
+					
+				/* stop here... */
+				return 0.0f;
+			}			
+			
+			/* use the final posed locations */
 			Mat4ToQuat(pchan->pose_mat, q1);
 			Mat4ToQuat(pchan2->pose_mat, q2);
 			
@@ -780,7 +835,6 @@
 			angle= ABS(angle);
 			
 			return (angle > M_PI) ? (float)((2.0f * M_PI) - angle) : (float)(angle);
-			*/
 		}
 			break;
 		

Deleted: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil.c	2009-04-20 10:20:18 UTC (rev 19812)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil.c	2009-04-20 10:45:25 UTC (rev 19813)
@@ -1,2161 +0,0 @@
-/**
- * $Id$
- *
- * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2008, Blender Foundation
- * This is a new part of Blender
- *
- * Contributor(s): Joshua Leung
- *
- * ***** END GPL LICENSE BLOCK *****
- */
- 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BMF_Api.h"
-
-#include "IMB_imbuf.h"
-#include "IMB_imbuf_types.h"
-
-#include "BLI_arithb.h"
-#include "BLI_blenlib.h"
-
-#include "DNA_listBase.h"
-#include "DNA_armature_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_vec_types.h"
-#include "DNA_view3d_types.h"
-
-#include "BKE_armature.h"
-#include "BKE_blender.h"
-#include "BKE_context.h"
-#include "BKE_curve.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_library.h"
-#include "BKE_utildefines.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "UI_view2d.h"
-
-#include "ED_armature.h"
-#include "ED_gpencil.h"
-#include "ED_sequencer.h"
-#include "ED_view3d.h"
-
-#include "PIL_time.h"			/* sleep				*/
-
-#include "gpencil_intern.h"
-
-/* XXX */
-static void BIF_undo_push() {}
-static void error() {}
-static int pupmenu() {return 0;}
-static void add_object_draw() {}
-static int get_activedevice() {return 0;}
-#define L_MOUSE 0
-#define R_MOUSE 0
-
-/* XXX */
-
-/* ************************************************** */
-/* GENERAL STUFF */
-
-/* --------- Memory Management ------------ */
-
-/* Free strokes belonging to a gp-frame */
-void free_gpencil_strokes (bGPDframe *gpf)
-{
-	bGPDstroke *gps, *gpsn;
-	
-	/* error checking */
-	if (gpf == NULL) return;
-	
-	/* free strokes */
-	for (gps= gpf->strokes.first; gps; gps= gpsn) {
-		gpsn= gps->next;
-		
-		/* free stroke memory arrays, then stroke itself */
-		if (gps->points) MEM_freeN(gps->points);
-		BLI_freelinkN(&gpf->strokes, gps);
-	}
-}
-
-/* Free all of a gp-layer's frames */
-void free_gpencil_frames (bGPDlayer *gpl)
-{
-	bGPDframe *gpf, *gpfn;
-	
-	/* error checking */
-	if (gpl == NULL) return;
-	
-	/* free frames */
-	for (gpf= gpl->frames.first; gpf; gpf= gpfn) {
-		gpfn= gpf->next;
-		
-		/* free strokes and their associated memory */
-		free_gpencil_strokes(gpf);
-		BLI_freelinkN(&gpl->frames, gpf);
-	}
-}
-
-/* Free all of the gp-layers for a viewport (list should be &gpd->layers or so) */
-void free_gpencil_layers (ListBase *list) 
-{
-	bGPDlayer *gpl, *gpln;
-	
-	/* error checking */
-	if (list == NULL) return;
-	
-	/* delete layers*/
-	for (gpl= list->first; gpl; gpl= gpln) {
-		gpln= gpl->next;
-		
-		/* free layers and their data */
-		free_gpencil_frames(gpl);
-		BLI_freelinkN(list, gpl);
-	}
-}
-
-/* Free gp-data and all it's related data */
-void free_gpencil_data (bGPdata *gpd)
-{
-	/* free layers then data itself */
-	free_gpencil_layers(&gpd->layers);
-	MEM_freeN(gpd);
-}
-
-/* -------- Container Creation ---------- */
-
-/* add a new gp-frame to the given layer */
-bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe)
-{
-	bGPDframe *gpf, *gf;
-	short state=0;
-	
-	/* error checking */
-	if ((gpl == NULL) || (cframe <= 0))
-		return NULL;
-		
-	/* allocate memory for this frame */
-	gpf= MEM_callocN(sizeof(bGPDframe), "bGPDframe");
-	gpf->framenum= cframe;
-	
-	/* find appropriate place to add frame */
-	if (gpl->frames.first) {
-		for (gf= gpl->frames.first; gf; gf= gf->next) {
-			/* check if frame matches one that is supposed to be added */
-			if (gf->framenum == cframe) {
-				state= -1;
-				break;
-			}
-			
-			/* if current frame has already exceeded the frame to add, add before */
-			if (gf->framenum > cframe) {
-				BLI_insertlinkbefore(&gpl->frames, gf, gpf);
-				state= 1;
-				break;
-			}
-		}
-	}
-	
-	/* check whether frame was added successfully */
-	if (state == -1) {
-		MEM_freeN(gpf);
-		printf("Error: frame (%d) existed already for this layer \n", cframe);
-	}
-	else if (state == 0) {
-		/* add to end then! */
-		BLI_addtail(&gpl->frames, gpf);
-	}
-	
-	/* return frame */
-	return gpf;
-}
-
-/* add a new gp-layer and make it the active layer */
-bGPDlayer *gpencil_layer_addnew (bGPdata *gpd)
-{
-	bGPDlayer *gpl;
-	
-	/* check that list is ok */
-	if (gpd == NULL)
-		return NULL;
-		
-	/* allocate memory for frame and add to end of list */
-	gpl= MEM_callocN(sizeof(bGPDlayer), "bGPDlayer");
-	
-	/* add to datablock */
-	BLI_addtail(&gpd->layers, gpl);
-	
-	/* set basic settings */
-	gpl->color[3]= 0.9f;
-	gpl->thickness = 3;
-	
-	/* auto-name */
-	sprintf(gpl->info, "GP_Layer");
-	BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info[0]), 128);
-	
-	/* make this one the active one */
-	gpencil_layer_setactive(gpd, gpl);
-	
-	/* return layer */
-	return gpl;
-}
-
-/* add a new gp-datablock */
-bGPdata *gpencil_data_addnew (void)
-{
-	bGPdata *gpd;
-	
-	/* allocate memory for a new block */
-	gpd= MEM_callocN(sizeof(bGPdata), "GreasePencilData");
-	
-	/* initial settings */
-	gpd->flag = (GP_DATA_DISPINFO|GP_DATA_EXPAND);
-	
-	return gpd;
-}
-
-/* -------- Data Duplication ---------- */
-
-/* make a copy of a given gpencil frame */
-bGPDframe *gpencil_frame_duplicate (bGPDframe *src)
-{
-	bGPDstroke *gps, *gpsd;
-	bGPDframe *dst;
-	
-	/* error checking */
-	if (src == NULL)
-		return NULL;
-		
-	/* make a copy of the source frame */
-	dst= MEM_dupallocN(src);
-	dst->prev= dst->next= NULL;
-	
-	/* copy strokes */
-	dst->strokes.first = dst->strokes.last= NULL;
-	for (gps= src->strokes.first; gps; gps= gps->next) {
-		/* make copy of source stroke, then adjust pointer to points too */
-		gpsd= MEM_dupallocN(gps);
-		gpsd->points= MEM_dupallocN(gps->points);
-		
-		BLI_addtail(&dst->strokes, gpsd);
-	}
-	
-	/* return new frame */
-	return dst;
-}
-
-/* make a copy of a given gpencil layer */
-bGPDlayer *gpencil_layer_duplicate (bGPDlayer *src)
-{
-	bGPDframe *gpf, *gpfd;
-	bGPDlayer *dst;
-	
-	/* error checking */
-	if (src == NULL)
-		return NULL;
-		
-	/* make a copy of source layer */
-	dst= MEM_dupallocN(src);
-	dst->prev= dst->next= NULL;
-	
-	/* copy frames */
-	dst->frames.first= dst->frames.last= NULL;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list