I assigned a material to a skybox during initialization, and when I tried to switch the material in another function, there was no error, but the material did not work, but the material did print out,Can someone tell me why, thanks
initBabylon(canvas, idx) {
let _this = this;
this.engine = new BABYLON.Engine(canvas, true);
const scene = new BABYLON.Scene(this.engine);
const camera = new BABYLON.FreeCamera(
"Camera",
new BABYLON.Vector3(-77.595, 41.452, -236.725),
scene
);
camera.attachControl(canvas, true);
camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);
camera.wheelPrecision = 10;
_this.lighter = new BABYLON.HemisphericLight(
"light",
new BABYLON.Vector3(1, 1, 0),
scene
);
this.skybox = BABYLON.MeshBuilder.CreateBox(
"skybox",
{ size: 1000.0 },
scene
);
const skyboxmat = new BABYLON.StandardMaterial("skyboxmat", scene);
skyboxmat.backFaceCulling = false;
skyboxmat.reflectionTexture = new BABYLON.CubeTexture(
"src/assets/img/",
scene,
[
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
]
);
skyboxmat.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
_this.skybox.material = skyboxmat;
console.log('_this.skybox.material', _this.skybox.material)
var modelNow;
if (idx == 0) {
modelNow = "/src/model/SmartBuilding.glb";
} else if (idx == 1) {
modelNow = "/src/model/1.glb";
}
BABYLON.SceneLoader.ImportMesh("", modelNow, "", scene, (meshes) => {
const model = meshes[0];
model.ellipsoid = new BABYLON.Vector3(0.5, 1.0, 0.5);
model.ellipsoidOffset = new BABYLON.Vector3(0, 1.0, 0);
model.type = "main";
_this.scene.addCamera(camera);
_this.scene.createDefaultEnvironment();
_this.scene.collisionsEnabled = true;
_this.scene.checkCollisions = true;
camera.speed = 0.4;
camera.inverseRotationSpeed = 1;
camera.setTarget(model.position);
camera.rotation = new BABYLON.Vector3(Math.PI / 25, Math.PI / 25, 0);
_this.sceneModel = meshes;
_this.modelLoaded = true;
});
this.engine.runRenderLoop(() => {
scene.render();
});
window.addEventListener("resize", () => {
this.engine.resize();
});
this.camera = camera;
this.scene = scene;
},
changeLight(light) {
let _this = this
let scene1 = this.scene
this.lighter.diffuse = BABYLON.Color3.Black();
const skyboxmat = new BABYLON.StandardMaterial("skyboxmat", scene1); //创建材质
if (light == "evening") {
skyboxmat.reflectionTexture = new BABYLON.CubeTexture(
"src/assets/img/",
scene1,
[
"Evening.jpg",
"Evening.jpg",
"Evening.jpg",
"Evening.jpg",
"Evening.jpg",
"Evening.jpg",
]
);
} else {
skyboxmat.reflectionTexture = new BABYLON.CubeTexture(
"src/assets/img/",
scene1,
[
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
"myp8qtsn0p_small.jpg",
]
);
}
_this.skybox.material = null
console.log('_this.skybox.material', _this.skybox.material)
_this.skybox.material = skyboxmat
console.log('_this.skybox.material', _this.skybox.material)
scene1.render();
this.scene = scene1
},