Error when setting uScale after creating ground?

The version numbers I use are:

"dependencies": {
    "@babylonjs/core": "^5.12.1",
    "@babylonjs/gui": "^5.12.1",
    "@babylonjs/loaders": "^5.12.1",

An attribute error occurred when I added a material to the ground, the code is as follows:

// Ground
     var ground = BABYLON.MeshBuilder.CreateGround("ground", { height: 50, width: 50, subdivisions: 4 }, scene);
     var groundMaterial = new BABYLON.StandardMaterial("groundMaterial", scene);
     groundMaterial.diffuseTexture = new BABYLON.Texture("textures/wood.jpg", scene);
     groundMaterial.diffuseTexture.uScale = 30;
     groundMaterial.diffuseTexture.vScale = 30;
     groundMaterial.specularColor = new BABYLON.Color3(.1, .1, .1);
     ground.material = groundMaterial;

Code taken from: https://playground.babylonjs.com/#AHQEIB#17


What is the reason for this please?

@yjkhaoyun

It is a type error from typescript. uScale is not defined in BABYLON.BaseTexture, but in BABAYLON.Texture.

The problem is BABYLON.StandardMaterial has diffuseTexture defined as type BaseTexture in babylon.js source code. You can work around this typescript transpile time error with either:

const texture = new BABYLON.Texture("textures/wood.jpg", scene);
texture.uScale = 30;
texture.vScale = 30;
groundMaterial.diffuseTexture = texture;

or

groundMaterial.diffuseTexture = new BABYLON.Texture("textures/wood.jpg", scene);
(groundMaterial.diffuseTexture as BABYLON.Texture).uScale = 30;
(groundMaterial.diffuseTexture as BABYLON.Texture).vScale = 30;
2 Likes

Thank you very much for your help, I solved the problem with this method :+1: