Skip to content

Commit

Permalink
Merge pull request xeolabs#497 from shrekshao/shrekshao-clipping-caps…
Browse files Browse the repository at this point in the history
…-stencil-plugin

Fix some bugs and add features
  • Loading branch information
xeolabs authored Aug 18, 2016
2 parents 1ebcf55 + d24fddf commit 36ba509
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
35 changes: 26 additions & 9 deletions api/latest/plugins/node/postprocess/clippingCap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ SceneJS.Types.addType("postprocess/clippingCap", {
construct: function (params) {

var clipsNodeId = params.clipsNodeId || "clippingCapClipsNode";
var stage1ContentNodeId = params.stage1ContentNodeId || "clippingCapStage1ContentNode";
var stage2ContentNodeId = params.stage2ContentNodeId || "clippingCapStage2ContentNode";
var stage3ContentNodeId = params.stage3ContentNodeId || "clippingCapStage3ContentNode";

var solidColorCaps = params.solidColorCaps !== undefined ? params.solidColorCaps : true;

Expand All @@ -18,9 +21,7 @@ SceneJS.Types.addType("postprocess/clippingCap", {

var frontClippingFS = [
"precision highp float;\n",
"uniform vec3 SCENEJS_uWorldEye;\n",
"uniform vec3 SCENEJS_uWorldLook;\n",
"uniform vec3 SCENEJS_uMaterialColor;\n"//,
"uniform vec3 SCENEJS_uWorldEye;\n"
];


Expand All @@ -38,7 +39,7 @@ SceneJS.Types.addType("postprocess/clippingCap", {

for (i = 0; i < lenClips; i++) {
frontClippingFS.push(" if (SCENEJS_uClipMode" + i + " != 0.0) {");
frontClippingFS.push(" if (dot(SCENEJS_uWorldLook - SCENEJS_uWorldEye, SCENEJS_uClipNormalAndDist" + i + ".xyz) < -SCENEJS_uClipNormalAndDist" + i + ".w) {");
frontClippingFS.push(" if (dot(SCENEJS_uWorldEye, SCENEJS_uClipNormalAndDist" + i + ".xyz) > SCENEJS_uClipNormalAndDist" + i + ".w) {");
frontClippingFS.push(" dist += clamp(dot(SCENEJS_vWorldVertex.xyz, SCENEJS_uClipNormalAndDist" + i + ".xyz) - SCENEJS_uClipNormalAndDist" + i + ".w, 0.0, 1000.0);");
frontClippingFS.push(" }");
frontClippingFS.push(" }");
Expand Down Expand Up @@ -76,8 +77,6 @@ SceneJS.Types.addType("postprocess/clippingCap", {
capDrawingNodes = params.capNodes;
}



this.addNodes([
{
type: "clips",
Expand Down Expand Up @@ -139,7 +138,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
}
],

nodes: params.nodes
nodes: [
{
id: stage1ContentNodeId,

nodes: params.nodes
}
]
}
]
}
Expand Down Expand Up @@ -168,7 +173,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
clearColorBuffer: true
},

nodes: params.nodes
nodes: [
{
id: stage2ContentNodeId,

nodes: params.nodes
}
]
}
]
}
Expand Down Expand Up @@ -211,7 +222,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
dppass: "keep"
},

nodes: capDrawingNodes
nodes: [
{
id: stage3ContentNodeId,

nodes: capDrawingNodes
}
]
}
]
}
Expand Down
1 change: 1 addition & 0 deletions src/core/scene/xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SceneJS.XForm.prototype._compile = function (ctx) {
var i, len;

core.numCores = 0;
if (!this.xformChildren) {this.xformChildren = [];}
for (i = 0, len = this.xformChildren.length; i < len; i++) {
var child = this.xformChildren[i];
if (!this.branchDirty && !child.dirty) {
Expand Down
35 changes: 26 additions & 9 deletions src/plugins/node/postprocess/clippingCap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ SceneJS.Types.addType("postprocess/clippingCap", {
construct: function (params) {

var clipsNodeId = params.clipsNodeId || "clippingCapClipsNode";
var stage1ContentNodeId = params.stage1ContentNodeId || "clippingCapStage1ContentNode";
var stage2ContentNodeId = params.stage2ContentNodeId || "clippingCapStage2ContentNode";
var stage3ContentNodeId = params.stage3ContentNodeId || "clippingCapStage3ContentNode";

var solidColorCaps = params.solidColorCaps !== undefined ? params.solidColorCaps : true;

Expand All @@ -18,9 +21,7 @@ SceneJS.Types.addType("postprocess/clippingCap", {

var frontClippingFS = [
"precision highp float;\n",
"uniform vec3 SCENEJS_uWorldEye;\n",
"uniform vec3 SCENEJS_uWorldLook;\n",
"uniform vec3 SCENEJS_uMaterialColor;\n"//,
"uniform vec3 SCENEJS_uWorldEye;\n"
];


Expand All @@ -38,7 +39,7 @@ SceneJS.Types.addType("postprocess/clippingCap", {

for (i = 0; i < lenClips; i++) {
frontClippingFS.push(" if (SCENEJS_uClipMode" + i + " != 0.0) {");
frontClippingFS.push(" if (dot(SCENEJS_uWorldLook - SCENEJS_uWorldEye, SCENEJS_uClipNormalAndDist" + i + ".xyz) < -SCENEJS_uClipNormalAndDist" + i + ".w) {");
frontClippingFS.push(" if (dot(SCENEJS_uWorldEye, SCENEJS_uClipNormalAndDist" + i + ".xyz) > SCENEJS_uClipNormalAndDist" + i + ".w) {");
frontClippingFS.push(" dist += clamp(dot(SCENEJS_vWorldVertex.xyz, SCENEJS_uClipNormalAndDist" + i + ".xyz) - SCENEJS_uClipNormalAndDist" + i + ".w, 0.0, 1000.0);");
frontClippingFS.push(" }");
frontClippingFS.push(" }");
Expand Down Expand Up @@ -76,8 +77,6 @@ SceneJS.Types.addType("postprocess/clippingCap", {
capDrawingNodes = params.capNodes;
}



this.addNodes([
{
type: "clips",
Expand Down Expand Up @@ -139,7 +138,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
}
],

nodes: params.nodes
nodes: [
{
id: stage1ContentNodeId,

nodes: params.nodes
}
]
}
]
}
Expand Down Expand Up @@ -168,7 +173,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
clearColorBuffer: true
},

nodes: params.nodes
nodes: [
{
id: stage2ContentNodeId,

nodes: params.nodes
}
]
}
]
}
Expand Down Expand Up @@ -211,7 +222,13 @@ SceneJS.Types.addType("postprocess/clippingCap", {
dppass: "keep"
},

nodes: capDrawingNodes
nodes: [
{
id: stage3ContentNodeId,

nodes: capDrawingNodes
}
]
}
]
}
Expand Down

0 comments on commit 36ba509

Please sign in to comment.