Code Monkey home page Code Monkey logo

Comments (7)

rasmuserik avatar rasmuserik commented on May 18, 2024 1

It works :)
Thanks!

(sorry about the late reply, – I was on vacation)

from noa.

fenomas avatar fenomas commented on May 18, 2024

Hi, yes, some BJS folks have asked me to support this and I'd like to do it properly! But I'm not sure how best to go about it.

First, note that I've just pushed a build to the develop branch to lay the groundwork for this - it now lets you pass in a babylon.js reference, rather than assuming it will be in global. I.e.:

var noaEngine = require('noa-engine')
var babylonJS = require('babylonjs')
var noa = noaEngine({
    babylon: babylonJS,
})

Now with that said, the problem currently with import is that noa treats babylon as peer dependency - that is noa doesn't import anything from Babylon directly, but various noa modules do new BABYLON.Vector3 and whatever. So I guess, the easiest way to do what you're talking about, today, would be for the game client to import only the specific classes noa uses and pass them in:

import { Engine } from '@babylonjs/core/Engines/engine'
import { Scene } from '@babylonjs/core/scene'
import { Vector3 } from '@ babylonjs/core/Maths/math'
// .. and all the other classes noa needs

var noa = noaEngine({
    babylon: {
        Scene,
        Engine,
        Vector3,
        // ...
    }, 
})

I assume this would work but it's not a nice solution. The alternative would be for noa to just declare a direct dependency on Babylon and import whatever classes it uses. However I guess this might make life difficult for a user who wants to use noa with a newer version of BJS, or with other BJS features that noa doesn't use.

Is your solution the same as one of those, or do you see other alternatives?

from noa.

rasmuserik avatar rasmuserik commented on May 18, 2024

Another option would be to declare @babylonjs/core as a peer depency in the noa's package.json as shown in this branch. Feel free to merge it if you want that approach, – otherwise I'll just pass the babylon modules as a parameter to noa, which works fine for me :)

from noa.

fenomas avatar fenomas commented on May 18, 2024

Hey, thanks for that link! It looks like I should do exactly that. I should probably also switch the rest of the code from require over to import - I've been meaning to do that eventually but didn't have a reason.

I'll work on this, thanks!

from noa.

fenomas avatar fenomas commented on May 18, 2024

@rasmuserik

I dove into this and it's working, but there were some complications. As a result I have pushed a branch to this repo that now uses @babylon/core as a peer dep, but I also had to move the example contents into a separate repo:

https://github.com/andyhall/noa-examples

Can you do me a huge favor, and try pointing your project at the noa branch #es6-modules-babylon-as-peer, and see if everything builds as expected? You will need to set your dependencies similarly to what's in the noa-examples repo, like:

    "dependencies": {
        "@babylonjs/core": "^4.0.3",
        "noa-engine": "github:andyhall/noa#es6-modules-babylon-as-peer"
    },

Since these are big changes I'd really like to confirm that it works for someone besides me 😁

Thanks!

from noa.

fenomas avatar fenomas commented on May 18, 2024

Cheers mate!

I will push a release pretty soon.

from noa.

fenomas avatar fenomas commented on May 18, 2024

This is pushed to #master and also npm as v0.26.0.

Let me know if anything breaks!

from noa.

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.