To initialize a basic 3D scene, you need to instantiate the OBC.Components manager, create a World via the Worlds component, and then define the scene, renderer, and camera. Finally, call components.init() to activate the system.
This example demonstrates creating a navigable 3D scene containing a single cube.
import * as THREE from "three";
import * as OBC from "@thatopen/components"; // Note: Import path depends on your setup
const container = document.getElementById("container")!;
// 1. Initialize the main components manager
const components = new OBC.Components();
// 2. Access the Worlds component to manage 3D environments
const worlds = components.get(OBC.Worlds);
// 3. Create a new world with specific implementations for Scene, Camera, and Renderer
const world = worlds.create<
OBC.SimpleScene,
OBC.SimpleCamera,
OBC.SimpleRenderer
>();
// 4. Assign the implementations to the world
world.scene = new OBC.SimpleScene(components);
world.renderer = new OBC.SimpleRenderer(components, container);
world.camera = new OBC.SimpleCamera(components);
// 5. Initialize the components system
components.init();
// 6. Add content to the scene using standard Three.js objects
const material = new THREE.MeshLambertMaterial({ color: "#6528D7" });
const geometry = new THREE.BoxGeometry();
const cube = new THREE.Mesh(geometry, material);
world.scene.three.add(cube);
// 7. Finalize scene setup
world.scene.setup();
// 8. Configure camera view
world.camera.controls.setLookAt(3, 3, 3, 0, 0, 0);