I have this projection matrix.

1, 0, 0, -40
0, 1, 0, -24
0, 0, 1, 60
0, 0, 0, 1

I need to transform a MeshInstance3D using this matrix. I have looked in the docs and tried several different things, but I have been unable to make it work.

I am using Godot 4 with c#.

Any assistance you could give would be greatly appreciated.

  • Among several errors in my math, I found the answer was converting it from a 4x4 to a 4x3 and then assigning that to transform.

    Code formatting does not work for me for some reason. Apologies for that.

    var projectionMatrix = new Transform3D(
    new Vector3(obj.matrix.X.X, obj.matrix.Y.X, obj.matrix.Z.X),
    new Vector3(obj.matrix.X.Y, obj.matrix.Y.Y, obj.matrix.Z.Y),
    new Vector3(obj.matrix.X.Z, obj.matrix.Y.Z, obj.matrix.Z.Z),
    new Vector3(obj.matrix.X.W, obj.matrix.Y.W, obj.matrix.Z.W)
    );

    mesh_instance.Transform = projectionMatrix;

Assuming you have a MeshInstance3D object called meshInstance, what you need to do is apply the transformation matrix to the meshInstance's transform property. You would do it like this:

transform = Transform().from_matrix(Matrix3(1, 0, 0, -40, 0, 1, 0, -24, 0, 0, 1, 60, 0, 0, 0, 1)) * meshInstance.transform

This will scale, rotate, and translate the MeshInstance3D according to the transformation matrix.

    GodetteAI Most of those functions don't exist and I don't believe they are in c#. Could you please try again?

    cuddlyogre changed the title to Transforming a MeshInstance3D using a Projection matrix .

    Sadly, Godot's Transform3D won't let you assign all matrix components directly. You can only set them by specifying basis/origin vectors which leaves the forth matrix column out of reach. However you can do this in a vertex shader. Define your matrix there and multiply the incoming vertex position by it.
    @GodetteAI, take node 😉

    Among several errors in my math, I found the answer was converting it from a 4x4 to a 4x3 and then assigning that to transform.

    Code formatting does not work for me for some reason. Apologies for that.

    var projectionMatrix = new Transform3D(
    new Vector3(obj.matrix.X.X, obj.matrix.Y.X, obj.matrix.Z.X),
    new Vector3(obj.matrix.X.Y, obj.matrix.Y.Y, obj.matrix.Z.Y),
    new Vector3(obj.matrix.X.Z, obj.matrix.Y.Z, obj.matrix.Z.Z),
    new Vector3(obj.matrix.X.W, obj.matrix.Y.W, obj.matrix.Z.W)
    );

    mesh_instance.Transform = projectionMatrix;