Explorar el Código

Fix onChange in TransformControls2.

master
Palash Bansal hace 2 años
padre
commit
9d523e0f09
No account linked to committer's email address

+ 4
- 4
README.md Ver fichero



That's it! You should now see a 3D model on your page. That's it! You should now see a 3D model on your page.


The 3D model can be opened in the [editor](TODO) to view and edit the scene settings, objects, materials, lights, cameras, post-processing, etc. and exported as a GLB file. All settings are automatically serialized and saved in the GLB file, which can be loaded into the viewer. Any plugins used in the editor can be added to the viewer to add the same functionality. The plugin data is automatically loaded(if the plugin is added) when the model is added to the scene.
The 3D model can be opened in the [editor](https://threepipe.org/examples/tweakpane-editor/) to view and edit the scene settings, objects, materials, lights, cameras, post-processing, etc. and exported as a GLB file. All settings are automatically serialized and saved in the GLB file, which can be loaded into the viewer. Any plugins used in the editor can be added to the viewer to add the same functionality. The plugin data is automatically loaded(if the plugin is added) when the model is added to the scene.


The viewer initializes with a Scene, Camera, Camera controls(Orbit Controls), several importers, exporters and a default rendering pipeline. Additional functionality can be added with plugins. The viewer initializes with a Scene, Camera, Camera controls(Orbit Controls), several importers, exporters and a default rendering pipeline. Additional functionality can be added with plugins.


Check out the GLTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#gltf-load/ Check out the GLTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#gltf-load/


Check out the [Plugins](#plugins) section below to learn how to add additional functionality to the viewer.
Check out the [Plugins](#plugin-system) section below to learn how to add additional functionality to the viewer.


## License ## License
The core framework([src](https://github.com/repalash/threepipe/tree/master/src), [dist](https://github.com/repalash/threepipe/tree/master/dist), [examples](https://github.com/repalash/threepipe/tree/master/examples) folders) and any [plugins](https://github.com/repalash/threepipe/tree/master/plugins) without a separate license are under the Free [Apache 2.0 license](https://github.com/repalash/threepipe/tree/master/LICENSE). The core framework([src](https://github.com/repalash/threepipe/tree/master/src), [dist](https://github.com/repalash/threepipe/tree/master/dist), [examples](https://github.com/repalash/threepipe/tree/master/examples) folders) and any [plugins](https://github.com/repalash/threepipe/tree/master/plugins) without a separate license are under the Free [Apache 2.0 license](https://github.com/repalash/threepipe/tree/master/LICENSE).


TODO: add support to export unsigned byte textures as png, jpeg, webp TODO: add support to export unsigned byte textures as png, jpeg, webp


### Exporting Images
### Exporting Images/Textures


Exporting Textures as Images with image of types ImageBitmap, HTMLImageElement, Exporting Textures as Images with image of types ImageBitmap, HTMLImageElement,
HTMLOrSVGImageElement, CanvasImageSource, HTMLCanvasElement, HTMLOrSVGImageElement, CanvasImageSource, HTMLCanvasElement,


When the plugin is added to the viewer, it interfaces with the [PickingPlugin](#pickingplugin) and shows the control gizmos when an object is selected and hides them when the object is unselected. When the plugin is added to the viewer, it interfaces with the [PickingPlugin](#pickingplugin) and shows the control gizmos when an object is selected and hides them when the object is unselected.


If the PickingPlugin is not added to the viewer before the TransformControlsPlugin, it is added automatically with the plugin.
If the `PickingPlugin` is not added to the viewer before the `TransformControlsPlugin`, it is added automatically with the plugin.


```typescript ```typescript
import {ThreeViewer, TransformControlsPlugin} from 'threepipe' import {ThreeViewer, TransformControlsPlugin} from 'threepipe'

+ 1
- 1
src/plugins/interaction/TransformControlsPlugin.ts Ver fichero



dependencies = [PickingPlugin] dependencies = [PickingPlugin]


@uiConfig()
@uiConfig(undefined, {expanded: true})
transformControls: TransformControls2 | undefined transformControls: TransformControls2 | undefined


protected _isInteracting = false protected _isInteracting = false

+ 9
- 12
src/three/controls/TransformControls2.ts Ver fichero

import {MathUtils} from 'three' import {MathUtils} from 'three'
import type {ICamera, IObject3D, ISceneEvent, IWidget} from '../../core' import type {ICamera, IObject3D, ISceneEvent, IWidget} from '../../core'
import {iObjectCommons} from '../../core' import {iObjectCommons} from '../../core'
import {uiDropdown, uiNumber, uiPanelContainer, uiToggle} from 'uiconfig.js'
import {onChange2} from 'ts-browser-helpers'
import {uiDropdown, uiFolderContainer, uiSlider, uiToggle} from 'uiconfig.js'


@uiPanelContainer('Transform Controls')
@uiFolderContainer('Transform Controls')
export class TransformControls2 extends TransformControls implements IWidget, IObject3D { export class TransformControls2 extends TransformControls implements IWidget, IObject3D {
isWidget = true as const isWidget = true as const
assetType = 'widget' as const assetType = 'widget' as const
setDirty = iObjectCommons.setDirty
setDirty = iObjectCommons.setDirty.bind(this)
refreshUi = iObjectCommons.refreshUi.bind(this) refreshUi = iObjectCommons.refreshUi.bind(this)


object: IObject3D | undefined object: IObject3D | undefined
this?.object?.setDirty({fadeFrame: false}) this?.object?.setDirty({fadeFrame: false})
// todo: do this.setDirty? // todo: do this.setDirty?
}) })
this.addEventListener('change', () => {
this.setDirty({fadeFrame: false})
})


this._keyUpListener = this._keyUpListener.bind(this) this._keyUpListener = this._keyUpListener.bind(this)
this._keyDownListener = this._keyDownListener.bind(this) this._keyDownListener = this._keyDownListener.bind(this)


// axis: 'X' | 'Y' | 'Z' | 'E' | 'XY' | 'YZ' | 'XZ' | 'XYZ' | 'XYZE' | null // axis: 'X' | 'Y' | 'Z' | 'E' | 'XY' | 'YZ' | 'XZ' | 'XYZ' | 'XYZE' | null


// onChange not required for before since they fire 'change' event on changed. see TransformControls.js

@uiDropdown('Mode', ['translate', 'rotate', 'scale'].map(label=>({label}))) @uiDropdown('Mode', ['translate', 'rotate', 'scale'].map(label=>({label})))
@onChange2('setDirty')
mode: 'translate' | 'rotate' | 'scale' mode: 'translate' | 'rotate' | 'scale'


translationSnap: number | null translationSnap: number | null
scaleSnap: number | null scaleSnap: number | null


@uiDropdown('Space', ['world', 'local'].map(label=>({label}))) @uiDropdown('Space', ['world', 'local'].map(label=>({label})))
@onChange2('setDirty')
space: 'world' | 'local' space: 'world' | 'local'
@uiNumber('Size')
@onChange2('setDirty')
@uiSlider('Size', [0.1, 10], 0.1)
size: number size: number
@uiToggle('Show X') @uiToggle('Show X')
@onChange2('setDirty')
showX: boolean showX: boolean
@uiToggle('Show Y') @uiToggle('Show Y')
@onChange2('setDirty')
showY: boolean showY: boolean
@uiToggle('Show Z') @uiToggle('Show Z')
@onChange2('setDirty')
showZ: boolean showZ: boolean


// dragging: boolean // dragging: boolean
// endregion // endregion





/** /**
* Get the threejs object * Get the threejs object
* @deprecated * @deprecated

Cargando…
Cancelar
Guardar