threepipe
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

script.ts 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {
  2. _testFinish, _testStart,
  3. AmbientLight2,
  4. Box3B,
  5. IObject3D,
  6. LoadingScreenPlugin,
  7. Mesh,
  8. Object3DWidgetsPlugin,
  9. PhysicalMaterial,
  10. PlaneGeometry,
  11. ThreeViewer,
  12. Vector3,
  13. } from 'threepipe'
  14. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  15. async function init() {
  16. const viewer = new ThreeViewer({
  17. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  18. msaa: true,
  19. dropzone: {
  20. allowedExtensions: ['gltf', 'glb', 'hdr', 'obj', 'fbx', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr'],
  21. addOptions: {
  22. disposeSceneObjects: true,
  23. autoSetEnvironment: true, // when hdr/exr is dropped
  24. },
  25. },
  26. plugins: [Object3DWidgetsPlugin, LoadingScreenPlugin],
  27. })
  28. // viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 10))
  29. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/ShadowmappableMesh.glb', {
  30. autoCenter: true,
  31. autoScale: true,
  32. })
  33. const ground = new Mesh(
  34. new PlaneGeometry(100, 100)
  35. .rotateX(-Math.PI / 2)
  36. .translate(0, new Box3B().expandByObject(result!).getSize(new Vector3()).y / -2, 0),
  37. new PhysicalMaterial({
  38. color: '#ffffff',
  39. })
  40. )
  41. viewer.scene.addObject(ground)
  42. const light = viewer.scene.addObject(new AmbientLight2(0x00ff00, 5))
  43. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  44. ui.appendChild(light.uiConfig, {expanded: true})
  45. }
  46. _testStart()
  47. init().finally(_testFinish)