-
Notifications
You must be signed in to change notification settings - Fork 25
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>
Content of the <dataflow>
element is evaluate from top to bottom. Every <compute>
element can access data declared in previous siblings. Each <compute>
includes a list of statements as previously found in the compute attribute, separated by semicolons. It is possible to have multiple <compute>
elements inside a <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 name="value"></float3>
<float3 param name="blend1"></float3>
<float3 param name="blend2"></float3>
<float param name="weight1"></float>
<float param 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 name="position"></float3>
<float3 param name="blend1Pos"></float3>
<float3 param name="blend2Pos"></float3>
<float param name="weight1">0.5</float>
<float param 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 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>
</data>
</data>
</proto>
<mesh type="triangles" proto="#morphShape" >
<data src="blend-mesh.xml#mesh" ></data>
<float name="weight1" >0.5</float>
<float name="weight2" >0.5</float>
</mesh>
And here the same example using <dataflow>
. We can drop <proto>
and reuse <dataflow>
to declare reusable computation components.
<dataflow id="doubleBlend" out="result">
<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>
<dataflow id="morphShape" out="position, normal" >
<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>
<mesh type="triangles" dataflow="#morphShape" >
<data src="blend-mesh.xml#mesh" ></data>
<float name="weight1" >0.5</float>
<float name="weight2" >0.5</float>
</mesh>