Skip to content
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

ModelInstanceCollection picking #4975

Merged
merged 4 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions Apps/Sandcastle/gallery/development/3D Models Instancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
var count = 1024;
var spacing = 0.0002;
var url = '../../SampleData/models/CesiumAir/Cesium_Air.gltf';
var dynamic = false;
var useCollection = true;

var centerLongitude = -123.0744619;
Expand All @@ -67,7 +66,6 @@
var collection = scene.primitives.add(new Cesium.ModelInstanceCollection({
url : url,
instances : instances,
dynamic : dynamic,
debugShowBoundingVolume : debugShowBoundingVolume,
debugWireframe : debugWireframe
}));
Expand Down Expand Up @@ -149,6 +147,19 @@
useCollection ? createCollection(instances) : createModels(instances);
}

// Scale picked instances
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(movement) {
var pickedInstance = scene.pick(movement.position);
if (Cesium.defined(pickedInstance)) {
console.log(pickedInstance);
var instance = useCollection ? pickedInstance : pickedInstance.primitive;
var scaleMatrix = Cesium.Matrix4.fromUniformScale(1.1);
var modelMatrix = Cesium.Matrix4.multiply(instance.modelMatrix, scaleMatrix, new Cesium.Matrix4());
instance.modelMatrix = modelMatrix;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

Sandcastle.addToolbarMenu([ {
text : '1024 instances',
onselect : function() {
Expand Down Expand Up @@ -234,20 +245,6 @@
}
}]);

Sandcastle.addToolbarMenu([ {
text : 'Static',
onselect : function() {
dynamic = false;
reset();
}
}, {
text : 'Dynamic',
onselect : function() {
dynamic = true;
reset();
}
}]);

//Sandcastle_End
Sandcastle.finishedLoading();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Renderer/ShaderSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ define([
this.pickColorQualifier = pickColorQualifier;
this.includeBuiltIns = defaultValue(options.includeBuiltIns, true);
}

ShaderSource.prototype.clone = function() {
return new ShaderSource({
sources : this.sources,
Expand Down
21 changes: 16 additions & 5 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2307,21 +2307,32 @@ define([
// Retrieve the compiled shader program to assign index values to attributes
var attributeLocations = {};

var index;
var technique = techniques[materials[primitive.material].technique];
var parameters = technique.parameters;
var attributes = technique.attributes;
var programAttributeLocations = model._rendererResources.programs[technique.program].vertexAttributes;
var program = model._rendererResources.programs[technique.program];
var programVertexAttributes = program.vertexAttributes;
var programAttributeLocations = program._attributeLocations;

// Note: WebGL shader compiler may have optimized and removed some attributes from programAttributeLocations
for (var location in programAttributeLocations){
if (programAttributeLocations.hasOwnProperty(location)) {
var attribute = attributes[location];
var index = programAttributeLocations[location].index;
if (defined(attribute)) {
var parameter = parameters[attribute];
attributeLocations[parameter.semantic] = index;
var vertexAttribute = programVertexAttributes[location];
if (defined(vertexAttribute)) {
index = vertexAttribute.index;
var parameter = parameters[attribute];
attributeLocations[parameter.semantic] = index;
}
} else {
// Pre-created attributes
// Pre-created attributes.
// Some pre-created attributes, like per-instance pickIds, may be compiled out of the draw program
// but should be included in the list of attribute locations for the pick program.
// This is safe to do since programVertexAttributes and programAttributeLocations are equivalent except
// that programVertexAttributes optimizes out unused attributes.
index = programAttributeLocations[location];
attributeLocations[location] = index;
}
}
Expand Down
Loading