Skip to content

Commit 1b8412c

Browse files
authored
Editor: Add compute tangents option. (#27461)
1 parent c337d03 commit 1b8412c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

editor/js/Sidebar.Geometry.Modifiers.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { UIDiv, UIButton, UIRow } from './libs/ui.js';
22

3+
import { computeMikkTSpaceTangents } from 'three/addons/utils/BufferGeometryUtils.js';
4+
import * as MikkTSpace from 'three/addons/libs/mikktspace.module.js';
5+
36
function SidebarGeometryModifiers( editor, object ) {
47

58
const strings = editor.strings;
@@ -25,6 +28,26 @@ function SidebarGeometryModifiers( editor, object ) {
2528
computeVertexNormalsRow.add( computeVertexNormalsButton );
2629
container.add( computeVertexNormalsRow );
2730

31+
// Compute Vertex Tangents
32+
33+
if ( geometry.hasAttribute( 'position' ) && geometry.hasAttribute( 'normal' ) && geometry.hasAttribute( 'uv' ) ) {
34+
35+
const computeVertexTangentsButton = new UIButton( strings.getKey( 'sidebar/geometry/compute_vertex_tangents' ) );
36+
computeVertexTangentsButton.onClick( async function () {
37+
38+
await MikkTSpace.ready;
39+
40+
computeMikkTSpaceTangents( geometry, MikkTSpace );
41+
42+
signals.geometryChanged.dispatch( object );
43+
44+
} );
45+
46+
const computeVertexTangentsRow = new UIRow();
47+
computeVertexTangentsRow.add( computeVertexTangentsButton );
48+
container.add( computeVertexTangentsRow );
49+
50+
}
2851

2952
// Center Geometry
3053

editor/js/Strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function Strings( config ) {
133133
'sidebar/geometry/bounds': 'Bounds',
134134
'sidebar/geometry/show_vertex_normals': 'Show Vertex Normals',
135135
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
136+
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
136137
'sidebar/geometry/center': 'Center',
137138

138139
'sidebar/geometry/box_geometry/width': 'Width',
@@ -483,6 +484,7 @@ function Strings( config ) {
483484
'sidebar/geometry/bounds': 'Limites',
484485
'sidebar/geometry/show_vertex_normals': 'Afficher normales',
485486
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
487+
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
486488
'sidebar/geometry/center': 'Center',
487489

488490
'sidebar/geometry/box_geometry/width': 'Largeur',
@@ -831,6 +833,7 @@ function Strings( config ) {
831833
'sidebar/geometry/bounds': '界限',
832834
'sidebar/geometry/show_vertex_normals': '显示顶点法线',
833835
'sidebar/geometry/compute_vertex_normals': '计算顶点法线',
836+
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
834837
'sidebar/geometry/center': '居中',
835838

836839
'sidebar/geometry/box_geometry/width': '宽度',

editor/sw.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const assets = [
2626

2727
'../examples/jsm/libs/meshopt_decoder.module.js',
2828

29+
'../examples/jsm/libs/mikktspace.module.js',
30+
2931
'../examples/jsm/libs/motion-controllers.module.js',
3032

3133
'../examples/jsm/libs/rhino3dm/rhino3dm.wasm',
@@ -73,6 +75,8 @@ const assets = [
7375

7476
'../examples/jsm/helpers/VertexNormalsHelper.js',
7577

78+
'../examples/jsm/utils/BufferGeometryUtils.js',
79+
7680
'../examples/jsm/webxr/VRButton.js',
7781
'../examples/jsm/webxr/XRControllerModelFactory.js',
7882

0 commit comments

Comments
 (0)