but0n / Ashes

WebGL2.0 3D Engine - Global Illumination - RayTracing
https://codepen.io/but0n/pen/jddYoX
MIT License
328 stars 16 forks source link

How to switch between multiple cameras embedded into glTF? #17

Closed cx20 closed 5 years ago

cx20 commented 5 years ago

I know that VC.gltf and project_polly.gltf have cool cameras built in them. However, I do not know how to use them in this library. Can you add samples if possible?

https://www.youtube.com/watch?v=l7TB1O51X_M

but0n commented 5 years ago

Currently, this library havn't parsing cameras information, but you can still implement this by attach the camera entity you already created to the target node at scene.

Example based on v0.0.47 Seems like the angle of view is incorrect.

cx20 commented 5 years ago

@but0n Thanks to your advice I was able to try out the camera embedded in the Polly model. Ashes v0.0.47 + project_polly result

BTW, I tried the same thing with VC.gltf, but I could not find the camera. Is it because the camera name is not set? image

but0n commented 5 years ago

Actually, the value of data-name is related with the nodes[n].name, not the camera name.

If the target node doesn’t has a name, it could be difficult to query the entity of target, unless you specify a name by modifying the glTF file.

cx20 commented 5 years ago

I understand that I am using a node name instead of a camera name.

I tried several other WebGL libraries for reference. It seems that if you do not set the node name or the camera name, it is automatically assigned numbers.

Below is example of three.js.

three.js + Polly model result: image

thre.js + VC.gltf result: image

Below is example of Babylon.js.

Babylon.js + Polly model resultl: image

Babylon.js + VC.gltf result: image

but0n commented 5 years ago

That will be useful! I will add this feature in next version.

cx20 commented 5 years ago

I confirmed that Ashes v0.0.49 will display nodes with no names. image However, I do not know which node the camera is tied to, so I'm happy if there is a way to know.

but0n commented 5 years ago

Now you can query those cameras and set one of them as main camera:

image

// screen  = Ashes.Screen.list['#screen']
screen.mainCamera = Ashes.EntityMgr.getComponents('Camera')[2]

image

cx20 commented 5 years ago

@but0n Thank you for support of the camera. I modified the gltf-test sample so that I switch the camera at regular intervals.

Ashes + VC.gltf + camera sample

let cameras =  Ashes.EntityMgr.getComponents('Camera');
if ( cameras.length > 0 ) {
    setInterval(function(){
        let cameraIndex = Math.floor(cameras.length * Math.random());
        screen.mainCamera = cameras[cameraIndex];
    }, 5000);
}