0
$\begingroup$

I'm working on a reverse-engineering tool, it extracts maps from a game, and the game actually stores the positions of objects instances using Matrices4x4 transformation.

I would like to know how I can apply a transform to an object or to a group of objects. The best would be to make it work with my current code, of course, but in any case I can still rewrite some stuff, doesn't matters.

myMatrix = mathutils.Matrix(
    (0.0, 1.254, 68.14, 0.0),
    (0.01546, 1.254, 204.85468, 0.0),
    (0.45, 0.0, 0.0, 0.0),
    (204.154, 451.943, 345.456, 1.0)
)

name = 0
myCollection = bpy.data.collections.new("Custom Collection")
for i in range(randint(10, 200))
    verts = []  # Just imagine that there's a list of vertices tuple.
    faces = []  # Same, imagine there's a list of faces tuple.
    edges = []  # Empty. Ignore it
    meshdata = bpy.data.meshes.new(f"MyObjData_{str(name)}")
    meshdata.from_pydata(verts, edges, faces)
    obj = bpy.data.objects.new(name=f"MyObj_{str(name)}", object_data=meshdata)
    myCollection.objects.link(obj)
    # How do I set the position of my object using the matrix myMatrix ?
$\endgroup$
4
  • 1
    $\begingroup$ Does this answer your question? Apply transforms to linked objects? meshdata.transform(myMatrix) $\endgroup$ Dec 6, 2022 at 0:34
  • $\begingroup$ Some are linked objects and some are basically just objects, does it still work ? $\endgroup$
    – V E L Δ
    Dec 6, 2022 at 13:17
  • $\begingroup$ @MarkusvonBroady it's making an error, it says meshdata.transform(tie_instance_matrix) TypeError: Mesh.transform(): error with argument 1, "matrix" - expected sequence items of type float, not Vector $\endgroup$
    – V E L Δ
    Dec 6, 2022 at 13:45
  • $\begingroup$ Resolved, problem was coming from me $\endgroup$
    – V E L Δ
    Dec 7, 2022 at 14:53

0

You must log in to answer this question.

Browse other questions tagged .