Mesh Builder Create Capsule Function

Yo @Deltakosh … Or @sebavan … Can you Pretty Please ask the person who makes the MeshBuilder, please, please, please… Make a CreateCapsule function that is similar to the CreateCylinder but with the capsule end pieces of course.

I mean for the sake of good clean code, I am using the other BABYLON.MeshBuilder.CreateXXXX functions… i would had to hate to HACK together some weird function that is not using the same constructs as the MeshBuilder is doing to create geometry… To be neat and clean there should really be a a CreateCapsule on the MeshBuilder…

Please :slight_smile:

Interesting idea,
Can’t a cylinder and two half spheres be used? :slight_smile:
but maybe the edges won’t align very well :thinking:

Edit;
Out of curiosity, i did a ‘prototype’, https://playground.babylonjs.com/#BWHY4C#1

image

Direct port of the Three.js method to make a capsule

PR started… Ill try to get the comments and linting done after my meetings tonight.

1 Like

Thanks guys so much for following up with this :slight_smile:

Cant wait for the PR to the MeshBuilder … For clean code sake :slight_smile:

We shoulda had this for a hot min to be honest…

Yo @Pryme8 … So how do you use… i tried with this command and the capsule looks funny ?

var capsule = BABYLON.MeshBuilder.CreateCapsule("sphere", { tessellation:4, subdivisions:16, capSubdivisions:16, height: 2, radius: 0.5 }, scene);

Check out: https://www.babylonjs-playground.com/#K6M44R#1764

Looks all square

Yo @Pryme8 … Either is not working, or i dont have the right options… So what are the required options ???

tessellation is number of sides.
https://www.babylonjs-playground.com/#K6M44R#1766

Sweet… Yo @Pryme8 … Thanks so much for making this PR :slight_smile:

Yo @Pryme8 … there is a slight issue with the height… That should be the TOTAL height… if i use height of 2 … that bapsule is taller than 2…

You must be using height for the cylinder portion only … So what is the cap height???

should it be if height = 2 … then cylinder portion should be (height - capHeight)

where height is the total height of the capsule… Right ???

Sure, most of this was not my code! I just converted it so anything like that might not have noticed yet. Ez fix though. I got you fam.

Not sure what the author had cap height for, Ill look now.

Pretty much the only thing I made was the orientation part and the conversion so keep ripping it apart so I can fix it!

UPDATE
I had a PR earlier but it failed the automatic tests, gotta replace the test image will make the new PR in the morning.

Yo @Pryme8 … Looks great… FYI … you left a console debug message in there

console.log("halfHeight", A);
1 Like

I’ll fix now good catch. Everything else working ok?