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 scene
import { useCamera, useScene } from '@zcomponent/three/lib/scenecontext';
// To get the renderer
import { useRenderer } from '@zcomponent/three/lib/context';
You can then create a variable and use these imports as so:
const scene = useScene(this.contextManager); // THREE.Scene
const renderer = useRenderer(this.contextManager) // THREE.Renderer
const 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 it
import { useCamera } from '@zcomponent/three/lib/scenecontext';
// ...
// Assign a variable to the camera; this is just a THREE.Camera
const 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 position
camera.lookAt(myContent.position);