提交 6e0a66ae 编写于 作者: T tschw

Editor: GLSL minification.

上级 113e2f06
......@@ -53,6 +53,80 @@ Menubar.Edit = function ( editor ) {
} );
options.add( option );
// Minify shaders
var option = new UI.Panel();
option.setClass( 'option' );
option.setTextContent( 'Minify Shaders' );
option.onClick( function() {
var root = editor.selected || editor.scene;
var errors = [];
var nMaterialsChanged = 0;
var path = [];
function getPath ( object ) {
path.length = 0;
var parent = object.parent;
if ( parent !== undefined ) getPath( parent );
path.push( object.name || object.uuid );
return path;
}
root.traverse( function ( object ) {
var material = object.material;
if ( material instanceof THREE.ShaderMaterial ) {
try {
var shader = glslprep.minifyGlsl( [
material.vertexShader, material.fragmentShader ] );
material.vertexShader = shader[ 0 ];
material.fragmentShader = shader[ 1 ];
++nMaterialsChanged;
} catch ( e ) {
var path = getPath( object ).join( "/" );
if ( e instanceof glslprep.SyntaxError )
errors.push( path + ":" +
e.line + ":" + e.column + ": " + e.message );
else {
errors.push( path +
": Unexpected error (see console for details)." );
console.error( e.stack || e );
}
}
}
} );
window.alert( nMaterialsChanged +
" material(s) were changed.\n" + errors.join( "\n" ) );
} );
options.add( option );
return container;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册