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

Is there any way to use this as an es6 module? #174

Closed
Vixeliz opened this issue Mar 1, 2022 · 10 comments
Closed

Is there any way to use this as an es6 module? #174

Vixeliz opened this issue Mar 1, 2022 · 10 comments

Comments

@Vixeliz
Copy link

Vixeliz commented Mar 1, 2022

Basically the title I would love to be able to use this without node and just as a es6 module

Edit:
I'm also curious can i just use the rendering portion of this but set up my own player controller and inputs?

@fenomas
Copy link
Owner

fenomas commented Mar 2, 2022

Hi!

For the es6 module, that's a great idea and it would be good to support. However noa uses the 3D engine Babylon.js as a peer dependency, and I don't think it publishes prebuilt e6 modules. If I'm wrong about that then I think the same should be doable here (but I haven't looked closely yet).

For changing player controls - yes! The engine uses an ECS internally, and handles player inputs/controls/movements by attaching components to the entity noa.playerEntity. So changing things just means removing the default components and adding different ones.

For example, here is the default movement component (that applies physics forces for moving/jumping/etc), and here is the engine code that adds that component to the player. So the easiest way to change stuff is to make a copy of the movement component, change whatever, and then do something like:

noa.entities.createComponent( myComponentDef )
noa.entities.removeComponent(noa.playerEntity, noa.entities.comps.movement.name)
noa.entities.addComponent(noa.playerEntity, myComponentDef.name)

The engine also adds components to do stuff like make the camera follow the player, consume key presses to cause movement, etc., so in general you can change any behavior by removing the default components from the playerEntity and adding new ones.

@Vixeliz
Copy link
Author

Vixeliz commented Mar 2, 2022

Hmm interesting. With that said do you think it would be possible to implement other control methods such as touch, game pad, and vr? As for es6 modules I believe babylonjs cdn files can be used as modules https://www.npmjs.com/package/babylonjs you c read about their cdns at the top of the description. However I may be wrong

@fenomas
Copy link
Owner

fenomas commented Mar 2, 2022

Hi, yes alternate input systems aren't in place at the moment but they'd be relatively straightforward to implement. Feel free to ask any questions!

@Vixeliz
Copy link
Author

Vixeliz commented Mar 2, 2022

Awesome thanks! I'm very interested in expanding noa to be more of a game base(like minetest if you know that project) than a framework for voxel rendering. I might look into making a library on top of noa that allows for some things like universal controls(vr, mobile, controller), multiplayer, mods, etc. Does noa have a discord server or something?

@Vixeliz
Copy link
Author

Vixeliz commented Mar 2, 2022

Would you consider upstream making this movement code

var fb = inputs.forward ? (inputs.backward ? 0 : 1) : (inputs.backward ? -1 : 0)
based off of a value from 0 to 1 for analog control? It might be a good start if you are interested in controls for more platforms

@fenomas
Copy link
Owner

fenomas commented Mar 3, 2022

Ooh that's a really good idea. I haven't looked closely at gamepad APIs but if they work as advertised this would be very straightforward to implement.

I can't get to this right away, but I'm adding a tracking issue (#175) and I'd like to support it. Or if you want to work on it, I'm happy to answer questions and take PRs.

For mobile controls, all the required APIs are there but a game client would need to create its own button overlays or thumb button, etc, and issue its own events. The specifics would change from game to game so I'm not sure if there's anything the engine should do here. But now that I think about it, if there's a UI library somewhere for gamepad-like controls on mobile, supporting that library by default would be a good first step..

@Vixeliz
Copy link
Author

Vixeliz commented Mar 3, 2022

Awesome to the tracking issue. As for gamepad api it is really simple to implement I may make a pr. One last question would you ever be interested in multiplayer support built into this library? Or maybe as an official separate addon library such as noa-networking?

@fenomas
Copy link
Owner

fenomas commented Mar 3, 2022

Thanks! Yes, the theory is that this engine should be abstract enough that it doesn't know whether it's part of a single player or a multiplayer game. Basically it's a dumb client that renders voxels and entities, but it doesn't know whether you're generating the voxel data and entity locations locally, or receiving them from a server, etc. So there's nothing multiplayer-related in this repo, but the engine tries to do everything necessary to support it.

If you check the demo apps in the readme one or two of them support multiplayer, but I don't know a lot about specifically what other libraries they use (or whether they're FOSS).

@lknlknim
Copy link

Is it possible to use this engine with Vite bundler? The require.context in entities.js seems to be webpack specific and I can't figure out how to properly use this as dependency in a Vite Vue/Svelte project.
Temporarily using it in Webpack Vue project but the HMR is slow.

@fenomas
Copy link
Owner

fenomas commented Jun 20, 2022

@lknlknim Hi, there is an issue for this that I forgot about - I'll pop over and fix it now. Should be fixed in #develop in a few minutes.

Also I'll close this since several topics have been touched, but feel free to open new issues for anything else.

@fenomas fenomas closed this as completed Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants