jpaver / opengametools

A set of open c++ game development tools that are lightweight, easy-to-integrate and free to use. Currently hosting a magicavoxel .vox full scene loader.
MIT License
373 stars 35 forks source link

ogt_vox: specify the target coordinate system and do the conversions inside the lib #51

Closed mgerhardy closed 1 year ago

mgerhardy commented 1 year ago

that would most likely ease the life of the users that are doing this on their own each time. I have a lot of code doing this conversion and I suppose a lot of other users suffer from the same code duplication.

jpaver commented 1 year ago

I'm not sure we should scope the library to do coordinate system conversions within the existing APIs. I think it's probably okay if you added an API that would modify the transforms in a writeable scene, but I'd have to see the API first to see whether it's likely to be broadly useful for many folk. Any examples of what you had in mind?

mgerhardy commented 1 year ago

it could also go into a separated ogt_vox_tools.h header. Or if the context discussion from the other tickets gets implemented, it would also be possible to add this to the context without changing any api.

mgerhardy commented 1 year ago

the ufbx library allows to specify the coordinate axes like this

// Coordinate axes the scene is represented in.
// NOTE: `front` is the _opposite_ from forward!
typedef struct ufbx_coordinate_axes {
    ufbx_coordinate_axis right;
    ufbx_coordinate_axis up;
    ufbx_coordinate_axis front;
} ufbx_coordinate_axes;

and defines some defaults like this

const ufbx_coordinate_axes ufbx_axes_right_handed_y_up = {
    UFBX_COORDINATE_AXIS_POSITIVE_X, UFBX_COORDINATE_AXIS_POSITIVE_Y, UFBX_COORDINATE_AXIS_POSITIVE_Z,
};
const ufbx_coordinate_axes ufbx_axes_right_handed_z_up = {
    UFBX_COORDINATE_AXIS_POSITIVE_X, UFBX_COORDINATE_AXIS_POSITIVE_Z, UFBX_COORDINATE_AXIS_NEGATIVE_Y,
};
const ufbx_coordinate_axes ufbx_axes_left_handed_y_up = {
    UFBX_COORDINATE_AXIS_POSITIVE_X, UFBX_COORDINATE_AXIS_POSITIVE_Y, UFBX_COORDINATE_AXIS_NEGATIVE_Z,
};
const ufbx_coordinate_axes ufbx_axes_left_handed_z_up = {
    UFBX_COORDINATE_AXIS_POSITIVE_X, UFBX_COORDINATE_AXIS_POSITIVE_Z, UFBX_COORDINATE_AXIS_POSITIVE_Y,
};

this would maybe also be useful for tools like vox2obj

jpaver commented 1 year ago

I'd like to avoid coordinate conversion in this library - keeping it narrowly scoped to reading/writing and merging lets it stay simple and good at those things without becoming too complicated.

As a bit of a middle-ground, I've actually exposed the ogt_vox_transform_multiply function in this PR: https://github.com/jpaver/opengametools/pull/56 - it'll allow the client to do whatever coordinate conversion they like by just doing another multiply on top of a global/flattened transform. eg.

const ogt_vox_transform coordinate_transform = { whatevs... };
ogt_vox_transform instance_transform = ogt_vox_transform_multiply( instance->transform, coordinate_transform );