Start a new topic

Dynamic AR.context scaling variables

Hi Wikitude staff !

I'm working on an Cordova based application, and wasa wondering if it's possible to dynamically change the behavior of an AR World regarding marker scaling ?

I'm specifically talking about the AR.context.scene.maxScalingDistance, AR.context.scene.minScalingDistance and AR.context.scene.scalingFactor.

Right now, I'm setting these variables with my default value when the world loads up.

I'd like to change their values "at runtime" and see the changes be effectively applied to present markers.

I've set up the logic for that, but this doesn't seem to work, as the marker doesn't change at all when the values are.

So my question is basically : is this theorically feasable and I'm just doing it wrong ? Or is it not possible and I'm 

Hello Mathias,

Yes, this is something that you can do. However, I would advice you to read carefully what is the purpose of these properties to be able to understand and test if they are actually changing dynamically or not.



Hello Eva,

Thanks for the answer, but... I'm sorry, I don't understand what you're saying :/

I know what these properties do, and I'm already changing them dynamically. But it doesn't seem that the AR World is applying these changes when it's loaded, since the scaling of my already loaded markers don't change "in live".

So, I was wondering if maybe these three properties I'm talking about are only used once when the world is loaded, and changing their values afterward has no impact on the current AR World behavior.

Would you have an exemple of AR.context properties that are dynamics ?

What I meant is that it is hard to actually test in live and see if the values of these properties change dynamically. So I would recommend is that you set the values for AR.context.scene.maxScalingDistance, AR.context.scene.minScalingDistance close to each other. Something like
scene.minScalingDistance: 1
scene.maxScalingDistance: 20
scene.scalingFactor: 0.1 (default)

This way you should be able to see the change when starting exactly on the POI and walking away slowly. Decreasing the 'scene.scalingFactor' even further, for example 0.01, should exaggerate the effect.

Oh. If I understood correctly, you're talking about seing the marker being rescaled as I walk around it ?

That's why you advise me to set these values, so that the scaling effect would be very visible ?

If that's the case, I think I may have badly expressed myself. Because I was not talking about that; I've witnessed this scaling effect on markers while developing my app.

So, let me be as clear as possible :)

If you refer to the example 08_BrowsingPois_3_LimitingRange of your Wikitude Cordova Demo App, you'll see that there is range slider on the UI that allow the user to update the distance at which Markers are visible in the AR World (the culling distance).

The code that does that is in the file 'limitrange.js' around line 186. Here's the specific part:


AR.context.scene.cullingDistance = Math.max(maxRangeMeters, 1);

An, in this example, the effect ot this cullingDistance change is immediately visible in the AR View : some Markers effectivly disappear when the value decrease.

In my case, I want to achieve something similar, that is using slider ranges on the UI to dynamically change the value of AR.context.scene properties and see the effect right away in my AR View.

But here, I don't want to change the culling Distance. Instead, I want to temper with maxScalingDistance, minScalingDistance and the scalingFactor and see the changes on my markers, without moving around, and while staying on the AR View, as your example I talk about does.

Because there should be changes on my markers size, right ? Since these three properties have an impact on the way the markers size is calculated, it should be updated when the properties value change.

Like if moving up the range slider for the scalingFactor, my markers should all be larger.

I've already implemented these sliders and tied them to the three properties, pretty much like what is done in your example. Except I don't see any impact on my markers.

Hence my question ^^

(You'll find in attaché a screenshot of what the range sliders I've implemented. I should have give you that in the first place, sorry !)


looking at the code that is called upon setting the distance scaling values, I suspect to have found why they are not updated on the fly. I will continue to investigate this next week.

- Daniel

1 person likes this

Good morning,

my initial assumption about the scaling values not being updated was incorrect; they are, in fact, updated. I implemented three range inputs to control the scaling values and found them to be working.

While implementing this, I had an error in my range slider implementation that caused the scaling values to not work. I'm thinking you might have the same issue in your application.

This is what my sliders look like:

<input type="range" min="1" value="10" max="20000" step="1" onchange="World.setMinScaling(value)">
<input type="range" min="1" value="20000" max="20000" step="1" onchange="World.setMaxScaling(value)">
<input type="range" min="0.0" value="0.1" max="1.0" step="0.001" onchange="World.setScalingFactor(value)">


The value passed to the functions registered to onchange are strings, not numbers, which will be disregarded by the Wikitude SDK if assigned as follows because of an internal type check.


setMinScaling: function(value) {
    AR.context.scene.minScalingDistance = value;


Using the following piece of code instead, however, worked for me.

setMinScaling: function(value) {
    AR.context.scene.minScalingDistance = parseInt(value);


Your POI augmentations should be updated upon the next location change after one of the scaling values has been changed. At least that what it looks like to me; I didn't check the code in regards to when the update actually happens.

- Daniel

Hello Daniel,

Thanks for the update!

You said: "The value passed to the functions registered to onchange are strings, not numbers, which will be disregarded by the Wikitude SDK if assigned as follows because of an internal type check."

And I think that's indeed why my code didn't worked, since I passed the value as-is to the variables.

Plus, being at a fixed location where my GPS detection is somewhat lacking, I have very few location updates. Regarding your last paragraph, that could also be the reason for my problem.

Thanks again for your time and your answer ;)

Login or Signup to post a comment