threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Object3DGeneratorPlugin.md 2.5KB

před 1 rokem
před 1 rokem
před 1 rokem
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ---
  2. prev:
  3. text: 'Object3DWidgetsPlugin'
  4. link: './Object3DWidgetsPlugin'
  5. next:
  6. text: 'DeviceOrientationControlsPlugin'
  7. link: './DeviceOrientationControlsPlugin'
  8. ---
  9. # Object3DGeneratorPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#object3d-generator-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/extras/Object3DGeneratorPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/Object3DGeneratorPlugin.html)
  14. Object3DGeneratorPlugin adds support for creating different types of lights and camera objects in the viewer.
  15. Call the `generate` method with any type to generate a type of object(like lights, cameras, mesh etc.).
  16. Support for the following types of generators is included in the plugin:
  17. * camera-perspective - Creates instance of `PerspectiveCamera2`
  18. * light-directional - Creates instance of `DirectionalLight2`
  19. * light-ambient - Creates instance of `AmbientLight2`
  20. * light-point - Creates instance of `PointLight2`
  21. * light-spot - Creates instance of `SpotLight2`
  22. * light-hemisphere - Creates instance of `HemisphereLight2`
  23. * light-rect-area - Creates instance of `RectAreaLight2`
  24. Additional types of generators can be added dynamically or by other plugins by adding a custom generator function to the `Object3DGeneratorPlugin.generators` object. This is done by [GeometryGeneratorPlugin](../package/plugin-geometry-generator) to add various type of primitive objects like plane, sphere, etc.
  25. A custom generator can take in any kind object as parameters and should return an `IObject3D`.
  26. Sample Usage
  27. ```typescript
  28. import {ThreeViewer, Object3DWidgetsPlugin, Object3DGeneratorPlugin, Mesh2} from 'threepipe'
  29. const viewer = new ThreeViewer({...})
  30. const generator = viewer.addPluginSync(Object3DGeneratorPlugin)
  31. generator.generate('camera-perspective', {
  32. position: new Vector3(5, 5, 0),
  33. name: 'My Camera'
  34. })
  35. const light = generator.generate('light-spot', {
  36. position: new Vector3(5, 0, 0),
  37. })
  38. // to add support for a custom helper
  39. plugin.generators['custom-object'] = (params)=>{
  40. const object = new Mesh2(new PlaneGeometry(1,1), new PhysicalMaterial())
  41. object.name = params.name ?? 'Custom Mesh'
  42. if(params.position) object.position.copy(params.position)
  43. return object
  44. }
  45. const obj = generator.generate('custom-object', {
  46. position: new Vector3(5, 0, 0),
  47. })
  48. // Add Object3DWidgetsPlugin to see the added lights and cameras.
  49. viewer.addPluginSync(new Object3DWidgetsPlugin())
  50. ```
  51. Check the [example](https://threepipe.org/examples/#object3d-generator-plugin/) for the UI.