Hi, I have a texture for several meshes. How to load it correctly? I don’t know how to start. Can somebody help me please?
https://www.babylonjs-playground.com/#9CG4LE#5
Thanks!
What is your issue exactly? It seems like you already know how to assign a texture to a material (line 19), so you just have to write gumball_mat.diffuseTexture = gumball_texture;
line 27, right?
Nearly . This texture is for all these nodes together (except for the camera, light and the last node).
And I don’t know how to load this texture onto these nodes (1 texture for all nodes, each part of the texture corresponds to some node).
The result should be like here link
The texture looks like this: texture
I want write something like this:
all_other_nodes.mesh.material = gumball_mat;
Not quite. That would be too easy. It still looks different from expectaсtation
Is it possible to create a mesh that contains other meshes (mesh of meshes, container, etc)? And then assign a texture to it, something like that
const gumpballMesh = new Mesh('gumpballMesh', scene);
result.meshes.forEach((mesh) => {
if (mesh.name !== "suelo1") {
gumpballMesh.addMesh(mesh)
}
})
gumpballMesh.material = gumball_mat;
You don’t assign a texture to meshes, you assign a material to meshes.
I think you have all the keys in your hands ; if you don’t want to select all the meshes, you can get only some of them with a nice naming convention for example.
Let’s say you’ve used a suffix kgm
for your meshes using kawaii_gumball_machine
texture, you can apply your material using:
scene.meshes.forEach((mesh) => {
if (mesh.name.indexOf("kgm") != -1) {
mesh.material = gumball_mat;
}
});
[edit] also about merging mesh, this page can take your interest Merging Meshes | Babylon.js Documentation
Here is how your model from Sketchfab looks in Sandbox
In order to achieve what do you want you need to merge all needed meshes into one and then apply UV map to it. It is much easier to do in some 3D editor tool.