JannisX11 / blockbench

Blockbench - A low poly 3D model editor
https://www.blockbench.net
GNU General Public License v3.0
3.29k stars 286 forks source link

Compiling a second time on overwrite ( bedrock ) #2485

Open Shadowkitten47 opened 2 weeks ago

Shadowkitten47 commented 2 weeks ago

Detailed description of your suggestion

This is more a question but either way I want to know why.

export_codec.write(export_codec.compile(), Project.export_path); 

(line 708 of io.js) Calls the compile function and sends it to write when saving below is Codec.write()

write(content, path) {
        if (fs.existsSync(path) && this.overwrite) {
            this.overwrite(content, path, path => this.afterSave(path))
        } else {
            Blockbench.writeFile(path, {content}, path => this.afterSave(path));
        }
    }

Witch if the file already exists sends to this.overwrite and if it's bedrock

var model = this.compile({raw: true})['minecraft:geometry'][0]

( line 1193 of bedrock.js in function .overwrite)

It calls this.compile AGAIN which I should have to say why this shouldn't be the case because this can really slow down performance on super large or complex bedrock models personally I'm trying to make models that already take 10min to compile I don't want another 10 minutes. On the alterative I think we you should call export_codec as raw from the beginning then stringifying it on write

Shadowkitten47 commented 2 weeks ago

Suggested changes

export_codec.write(export_codec.compile({raw: true}), Project.export_path)

( line 708 of io.js ) Make the initial compile raw

write(content, path) {
        if (fs.existsSync(path) && this.overwrite) {
            this.overwrite(content, path, path => this.afterSave(path))
        } else {
            Blockbench.writeFile(path, { content: autoStringify(content) }, path => this.afterSave(path));
        }
    }

( line 128 of codec.js, codec::write() ) add autoStringify on non-overwriting

var model = content['minecraft:geometry'][0]

( line 1193 of bedrock.js within function overwrite) Use content rather than recompiling

obj[model_name] = content;

( line 400 of bedrock_old.js ) again use content rather than recompile