Code Monkey home page Code Monkey logo

Comments (9)

mgerhardy avatar mgerhardy commented on May 22, 2024

_t and _r are not handled properly across the whole scenegraph. Loading a complex scene doesn't put the volumes at the right offset or the right rotation.
The saving is broken: https://github.com/mgerhardy/engine/blob/master/src/modules/voxelformat/VoxFormat.cpp#L67 as well as the loading https://github.com/mgerhardy/engine/blob/master/src/modules/voxelformat/VoxFormat.cpp#L722

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

Found this in #dev-talk of MV Community (Discord) (User Eisenwave)

If anybody's trying to figure out how to correctly apply the transformations of Vox chunks to the positions inside, this is how you do it.

i32 div2Floor(i32 n) {
    return (n - (n < 0)) / 2 ;
}

Vec3i32 applyTransform(Matrix3i32 matrix, Vec3i32 translation, Vec3i32 pointInChunk, Vec3i32 chunkSize)
{
    Vec3i32 doublePivot = Vec3i32{chunkSize[0] & ~1, chunkSize[1] & ~1, chunkSize[2] & ~1} + Vec3i32{1, 1, 1}
    Vec3i32 doublePointRelToCenter = pointInChunk + pointInChunk - ;
    Vec3i32 rotated = {
        div2Floor(dot(matrix.row(0), doublePointRelToCenter)),
        div2Floor(dot(matrix.row(1), doublePointRelToCenter)),
        div2Floor(dot(matrix.row(2), doublePointRelToCenter))
    };
    return rotated + translation;
}

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

https://gist.github.com/Eisenwave/aca18b48fdaea3259894ceb4d8e0b846

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

The rotation is fixed now.

The scenegraph is still not support though - I misunderstood some of the concepts while implementing it. The problem is, that I've assigned each layer a volume - this is not correct. The layers and objects in the scene graph share the volume with other objects - but have different translation and rotation assigned by the scene graph node properties.

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

vox2vxm

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

https://godotengine.org/asset-library/asset/341

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

Info from mv Discord:

Hey <@!529750511977627648> , so the trick is that the transform stored in _r/_t for each nTRN node is a local_transform (ie. transforms from local coordinates into parent coordinates), not a world_transform (converts from local coordinates into world coordinates), so it's defined relative to the transform for the parent nTRN node. So if you have this node hierarchy:

  • nTRN0
    • nTRN1
      • nTRN2

You find the "world space" transform of nTRN2 by computing the world transform for its parent node, something like so:
nTRN0.world_transform = nTRN0.local_transform; // it has no parent,
nTRN1.world_transform = nTRN1.local_transform * nTRN0.world_transform
nTRN2.world_transform = nTRN2.local_transform * nTRN1.world_transform

In ogt_vox, this is done (admittedly hard to decipher) and implicitly in recursive calls to generate_instances_for_node:

  • the local_transform for an nTRN node is obtained by passing the _r/_t strings from the node dictionary to _vox_make_transform_from_dict_strings.
  • the world_transform ultimately assigned to a (model) instance is obtained by a matrix multiply against the parent nTRN's world_transform here:
    _vox_transform_multiply(node->u.transform.transform, transform);
    -- the LHS in this multiply is the local transform in this context,
    -- the RHS in this multiply is the world transform of the parent nTRN node

Hope this helps

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

c298633 should fix this issue. Feedback welcome.

from vengi.

mgerhardy avatar mgerhardy commented on May 22, 2024

0fd8613 should fix the remaining issue

from vengi.

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.