UNPKG

threepipe

Version:

A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.

36 lines (35 loc) 1.57 kB
import { _testFinish, LoadingScreenPlugin, PickingPlugin, SSAAPlugin, ThreeViewer, Vector3, } from 'threepipe'; import { TweakpaneUiPlugin } from '@threepipe/plugin-tweakpane'; // @ts-expect-error todo fix import { BloomPlugin, DepthOfFieldPlugin } from '@threepipe/webgi-plugins'; async function init() { const viewer = new ThreeViewer({ canvas: document.getElementById('mcanvas'), msaa: true, // rgbm: false, plugins: [LoadingScreenPlugin, SSAAPlugin, BloomPlugin, PickingPlugin], }); const dofPlugin = viewer.addPluginSync(DepthOfFieldPlugin); const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true)); await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', { setBackground: true, }); const result = await viewer.load('https://threejs.org/examples/models/gltf/kira.glb', { autoCenter: true, autoScale: true, autoScaleRadius: 15, }); const model = result?.getObjectByName('node_damagedHelmet_-6514'); const materials = (model?.materials || []); ui.setupPluginUi(dofPlugin); for (const material of materials) { ui.appendChild(material.uiConfig); } const target = new Vector3(3.8885332252383376, -1.7116614197503317, 5.3296364320040475); dofPlugin.setFocalPoint(target, false, true); dofPlugin.enableEdit = true; viewer.scene.mainCamera.target.copy(target); viewer.scene.mainCamera.position.set(0, 0, -5); viewer.scene.mainCamera.setDirty(); } init().then(_testFinish);