Improve graph selectin accuracy

Fix molang keyframes not displayed when first adding animator to timeline
Improve texture import on java block/item parent models
This commit is contained in:
JannisX11 2023-07-17 00:44:34 +02:00
parent 3cbc016eff
commit d234f3196c
3 changed files with 21 additions and 21 deletions

View File

@ -1321,21 +1321,27 @@ Interface.definePanels(() => {
},
clickGraphEditor(event) {
if (!this.show_other_graphs || !this.graph_editor_animator) return;
let time = event.offsetX / this.size;
let value = (this.graph_offset - event.offsetY) / this.graph_size;
let original_time = Timeline.time;
Timeline.time = time;
let distances = ['x', 'y', 'z'].map(axis => {
let axis_value = this.graph_editor_animator.interpolate(this.graph_editor_channel, false, axis);
let diff = Math.abs(axis_value - value) * this.graph_size;
if (diff < 12.5) {
return {axis, diff};
}
}).filter(a => a);
let tryAt = (x_coord) => {
let time = (x_coord) / this.size;
Timeline.time = time;
if (distances.length) {
let distances = ['x', 'y', 'z'].map(axis => {
let axis_value = this.graph_editor_animator.interpolate(this.graph_editor_channel, false, axis);
let diff = Math.abs(axis_value - value) * this.graph_size;
if (diff < 12.5) {
return {axis, diff};
}
}).filter(a => a);
if (distances.length) return distances;
}
let real_x_coord = event.offsetX-8;
let distances = tryAt(real_x_coord) || tryAt(real_x_coord + 4) || tryAt(real_x_coord - 4);
if (distances) {
distances.sort((a, b) => a.diff - b.diff);
this.graph_editor_axis = distances[0].axis;
}

View File

@ -37,6 +37,7 @@ class GeneralAnimator {
if (!this[channel]) this[channel] = [];
}
if (!this.expanded) this.expanded = true;
TickUpdates.keyframe_selection = true;
return this;
}
addKeyframe(data, uuid) {

View File

@ -308,7 +308,7 @@ var codec = new Codec('java_block', {
if (link.startsWith('#') && texture_arr[link.substring(1)]) {
link = texture_arr[link.substring(1)];
}
let texture = new Texture({id: key}).fromJavaLink(texture_arr[key], path_arr.slice()).add();
let texture = new Texture({id: key}).fromJavaLink(link, path_arr.slice()).add();
texture_paths[texture_arr[key].replace(/^minecraft:/, '')] = texture_ids[key] = texture;
new_textures.push(texture);
}
@ -450,13 +450,6 @@ var codec = new Codec('java_block', {
}
}, (result) => {
if (result) {
let textures;
if (result == 'open_with_textures') {
textures = {};
Texture.all.forEach(tex => {
textures[tex.id] = tex;
})
}
let parent = model.parent.replace(/\w+:/, '');
let path_arr = path.split(osfs);
let index = path_arr.length - path_arr.indexOf('models');
@ -468,9 +461,9 @@ var codec = new Codec('java_block', {
loadModelFile(files[0]);
if (result == 'open_with_textures') {
Texture.all.forEach(tex => {
Texture.all.forEachReverse(tex => {
if (tex.error == 3 && tex.name.startsWith('#')) {
let loaded_tex = textures[tex.name.replace(/#/, '')];
let loaded_tex = texture_ids[tex.name.replace(/#/, '')];
if (loaded_tex) {
tex.fromPath(loaded_tex.path);
tex.namespace = loaded_tex.namespace;