threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ---
  2. prev:
  3. text: 'Material Extension'
  4. link: './material-extension'
  5. next:
  6. text: 'Serialization'
  7. link: './serialization'
  8. ---
  9. # UI Configuration
  10. Almost all the classes and plugins in Threepipe include [uiconfig.js](https://repalash.com/uiconfig.js/) support and can be used to create configuration UIs, 3d configurators and even full-editors.
  11. The UIs are automatically generated based on the configuration object under `.uiConfig` property on all objects. These are of type [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html).
  12. In some classes, the ui configs are also generated using typescript decorators.
  13. The `uiConfig` is also added to all three.js objects and materials when they are added to the scene.
  14. The UIs can be generated at runtime using any of the UI plugins like [TweakpaneUIPlugin](../package/plugin-tweakpane), [BlueprintJsUiPlugin](../package/plugin-blueprintjs)
  15. An example showing how to create a UI for a material
  16. ```typescript
  17. const ui = viewer.addPluginSync(TweakpaneUiPlugin)
  18. const object = viewer.scene.getObjectByName('objectName');
  19. const material = object.material as PhysicalMaterial;
  20. ui.appendChild(material.uiConfig)
  21. ```
  22. See it in action: https://threepipe.org/examples/#material-uiconfig/
  23. Check more examples showing [Viewer UI](https://threepipe.org/examples/#viewer-uiconfig/), [Scene UI](https://threepipe.org/examples/#scene-uiconfig/), [Object UI](https://threepipe.org/examples/#object-uiconfig/), [Camera UI](https://threepipe.org/examples/#camera-uiconfig/)
  24. ::: info
  25. [TweakpaneEditorPlugin](../package/plugin-tweakpane-editor) further uses the Tweakpane configuration panel along with various plugins to create a 3d editor.
  26. :::
  27. Custom UI configuration can be created to generate custom UI for the editor or tweaking.
  28. This can be done by using typescript decorators or defining the UI in javascript as a [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html) object.
  29. Here is a sample of extending the orbit controls class with decorators to automatically generate UI.
  30. ```typescript
  31. @uiPanelContainer('Orbit Controls')
  32. export class OrbitControlsWithUi extends OrbitControls implements IUiConfigContainer {
  33. // for autocomplete
  34. uiConfig?: UiObjectConfig<void, 'panel'>
  35. @uiToggle() enabled = true
  36. @uiToggle() dollyZoom = false
  37. @uiToggle() enableDamping = true
  38. @uiInput() dampingFactor = 0.08
  39. @uiToggle() autoRotate = false
  40. @uiInput() autoRotateSpeed = 2.0
  41. @uiToggle() enableZoom = true
  42. @uiInput() zoomSpeed = 0.15
  43. @uiInput() maxZoomSpeed = 0.20
  44. @uiToggle() enableRotate = true
  45. @uiInput() rotateSpeed = 2.0
  46. @uiToggle() enablePan = true
  47. @uiInput() panSpeed = 1.0
  48. @uiInput() autoPushTarget = false
  49. @uiInput() autoPullTarget = false
  50. @uiInput() minDistance = 0.35
  51. @uiInput() maxDistance = 1000
  52. @uiInput() minZoom = 0.01
  53. @uiInput() maxZoom = 1000
  54. @uiInput() minPolarAngle = 0
  55. @uiInput() maxPolarAngle = Math.PI
  56. @uiInput() minAzimuthAngle = -10000 // should be -Infinity but this breaks the UI
  57. @uiInput() maxAzimuthAngle = 10000
  58. }
  59. ```
  60. Check out the full source code:
  61. [./src/three/controls/OrbitControls3.ts](https://github.com/repalash/threepipe/blob/master/src/three/controls/OrbitControls3.ts) for proper implementation
  62. See it in action: https://threepipe.org/examples/#camera-uiconfig/ Open the Camera UI and click on the Orbit Controls panel.
  63. There are many available decorators like `uiToggle`, `uiSlider`, `uiInput`, `uiNumber`, `uiColor`, `uiImage`.
  64. Check the complete list in the [uiconfig.js documentation](https://repalash.com/uiconfig.js/).
  65. The UI configuration can also be created using json objects in both typescript and javascript
  66. ```javascript
  67. const viewer = new ThreeViewer({...})
  68. const ui = viewer.addPluginSync(TweakpaneUiPlugin)
  69. const state = {
  70. position: new Vector3(),
  71. scale: 1,
  72. }
  73. ui.appendChild({
  74. type: 'folder',
  75. label: 'Custom UI',
  76. children: [
  77. {
  78. type: 'vec3',
  79. label: 'Position',
  80. property: [state, 'position']
  81. },
  82. {
  83. type: 'slider',
  84. label: ()=>'Scale', // everything can be a function as well.
  85. property: [state, 'scale'],
  86. bounds: [1, 2],
  87. stepSize: 0.1,
  88. }
  89. ]
  90. })
  91. ```
  92. [//]: # (TODO: create example/codepen for this)