Getting localToWorldMatrix without a transform from just position, rotation, and scale

Hi,
I need to set the CombineInstance*.transform* which is a Matrix4x4.

I have a list of mesh and their respective required local position, rotation, and scale. My current solution is just moving a transform(the final mesh holder) to that and using the transform.localToWorldMatrix to get the desired CombineInstance*.transform* matrix. Returning the transform to its old position, rotation, scale, and parent after it’s done. Its transform still gets marked dirty for stuff like prefab overrrides which needs to cleaned up.

Now I was just wondering if there is any way to get that localToWorldMatrix for each mesh without using a transform. This would solve a lot of headaches.

Here is an example code of what I do atm. (Apologies if there is any mistake here. I cleared up a pretty messy code)

```csharp
*//here mesh layouts contain mesh, desired position, rotation, scale
CombineInstance combine = new CombineInstance[meshLayouts.Count];
int i = 0;
while (i < meshLayouts.Count)
{
combine[i].mesh = meshLayouts[i].mesh;
//combine[i].transform = meshFilters[i].transform.localToWorldMatrix; //I don’t want to instantiate the meshes anymore. Just getting them from prefabs

        parent.position = meshLayouts[i].position; 
        parent.rotation = meshLayouts[i].rotation;
        parent.localScale = meshLayouts[i].scale;
        combine[i].transform = parent.localToWorldMatrix;

        i++;
    }*</em>

```

What about just using the factory methods that Matrix4x4 expresses, like perhaps TRS() ?

2 Likes

Didn’t know about that. Looked up the reference. Seems to be what I was looking for.

Thanks a bunch! I will try it out now.

1 Like

That worked perfectly!
You are amazing!

1 Like