I want to change the size of an imported image. What should I do?

For example, if the width of the image is 100 and the height is 100, I want to get the image as wide as 50 and as high as 50 from the center of the image.

try below?

var createScene = function (engine) {
    var scene = new BABYLON.Scene(engine);

    var camera = new BABYLON.ArcRotateCamera("camera1", Math.PI / 2, 0, 1000, BABYLON.Vector3.Zero(), scene);

    camera.attachControl(canvas);

    var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
    light.intensity = 0.7;

    // Ground
    var ground = BABYLON.Mesh.CreateBox("Mirror", 1.0, scene);
    const img = new Image()
    img.src = 'textures/amiga.jpg'
    const width = img.width / 2
    const height = img.height / 2
    ground.scaling = new BABYLON.Vector3(width, height, 5);
    ground.material = new BABYLON.StandardMaterial("ground", scene);
    ground.material.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene);
    // ground.material.diffuseTexture.uScale = 10;
    // ground.material.diffuseTexture.vScale = 10;
    // ground.position = new BABYLON.Vector3(0, -2, 0);

    return scene;
};

What is the problem with using uScale / vScale?

You can use the uOffset/vOffset properties if you want to move the picture:

2 Likes