Auto set imported textures UV size

Texture loading fixes
This commit is contained in:
JannisX11 2023-11-16 22:07:44 +01:00
parent a2914809d4
commit a3c634ce98
2 changed files with 26 additions and 13 deletions

View File

@ -323,12 +323,12 @@ var codec = new Codec('project', {
}
if (model.elements) {
let default_texture = Texture.getDefault();
model.elements.forEach(function(element) {
model.elements.forEach(function(template) {
var copy = OutlinerElement.fromSave(element, true)
for (var face in copy.faces) {
if (!Format.single_texture && element.faces) {
var texture = element.faces[face].texture !== null && Texture.all[element.faces[face].texture]
let copy = OutlinerElement.fromSave(template, true)
for (let face in copy.faces) {
if (!Format.single_texture && template.faces) {
let texture = template.faces[face].texture !== null && Texture.all[template.faces[face].texture]
if (texture) {
copy.faces[face].texture = texture.uuid
}
@ -337,7 +337,6 @@ var codec = new Codec('project', {
}
}
copy.init()
})
}
if (model.outliner) {
@ -408,6 +407,7 @@ var codec = new Codec('project', {
}
Canvas.updateAllBones()
Canvas.updateAllPositions()
Canvas.updateAllFaces()
ReferenceImage.updateAll();
Validator.validate()
this.dispatchEvent('parsed', {model})
@ -640,6 +640,7 @@ var codec = new Codec('project', {
Undo.finishEdit('Merge project')
Canvas.updateAllBones()
Canvas.updateAllPositions()
Canvas.updateAllFaces()
ReferenceImage.updateAll();
this.dispatchEvent('parsed', {model})
}

View File

@ -28,7 +28,7 @@ class Texture {
this.internal = !isApp;
this.uuid = uuid || guid()
Project.texture_selections[this.uuid] = new IntMatrix(0, 0);
this.flags = new Set();
//Setup Img/Mat
this.canvas = document.createElement('canvas');
@ -171,8 +171,8 @@ class Texture {
var size_control = {};
this.img.onload = function() {
this.tex.needsUpdate = true;
this.img.onload = () => {
tex.needsUpdate = true;
let dimensions_changed = scope.width !== img.naturalWidth || scope.height !== img.naturalHeight;
scope.width = img.naturalWidth;
scope.height = img.naturalHeight;
@ -190,6 +190,12 @@ class Texture {
scope.ctx.drawImage(img, 0, 0);
}
if (this.flags.has('update_uv_size_from_resolution')) {
this.flags.delete('update_uv_size_from_resolution');
this.uv_width = scope.width;
this.uv_height = scope.display_height;
}
if (scope.isDefault) {
console.log('Successfully loaded '+scope.name+' from default pack')
}
@ -248,7 +254,7 @@ class Texture {
}
})
}
this.img.onerror = function(error) {
this.img.onerror = (error) => {
if (isApp &&
!scope.isDefault &&
scope.mode !== 'bitmap' &&
@ -753,7 +759,7 @@ class Texture {
let timeout;
this.watcher = fs.watch(scope.path, (eventType) => {
if (this.file_just_changed_flag) return;
if (this.flags.has('file_just_changed')) return;
if (eventType == 'change') {
if (timeout) clearTimeout(timeout)
timeout = setTimeout(() => {
@ -879,6 +885,9 @@ class Texture {
if (Texture.all.find(t => t.render_mode == 'layered')) {
this.render_mode = 'layered';
}
if (Format.per_texture_uv_size) {
this.flags.add('update_uv_size_from_resolution');
}
if (undo) {
Undo.initEdit({textures: []})
}
@ -1456,8 +1465,8 @@ class Texture {
}
if (!as && this.path && fs.existsSync(this.path)) {
this.file_just_changed_flag = true;
setTimeout(() => {delete this.file_just_changed_flag}, 100);
this.flags.add('file_just_changed');
setTimeout(() => {this.flags.delete('file_just_changed')}, 100);
fs.writeFileSync(this.path, image);
postSave(this.path);
this.mode = 'link';
@ -2391,6 +2400,9 @@ Interface.definePanels(function() {
return texture.getErrorMessage()
} else {
let message = texture.width + ' x ' + texture.height + 'px';
if (!Format.image_editor) {
message += ` (${texture.width / texture.getUVWidth() * 16}x)`;
}
if (texture.frameCount > 1) {
message += ` - ${texture.currentFrame+1}/${texture.frameCount}`
}