Explorar o código

Editor: Added background rotation support. (#27790)

mrdoob hai 1 ano
pai
achega
c97c257bf5
Modificáronse 2 ficheiros con 31 adicións e 12 borrados
  1. 6 1
      editor/js/Sidebar.Scene.js
  2. 25 11
      editor/js/Viewport.js

+ 6 - 1
editor/js/Sidebar.Scene.js

@@ -195,6 +195,9 @@ function SidebarScene( editor ) {
 	const backgroundIntensity = new UINumber( 1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onBackgroundChanged );
 	const backgroundIntensity = new UINumber( 1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onBackgroundChanged );
 	backgroundEquirectRow.add( backgroundIntensity );
 	backgroundEquirectRow.add( backgroundIntensity );
 
 
+	const backgroundRotation = new UINumber( 0 ).setWidth( '40px' ).setRange( -180, 180 ).setStep( 10 ).setNudge( 0.1 ).setUnit( '°' ).onChange( onBackgroundChanged );
+	backgroundEquirectRow.add( backgroundRotation );
+
 	container.add( backgroundEquirectRow );
 	container.add( backgroundEquirectRow );
 
 
 	function onBackgroundChanged() {
 	function onBackgroundChanged() {
@@ -205,7 +208,8 @@ function SidebarScene( editor ) {
 			backgroundTexture.getValue(),
 			backgroundTexture.getValue(),
 			backgroundEquirectangularTexture.getValue(),
 			backgroundEquirectangularTexture.getValue(),
 			backgroundBlurriness.getValue(),
 			backgroundBlurriness.getValue(),
-			backgroundIntensity.getValue()
+			backgroundIntensity.getValue(),
+			backgroundRotation.getValue()
 		);
 		);
 
 
 	}
 	}
@@ -229,6 +233,7 @@ function SidebarScene( editor ) {
 	const environmentType = new UISelect().setOptions( {
 	const environmentType = new UISelect().setOptions( {
 
 
 		'None': '',
 		'None': '',
+		'Background': 'Background',
 		'Equirectangular': 'Equirect',
 		'Equirectangular': 'Equirect',
 		'ModelViewer': 'ModelViewer'
 		'ModelViewer': 'ModelViewer'
 
 

+ 25 - 11
editor/js/Viewport.js

@@ -485,15 +485,11 @@ function Viewport( editor ) {
 
 
 	// background
 	// background
 
 
-	signals.sceneBackgroundChanged.add( function ( backgroundType, backgroundColor, backgroundTexture, backgroundEquirectangularTexture, backgroundBlurriness, backgroundIntensity ) {
+	signals.sceneBackgroundChanged.add( function ( backgroundType, backgroundColor, backgroundTexture, backgroundEquirectangularTexture, backgroundBlurriness, backgroundIntensity, backgroundRotation ) {
 
 
-		switch ( backgroundType ) {
-
-			case 'None':
+		scene.background = null;
 
 
-				scene.background = null;
-
-				break;
+		switch ( backgroundType ) {
 
 
 			case 'Color':
 			case 'Color':
 
 
@@ -516,9 +512,19 @@ function Viewport( editor ) {
 				if ( backgroundEquirectangularTexture ) {
 				if ( backgroundEquirectangularTexture ) {
 
 
 					backgroundEquirectangularTexture.mapping = THREE.EquirectangularReflectionMapping;
 					backgroundEquirectangularTexture.mapping = THREE.EquirectangularReflectionMapping;
+
 					scene.background = backgroundEquirectangularTexture;
 					scene.background = backgroundEquirectangularTexture;
 					scene.backgroundBlurriness = backgroundBlurriness;
 					scene.backgroundBlurriness = backgroundBlurriness;
 					scene.backgroundIntensity = backgroundIntensity;
 					scene.backgroundIntensity = backgroundIntensity;
+					scene.backgroundRotation.y = backgroundRotation * THREE.MathUtils.DEG2RAD;
+
+					if ( useBackgroundAsEnvironment ) {
+
+						scene.environment = scene.background;
+						scene.environmentRotation.y = backgroundRotation * THREE.MathUtils.DEG2RAD;
+
+					}
+
 
 
 				}
 				}
 
 
@@ -532,20 +538,28 @@ function Viewport( editor ) {
 
 
 	// environment
 	// environment
 
 
+	let useBackgroundAsEnvironment = false;
+
 	signals.sceneEnvironmentChanged.add( function ( environmentType, environmentEquirectangularTexture ) {
 	signals.sceneEnvironmentChanged.add( function ( environmentType, environmentEquirectangularTexture ) {
 
 
+		scene.environment = null;
+
+		useBackgroundAsEnvironment = false;
+
 		switch ( environmentType ) {
 		switch ( environmentType ) {
 
 
-			case 'None':
 
 
-				scene.environment = null;
+			case 'Background':
+
+				useBackgroundAsEnvironment = true;
+
+				scene.environment = scene.background;
+				scene.environmentRotation.y = scene.backgroundRotation.y;
 
 
 				break;
 				break;
 
 
 			case 'Equirectangular':
 			case 'Equirectangular':
 
 
-				scene.environment = null;
-
 				if ( environmentEquirectangularTexture ) {
 				if ( environmentEquirectangularTexture ) {
 
 
 					environmentEquirectangularTexture.mapping = THREE.EquirectangularReflectionMapping;
 					environmentEquirectangularTexture.mapping = THREE.EquirectangularReflectionMapping;