Skip to content

Xflow syntax change

lachsen edited this page Oct 8, 2013 · 10 revisions

Xflow program flows are hard to read:

<data compute="position = xflow.morph(position, posAdd2, weight2)" >
	<data compute="position = xflow.morph(position, posAdd1, weight1)" >
		<data compute="posAdd1 = xflow.sub(blend1Pos, position)" >
			<data compute="posAdd2 = xflow.sub(blend2Pos, position)" >
				<data src="blend-mesh.xml#mesh"></data>
				<float name="weight1" >1</float>
				<float name="weight2" >1</float>
			</data>
		</data>
	</data>
</data>

We can introduce the <dataflow> element to make Xflow more readable:

<dataflow>
	<data src="blend-mesh.xml#mesh"></data>
	<float name="weight1" >1</float>
	<float name="weight2" >1</float>
	<compute>
		posAdd1 = xflow.sub(position, blend1Pos);
		position = xflow.morph(position, posAdd1, weight1);
		posAdd2 = xflow.sub(position, blend2Pos);
		position = xflow.morph(position, posAdd2, weight2);
	</compute>
</dataflow>

Here a more complicated example with prototypes:

<proto id="doubleBlend" filter="keep(result)" compute="result = xflow.morph(value, valueAdd2, weight2)">
	<data compute="value = xflow.morph(value, valueAdd1, weight1)">
		<data compute="valueAdd2 = xflow.sub(blend2, value)">
			<data compute="valueAdd1 = xflow.sub(blend1, value)">
				<float3 param="true" name="value"></float3>
				<float3 param="true" name="blend1"></float3>
				<float3 param="true" name="blend2"></float3>
				<float param="true" name="weight1"></float>
				<float param="true" name="weight2"></float>
			</data>
		</data>
	</data>
</proto>

<proto id="morphShape" filter="keep(position, normal)">
	<data filter="rename({position : result})"
		  proto="[#doubleBlend]({value: position, blend1: blend1Pos, blend2: blend2Pos, weight1: })">
		<data filter="rename({value: position, blend1: blend1Pos, blend2: blend2Pos})">
			<float3 param="true" name="position"></float3>
			<float3 param="true" name="blend1Pos"></float3>
			<float3 param="true" name="blend2Pos"></float3>
			<float param="true" name="weight1">0.5</float>
			<float param="true" name="weight2">0.5</float>
		</data>
	</data>
	<data filter="rename({normal : result})" proto="#doubleBlend">
		<data filter="rename({value: normal, blend1: blend1Normal, blend2: blend2Normal})">
			<float3 param="true" name="normal"></float3>
			<float3 param="true" name="blend1Normal"></float3>
			<float3 param="true" name="blend2Normal"></float3>
			<float param="true" name="weight1">0.5</float>
			<float param="true" name="weight2">0.5</float>
		</data>
	</data>
</proto>

And here the same example using <dataflow>:

<proto id="doubleBlend" out="result"> 
	<dataflow>
		<float3 param name="value"></float3>
		<float3 param name="blend1"></float3>
		<float3 param name="blend2"></float3>
		<float  param name="weight1"></float>
		<float  param name="weight2"></float>
		<compute>
			add1 = xflow.sub(value, blend1);
			add2 = xflow.sub(value, blend2);
			result = xflow.morph(position, posAdd1, weight1);
			result = xflow.morph(result, posAdd2, weight2);
		</compute>		
	</dataflow>
</proto>

<proto id="morphShape" out="position, normal" >
	<dataflow>
		<float3 param name="position"></float3>
		<float3 param name="blend1Pos"></float3>
		<float3 param name="blend2Pos"></float3>
		<float3 param name="normal"></float3>
		<float3 param name="blend1Normal"></float3>
		<float3 param name="blend2Normal"></float3>
		<float param  name="weight1">0.5</float>
		<float param  name="weight2">0.5</float>
		<compute>
			position = [#doubleBlend](position, blend1Pos, blend2Pos, weight1, weight2);
			normal = [#doubleBlend](normal, blend1Normal, blend2Normal, weight1, weight2);
		</compute>		
	</dataflow>
</proto>
Clone this wiki locally