threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

script.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {
  2. _testFinish,
  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. init().finally(_testFinish)