1
$\begingroup$

I need to save multiple objects' location in XYZ as RGBA data on an image. The colors should match that of blender in metric, so if I move the object up 105.4 centimeters in blender, the color should be 1.054. Just like shown here. And even go in the negatives, like the blue. enter image description here

Furthermore I need to save their rotation in quaternions as RGBA as well, different image though.

I've found this script, but it doesn't do exactly as I need, could it be rewritten, or how would I go about it?

Since I also need the data from multiple objects, saved in a string of pixels. https://github.com/JoshRBogart/unreal_tools?files=1

For a visual representation of what I need to do, I need to place these track elements (shown in green outline) in a shape to form the belt for a tracked machine. Each pixel corresponds to one element and it's position/rotation. So the number of pixels should match the number of objects. enter image description here

The rest will then be handled by the shader in the game.

I've included an original file from the game, if it helps. https://www.dropbox.com/s/amvvysvzrba3w9f/trackArray.rar?dl=0

Thanks.

$\endgroup$

1 Answer 1

1
$\begingroup$

If I understand correctly you would basically do

def locations_to_image(objects, image_name='Locations'):
    im = bpy.data.images.new(image_name, len(objects), 1)
    i = 0
    for ob in objects:
        im.pixels[i:i+3] = xyz_to_rgb(ob.matrix_world.translation)
        i += 4
    return im

def xyz_to_rgb(xyz):
    # Replace with however you want locations encoded.
    # This is just an example.
    bb_max = 50  # bounding box size
    return [(v + bb_max)/(2*bb_max) for v in xyz]

Edit to match your specifications.

PS. RGBA components are always in the range [0,1], so you'll need to encode them somehow.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .