Unlike in this example I’m trying to to add materials to an object I loaded with the gltf-loader.
(so there is no group like in “BoxBufferGeometry”)
So I was wondering if it’s possible to create an own group for my loaded object? Or is there a better way to add multiple materials to an object?
In my case -> I have a shiny object (base layer) which I want to have a rough-looking sticker for example. (second layer)
Okay, now I had the problem which gave me the impression that BoxBufferGeometry was an exception.
If I try the code → myObject.addGroup(0, Infinity, 0);
I get this error → myObject.addGroup is not a function.
To put it more into context:
let loader = new THREE.GLTFLoader();
loader.load('myObjects/myObject.glb', function (gltf) {
myObject = gltf.scene;
myObject.addGroup(0, Infinity, 0);
myObject.addGroup(0, Infinity, 1);
let myMaterials = [material1, material2];
myNewObject = new THREE.Mesh(myObject, materials);
scene.add(myNewObject);
But the code stops working because of the error mentioned above.
myObject.traverse(function (child) {
if (child.isMesh) {
child.material = myNewMaterial;
}
Even though the last code doesnt make much sense (assigning to myNewMaterial) I just wanted to show that myObject ist actually a mesh/geometry. (Because of “if(child.isMesh)”)
Is there a step I am missing? Or do I get something wrong?
Okay, thats what I kind of though. (thanks for the correction tho)
But what I actually wanted to know:
Is there a way to do something similar to my imported object?
Because I want a similar result for my object (like in the links I shared)
Because I want my object to have something like a group so I can add multiple materials/layers like in the examples.
loader.load('myObjects/myObject.glb', function (gltf) {
myObject = gltf.scene;
myObject.addGroup(0, Infinity, 0);
myObject.addGroup(0, Infinity, 1);
let myMaterials = [material1, material2];
myNewObject = new THREE.Mesh(myObject, materials);
scene.add(myNewObject);
As U mentioned → there is no “addGroup”-method for my object “myObject” since it’s no BufferGeometry.
But which step would you recommend if I want to give my object “myObject” multiple materials?
Now how should I be able to use addGroup() if I’m using an imported object ( and not a BufferGeometry)
Do I have to save/put “myObject” into another mesh or group?
Sorry but I’m still having trouble understanding your advice.
Okay, thats good to know!
So these B’s are my BufferGeometry-Instances. Do I still need to parse them to get their information?
Because my code obviously doesn’t know what B is.