forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSidebar.Geometry.Modifiers.js
73 lines (42 loc) · 1.82 KB
/
Sidebar.Geometry.Modifiers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { UIDiv, UIButton, UIRow } from './libs/ui.js';
import { computeMikkTSpaceTangents } from 'three/addons/utils/BufferGeometryUtils.js';
import * as MikkTSpace from 'three/addons/libs/mikktspace.module.js';
function SidebarGeometryModifiers( editor, object ) {
const strings = editor.strings;
const signals = editor.signals;
const container = new UIDiv().setMarginLeft( '120px' );
const geometry = object.geometry;
// Compute Vertex Normals
const computeVertexNormalsButton = new UIButton( strings.getKey( 'sidebar/geometry/compute_vertex_normals' ) );
computeVertexNormalsButton.onClick( function () {
geometry.computeVertexNormals();
signals.geometryChanged.dispatch( object );
} );
const computeVertexNormalsRow = new UIRow();
computeVertexNormalsRow.add( computeVertexNormalsButton );
container.add( computeVertexNormalsRow );
// Compute Vertex Tangents
if ( geometry.hasAttribute( 'position' ) && geometry.hasAttribute( 'normal' ) && geometry.hasAttribute( 'uv' ) ) {
const computeVertexTangentsButton = new UIButton( strings.getKey( 'sidebar/geometry/compute_vertex_tangents' ) );
computeVertexTangentsButton.onClick( async function () {
await MikkTSpace.ready;
computeMikkTSpaceTangents( geometry, MikkTSpace );
signals.geometryChanged.dispatch( object );
} );
const computeVertexTangentsRow = new UIRow();
computeVertexTangentsRow.add( computeVertexTangentsButton );
container.add( computeVertexTangentsRow );
}
// Center Geometry
const centerButton = new UIButton( strings.getKey( 'sidebar/geometry/center' ) );
centerButton.onClick( function () {
geometry.center();
signals.geometryChanged.dispatch( object );
} );
const centerRow = new UIRow();
centerRow.add( centerButton );
container.add( centerRow );
//
return container;
}
export { SidebarGeometryModifiers };