Importing and attaching a mesh to a custom mesh generated in real time

Yep. Inside the import function and outside it as well. Tried all alternatives.

Hey, @Evgeni_Popov is there a way to represent the scaling and position of cap in terms of other variables and not as constants?
https://playground.babylonjs.com/#CYDTLA#7
Can you please help

Also, without changing the indices and other things

Sorry, I donā€™t understand what you meanā€¦

Sorry for not being able to explain it properly. Over here:

cap.position.set(42, 260, 13);

cap.scaling = new BABYLON.Vector3(0.700, 0.700, 0.700);

can you explain how did you get these values?
42, 260, 13 for position and 0.700, 0.700, 0.700 for scaling

What I want is to place the cap on the head in this playground https://playground.babylonjs.com/#CYDTLA#7

But instead of having constant values like

cap.position.set(42, 260, 13);

cap.scaling = new BABYLON.Vector3(0.700, 0.700, 0.700);

I want to calculate these using the already existing variables

I just tried and tested different values until that was ok visually :slight_smile:

1 Like

Which existing variables? And why do you want to do that? In which way using existing variables (once it is cleared up) is better than setting the right position / scaling manually? If you want to move the head + cap once the cap is correctly positionned, you can simply move the head (customMesh): the cap will follow as it is a child of the head.

Something is eluding me as I really canā€™t understand what you want to achieveā€¦

Existing variables like the position of the head mesh

The reason is that the positions array in my code is dynamic, so the position of the generated head mesh keeps on changing.
Hence, the position of the cap should also change along with it.

Ok, so something like this should do it:

https://playground.babylonjs.com/#CYDTLA#8

You can simulate your positions being dynamic by updating the values at lines 7942 to 7948.

1 Like

Wow interesting. Thanks. Maybe I can build upon this.

    const scaleX = 0.7 * (meshBB.extendSizeWorld.x / capBB.extendSizeWorld.x) / 0.6244;
    const scaleY = 0.7 * (meshBB.extendSizeWorld.y / capBB.extendSizeWorld.y) / 0.7555;
    const scaleZ = 0.7 * (meshBB.extendSizeWorld.z / capBB.extendSizeWorld.z) / 0.2038;

    cap.position.y += 80 * scaleY / 0.7;
    cap.position.z -= 30 * scaleZ / 0.7;

These constants were also obtained by trying and testing?

Indeed.