[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54235] trunk/blender/source/blender: Apply patch [#33999] Wrapping mode for the "translate" compositing node

Monique Dewanchand m.dewanchand at atmind.nl
Thu Jan 31 16:08:38 CET 2013


Revision: 54235
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54235
Author:   mdewanchand
Date:     2013-01-31 15:08:37 +0000 (Thu, 31 Jan 2013)
Log Message:
-----------
 Apply patch [#33999] Wrapping mode for the "translate" compositing node

this patch enables the translate node to wrap around the image borders. This is especially needed if the translate node is not used to position elements on a layer but when it is used instead for seamless backgrounds like mountains or clouds that should be repeated over time (by animating the x/y values).

No trunk without docs! So here is my documentation: http://wiki.blender.org/index.php/User:Plasmasolutions/TranslateNodeExtension

The code is properly documented and should be easy to read and understand. When there are any problems or issues, please comment, I'll tackle them right away!

Greetings, Thomas Beck


 * optimized determination dependant areas
 * fixed some issues with scale node

There are still some issues when scaling very small values (x=0.0001)

 - At Mind -

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.h
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_translate.c

Modified: trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/compositor/nodes/COM_TranslateNode.cpp	2013-01-31 15:08:37 UTC (rev 54235)
@@ -37,10 +37,15 @@
 	InputSocket *inputYSocket = this->getInputSocket(2);
 	OutputSocket *outputSocket = this->getOutputSocket(0);
 	TranslateOperation *operation = new TranslateOperation();
-	
+
+	bNode *editorNode = this->getbNode();
+	NodeTranslateData *data = (NodeTranslateData *)editorNode->storage;
+	operation->setWrapping(data->wrap_axis);
+
 	inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
 	inputXSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
 	inputYSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
 	outputSocket->relinkConnections(operation->getOutputSocket(0));
 	graph->addOperation(operation);
 }
+

Modified: trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.cpp	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.cpp	2013-01-31 15:08:37 UTC (rev 54235)
@@ -15,9 +15,10 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor: 
- *		Jeroen Bakker 
+ * Contributor:
+ *		Jeroen Bakker
  *		Monique Dewanchand
+ *		Thomas Beck (plasmasolutions.de)
  */
 
 #include "COM_TranslateOperation.h"
@@ -40,6 +41,12 @@
 	this->m_inputXOperation = this->getInputSocketReader(1);
 	this->m_inputYOperation = this->getInputSocketReader(2);
 
+	ensureDelta();
+
+	//Calculate the relative offset once per execution, no need to do this per pixel
+	this->m_relativeOffsetX = fmodf(this->getDeltaX(), this->getWidth());
+	this->m_relativeOffsetY = fmodf(this->getDeltaY(), this->getHeight());
+
 }
 
 void TranslateOperation::deinitExecution()
@@ -53,18 +60,113 @@
 void TranslateOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 {
 	ensureDelta();
-	this->m_inputOperation->read(output, x - this->getDeltaX(), y - this->getDeltaY(), sampler);
+
+	float originalXPos = x - this->getDeltaX();
+	float originalYPos = y - this->getDeltaY();
+
+	switch(m_wrappingType) {
+		case 0:
+			//Intentionally empty, originalXPos and originalYPos have been set before
+			break;
+		case 1:
+			// wrap only on the x-axis
+			originalXPos = this->getWrappedOriginalXPos(x);
+			break;
+		case 2:
+			// wrap only on the y-axis
+			originalYPos = this->getWrappedOriginalYPos(y);
+			break;
+		case 3:
+			// wrap on both
+			originalXPos = this->getWrappedOriginalXPos(x);
+			originalYPos = this->getWrappedOriginalYPos(y);
+			break;
+	}
+
+	this->m_inputOperation->read(output, originalXPos , originalYPos, sampler);
+
 }
 
 bool TranslateOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
 {
+	rcti newInput;
+
 	ensureDelta();
-	rcti newInput;
-	
+
+	newInput.xmin = input->xmin - this->getDeltaX();
 	newInput.xmax = input->xmax - this->getDeltaX();
-	newInput.xmin = input->xmin - this->getDeltaX();
+	newInput.ymin = input->ymin - this->getDeltaY();
 	newInput.ymax = input->ymax - this->getDeltaY();
-	newInput.ymin = input->ymin - this->getDeltaY();
-	
+
+	if (m_wrappingType == 1 || m_wrappingType == 3){
+		// wrap only on the x-axis if tile is wrapping
+		newInput.xmin = getWrappedOriginalXPos(input->xmin);
+		newInput.xmax = getWrappedOriginalXPos(input->xmax);
+		if(newInput.xmin > newInput.xmax){
+			newInput.xmin = 0;
+			newInput.xmax = this->getWidth();
+		}
+	}
+	if(m_wrappingType == 2 || m_wrappingType == 3) {
+		// wrap only on the y-axis if tile is wrapping
+		newInput.ymin = getWrappedOriginalYPos(input->ymin);
+		newInput.ymax = getWrappedOriginalYPos(input->ymax);
+		if (newInput.ymin > newInput.ymax){
+			newInput.ymin = 0;
+			newInput.ymax = this->getHeight();
+		}
+	}
+
+
 	return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
 }
+
+void TranslateOperation::setWrapping(char wrapping_type)
+{
+	m_wrappingType = wrapping_type;
+}
+
+float TranslateOperation::getWrappedOriginalXPos(float x)
+{
+	float originalXPos = 0;
+
+	// Positive offset: Append image data from the left
+	if ( this->m_relativeOffsetX > 0 ) {
+		if ( x < this->m_relativeOffsetX )
+			originalXPos = this->getWidth() - this->m_relativeOffsetX + x;
+		else
+			originalXPos =  x - this->m_relativeOffsetX;
+	} else {
+		// Negative offset: Append image data from the right
+		if (x < (this->getWidth() + this->m_relativeOffsetX))
+			originalXPos = x - this->m_relativeOffsetX;
+		else
+			originalXPos = x - (this->getWidth() + this->m_relativeOffsetX);
+	}
+
+	while (originalXPos < 0) originalXPos += this->m_width;
+	return fmodf(originalXPos, this->getWidth());
+}
+
+
+float TranslateOperation::getWrappedOriginalYPos(float y)
+{
+	float originalYPos = 0;
+
+	// Positive offset: Append image data from the bottom
+	if (  this->m_relativeOffsetY > 0 ) {
+		if ( y < this->m_relativeOffsetY )
+			originalYPos = this->getHeight()- this->m_relativeOffsetY + y;
+		else
+			originalYPos =  y - this->m_relativeOffsetY;
+	} else {
+		// Negative offset: Append image data from the top
+		if (y < (this->getHeight() + this->m_relativeOffsetY))
+			originalYPos = y - this->m_relativeOffsetY;
+		else
+			originalYPos = y - (this->getHeight() + this->m_relativeOffsetY);
+	}
+
+	while (originalYPos < 0) originalYPos += this->m_height;
+	return fmodf(originalYPos, this->getHeight());
+}

Modified: trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.h	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/compositor/operations/COM_TranslateOperation.h	2013-01-31 15:08:37 UTC (rev 54235)
@@ -33,6 +33,9 @@
 	float m_deltaX;
 	float m_deltaY;
 	bool m_isDeltaSet;
+	float m_relativeOffsetX;
+	float m_relativeOffsetY;
+	char m_wrappingType;
 public:
 	TranslateOperation();
 	bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
@@ -54,6 +57,10 @@
 			this->m_isDeltaSet = true;
 		}
 	}
+
+	void setWrapping(char wrapping_type);
+	float getWrappedOriginalXPos(float x);
+	float getWrappedOriginalYPos(float y);
 };
 
 #endif

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2013-01-31 15:08:37 UTC (rev 54235)
@@ -2379,6 +2379,11 @@
 	uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
 }
 
+static void node_composit_buts_translate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "wrap_axis", 0, NULL, ICON_NONE);
+}
+
 static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
 	uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE);
@@ -2931,6 +2936,9 @@
 		case CMP_NODE_TRANSFORM:
 			ntype->uifunc = node_composit_buts_transform;
 			break;
+		case CMP_NODE_TRANSLATE:
+			ntype->uifunc = node_composit_buts_translate;
+			break;
 		case CMP_NODE_MOVIEDISTORTION:
 			ntype->uifunc = node_composit_buts_moviedistortion;
 			break;

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2013-01-31 15:08:37 UTC (rev 54235)
@@ -711,6 +711,11 @@
 	char track_name[64];
 } NodeTrackPosData;
 
+typedef struct NodeTranslateData {
+		char wrap_axis, pad[7];
+} NodeTranslateData;
+
+
 typedef struct NodeShaderScript {
 	int mode;
 	int flag;

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-01-31 15:08:37 UTC (rev 54235)
@@ -4225,6 +4225,28 @@
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_cmp_translate(StructRNA *srna)
+{
+	static EnumPropertyItem translate_items[] = {
+		{0, "NONE",	 0, "None",		"No wrapping on x and y"},
+		{1, "XAXIS", 0, "X-Axis",	"Wrap all pixels on the x-Axis"},
+	    {2, "YAXIS", 0, "Y-Axis",	"Wrap all pixels on the y-Axis"},
+	    {3, "BOTH", 0, "Both axes",	"Wrap all pixels on the both axes"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	PropertyRNA *prop;
+
+	RNA_def_struct_sdna_from(srna, "NodeTranslateData", "storage");
+
+	prop = RNA_def_property(srna, "wrap_axis", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "wrap_axis");
+	RNA_def_property_enum_items(prop, translate_items);
+	RNA_def_property_ui_text(prop, "Wrapping", "Wrap image on a specific axis");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
+
 /* -- Texture Nodes --------------------------------------------------------- */
 
 static void def_tex_output(StructRNA *srna)

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h	2013-01-31 14:25:07 UTC (rev 54234)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h	2013-01-31 15:08:37 UTC (rev 54235)
@@ -127,7 +127,7 @@
 DefNode( CompositorNode, CMP_NODE_COMPOSITE,      0,                      "COMPOSITE",      Composite,        "Composite",         ""              )
 DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    def_cmp_output_file,    "OUTPUT_FILE",    OutputFile,       "File Output",       ""              )

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list