By default, the playground does not scale the grey sphere. You will note that the green sphere moves horizontally parallel to the grey cube behind it.
All objects (except the ground) are children of the grey sphere. If you comment out the line (currently 60): var newScale = sphere.scaling.x;
and remove the comment from: //var newScale = sphere.scaling.x + (0.005 * sphere.scaleDirection);
Running in this configuration results in the yellow trail no longer representing the object’s movement in 3D space but rather screen space.
I need to figure out how to make the TrailMesh object scale as per the green sphere and grey cube. Help please!
Why would you scale everything on each frame? the objects stay the same, it is the distance between you and the object that makes it look like it is being re-scaled.
But this part aside, this is less about AR and more about trailmesh. I guess we will need to know what the expected behavior is, because I sadly didn’t understand the issue.
Interesting regarding AR… I’m using 8th wall and their SDK examples all provide a scale that you need to apply to a parent object in the scene to make it appear in the correct place. I’ll happily take any guidance on a better approach (indeed different libraries).
The issue with the TrailMesh is that it doesn’t scale in space. In the playground example it is essentially parented as:
Sphere -> movingObject -> TrailMesh
As the scale changes the trail bascially moves about the screen tracing where the moving object has been rendered.
I was expecting it to remain ‘static’ as it were in reference to the mesh that is set as it’s emitter.
I placed a box called guide that is also a child to the main sphere. The green child sphere moves directly left/right in front of the guide even when scaled. The trailmesh does not.
The best way to see what i mean is to remove the comment on line 61 in the playground
This is probably since 8th wall can’t control the camera’s position which is fixed in one place. Using WebXR you can track you rpoisition in space using native functionality in your browser. It still lacks some features that the 8th wall do offer, but it is developing rapidly. You can read about it here - https://doc.babylonjs.com/how_to/webxr_augmented_reality
I would love to be able to use webXR. Unfortunately it’s really limited in terms of platform support at the moment.
I plan on looking at ar.js and jsartoolkit when we have a gap in between projects. Having come from using Sumerian for a few projects I’m really enjoying the depth of control and feature set of babylonjs. Although the learning curve is a bit steeper.
The first two images are whilst the example runs with no scaling happening at runtime… They also represent what I believe should be the correct behaviour of the trailmesh.
^ Running with a scale for sphere of 1,1,1
^ Running with a scale for sphere of 0.3,0.3,0.3
^ What the trailmesh does with the following code enabled: var newScale = sphere.scaling.x + (0.05 * sphere.scaleDirection); sphere.scaling = new BABYLON.Vector3(newScale, newScale, newScale);
Note that:
The green sphere always moves horizontally and in front of the grey box
The green sphere only moves on the x-axis
EVERYTHING bar the ground plane is a child of the grey sphere
I would expect the trail to scale in world space and give a result similar to the first two pictures. Since the object it is a trail of only ever moves horizontally in world space, the trail should only ever be horizontal as well.
In practice, the trailmesh highlights where the green sphere has been on the screen not in world space
I am so sorry @Darren, i know it might look like I am trying to just “convince” you that everything is as it should be, but I don’t, I am really trying to understand the issue.
There is a catch here, especially with trail mesh. Trail mesh takes the current state of the generator, and generates new points in space (in world space). To get the trail mesh to scale down together with the sphere, you will need to set its scaling correctly as well. The trail mesh is not a child of the sphere, it is using the sphere to generate its trajectory. afterwards it fades out the trail it has created, but it doesn’t know the context in which previous points were made in.
If you set the trail mesh’s scaling thou, you will see weird behavior, due to the space in which the dots were made in (here is the example - https://www.babylonjs-playground.com/#20OAV9#2629) . You will need to reposition the trail mesh correctly.