@@ -28,6 +28,11 @@ const DirectionalLightNode: React.FC<{ color: Color; intensity: number }> = ({ c
2828 return < directionalLight ref = { ref } color = { color } intensity = { intensity } /> ;
2929} ;
3030
31+ const DirectionalLightBare : React . FC < { color : Color ; intensity : number } > = ( { color, intensity } ) => {
32+ const ref = useRef < DirectionalLight > ( null ! ) ;
33+ return < directionalLight ref = { ref } color = { color } intensity = { intensity } /> ;
34+ } ;
35+
3136const SpotLightNode : React . FC < {
3237 color : Color ;
3338 intensity : number ;
@@ -44,6 +49,20 @@ const SpotLightNode: React.FC<{
4449 ) ;
4550} ;
4651
52+ const SpotLightBare : React . FC < {
53+ color : Color ;
54+ intensity : number ;
55+ distance : number ;
56+ angle : number ;
57+ penumbra : number ;
58+ decay : number ;
59+ } > = ( { color, intensity, distance, angle, penumbra, decay } ) => {
60+ const ref = useRef < SpotLight > ( null ! ) ;
61+ return (
62+ < spotLight ref = { ref } color = { color } intensity = { intensity } distance = { distance } angle = { angle } penumbra = { penumbra } decay = { decay } />
63+ ) ;
64+ } ;
65+
4766const PointLightNode : React . FC < { color : Color ; intensity : number ; distance : number ; decay : number } >
4867 = ( { color, intensity, distance, decay } ) => {
4968 const ref = useRef < PointLight > ( null ! ) ;
@@ -52,6 +71,12 @@ const PointLightNode: React.FC<{ color: Color; intensity: number; distance: numb
5271 return < pointLight ref = { ref } color = { color } intensity = { intensity } distance = { distance } decay = { decay } /> ;
5372 } ;
5473
74+ const PointLightBare : React . FC < { color : Color ; intensity : number ; distance : number ; decay : number } >
75+ = ( { color, intensity, distance, decay } ) => {
76+ const ref = useRef < PointLight > ( null ! ) ;
77+ return < pointLight ref = { ref } color = { color } intensity = { intensity } distance = { distance } decay = { decay } /> ;
78+ } ;
79+
5580const RectAreaLightNode : React . FC < { color : Color ; intensity : number ; width : number ; height : number } >
5681 = ( { color, intensity, width, height } ) => {
5782 const ref = useRef < RectAreaLight > ( null ! ) ;
@@ -60,6 +85,12 @@ const RectAreaLightNode: React.FC<{ color: Color; intensity: number; width: numb
6085 return < rectAreaLight ref = { ref } color = { color } intensity = { intensity } width = { width } height = { height } /> ;
6186 } ;
6287
88+ const RectAreaLightBare : React . FC < { color : Color ; intensity : number ; width : number ; height : number } >
89+ = ( { color, intensity, width, height } ) => {
90+ const ref = useRef < RectAreaLight > ( null ! ) ;
91+ return < rectAreaLight ref = { ref } color = { color } intensity = { intensity } width = { width } height = { height } /> ;
92+ } ;
93+
6394// Camera helper wrappers
6495const PerspectiveCameraNode : React . FC < { fov : number ; near : number ; far : number } >
6596 = ( { fov, near, far } ) => {
@@ -69,6 +100,12 @@ const PerspectiveCameraNode: React.FC<{ fov: number; near: number; far: number }
69100 return < perspectiveCamera ref = { ref } fov = { fov } near = { near } far = { far } /> ;
70101 } ;
71102
103+ const PerspectiveCameraBare : React . FC < { fov : number ; near : number ; far : number } >
104+ = ( { fov, near, far } ) => {
105+ const ref = useRef < PerspectiveCamera > ( null ! ) ;
106+ return < perspectiveCamera ref = { ref } fov = { fov } near = { near } far = { far } /> ;
107+ } ;
108+
72109const OrthographicCameraNode : React . FC < { left : number ; right : number ; top : number ; bottom : number ; near : number ; far : number } >
73110 = ( { left, right, top, bottom, near, far } ) => {
74111 const ref = useRef < OrthographicCamera > ( null ! ) ;
@@ -77,6 +114,12 @@ const OrthographicCameraNode: React.FC<{ left: number; right: number; top: numbe
77114 return < orthographicCamera ref = { ref } left = { left } right = { right } top = { top } bottom = { bottom } near = { near } far = { far } /> ;
78115 } ;
79116
117+ const OrthographicCameraBare : React . FC < { left : number ; right : number ; top : number ; bottom : number ; near : number ; far : number } >
118+ = ( { left, right, top, bottom, near, far } ) => {
119+ const ref = useRef < OrthographicCamera > ( null ! ) ;
120+ return < orthographicCamera ref = { ref } left = { left } right = { right } top = { top } bottom = { bottom } near = { near } far = { far } /> ;
121+ } ;
122+
80123
81124type Props = { objectId : string } ;
82125
@@ -105,63 +148,87 @@ const ObjectNode: React.FC<Props> = ({ objectId }) => {
105148 scale = { [ t . scale . x , t . scale . y , t . scale . z ] }
106149 visible = { obj . visible }
107150 >
108- { obj . type === 'mesh' && < MeshView objectId = { objectId } noTransform /> }
151+ { obj . type === 'mesh' && < MeshView objectId = { objectId } noTransform /> }
109152 { obj . type === 'light' && obj . lightId && ( ( ) => {
110153 const light = scene . lights [ obj . lightId ! ] ;
111154 if ( ! light ) return null ;
112155 const color = new Color ( light . color . x , light . color . y , light . color . z ) ;
113- const active = shading === 'material' ;
156+ const isMaterial = ( shading as unknown as string ) === 'material' ;
114157 switch ( light . type ) {
115158 case 'directional' :
116- return < DirectionalLightNode color = { color } intensity = { active ? light . intensity : 0 } /> ;
159+ return isMaterial
160+ ? < DirectionalLightBare color = { color } intensity = { light . intensity } />
161+ : < DirectionalLightNode color = { color } intensity = { 0 } /> ;
117162 case 'spot' :
118163 return (
119- < SpotLightNode
120- color = { color }
121- intensity = { active ? light . intensity : 0 }
122- distance = { light . distance ?? 0 }
123- angle = { light . angle ?? Math . PI / 6 }
124- penumbra = { light . penumbra ?? 0 }
125- decay = { light . decay ?? 2 }
126- />
164+ isMaterial ? (
165+ < SpotLightBare
166+ color = { color }
167+ intensity = { light . intensity }
168+ distance = { light . distance ?? 0 }
169+ angle = { light . angle ?? Math . PI / 6 }
170+ penumbra = { light . penumbra ?? 0 }
171+ decay = { light . decay ?? 2 }
172+ />
173+ ) : (
174+ < SpotLightNode
175+ color = { color }
176+ intensity = { 0 }
177+ distance = { light . distance ?? 0 }
178+ angle = { light . angle ?? Math . PI / 6 }
179+ penumbra = { light . penumbra ?? 0 }
180+ decay = { light . decay ?? 2 }
181+ />
182+ )
127183 ) ;
128184 case 'rectarea' :
129185 return (
130- < RectAreaLightNode
131- color = { color }
132- intensity = { active ? light . intensity : 0 }
133- width = { light . width ?? 1 }
134- height = { light . height ?? 1 }
135- />
186+ isMaterial ? (
187+ < RectAreaLightBare color = { color } intensity = { light . intensity } width = { light . width ?? 1 } height = { light . height ?? 1 } />
188+ ) : (
189+ < RectAreaLightNode color = { color } intensity = { 0 } width = { light . width ?? 1 } height = { light . height ?? 1 } />
190+ )
136191 ) ;
137192 case 'point' :
138193 default :
139194 return (
140- < PointLightNode
141- color = { color }
142- intensity = { active ? light . intensity : 0 }
143- distance = { light . distance ?? 0 }
144- decay = { light . decay ?? 2 }
145- />
195+ isMaterial ? (
196+ < PointLightBare color = { color } intensity = { light . intensity } distance = { light . distance ?? 0 } decay = { light . decay ?? 2 } />
197+ ) : (
198+ < PointLightNode color = { color } intensity = { 0 } distance = { light . distance ?? 0 } decay = { light . decay ?? 2 } />
199+ )
146200 ) ;
147201 }
148202 } ) ( ) }
149203 { obj . type === 'camera' && obj . cameraId && ( ( ) => {
150204 const camRes = scene . cameras [ obj . cameraId ! ] ;
151205 if ( ! camRes ) return null ;
206+ const isMaterial = ( shading as unknown as string ) === 'material' ;
152207 if ( camRes . type === 'perspective' ) {
153- return < PerspectiveCameraNode fov = { camRes . fov ?? 50 } near = { camRes . near } far = { camRes . far } /> ;
208+ return isMaterial
209+ ? < PerspectiveCameraBare fov = { camRes . fov ?? 50 } near = { camRes . near } far = { camRes . far } />
210+ : < PerspectiveCameraNode fov = { camRes . fov ?? 50 } near = { camRes . near } far = { camRes . far } /> ;
154211 }
155- return (
156- < OrthographicCameraNode
157- left = { camRes . left ?? - 1 }
158- right = { camRes . right ?? 1 }
159- top = { camRes . top ?? 1 }
160- bottom = { camRes . bottom ?? - 1 }
161- near = { camRes . near }
162- far = { camRes . far }
163- />
164- ) ;
212+ return isMaterial
213+ ? (
214+ < OrthographicCameraBare
215+ left = { camRes . left ?? - 1 }
216+ right = { camRes . right ?? 1 }
217+ top = { camRes . top ?? 1 }
218+ bottom = { camRes . bottom ?? - 1 }
219+ near = { camRes . near }
220+ far = { camRes . far }
221+ />
222+ ) : (
223+ < OrthographicCameraNode
224+ left = { camRes . left ?? - 1 }
225+ right = { camRes . right ?? 1 }
226+ top = { camRes . top ?? 1 }
227+ bottom = { camRes . bottom ?? - 1 }
228+ near = { camRes . near }
229+ far = { camRes . far }
230+ />
231+ ) ;
165232 } ) ( ) }
166233 { obj . children . map ( ( cid ) => (
167234 < ObjectNode key = { cid } objectId = { cid } />
0 commit comments