threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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