aardgoose / CaveView.js

Web native 3d cave survey viewer
https://aardgoose.github.io/CaveView.js/
MIT License
44 stars 11 forks source link

Consider doing in WebXR #26

Closed goatchurchprime closed 4 years ago

goatchurchprime commented 4 years ago

This would mean we could have cave surveys that are 1:1.

https://www.w3.org/TR/webxr/
https://immersiveweb.dev/
aardgoose commented 4 years ago

I plan to look at the AR Mode at some point. Obviously testing isn't possible at the moment. As for VR mode, I think 1:1 is pushing it a bit & availability of kit (although one of the Three.js contributors has produced an emulator extension for testing in desktop browesrs. I was going to have a look before but WebVR was in the process of being replaced by WebXR.

goatchurchprime commented 4 years ago

I've been going through these samples: https://immersive-web.github.io/webxr-samples/

Do you think the way forward is to make a svx -> gltf converter, which could then be loaded into someone else's framework?

There are so many model formats I've never heard of before, but gltf seems to be supported in a lot of places, and allows for colours and textures.

goatchurchprime commented 4 years ago

I've had a go at making a gltf from a 3d file. My code is here https://bitbucket.org/goatchurch/survexprocessing/src/master/ (you'd have to download it as bitbucket don't do previewing of jupyter notebooks).

image

However, I've found that there is already a GLTFExporter in threejs, so I don't know why I'm wasting my time.

I know: it's because I'm a python programmer who hasn't got the hang of this npm/node stuff in a way that allows me to interact and debug it in a tight iteration loop. Maybe I should try harder.

Is it possible we could have a chat about these sorts of things sometime, so that I can hopefully work out a modest PR that would help out? I've been playing games on a really good VR kit this past month, which explains why I've got keen on this sort of stuff.

aardgoose commented 4 years ago

I had a look at GLTF Three.js export last year, but didn't pursue it at the time because I didn't have an immediate use. It should be quite simple to add, or create a simple converter. The only difficulty is having objects in the scene graph that don't use standard materials, so there is a small amount of work to either remove them, or if required use supported materials. I'll take a look.

goatchurchprime commented 4 years ago

I had a go at forcing a GLTF export in the following way:

into your Three.js exports file.

Then I was able to run the following on the console to output a GLTF file:

document.DDgltfExporter.parse(document.DDscene, function(result) { document.DDresult = result });

var DDoutput = JSON.stringify(document.DDresult, null, 2 );

var link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild(link); 
blob = new Blob([ DDoutput ], { type: 'text/plain' }); 

link.href = URL.createObjectURL(blob);
link.download = "output.gltf";
link.click();

Unfortunately, this only had some boring camera positions in it, and no graphics.

I was not able to find where you've put the cave geometry so that I could experiment with the GLTFExport on it. No amount of hacking and adding references to objects onto document seemed to work. Are you rendering it in some direct way without using a Scene object? (Anyway, there's got to be a better way to debug this javascript, but I don't know it.)

A good GLTFExport file (with all the right colours on the tubes) might make it possible to port it across into one of the WebXR examples and try it out on a VR headset. So many links in the chain just for this one simple idea.

aardgoose commented 4 years ago

I'll have a look. It might be that it was skipping the non standard materials. Everything is attached to the Scene() object. It should be relatively simple to work something out....

aardgoose commented 4 years ago

Ok, the major issue is that I use a lot of custom materials for accurate gradient etc rendering. If you want nice coloured models that will take a bit more work but doable at some expense of memory. However hacked a quick export using a default 'StandardMaterial' of the sort GLTF expects which looks like this in blender (I've never used blender before, but a straight import worked as you would expect), so the basic export is quite simple.

Annotation 2020-05-02 114412

aardgoose commented 4 years ago

Ok, working test version on the demo site now.

There are download options in the 'Info' menu (not the ideal place but I don't want to add more tabs if possible). I've moved the exporter into a worker thread to avoid bloating the code too much and stalling the main thread.

The exporter has needed some minor changes to work in the background, it would be nice to get them upstream. Screen shot of the online viewer written by the primary author of the Three GLTF loader/exporter displaying a .lox model with lots of scraps. https://gltf-viewer.donmccurdy.com/

Annotation 2020-05-04 180000

goatchurchprime commented 4 years ago

This works pretty well! Though maybe there's an option for swapping Y and Z or something. I imported it into godot, but then had problems with the material making it work in the lights, but that's probably me.

The download file is problematic. It comes out with the filename "file set" when it probably should be "cavename.gltf"

aardgoose commented 4 years ago

I noticed the odd filename, I'll fix that, I mainly tested with a preloaded file. I wondered about rotating the axes, I've added rotation as an option now. I wonder if making a binary file format an option is useful. It produces smaller files. It's a shame facebook have stopped support gltf models in posts.

goatchurchprime commented 4 years ago

I've found something better than WebXR, which is the Godot game engine, where I've spent a few days hacking a rather crude voxel terrain model with my own VR interface.

I really think I may be on to something. https://www.youtube.com/watch?v=BsqFC-Vi3zI&feature=youtu.be

It's so rushed I've not got round to making a PC+keyboard+mouse interface. One of those bits of geometry are the passages imported from the gltf file.

Code is here, https://github.com/goatchurchprime/digreality It uses the Godot game engine (which I discovered only 8 days ago).

The terrain model will need a lot of work before it can be used for mapping out caves by digging out voxels around the centreline as well as adding textures (rocks, sand, scallop walls) and annotations. It would also need to be co-edited like OpenStreetMaps so everyone can see the changes as they happen, like in most multiplayer games.

I am convinced that this is going to be a lot faster+more fun+more participation than our old cave drawing methods. There is every possibility it could be designed to work on a PhoneVR (box with lenses and a single controller), so be cheap as well.