Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babylon.js Support #265

Open
andreyrd opened this issue Mar 14, 2022 · 6 comments
Open

Babylon.js Support #265

andreyrd opened this issue Mar 14, 2022 · 6 comments
Assignees
Labels
Babylonjs question Further information is requested

Comments

@andreyrd
Copy link

I've been working on a Babylon.js renderer for ARnft. I found online that there used to be a branch where you were working on adding it. I have things half-working, right now I can't get the model to track with any stability.

@kalwalt kalwalt self-assigned this Mar 14, 2022
@kalwalt kalwalt added question Further information is requested Babylonjs labels Mar 14, 2022
@kalwalt
Copy link
Member

kalwalt commented Mar 14, 2022

Yes it is right, there was a also a PR #150 but as said in this #150 (comment) ARnft now is independent from rendering, it send only data matrix and nft infos(width, height and dpi).

@kalwalt
Copy link
Member

kalwalt commented Mar 14, 2022

I was working on this repository https://github.com/kalwalt/ARnft-babylonjs but its is still a Wip, i'm not a Babylonjs expert so i found some difficulties to set up the project. Maybe i will come back. Anyway i looked on @eddiecarbin repository https://github.com/kalwalt/InsectMobileDemo/ (my fork, look at testing-branch).

@andreyrd
Copy link
Author

So my separate repo takes a similar approach to the threejs renderer. Except it 1) does not rely on Typescript and can be much more easily imported with webpack 2) simplifies the API a little bit to make it easier to use without losing functionality.

I think what I was missing was decomposing the matrix, like you are in your repo. I was trying to assign the matrix directly using freeze(World|Projection)Matrix.

If you don't mind, I'd like to show you the repo I have, so you can choose which to move forward with.

@kalwalt
Copy link
Member

kalwalt commented Mar 15, 2022

So my separate repo takes a similar approach to the threejs renderer. Except it 1) does not rely on Typescript and can be much more easily imported with webpack 2) simplifies the API a little bit to make it easier to use without losing functionality.

Typescript is not a must, there are advantages and disadvantages choosing Typescript, and from a webpack point of view yes it's easier to setup. If you have made some simplifications that make the code better i would like to see them.

I think what I was missing was decomposing the matrix, like you are in your repo. I was trying to assign the matrix directly using freeze(World|Projection)Matrix.

Are you referring to Babylonjs code?

If you don't mind, I'd like to show you the repo I have, so you can choose which to move forward with.
Absolutely i will happy to see and test the code. After we can think also to create a repository inside the webarkit org to work on.

@andreyrd
Copy link
Author

I think what I was missing was decomposing the matrix, like you are in your repo. I was trying to assign the matrix directly using freeze(World|Projection)Matrix.

Are you referring to Babylonjs code?

Yeah, in the code that updates the root mesh:

    // Shared by all add* methods. Sets up the root mesh to listen to AR controller events with new matrix
    _addRoot (root, name, visibility) {
        this.target.addEventListener(`getMatrixGL_RH-${this.uuid}-${name}`, e => {
            root.setEnabled(true);
            
            const matrix = this._objectToMatrix(e.detail.matrixGL_RH);
            const rotationMatrix = matrix.getRotationMatrix();
            const rotation = new Quaternion().fromRotationMatrix(rotationMatrix);
            root.rotation = rotation.toEulerAngles();
            const position = Vector3.TransformCoordinates(Vector3.Zero(), matrix);
            root.setAbsolutePosition(position);
            // root.freezeWorldMatrix(matrix);
        });

        this.target.addEventListener(`nftTrackingLost-${this.uuid}-${name}`, e => {
            root.setEnabled(!!visibility);
        });
    }

I thought it'd be enough to set the matrix directly, like in Three.js, but using freezeWorldMatrix in Babylon.js. But no, we need to decompose the matrix into rotation & position, like you guys did in your repos.

Typescript is not a must, there are advantages and disadvantages choosing Typescript, and from a webpack point of view yes it's easier to setup. If you have made some simplifications that make the code better i would like to see them.

Absolutely i will happy to see and test the code. After we can think also to create a repository inside the webarkit org to work on.

Here is the repo: https://github.com/i8studios/ARnft-Babylon.js

The README should have a simple enough usage example, but let me know if something doesn't work, feel free to message me on Slack as well for a faster reply. I've implemented addModel and addVideo so far.

@kalwalt
Copy link
Member

kalwalt commented Mar 15, 2022

Thank you Andrew, i will look at your code! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Babylonjs question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants