threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

iGeometryCommons.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {UiObjectConfig} from 'uiconfig.js'
  2. import {IGeometry, IGeometrySetDirtyOptions} from '../IGeometry'
  3. export const iGeometryCommons = {
  4. setDirty: function(this: IGeometry, options?: IGeometrySetDirtyOptions): void {
  5. this.dispatchEvent({bubbleToObject: true, ...options, type: 'geometryUpdate', geometry: this}) // this sets sceneUpdate in root scene
  6. this.refreshUi()
  7. },
  8. refreshUi: function(this: IGeometry) {
  9. this.uiConfig?.uiRefresh?.(true, 'postFrame', 1)
  10. },
  11. upgradeGeometry: upgradeGeometry,
  12. makeUiConfig: function(this: IGeometry): UiObjectConfig {
  13. if (this.uiConfig) return this.uiConfig
  14. return {
  15. label: 'Geometry',
  16. type: 'folder',
  17. children: [
  18. {
  19. type: 'input',
  20. property: [this, 'uuid'],
  21. disabled: true,
  22. },
  23. // {
  24. // type: 'input',
  25. // property: [this, 'name'],
  26. // },
  27. {
  28. type: 'button',
  29. label: 'Create uv2 from uv',
  30. value: () => {
  31. if (this.hasAttribute('uv2')) {
  32. if (!confirm('uv2 already exists, replace with uv data?')) return
  33. }
  34. this.setAttribute('uv2', this.getAttribute('uv'))
  35. },
  36. },
  37. {
  38. type: 'button',
  39. label: 'Remove vertex color attribute',
  40. hidden: () => !this.hasAttribute('color'),
  41. value: () => {
  42. if (!this.hasAttribute('color')) {
  43. prompt('No color attribute found')
  44. return
  45. }
  46. if (!confirm('Remove color attribute?')) return
  47. this.deleteAttribute('color')
  48. },
  49. },
  50. // {
  51. // type: 'button',
  52. // label: 'Invert eigen vectors',
  53. // value: () => {
  54. // console.log(geometry)
  55. // const offsets = geometry.userData.normalsCaptureOffsets
  56. // if (!offsets) return
  57. // const m = offsets.offsetMatrix as Matrix4
  58. // console.log(offsets.offsetMatrix.toArray())
  59. // console.log(m.determinant())
  60. //
  61. // const m1 = new Matrix4().makeRotationX(Math.PI / 2)
  62. // m.multiply(m1)
  63. //
  64. // console.log(m.determinant())
  65. // offsets.offsetMatrixInv.copy(m).invert()
  66. // console.log(offsets.offsetMatrix.toArray())
  67. // },
  68. // },
  69. {
  70. type: 'input',
  71. label: 'Mesh count',
  72. getValue: () => this.appliedMeshes?.size ?? 0,
  73. disabled: true,
  74. },
  75. ],
  76. }
  77. },
  78. }
  79. export function upgradeGeometry(this: IGeometry) {
  80. if (this.assetType === 'geometry') return // already upgraded
  81. if (!this.isBufferGeometry) {
  82. console.error('Material is not a this', this)
  83. return
  84. }
  85. this.assetType = 'geometry'
  86. if (!this.setDirty) this.setDirty = iGeometryCommons.setDirty
  87. if (!this.refreshUi) this.refreshUi = iGeometryCommons.refreshUi
  88. if (!this.appliedMeshes) this.appliedMeshes = new Set()
  89. if (!this.userData) this.userData = {}
  90. this.uiConfig = iGeometryCommons.makeUiConfig.call(this)
  91. // todo: dispose uiconfig on geometry dispose
  92. // todo: add serialization?
  93. }