Hi, I just started learning Babylon.js and started doing the Features Tutorial.
I’m currently creating the car with the material.
function createCar() {
//base
const outline = [
new BABYLON.Vector3(-0.3, 0, -0.1),
new BABYLON.Vector3(0.2, 0, -0.1),
]
//curved front
for (let i = 0; i < 20; i++) {
outline.push(new BABYLON.Vector3(0.2 * Math.cos(i * Math.PI / 40), 0, 0.2 * Math.sin(i * Math.PI / 40) - 0.1));
}
//top
outline.push(new BABYLON.Vector3(0, 0, 0.1));
outline.push(new BABYLON.Vector3(-0.3, 0, 0.1));
const carUV = [];
carUV[0] = new BABYLON.Vector4(0, 0.5, 0.38, 1);
carUV[1] = new BABYLON.Vector4(0, 0, 1, 0.5);
carUV[2] = new BABYLON.Vector4(0.38, 1, 0, 0.5);
const car = BABYLON.MeshBuilder.ExtrudePolygon("car", {shape: outline, depth: 0.2, faceUV: carUV});
const carMaterial = new BABYLON.StandardMaterial("carMaterial");
const carTexture = new BABYLON.Texture("https://assets.babylonjs.com/environments/car.png");
carMaterial.diffuseTexture = carTexture;
car.material = carMaterial;
const wheelUV = [];
wheelUV[0] = new BABYLON.Vector4(0, 0, 1, 1);
wheelUV[1] = new BABYLON.Vector4(0, 0.5, 0, 0.5);
wheelUV[2] = new BABYLON.Vector4(0, 0, 1, 1);
const wheelRB = BABYLON.MeshBuilder.CreateCylinder("wheelRB", {diameter: 0.125, height: 0.05, faceUV: wheelUV})
wheelRB.parent = car;
wheelRB.position.z = -0.1;
wheelRB.position.x = -0.2;
wheelRB.position.y = 0.035;
const wheelMaterial = new BABYLON.StandardMaterial("wheelMaterial");
const wheelTexture = new BABYLON.Texture("https://assets.babylonjs.com/environments/wheel.png");
wheelMaterial.diffuseTexture = wheelTexture;
wheelRB.material = wheelMaterial;
const wheelRF = wheelRB.clone("wheelRF");
wheelRF.position.x = 0.1;
const wheelLB = wheelRB.clone("wheelLB");
wheelLB.position.y = -0.2 - 0.035;
const wheelLF = wheelRF.clone("wheelLF");
wheelLF.position.y = -0.2 - 0.035;
car.position.y = 1.16;
car.rotation.x = BABYLON.Tools.ToRadians(-90);
}
But the front, top and back do not look right.
I’m expecting to see something like
A Simple Car | Babylon.js Playground
But the car in my playground looks like this
Babylon.js Playground - #KBS9I5#39857
Please help me spot the issue.
I already double checked the uv’s but they look correct.
After further investigation I think the issue is that the image is applied to every face of the front,top,back,bottom but I don’t know why.