Code Monkey home page Code Monkey logo

Comments (4)

jpaver avatar jpaver commented on May 18, 2024

Oh interesting, I wasn't aware that magicavoxel can support transform flips. I'll look into that. Thanks!

from opengametools.

jpaver avatar jpaver commented on May 18, 2024

Hey @mgerhardy - so I'm able to import that vox file into my own engine and it looks identical to what is visible in magicavoxel when I open it there. Is there anything particular about the way you're importing it in your vengi tools?

from opengametools.

mgerhardy avatar mgerhardy commented on May 18, 2024

hm. I only do the coordinate conversion with this matrix

glm::mat4 {
  -1.0f, 0.0f, 0.0f, 0.0f, 
   0.0f, 0.0f, 1.0f, 0.0f, 
   0.0f, 1.0f, 0.0f, 0.0f, 
   0.0f, 0.0f, 0.0f, 1.0f
};

which is basically this

glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)), glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));

and here is my per voxel transform:

static inline glm::vec4 calcTransform(const glm::mat4x4 &mat, const glm::ivec3 &pos, const glm::vec4 &pivot) {
  return glm::floor(mat * (glm::vec4((float)pos.x + 0.5f, (float)pos.y + 0.5f, (float)pos.z + 0.5f, 1.0f) - pivot));
}

pivot is this:

glm::vec4 pivot((float)(int)(ogtModel->size_x / 2), (float)(int)(ogtModel->size_y / 2), (float)(int)(ogtModel->size_z / 2), 0.0f);

and the last step is basically this

for (uint32_t k = 0; k < ogtModel->size_z; ++k) {
  for (uint32_t j = 0; j < ogtModel->size_y; ++j) {
    for (uint32_t i = 0; i < ogtModel->size_x; ++i, ++ogtVoxel) {
      if (ogtVoxel[0] == 0) {
        continue;
      }
      const voxel::Voxel voxel = voxel::createVoxel(palette, ogtVoxel[0] - 1);
      const glm::ivec3 &pos = calcTransform(ogtMat, glm::ivec3(i, j, k), pivot);
      const glm::ivec3 &poszUp = calcTransform(zUpMat, pos, glm::ivec4(0));
      const glm::ivec3 &regionPos = poszUp - shift;
      v->setVoxel(regionPos, voxel);
    }
  }
}

there I iterate over all voxels and do the transform - the first for the ogt_vox transform matrix and the second for the coordinate system change.

I wonder if you are doing the transformation on a per-voxel basis - or if you just load the model and apply the transformation matrix to the vertices? Asking because I move the rotated volume back to 0,0,0 (that's the strange shift value in the for loop above) - but I would rather prefer to apply the transforms only to the scene graph nodes - and thus the vertices.

from opengametools.

mgerhardy avatar mgerhardy commented on May 18, 2024

this is not an issue of ogt_vox - but an issue on my side - sorry for the noise.

i've now compiled vox2obj and can see that ogt_vox handles everything correctly.

from opengametools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.