Skip to content

Commit

Permalink
Add systemDataNode in data adapter. Add getChildByName to dataNode
Browse files Browse the repository at this point in the history
Fixed a bug in recursiveDataAdapterConstruction and use getChildByName() to
get the system parameters. Add a warning message if the global parameter
does not exist in systemDataNode.

Fix duplicate systemDataNode.
  • Loading branch information
Kristian Sons authored and ariyapour committed Nov 9, 2015
1 parent 4770799 commit c42fe00
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 88 deletions.
76 changes: 56 additions & 20 deletions src/data/adapter/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,63 @@ function recursiveDataNodeAttrInit(parentNode) {

function recursiveDataAdapterConstruction(adapter) {
for (var child = adapter.node.firstElementChild; child !== null; child = child.nextElementSibling) {
var subadapter = adapter.factory.getAdapter(child);
if (subadapter) {
if (subadapter.getXflowNode) {
adapter.xflowDataNode.appendChild(subadapter.getXflowNode());
} else if (subadapter.getScriptType) {
var scriptId = subadapter.node.name;
if (!scriptId) {
XML3D.debug.logError("Parsing error: Externally referenced operators must have a 'name' attribute matching the name they were registered with. ", subadapter.node);
scriptId = "unknown_operator";
}
adapter.externalScripts[scriptId] = subadapter;
if (subadapter.connectedAdapterHandle) {
adapter.connectAdapterHandle(scriptId, subadapter.connectedAdapterHandle);
}
adapter.xflowDataNode.setLoading(true);
}
// Passes _platform values to children nodes starting from the node
// where these attributes are first defined
if (adapter.xflowDataNode._platform !== null) {
recursiveDataNodeAttrInit(adapter.xflowDataNode);
//Here we check for data nodes with sys flag set
if (child.sys != undefined){
//Going up in the DOM hierarchy to find XML3D node
var xml3dNode = child;
while(xml3dNode.localName != "xml3d"){
xml3dNode = xml3dNode.parentNode;
}
var systemDataNode = adapter.factory.getAdapter(xml3dNode).xflowDataNode;

//Check if a system parameter with this name exists
if (systemDataNode.getChildByName("_system_" + child.name)) {
//Check if the systemDataNode is already added to adapter or not
var adapterSystemDataNode = adapter.xflowDataNode.hasSystemDataNode();
if (!adapterSystemDataNode){
var filter = systemDataNode.filterMapping;
if (!filter) {
filter = "keep({";
filter += child.name + ":_system_" + child.name + ",";
filter = filter.slice(0, -1) + "})";
systemDataNode.setFilter(filter);
} else {
filter.setNamePair(child.name, "_system_" + child.name);
}
adapter.xflowDataNode.appendChild(systemDataNode);
}
else{
//SystemDataNode is already added to the adapter. We only update the filter
adapterSystemDataNode.filterMapping.setNamePair(child.name, "_system_" + child.name);
}
} else {
XML3D.debug.logWarning("Parameter "+ child.name + " doesn't exist in global parameters!");
}
}
else{
var subadapter = adapter.factory.getAdapter(child);
if (subadapter) {
if (subadapter.getXflowNode) {
adapter.xflowDataNode.appendChild(subadapter.getXflowNode());
} else if (subadapter.getScriptType) {
var scriptId = subadapter.node.name;
if (!scriptId) {
XML3D.debug.logError("Parsing error: Externally referenced operators must have a 'name' attribute matching the name they were registered with. ", subadapter.node);
scriptId = "unknown_operator";
}
adapter.externalScripts[scriptId] = subadapter;
if (subadapter.connectedAdapterHandle) {
adapter.connectAdapterHandle(scriptId, subadapter.connectedAdapterHandle);
}
adapter.xflowDataNode.setLoading(true);
}

}
}
// Passes _platform values to children nodes starting from the node
// where these attributes are first defined
if (adapter.xflowDataNode._platform !== null) {
recursiveDataNodeAttrInit(adapter.xflowDataNode);
}
}
}
Expand Down
38 changes: 1 addition & 37 deletions src/data/adapter/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,7 @@ ValueDataAdapter.prototype.init = function()
}
else{
delete config.scriptValue;
if (this.node.sys != undefined){
// get the parent data adapter
var parentDataAdapter = this.factory.getAdapter(this.node.parentNode);

//Going up in the DOM hierarchy to find XML3D node
var xml3dNode = this.node;
while(xml3dNode.localName != "xml3d"){
xml3dNode = xml3dNode.parentNode;
}

var systemDataNode= this.factory.getAdapter(xml3dNode).xflowDataNode;
// FIXME: Append system to parent data adapter, remove BufferEntry if it exists
// TODO: forEach, getChildByName
// TODO: Move up to the DataAdapter
for (var child in systemDataNode._children) {
if (systemDataNode._children[child].name == "_system_" + this.node.name) {
this.xflowInputNode = systemDataNode._children[child];
var filter = systemDataNode.filterMapping;
if (!filter) {
filter = "rename({";
filter += this.node.name + ":_system_" + this.node.name + ",";
filter = filter.slice(0, -1) + "})";
systemDataNode.setFilter(filter);
} else {
filter.setNamePair(this.node.name, "_system_" + this.node.name);
}
parentDataAdapter.xflowDataNode.insertBefore(systemDataNode, parentDataAdapter.xflowDataNode._children[0]);
return;
} else {
// Print an info (once)
}

}

}
else
value = this.node.value;
value = this.node.value;
}

var type = XC.DATA_TYPE.fromString(this.node.localName);
Expand Down
6 changes: 6 additions & 0 deletions src/data/adapter/xml3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ XML3DDataAdapter.prototype.init = function()
this.xflowDataNode = new DataNode(false);
this.xflowDataNode.addLoadListener(this.onXflowLoadEvent.bind(this));
this.xflowDataNode.userData = this.node;
this.xflowDataNode.systemDataAdapter = true;
this.setDefaultValues();

};
Expand All @@ -34,6 +35,11 @@ XML3DDataAdapter.prototype.setDefaultValues = function(){
inputNode.name="_system_time";
inputNode.data = new BufferEntry(XC.DATA_TYPE.FLOAT, new Float32Array([0.0]));
this.xflowDataNode.appendChild(inputNode);

inputNode = new InputNode();
inputNode.name="_system_test";
inputNode.data = new BufferEntry(XC.DATA_TYPE.FLOAT, new Float32Array([5.0]));
this.xflowDataNode.appendChild(inputNode);
}

XML3DDataAdapter.prototype.onXflowLoadEvent = function(node, newLevel, oldLevel){
Expand Down
16 changes: 4 additions & 12 deletions src/renderer/renderer/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,11 @@ XML3D.createClass(Scene, EventEmitter, {
},

setRendererIndependentData: function () {
// TODO(jasu): forEach
for (var child in this.systemDataAdapter.xflowDataNode._children) {
//Here we set rendered-independent values
// TODO: Check if there is an easier way to set values, add a DataNode::getChildByName (xml3d.js\src\xflow\interface\graph.js)
if (this.systemDataAdapter.xflowDataNode._children[child].name == "_system_time") {
this.systemDataAdapter.xflowDataNode._children[child].data.setValue(new Float32Array([performance.now()]));

}
}
//Set the time
this.systemDataAdapter.xflowDataNode.getChildByName("_system_time").data.setValue(new Float32Array([performance.now()]));
this.systemDataAdapter.xflowDataNode.getChildByName("_system_test").data.setValue(new Float32Array([10.0]));

}



});

module.exports = Scene;
13 changes: 0 additions & 13 deletions src/renderer/webgl/scene/glscene.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,7 @@ XML3D.extend(GLScene.prototype, {
},

setRendererDependentData: function(){
for (child in this.systemDataAdapter.xflowDataNode._children){
// Here we set the renderer dependent values

}
},
// setSystemDataFilter: function(){
//// this.systemDataAdapter.xflowDataNode.filterType= "rename";
// var filter = "rename({";
// for (child in this.systemDataAdapter.xflowDataNode._children){
// filter += this.systemDataAdapter.xflowDataNode._children[child]._name.replace("_system_","") +":" +this.systemDataAdapter.xflowDataNode._children[child]._name +",";
// }
// filter= filter.slice(0,-1)+"})";
// this.systemDataAdapter.xflowDataNode.setFilter(filter);
// }
});
module.exports = GLScene;

19 changes: 18 additions & 1 deletion src/xflow/interface/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,24 @@ DataNode.prototype.removeChild = function(child){
this.notify( C.RESULT_STATE.CHANGED_STRUCTURE);
Base._flushResultCallbacks();
};

/**
* @param {InputNodeI|dataNode} child
*/
DataNode.prototype.getChildByName = function(name){
for (var i in this._children){
if (this._children[i].name == name)
return this._children[i];
}
};
/**
* @param {dataNode} child
*/
DataNode.prototype.hasSystemDataNode = function(){
for (var i in this._children){
if (this._children[i].systemDataAdapter != undefined)
return this._children[i];
}
};
/**
* @param {GraphNode} child
* @param {GraphNode} beforeNode
Expand Down
6 changes: 3 additions & 3 deletions tests/scenes/scripts/animateColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Xflow.registerOperator("xflow.animateColor", {
platforms: ["JAVASCRIPT", "GLSL_VS"],
evaluate: function(diffuseColor,time) {
var d = new Date();
diffuseColor[0] = time[0];
diffuseColor[1] = 0;
diffuseColor[2] = time[0];
diffuseColor[0] = Math.cos(time[0]/500);
diffuseColor[1] = Math.sin(time[0]/500);
diffuseColor[2] = Math.tan(time[0]/500);
return diffuseColor;
}
});
Expand Down
4 changes: 2 additions & 2 deletions tests/scenes/system-parameters.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
</material>
<material id="Material" script="urn:xml3d:material:phong">
<float3 name="diffuseColor">0.800000011920929 0.800000011920929 0.800000011920929</float3>
<int name="test" sys>3</int>
</material>
</defs>
<view id="v_pview" position="0 0 31" orientation="0 0 1 1.57"></view>
Expand All @@ -35,7 +34,8 @@
<float3 name="normal">-1.0 0.0 -0.0 -1.0 0.0 -0.0 -1.0 0.0 -0.0 -1.0 0.0 -0.0 0.0 1.0 -0.0 0.0 1.0 -0.0 0.0 1.0 -0.0 0.0 1.0 -0.0 1.0 0.0 -0.0 1.0 0.0 -0.0 1.0 0.0 -0.0 1.0 0.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 0.0 -1.0 -0.0 0.0 1.0 -0.0 0.0 1.0 -0.0 0.0 1.0 -0.0 0.0 1.0</float3>
<int name="index">0 1 2 2 3 0 4 5 6 6 7 4 8 9 10 10 11 8 12 13 14 14 15 12 16 17 18 18 19 16 20 21 22 22 23 20 </int>
<data compute="(diffuseColor) = xflow.animateColor(time)"><!-- TODO: Implement xflow.animateColor -->
<float name="time" id="time" sys></float>
<float name="time" sys></float>
<float name="test" sys></float>
</data>
</mesh>
</group>
Expand Down

0 comments on commit c42fe00

Please sign in to comment.