Skip to content

Commit

Permalink
feat: bundle RectAreaLightUniformsLib for app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
linbingquan committed Apr 24, 2024
1 parent dc20c1f commit 2126aa2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions editor/js/Sidebar.Project.App.js
Expand Up @@ -85,6 +85,14 @@ function SidebarProjectApp( editor ) {

const toZip = {};

const scene = editor.scene;
let hasRectAreaLight = false;
scene.traverse( function ( child ) {

if ( child.isRectAreaLight === true ) hasRectAreaLight = true;

} );

//

let output = editor.toJSON();
Expand Down Expand Up @@ -136,6 +144,30 @@ function SidebarProjectApp( editor ) {

content = content.replace( '\t\t\t/* edit button */', editButton );

const importAddonsScripts = [];
if ( hasRectAreaLight ) importAddonsScripts.push( '\t\t\timport { RectAreaLightUniformsLib } from \'three/addons/lights/RectAreaLightUniformsLib.js\';' );
if ( importAddonsScripts.length > 0 ) {

content = content.replace( '\t\t\t/* import addons js */', importAddonsScripts.join( '\n\t\t\t' ) );

} else {

content = content.replace( '\t\t\t/* import addons js */\r\n', '' );

}

const initAddonsScripts = [];
if ( hasRectAreaLight ) initAddonsScripts.push( '\t\t\tRectAreaLightUniformsLib.init();' );
if ( initAddonsScripts.length > 0 ) {

content = content.replace( '\t\t\t/* init addons js */', initAddonsScripts.join( '\n\t\t\t' ) );

} else {

content = content.replace( '\t\t\t/* init addons js */\r\n', '' );

}

toZip[ 'index.html' ] = strToU8( content );

} );
Expand All @@ -150,6 +182,16 @@ function SidebarProjectApp( editor ) {

} );

if ( hasRectAreaLight ) {

loader.load( '../examples/jsm/lights/RectAreaLightUniformsLib.js', function ( content ) {

toZip[ 'js/lights/RectAreaLightUniformsLib.js' ] = strToU8( content );

} );

}

} );
container.add( publishButton );

Expand Down
5 changes: 4 additions & 1 deletion editor/js/libs/app/index.html
Expand Up @@ -21,16 +21,19 @@
<script type="importmap">
{
"imports": {
"three": "./js/three.module.js"
"three": "./js/three.module.js",
"three/addons/": "./js/"
}
}
</script>
<script type="module">

import * as THREE from 'three';
/* import addons js */
import { APP } from './js/app.js';

window.THREE = THREE; // Used by APP Scripts.
/* init addons js */

var loader = new THREE.FileLoader();
loader.load( 'app.json', function ( text ) {
Expand Down

0 comments on commit 2126aa2

Please sign in to comment.