Near Far Scalar with Models

Hey all,

Wondering if there are plans to implement a NearFarScalar attribute for Models (similar to Billboards)? I’d be happy to try to do this myself and submit a Pull Request, but I might need some guidance on the best way to go about it.

Mike

Hi Mike,

Does the existing minimumPixelSize property fit your use case?

There are no short-term plans for AGI to implement NearFarScalar for Models, but we welcome the contribution. I imagine nearValue and farValue would be scales, in meters, applied to the model with linear interpolation for now (linear is quite boring so I would expect others later). Look at the existing scale property for implementation guidance. This will, of course, affect the bounding sphere computation and will require traversing the node hierarchy when the computed scale changed (and only then, please).

Test it carefully using the debugShowBoundingVolume property and include unit tests.

Also, AGI is starting to do funded development, so let me know if you would rather us put this on the near-term roadmap.

Patrick

I realize I muddled some terms on my original question but I think you understood my intent. I’m looking to do a ‘scaleByDistance’ property using NearFarScalar on a model. :slight_smile:

The minimumPixelSize does work for an 80% solution, the only issue is when you’ve got several models on the screen, and the camera is showing the whole earth, then the models are a bit too prominent. We’ve hacked together some functions that listen to the changes of the camera, compute its height and then manually go change the min-pixelSize but the nearFarScalar seems like that 100% solution we’re looking for.

I’d like to try taking this on myself, though I’m not very experienced in the cesium internals. I’d like to ask some follow up questions if that’s OK, more about high level direction.

I’ve been looking at the code, especially for BillboardCollection.js and all the other files for rendering Billboards with the ‘scaleByDistance’ property. My original thought is that I could try using that code as a guide in doing the same thing for models. However, it looks like models are fundamentally different than billboards and that approach would not work.

So, re-reading your post, it sounds like a better approach would be to add a ‘scaleByDistance’ property to the model, then I would modify the getScale function to check the scaleByDistance property as well as the minimumPixelSize and compute the proper scale from that. All of course covered by unit tests. What I’m not getting is why I’d need to look at the bounding sphere computation as the getScale function doesn’t seem to need to do this? Is it performance related?

Should mimimumPixelSize ‘win’ out over the scaleByDistance if both are defined?

Should I make an Issue on github and move this conversation there?

Thanks as always for the help and awesome tool!

Answers below.

What I’m not getting is why I’d need to look at the bounding sphere computation as the getScale function doesn’t seem to need to do this?

Since we are going to scale the model dynamically based on the view distance, the bounding sphere is also going to change. If we don’t take it into account, the bounding sphere is going to be wrong. See here.

Is it performance related?

For performance, we want to check to see if the dynamic scale changed from the previous frame (like here) and only then walk the node hierarchy. Otherwise, we are going to burn CPU and hurt performance.

Should mimimumPixelSize ‘win’ out over the scaleByDistance if both are defined?

They should work together just like scale and minimumPixelSize, and, yes, minimumPixelSize has the final say.

Should I make an Issue on github and move this conversation there?

Sure. Or perhaps you have enough info to open the pull request? The change will be pretty small, it just needs to be done carefully so it doesn’t cause culling issues.

Patrick