Просмотр исходного кода

Editor: fix app publishing for project using WebGPURenderer (#32897)

ycw 3 недель назад
Родитель
Сommit
7f71a050c8
2 измененных файлов с 52 добавлено и 11 удалено
  1. 51 3
      editor/js/Sidebar.Project.App.js
  2. 1 8
      editor/js/libs/app/index.html

+ 51 - 3
editor/js/Sidebar.Project.App.js

@@ -85,6 +85,8 @@ function SidebarProjectApp( editor ) {
 
 		const toZip = {};
 
+		const rendererType = config.getKey( 'project/renderer/type' );
+
 		//
 
 		let output = editor.toJSON();
@@ -115,6 +117,26 @@ function SidebarProjectApp( editor ) {
 
 			content = content.replace( '<!-- title -->', title );
 
+			//
+
+			const IMPORTMAP = {
+				WebGLRenderer: {
+					imports: {
+						'three': './js/three.module.js'
+					}
+				},
+				WebGPURenderer: {
+					imports: {
+						'three': './js/three.webgpu.js',
+						'three/webgpu': './js/three.webgpu.js'
+					}
+				}
+			};
+			const importmap = JSON.stringify( IMPORTMAP[ rendererType ], null, '\t' );
+			content = content.replace( '<!-- importmap -->', indent( '\n' + indent( importmap, 1 ) + '\n', 2 ) );
+
+			//
+
 			let editButton = '';
 
 			if ( config.getKey( 'project/editable' ) ) {
@@ -145,11 +167,24 @@ function SidebarProjectApp( editor ) {
 			toZip[ 'js/three.core.js' ] = strToU8( content );
 
 		} );
-		loader.load( '../build/three.module.js', function ( content ) {
 
-			toZip[ 'js/three.module.js' ] = strToU8( content );
+		if ( rendererType === 'WebGPURenderer' ) {
 
-		} );
+			loader.load( '../build/three.webgpu.js', function ( content ) {
+
+				toZip[ 'js/three.webgpu.js' ] = strToU8( content );
+
+			} );
+
+		} else {
+
+			loader.load( '../build/three.module.js', function ( content ) {
+
+				toZip[ 'js/three.module.js' ] = strToU8( content );
+
+			} );
+
+		}
 
 	} );
 	container.add( publishButton );
@@ -167,4 +202,17 @@ function SidebarProjectApp( editor ) {
 
 }
 
+//
+
+function indent( text, count, space = '\t' ) {
+
+	return text
+		.split( '\n' )
+		.map( line => space.repeat( count ) + line )
+		.join( '\n' );
+
+}
+
+//
+
 export { SidebarProjectApp };

+ 1 - 8
editor/js/libs/app/index.html

@@ -18,14 +18,7 @@
 		</style>
 	</head>
 	<body ontouchstart="">
-		<script type="importmap">
-			{
-				"imports": {
-					"three": "./js/three.module.js",
-					"three/webgpu": "./js/three.webgpu.js"
-				}
-			}
-		</script>
+		<script type="importmap"><!-- importmap --></script>
 		<script type="module">
 
 			import * as THREE from 'three';

粤ICP备19079148号