-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primitive picking #1524
Primitive picking #1524
Changes from 4 commits
42f5401
19ea641
a24eac4
ed0faa4
a5ee5b0
c6a2235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,7 +321,8 @@ define([ | |
this._backFaceRS = undefined; | ||
this._sp = undefined; | ||
|
||
this._pickRS = undefined; | ||
this._pickBackFaceRS = undefined; | ||
this._pickFrontFaceRS= undefined; | ||
this._pickSP = undefined; | ||
this._pickIds = []; | ||
|
||
|
@@ -764,9 +765,10 @@ define([ | |
|
||
if (createRS) { | ||
var renderState = appearance.getRenderState(); | ||
var rs; | ||
|
||
if (twoPasses) { | ||
var rs = clone(renderState, false); | ||
rs = clone(renderState, false); | ||
rs.cull = { | ||
enabled : true, | ||
face : CullFace.BACK | ||
|
@@ -781,18 +783,30 @@ define([ | |
} | ||
|
||
if (allowPicking) { | ||
// Only need backface pass for picking when two-pass rendering is used. | ||
this._pickRS = this._backFaceRS; | ||
this._pickBackFaceRS = this._backFaceRS; | ||
this._pickFrontFaceRS = this._frontFaceRS; | ||
} else { | ||
// Still occlude if not pickable. | ||
var pickRS = clone(renderState, false); | ||
pickRS.colorMask = { | ||
rs = clone(renderState, false); | ||
renderState.colorMask = { | ||
red : false, | ||
green : false, | ||
blue : false, | ||
alpha : false | ||
}; | ||
this._pickRS = context.createRenderState(pickRS); | ||
|
||
if (twoPasses) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry - one more idea here that is closer to your original fix. If |
||
rs.cull = { | ||
enabled : true, | ||
face : CullFace.BACK | ||
}; | ||
this._pickFrontFaceRS = context.createRenderState(rs); | ||
|
||
rs.cull.face = CullFace.FRONT; | ||
this._pickBackFaceRS = context.createRenderState(rs); | ||
} else { | ||
this._pickFrontFaceRS = context.createRenderState(renderState); | ||
this._pickBackFaceRS = this._pickFrontFaceRS; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -823,11 +837,10 @@ define([ | |
var pass = translucent ? Pass.TRANSLUCENT : Pass.OPAQUE; | ||
|
||
colorCommands.length = this._va.length * (twoPasses ? 2 : 1); | ||
pickCommands.length = this._va.length; | ||
pickCommands.length = this._va.length * (twoPasses ? 2 : 1); | ||
|
||
length = colorCommands.length; | ||
var vaIndex = 0; | ||
var m = 0; | ||
for (i = 0; i < length; ++i) { | ||
if (twoPasses) { | ||
colorCommand = colorCommands[i]; | ||
|
@@ -842,6 +855,18 @@ define([ | |
colorCommand.uniformMap = uniforms; | ||
colorCommand.pass = pass; | ||
|
||
pickCommand = pickCommands[i]; | ||
if (!defined(pickCommand)) { | ||
pickCommand = pickCommands[i] = new DrawCommand(); | ||
} | ||
pickCommand.owner = this; | ||
pickCommand.primitiveType = this._primitiveType; | ||
pickCommand.vertexArray = this._va[vaIndex]; | ||
pickCommand.renderState = this._pickBackFaceRS; | ||
pickCommand.shaderProgram = this._pickSP; | ||
pickCommand.uniformMap = uniforms; | ||
pickCommand.pass = pass; | ||
|
||
++i; | ||
} | ||
|
||
|
@@ -857,18 +882,17 @@ define([ | |
colorCommand.uniformMap = uniforms; | ||
colorCommand.pass = pass; | ||
|
||
pickCommand = pickCommands[m]; | ||
pickCommand = pickCommands[i]; | ||
if (!defined(pickCommand)) { | ||
pickCommand = pickCommands[m] = new DrawCommand(); | ||
pickCommand = pickCommands[i] = new DrawCommand(); | ||
} | ||
pickCommand.owner = this; | ||
pickCommand.primitiveType = this._primitiveType; | ||
pickCommand.vertexArray = this._va[vaIndex]; | ||
pickCommand.renderState = this._pickRS; | ||
pickCommand.renderState = this._pickFrontFaceRS; | ||
pickCommand.shaderProgram = this._pickSP; | ||
pickCommand.uniformMap = uniforms; | ||
pickCommand.pass = pass; | ||
++m; | ||
|
||
++vaIndex; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was probably my idea, but another problem with the old approach is that if another object occluded the backfaces but not the front, this object would not get picked (or picked first with drill picking).