Skip to content

Commit

Permalink
More testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Nov 13, 2023
1 parent f8094c4 commit bbdcac1
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 162 deletions.
87 changes: 59 additions & 28 deletions Apps/Sandcastle/gallery/development/3D Tiles Picking.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,72 @@
baseLayerPicker: false,
globe: false,
});

// Enable rendering the sky
viewer.scene.skyAtmosphere.show = true;
const scene = viewer.scene;

let tileset;
// Add Photorealistic 3D Tiles
try {
tileset = await Cesium.createGooglePhotorealistic3DTileset(
undefined,
{
enableDebugWireframe: true,
}
);
viewer.scene.primitives.add(tileset);
} catch (error) {
console.log(`Error loading Photorealistic 3D Tiles tileset.
${error}`);
}
const options = [
{
text: "Google P3DT",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.createGooglePhotorealistic3DTileset();
scene.primitives.add(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Maxar OWT WFF 1.2",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromIonAssetId(691510, {
maximumScreenSpaceError: 4,
});
scene.primitives.add(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Bentley BIM Model",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402);
scene.primitives.add(tileset);
viewer.zoomTo(tileset);
} catch (error) {
console.log(error);
}
},
},
{
text: "Instanced",
onselect: async () => {
scene.primitives.remove(tileset);
try {
tileset = await Cesium.Cesium3DTileset.fromUrl(
"../../SampleData/Cesium3DTiles/Instanced/InstancedWithBatchTable/tileset.json"
);
scene.primitives.add(tileset);
viewer.zoomTo(tileset);
} catch (error) {
console.log(error);
}
},
},
];

viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
const inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;
inspectorViewModel.tileset = tileset;

const scene = viewer.scene;
Sandcastle.addDefaultToolbarMenu(options);

const scratchCartesian = new Cesium.Cartesian3();
const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
const pickedPositionResult = scene.pickPosition(movement.position);
console.log(pickedPositionResult);
if (Cesium.defined(pickedPositionResult)) {
viewer.entities.add({
position: pickedPositionResult,
Expand All @@ -83,12 +119,7 @@
}

const ray = scene.camera.getPickRay(movement.position);
const picked = tileset.pick(
ray,
scene.frameState,
true,
scratchCartesian
);
const picked = tileset.pick(ray, scene.frameState, scratchCartesian);

if (Cesium.defined(picked)) {
viewer.entities.add({
Expand Down
8 changes: 1 addition & 7 deletions packages/engine/Source/Scene/Cesium3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,12 @@ Cesium3DTileContent.prototype.update = function (tileset, frameState) {
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {boolean} [cullBackFaces=true] If false, back faces are not culled and will return an intersection if picked.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Cesium3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Cesium3DTileContent.prototype.pick = function (ray, frameState, result) {
DeveloperError.throwInstantiationError();
};

Expand Down
20 changes: 9 additions & 11 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3427,24 +3427,19 @@ Cesium3DTileset.prototype.getHeight = function (cartographic, scene) {
};

const scratchSphereIntersection = new Interval();
const scratchPickIntersection = new Cartesian3();

/**
* Find an intersection between a ray and the tileset surface that was rendered. The ray must be given in world coordinates.
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {boolean} [cullBackFaces=true] If false, back faces are not culled and will return an intersection if picked.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Cesium3DTileset.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Cesium3DTileset.prototype.pick = function (ray, frameState, result) {
const selectedTiles = this._selectedTiles;
const selectedLength = selectedTiles.length;

Expand All @@ -3461,15 +3456,19 @@ Cesium3DTileset.prototype.pick = function (
continue;
}

const candidate = tile.content.pick(ray, frameState, cullBackFaces, result);
const candidate = tile.content.pick(
ray,
frameState,
scratchPickIntersection
);

if (!defined(candidate)) {
continue;
}

const distance = Cartesian3.distance(ray.origin, candidate);
if (distance < minDistance) {
intersection = candidate;
intersection = Cartesian3.clone(candidate, result);
minDistance = distance;
}
}
Expand All @@ -3478,8 +3477,7 @@ Cesium3DTileset.prototype.pick = function (
return undefined;
}

Cartesian3.clone(intersection, result);
return result;
return intersection;
};

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/engine/Source/Scene/Composite3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,12 @@ Composite3DTileContent.prototype.update = function (tileset, frameState) {
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {boolean} [cullBackFaces=true] If false, back faces are not culled and will return an intersection if picked.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Composite3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Composite3DTileContent.prototype.pick = function (ray, frameState, result) {
if (!this._ready) {
return undefined;
}
Expand All @@ -375,7 +369,7 @@ Composite3DTileContent.prototype.pick = function (
const length = contents.length;

for (let i = 0; i < length; ++i) {
const candidate = contents[i].pick(ray, frameState, cullBackFaces, result);
const candidate = contents[i].pick(ray, frameState, result);

if (!defined(candidate)) {
continue;
Expand Down
7 changes: 1 addition & 6 deletions packages/engine/Source/Scene/Empty3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ Empty3DTileContent.prototype.applyStyle = function (style) {};

Empty3DTileContent.prototype.update = function (tileset, frameState) {};

Empty3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Empty3DTileContent.prototype.pick = function (ray, frameState, result) {
return undefined;
};

Expand Down
7 changes: 1 addition & 6 deletions packages/engine/Source/Scene/Geometry3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,7 @@ Geometry3DTileContent.prototype.update = function (tileset, frameState) {
}
};

Geometry3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Geometry3DTileContent.prototype.pick = function (ray, frameState, result) {
return undefined;
};

Expand Down
7 changes: 1 addition & 6 deletions packages/engine/Source/Scene/Implicit3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,7 @@ Implicit3DTileContent.prototype.applyStyle = function (style) {};

Implicit3DTileContent.prototype.update = function (tileset, frameState) {};

Implicit3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Implicit3DTileContent.prototype.pick = function (ray, frameState, result) {
return undefined;
};

Expand Down
5 changes: 2 additions & 3 deletions packages/engine/Source/Scene/Model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2489,14 +2489,13 @@ Model.prototype.isClippingEnabled = function () {
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {boolean} [cullBackFaces=true] If false, back faces are not culled and will return an intersection if picked.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Model.prototype.pick = function (ray, frameState, cullBackFaces, result) {
return pickModel(this, ray, frameState, cullBackFaces, result);
Model.prototype.pick = function (ray, frameState, result) {
return pickModel(this, ray, frameState, result);
};

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/engine/Source/Scene/Model/Model3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,23 +421,17 @@ Model3DTileContent.fromGeoJson = async function (
*
* @param {Ray} ray The ray to test for intersection.
* @param {FrameState} frameState The frame state.
* @param {boolean} [cullBackFaces=true] If false, back faces are not culled and will return an intersection if picked.
* @param {Cartesian3|undefined} [result] The intersection or <code>undefined</code> if none was found.
* @returns {Cartesian3|undefined} The intersection or <code>undefined</code> if none was found.
*
* @private
*/
Model3DTileContent.prototype.pick = function (
ray,
frameState,
cullBackFaces,
result
) {
Model3DTileContent.prototype.pick = function (ray, frameState, result) {
if (!defined(this._model) || !this._ready) {
return undefined;
}

return this._model.pick(ray, frameState, cullBackFaces, result);
return this._model.pick(ray, frameState, result);
};

function makeModelOptions(tileset, tile, content, additionalOptions) {
Expand Down
Loading

0 comments on commit bbdcac1

Please sign in to comment.