Get the active camera, renderer, and scene
Whilst developing with Mattercraft, you may need to get the active camera, renderer or scene.
To do so, you must first import the relevant component(s) using the following code:
// To get the camera and/or sceneimport { useCamera, useScene } from '@zcomponent/three/lib/scenecontext';
// To get the rendererimport { useRenderer } from '@zcomponent/three/lib/context';
You can then create a variable and use these imports as so:
const scene = useScene(this.contextManager); // THREE.Sceneconst renderer = useRenderer(this.contextManager) // THREE.Rendererconst camera = useCamera(this.contextManager).value; // THREE.Camera
You may then use the scene, renderer and camera as you may ordinarily in a three.js workflow.
Example usage
// Make sure to import the camera before we fetch itimport { useCamera } from '@zcomponent/three/lib/scenecontext';
// ...
// Assign a variable to the camera; this is just a THREE.Cameraconst camera = useCamera(this.contextManager).value;
// Add content...
// Makes the camera face a point in world space; in this case,// directly at the specified content's positioncamera.lookAt(myContent.position);