Spherified cube NOT USING vertex.normalized ( Not normalized cube )

Hello
I’m creating a planet which consists of six planes directed along every Vector3 directions ( forward, back, right …) .
I used this code to spherify the grid(vertices of grid are : -size >= x >= size ; y = 0 ; -size >= z >= size)

Matrix4x4 pl = Matrix4x4.TRS(planet.Position, pllanet.Rotation, Vector3.one);
Matrix4x4 ch = Matrix4x4.TRS(chunk.Position, chunk.Rotation, Vector3.one); 
for (var i = 0; i < vertices.Length; i++)
{
           Vector3 vertex = vertices*;*

Vector3 pos = pl.inverse.MultiplyPoint3x4(ch.MultiplyPoint3x4(vertex));
vertices = ch.inverse.MultiplyPoint3x4(
pl.MultiplyPoint3x4(pos.normalized * radius));
}
I use Matrix4x4 becase I can not use Transform in Thread. It is the same as TransformPoint and InverseTransformPoint functions, but the problem is not here.
I found a formula [Here][1] and the problem is that I cannot implement it to this code. I also found the tutorial [Here][2], but it did not help a lot. Can somebody help me? Some little example or something else.
Thanks in advance
_[1]: http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html*_
_
[2]: https://catlikecoding.com/unity/tutorials/cube-sphere/*_

Sorry but it’s hard to follow your code here. Also it’s incredible inefficient to calculate two matrix inverses each iteration. If you want a specific transform you may just want to multiply your desired matrices before the loop since the matrices do not change inside the loop.

As i said we have no idea wbat the pl and what the ch coordinate space represent in your case. It seems you over complicate the generation of a sphere out of a cube. I’ve made a general purpose script over here which allows to create several quad patches per cube side. This was mainly because of the 16 bit index buffer restriction but you could have other reasons to further split up the surface. Anyways just defining all vertices in the desired localspace of the planet is enough.

I also don’t get why you mentioned to not use “vertex.normalized” when you actually do “pos.normalized”.

Note that the actual generation of the vertices do not require any access to Unity APIs that are not thread safe. My simple straight forward implementation just creates a seperate gameobject for each mesh. Keep in mind that the pure generation of the vertex data is probably just a small part of the time it takes to setup the whole mesh(es).