itowns icon indicating copy to clipboard operation
itowns copied to clipboard

How to customize the management of 3DTiles refinement with iTowns ?

Open LorenzoMarnat opened this issue 3 years ago • 5 comments

Your Environment

  • Version used: 2.33.0
  • Browser Name and version: Mozilla Firefox 89.0.2
  • Operating System and version (desktop or mobile): Windows 10
  • Link to your project: UD-Viz-demo

Context

Hi, I'm working on levels of details for 3DTiles, at the Liris (Lyon, France). I create tilesets of buildings with several levels of details, and visualize those tilesets with our web application UD-Viz (using iTowns).
part_dieu_lod

To handle refinement when zooming in/out, I change the geometric error of the different levels of details when creating the tileset.json
image
and I change the seeTreshold in the 3DTileslayer. image

With this, I can handle the distance to refine pretty well (by letting iTowns refine when necessary), but I'm lacking control and precision on which tiles to refine and when to refine them.

Expected Behavior

I would like to know if there is a way to 'customize' the management of refinement in iTowns (i.e use another parameter than the geometric error to know when to refine). For example, I'd like to use the distance between the camera and a tile to refine, or semantic data.

Is there a way to override/customize the iTowns refinement strategy ? or a way to implement our own refinement strategy ?

LorenzoMarnat avatar Jul 07 '21 14:07 LorenzoMarnat

Yes, it's possible to customize but the default methods aren't exposed in itowns.

I will do a PR to expose the default methods :

  • process3dTilesNode : default method to update 3dtiles node depending on the context.
  • $3dTilesCulling : default culling method
  • $3dTilesSubdivisionControl : default refinement strategy method.

To customize it's necessary to overload the C3DTilesLayer.update method.

const yourMethod = (context, layer, node) => {
    //...
    return childrenVisible;
}

c3d_tiles_layer.update = yourMethod;

When default methods will be exposed, you could just redefine refinement strategy:

const yourRefinementStrategy = (context, layer, node) => {
    const default = $3dTilesSubdivisionControl(context, layer, node);
    // your code
    // return true to refine node
}
// to overload refinement strategy
c3d_tiles_layer.update = itowns.process3dTilesNode(itowns.$3dTilesCulling, yourRefinementStrategy);

gchoqueux avatar Jul 13 '21 12:07 gchoqueux

Pr opens #1689

gchoqueux avatar Jul 13 '21 12:07 gchoqueux

The PR #1689 is merged and is in release 2.34.0. Could you confirm that it meets your expectations?

gchoqueux avatar Aug 04 '21 12:08 gchoqueux

Hi, thank you, it seems very promising, I think I'd be able to do what I want.
I will try this and come back to you if I have any question or remark.

LorenzoMarnat avatar Aug 24 '21 09:08 LorenzoMarnat

Hi, I'm back to share what I've been able to produce thanks to your modifications. I didn't encounter any major difficulty and I found what I needed in the iTowns API.

The goal of my production was to use the mouse position to refine the 3DTiles buildings. In order to do that, I have created customized subdivision control and SSE computation methods to use to mouse position instead of the camera position.
mouse

The produced code can be found in this repo, especially in 3dtilesProcessing.js for the code using customized iTowns methods.

An online demo is available here if you want to see the result.
A docker version is also available in this repo.

Thank you for your time and your work on this issue !

LorenzoMarnat avatar Sep 28 '21 09:09 LorenzoMarnat