fenomas / noa

Experimental voxel game engine.
MIT License
608 stars 86 forks source link

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

Closed Vixeliz closed 2 years ago

Vixeliz commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Would you consider upstream making this movement code https://github.com/fenomas/noa/blob/d9fe5d1549bc4596c5756fdcac852c9b07e535f0/src/components/receivesInputs.js#L49 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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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.