fenomas / noa

Experimental voxel game engine.
MIT License
611 stars 87 forks source link

A question about custom meshes #129

Closed csf30816 closed 4 years ago

csf30816 commented 4 years ago

Hi, as you might've already guessed I am a noob with BabylonJS. I want to add a grass object that I made in Blender into noa-engine so I used the AssetManager and glb format.

cosnt mgr = new AssetsManager(...);
mgr.addMeshTask(...);
mgr.load();
mgr.onFinish = (tasks) => {
    // register block here
}

And then I register that mesh like this.

blocks[b.name] = noa.registry.registerBlock(id++, {customMesh: tasks[0].loadedMesh[1], opaque: false});

And then in my worldgen.js file, I place the grass places. Originally nothing showed up and the blocks were just clear blocks. Then I added a white material and the boxes showed up as white but no grass. In Blender, I applied all the transforms but to no avail. I'm just wondering if someone here could give me an example on how to use custom mesh with an imported glb (obj, fbx, etc.)

fenomas commented 4 years ago

Hi, I've never used glb or Babylon's asset-related features, but at first blush this sounds like an async issue. It looks like you're registering the custom block after Babyon finishes loading and processing the asset, but does worldgen (or just creating the noa instance) get deferred until after that? If not then probably noa is trying to create terrain with a block that hasn't been registered yet. (which I'd think would throw an error, but there could be a bug.)

If that's not the issue, there is some sample code for custom blocks in the test world - a mesh is created here, and then the block is registered here. That should work for any kind of Babylon mesh, unless there's something special about meshes from the asset system that I don't know about.

csf30816 commented 4 years ago

I do worldgen after registering the blocks and I register the blocks after the mesh has been completely loaded. Its either a problem with my mesh or something else.

Jarred-Sumner commented 4 years ago

GLBs/GLTFs in Babylon are loaded with a few wrapping meshes. Usually a Mesh -> TransformNode -> [real content here]

I suspect the issue you're seeing is that its only adding that first mesh to the scene.

csf30816 commented 4 years ago

That's probably it. I noticed there were two different meshes I just selected the one that had the right id

fenomas commented 4 years ago

Assuming this is fixed, please update if not!