1+ import type { Node } from "../rendering/types/node" ;
2+
13export class Inspector {
24 private container : HTMLElement ;
3- public current_node : any | null = null ;
5+ public current_node : Node | null = null ;
46
57 private move_speed = 0.5 ;
68 private rot_speed = 0.26 ;
@@ -14,7 +16,7 @@ export class Inspector {
1416 this . setup_keyboard_controls ( ) ;
1517 }
1618
17- public inspect ( node : any | null ) {
19+ public inspect ( node : Node | null ) {
1820 this . current_node = node ;
1921 this . container . innerHTML = "" ;
2022
@@ -23,40 +25,58 @@ export class Inspector {
2325 return ;
2426 }
2527
26- this . container . innerHTML = `<h3>Action Inspector</h3>` ;
27- this . container . innerHTML += `<p style="font-size: 12px; color: gray;">WASD to move X/Z. Q/E to move Y.</p>` ;
28-
29- this . create_action_row ( "Move X" ,
28+ const h3 = document . createElement ( "h3" ) ;
29+ const title_font = document . createElement ( "font" ) ;
30+ title_font . setAttribute ( "face" , "Arial" ) ;
31+ title_font . innerText = "Action Inspector" ;
32+ h3 . appendChild ( title_font ) ;
33+ this . container . appendChild ( h3 ) ;
34+
35+ const hint = document . createElement ( "font" ) ;
36+ hint . setAttribute ( "size" , "2" ) ;
37+ hint . setAttribute ( "color" , "gray" ) ;
38+ hint . setAttribute ( "face" , "Arial" ) ;
39+ hint . innerText = "WASD to move X/Z. Q/E to move Y." ;
40+ this . container . appendChild ( hint ) ;
41+
42+ this . container . appendChild ( document . createElement ( "br" ) ) ;
43+ this . container . appendChild ( document . createElement ( "br" ) ) ;
44+
45+ const table = document . createElement ( "table" ) ;
46+ table . setAttribute ( "border" , "0" ) ;
47+ table . setAttribute ( "cellpadding" , "2" ) ;
48+ this . container . appendChild ( table ) ;
49+ this . create_action_row ( table , "Move X" ,
3050 ( ) => { node . position [ 0 ] -= this . move_speed ; node . update_matrix ( ) ; } ,
3151 ( ) => { node . position [ 0 ] += this . move_speed ; node . update_matrix ( ) ; }
3252 ) ;
33- this . create_action_row ( "Move Y" ,
53+ this . create_action_row ( table , "Move Y" ,
3454 ( ) => { node . position [ 1 ] -= this . move_speed ; node . update_matrix ( ) ; } ,
3555 ( ) => { node . position [ 1 ] += this . move_speed ; node . update_matrix ( ) ; }
3656 ) ;
37- this . create_action_row ( "Move Z" ,
57+ this . create_action_row ( table , "Move Z" ,
3858 ( ) => { node . position [ 2 ] -= this . move_speed ; node . update_matrix ( ) ; } ,
3959 ( ) => { node . position [ 2 ] += this . move_speed ; node . update_matrix ( ) ; }
4060 ) ;
4161
42- this . container . appendChild ( document . createElement ( "hr" ) ) ;
62+ this . add_divider ( table ) ;
4363
44- this . create_action_row ( "Rotate X" ,
64+ this . create_action_row ( table , "Rotate X" ,
4565 ( ) => { node . rotation [ 0 ] -= this . rot_speed ; node . update_matrix ( ) ; } ,
4666 ( ) => { node . rotation [ 0 ] += this . rot_speed ; node . update_matrix ( ) ; }
4767 ) ;
48- this . create_action_row ( "Rotate Y" ,
68+ this . create_action_row ( table , "Rotate Y" ,
4969 ( ) => { node . rotation [ 1 ] -= this . rot_speed ; node . update_matrix ( ) ; } ,
5070 ( ) => { node . rotation [ 1 ] += this . rot_speed ; node . update_matrix ( ) ; }
5171 ) ;
52- this . create_action_row ( "Rotate Z" ,
72+ this . create_action_row ( table , "Rotate Z" ,
5373 ( ) => { node . rotation [ 2 ] -= this . rot_speed ; node . update_matrix ( ) ; } ,
5474 ( ) => { node . rotation [ 2 ] += this . rot_speed ; node . update_matrix ( ) ; }
5575 ) ;
5676
57- this . container . appendChild ( document . createElement ( "hr" ) ) ;
77+ this . add_divider ( table ) ;
5878
59- this . create_action_row ( "Scale" ,
79+ this . create_action_row ( table , "Scale" ,
6080 ( ) => {
6181 node . scale_vec [ 0 ] -= this . scale_factor ;
6282 node . scale_vec [ 1 ] -= this . scale_factor ;
@@ -70,35 +90,85 @@ export class Inspector {
7090 node . update_matrix ( ) ;
7191 }
7292 ) ;
93+
94+ this . add_divider ( table ) ;
95+
96+ if ( node . mesh && node . mesh . albedo ) {
97+ this . create_color_row ( table , "Color" , node . mesh . albedo ) ;
98+ }
7399 }
74100
75101 private clear ( ) {
76- this . container . innerHTML = `<p style="color: gray;" >Select an object to inspect.</p >` ;
102+ this . container . innerHTML = `<font color=" gray" face="Arial" >Select an object to inspect.</font >` ;
77103 }
78104
79- private create_action_row ( label : string , on_minus : ( ) => void , on_plus : ( ) => void ) {
80- const wrapper = document . createElement ( "div" ) ;
81- wrapper . style . marginBottom = "8px" ;
82-
83- const label_el = document . createElement ( "span" ) ;
84- label_el . innerText = `${ label } : ` ;
85- label_el . style . display = "inline-block" ;
86- label_el . style . width = "70px" ;
105+ private add_divider ( table : HTMLElement ) {
106+ const tr = document . createElement ( "tr" ) ;
107+ const td = document . createElement ( "td" ) ;
108+ td . setAttribute ( "colspan" , "3" ) ;
109+ td . appendChild ( document . createElement ( "hr" ) ) ;
110+ tr . appendChild ( td ) ;
111+ table . appendChild ( tr ) ;
112+ }
113+
114+ private create_action_row ( table : HTMLElement , label : string , on_minus : ( ) => void , on_plus : ( ) => void ) {
115+ const tr = document . createElement ( "tr" ) ;
87116
117+ const td_label = document . createElement ( "td" ) ;
118+ const font = document . createElement ( "font" ) ;
119+ font . setAttribute ( "face" , "Arial" ) ;
120+ font . innerText = `${ label } : ` ;
121+ td_label . appendChild ( font ) ;
122+
123+ const td_minus = document . createElement ( "td" ) ;
88124 const btn_minus = document . createElement ( "button" ) ;
89125 btn_minus . innerText = " - " ;
90- btn_minus . style . width = "30px" ;
91126 btn_minus . onclick = on_minus ;
127+ td_minus . appendChild ( btn_minus ) ;
92128
129+ const td_plus = document . createElement ( "td" ) ;
93130 const btn_plus = document . createElement ( "button" ) ;
94131 btn_plus . innerText = " + " ;
95- btn_plus . style . width = "30px" ;
96132 btn_plus . onclick = on_plus ;
133+ td_plus . appendChild ( btn_plus ) ;
134+
135+ tr . appendChild ( td_label ) ;
136+ tr . appendChild ( td_minus ) ;
137+ tr . appendChild ( td_plus ) ;
138+ table . appendChild ( tr ) ;
139+ }
140+
141+ private create_color_row ( table : HTMLElement , label : string , color_vec : Float32Array | number [ ] ) {
142+ const tr = document . createElement ( "tr" ) ;
143+
144+ const td_label = document . createElement ( "td" ) ;
145+ const font = document . createElement ( "font" ) ;
146+ font . setAttribute ( "face" , "Arial" ) ;
147+ font . innerText = `${ label } : ` ;
148+ td_label . appendChild ( font ) ;
149+
150+ const td_input = document . createElement ( "td" ) ;
151+ td_input . setAttribute ( "colspan" , "2" ) ;
152+
153+ const color_picker = document . createElement ( "input" ) ;
154+ color_picker . type = "color" ;
155+
156+ const r = Math . max ( 0 , Math . min ( 255 , Math . round ( color_vec [ 0 ] * 255 ) ) ) . toString ( 16 ) . padStart ( 2 , '0' ) ;
157+ const g = Math . max ( 0 , Math . min ( 255 , Math . round ( color_vec [ 1 ] * 255 ) ) ) . toString ( 16 ) . padStart ( 2 , '0' ) ;
158+ const b = Math . max ( 0 , Math . min ( 255 , Math . round ( color_vec [ 2 ] * 255 ) ) ) . toString ( 16 ) . padStart ( 2 , '0' ) ;
159+ color_picker . value = `#${ r } ${ g } ${ b } ` ;
160+
161+ color_picker . addEventListener ( "input" , ( e ) => {
162+ const hex = ( e . target as HTMLInputElement ) . value ;
163+ color_vec [ 0 ] = parseInt ( hex . substring ( 1 , 3 ) , 16 ) / 255.0 ;
164+ color_vec [ 1 ] = parseInt ( hex . substring ( 3 , 5 ) , 16 ) / 255.0 ;
165+ color_vec [ 2 ] = parseInt ( hex . substring ( 5 , 7 ) , 16 ) / 255.0 ;
166+ } ) ;
97167
98- wrapper . appendChild ( label_el ) ;
99- wrapper . appendChild ( btn_minus ) ;
100- wrapper . appendChild ( btn_plus ) ;
101- this . container . appendChild ( wrapper ) ;
168+ td_input . appendChild ( color_picker ) ;
169+ tr . appendChild ( td_label ) ;
170+ tr . appendChild ( td_input ) ;
171+ table . appendChild ( tr ) ;
102172 }
103173
104174 private setup_keyboard_controls ( ) {
0 commit comments