Paint a terrain with its textures
Updated
A ball rolls in circles over a meadow terrain and paints a trail of the terrain’s own Terrain Textures under it, switching between the two images each lap: the textures of the runtime Sky & Terrain demo.
Watch the trail of images appear behind the ball, a different image each lap. Drag to orbit the camera, scroll to zoom.
Paint a terrain with its textures
#pragma lifecycle(startup, update)
const RADIUS = 3; // metres, the circle the ball rolls roundconst SPEED = 0.6; // radians a secondconst STEP = 0.15; // seconds between strokeslet terrain;let textures;let ball;let angle = 0;let timer = 0;let lap = 0;const point = new THREE.Vector3();
function startup() { const ground = findEntity('Terrain'); terrain = ground.getComponent(TerrainComponent); textures = ground.getComponents(TerrainTextureComponent); ball = findEntity('Painter Ball'); log('Terrain textures:', textures.length);}
function update(dt) { angle += dt * SPEED; const x = Math.cos(angle) * RADIUS; const z = Math.sin(angle) * RADIUS; const ground = terrain.heightAt(x, z); ball.position.set(x, ground + 0.35, z); ball.rotation.z = -angle * 4;
if (Math.floor(angle / M_TAU) !== lap) { lap = Math.floor(angle / M_TAU); log('Lap', lap, '- painting with texture', (lap % textures.length) + 1); } timer += dt; if (timer < STEP) return; timer = 0; point.set(x, ground, z); // A soft disc; scale 0.25 tiles the image four times smaller. terrain.paintAt(point, 0.6, textures[lap % textures.length], 1, 0.6, { scale: 0.25, rotation: (angle * RAD_TO_DEG(1)) % 360 });}Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
LemonTrail.xrproj