-
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
Fix models in 2D near the IDL. #3936
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c46182e
Fix models in 2D near the IDL.
bagnell 24ecefb
Fix picking when the model crosses the IDL and more updates from review.
bagnell 4810cb2
Merge branch 'models-2D' into models-2D-idl
bagnell d1bbe1c
Add test for rendering a model on the IDL.
bagnell 6b8257b
Merge branch 'models-2D' into models-2D-idl
bagnell 282781a
Fix conversion from model matrix to 2D.
bagnell 40b25ff
Merge branch 'models-2D' into models-2D-idl
bagnell 915c0e8
Merge branch 'models-2D' into models-2D-idl
bagnell 81c8c5a
Fix jsHint error.
bagnell 1db0894
Merge branch 'models-2D' into models-2D-idl
bagnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2520,7 +2520,7 @@ define([ | |
}; | ||
} | ||
|
||
function createCommand(model, gltfNode, runtimeNode, context) { | ||
function createCommand(model, gltfNode, runtimeNode, context, scene3DOnly) { | ||
var nodeCommands = model._nodeCommands; | ||
var pickIds = model._pickIds; | ||
var allowPicking = model.allowPicking; | ||
|
@@ -2660,19 +2660,35 @@ define([ | |
}); | ||
} | ||
|
||
var command2D; | ||
var pickCommand2D; | ||
if (!scene3DOnly) { | ||
command2D = DrawCommand.shallowClone(command); | ||
command2D.boundingVolume = new BoundingSphere(); | ||
command2D.modelMatrix = new Matrix4(); | ||
|
||
if (allowPicking) { | ||
pickCommand2D = DrawCommand.shallowClone(pickCommand); | ||
pickCommand2D.boundingVolume = new BoundingSphere(); | ||
pickCommand2D.modelMatrix = new Matrix4(); | ||
} | ||
} | ||
|
||
var nodeCommand = { | ||
show : true, | ||
boundingSphere : boundingSphere, | ||
command : command, | ||
pickCommand : pickCommand | ||
pickCommand : pickCommand, | ||
command2D : command2D, | ||
pickCommand2D : pickCommand2D | ||
}; | ||
runtimeNode.commands.push(nodeCommand); | ||
nodeCommands.push(nodeCommand); | ||
} | ||
} | ||
} | ||
|
||
function createRuntimeNodes(model, context) { | ||
function createRuntimeNodes(model, context, scene3DOnly) { | ||
var loadResources = model._loadResources; | ||
|
||
if (!loadResources.finishedEverythingButTextureCreation()) { | ||
|
@@ -2730,7 +2746,7 @@ define([ | |
} | ||
|
||
if (defined(gltfNode.meshes)) { | ||
createCommand(model, gltfNode, runtimeNode, context); | ||
createCommand(model, gltfNode, runtimeNode, context, scene3DOnly); | ||
} | ||
|
||
var children = gltfNode.children; | ||
|
@@ -2751,6 +2767,7 @@ define([ | |
|
||
function createResources(model, frameState) { | ||
var context = frameState.context; | ||
var scene3DOnly = frameState.scene3DOnly; | ||
|
||
if (model._loadRendererResourcesFromCache) { | ||
var resources = model._rendererResources; | ||
|
@@ -2788,8 +2805,8 @@ define([ | |
// Could use copy-on-write if it is worth it. Probably overkill. | ||
} | ||
|
||
createUniformMaps(model, context); // using glTF materials/techniques | ||
createRuntimeNodes(model, context); // using glTF scene | ||
createUniformMaps(model, context); // using glTF materials/techniques | ||
createRuntimeNodes(model, context, scene3DOnly); // using glTF scene | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
|
@@ -2860,6 +2877,23 @@ define([ | |
Matrix4.clone(command.modelMatrix, pickCommand.modelMatrix); | ||
BoundingSphere.clone(command.boundingVolume, pickCommand.boundingVolume); | ||
} | ||
|
||
// If the model crosses the IDL in 2D, it will be drawn in one viewport, but part of it | ||
// will be clipped by the viewport. We create a second command that translates the model | ||
// model matrix to the opposite side of the map so the part that was clipped in one viewport | ||
// is drawn in the other. | ||
command = primitiveCommand.command2D; | ||
if (defined(command) && model._mode === SceneMode.SCENE2D) { | ||
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. Add a comment about why we are doing this. |
||
Matrix4.clone(nodeMatrix, command.modelMatrix); | ||
command.modelMatrix[13] -= CesiumMath.sign(command.modelMatrix[13]) * 2.0 * CesiumMath.PI * projection.ellipsoid.maximumRadius; | ||
BoundingSphere.transform(primitiveCommand.boundingSphere, command.modelMatrix, command.boundingVolume); | ||
|
||
if (allowPicking) { | ||
var pickCommand2D = primitiveCommand.pickCommand2D; | ||
Matrix4.clone(command.modelMatrix, pickCommand2D.modelMatrix); | ||
BoundingSphere.clone(command.boundingVolume, pickCommand2D.boundingVolume); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -3394,11 +3428,21 @@ define([ | |
var i; | ||
var nc; | ||
|
||
var idl2D = frameState.mapProjection.ellipsoid.maximumRadius * CesiumMath.PI; | ||
var boundingVolume; | ||
|
||
if (passes.render) { | ||
for (i = 0; i < length; ++i) { | ||
nc = nodeCommands[i]; | ||
if (nc.show) { | ||
commandList.push(nc.command); | ||
var command = nc.command; | ||
commandList.push(command); | ||
|
||
boundingVolume = command.boundingVolume; | ||
if (frameState.mode === SceneMode.SCENE2D && | ||
(boundingVolume.center.y + boundingVolume.radius > idl2D || boundingVolume.center.y - boundingVolume.radius < idl2D)) { | ||
commandList.push(nc.command2D); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -3407,7 +3451,14 @@ define([ | |
for (i = 0; i < length; ++i) { | ||
nc = nodeCommands[i]; | ||
if (nc.show) { | ||
commandList.push(nc.pickCommand); | ||
var pickCommand = nc.pickCommand; | ||
commandList.push(pickCommand); | ||
|
||
boundingVolume = pickCommand.boundingVolume; | ||
if (frameState.mode === SceneMode.SCENE2D && | ||
(boundingVolume.center.y + boundingVolume.radius > idl2D || boundingVolume.center.y - boundingVolume.radius < idl2D)) { | ||
commandList.push(nc.pickCommand2D); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does picking work for models crossing the IDL?
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.
So picking works across the IDL even though there is only one pick command?
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.
Never mind, I see.