mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-02-17 16:20:13 +08:00
Automatically load animations from entity file
This commit is contained in:
parent
3068f6b55d
commit
5de22865a5
@ -255,7 +255,7 @@ class Animation {
|
||||
if (selected_bone) {
|
||||
selected_bone.select();
|
||||
}
|
||||
Animator.preview();
|
||||
if (Modes.animate) Animator.preview();
|
||||
return this;
|
||||
}
|
||||
setLength(len) {
|
||||
@ -803,25 +803,9 @@ class EffectAnimator extends GeneralAnimator {
|
||||
}
|
||||
EffectAnimator.prototype.channels = ['particle', 'sound', 'timeline']
|
||||
|
||||
//Misc Functions
|
||||
function findBedrockAnimation() {
|
||||
var animation_path = ModelMeta.export_path.split(osfs)
|
||||
var index = animation_path.lastIndexOf('models')
|
||||
animation_path.splice(index)
|
||||
var path1 = [...animation_path, 'animations', pathToName(ModelMeta.export_path)+'.json'].join(osfs)
|
||||
var path2 = [...animation_path, 'animations', pathToName(ModelMeta.export_path).replace('.geo', '')+'.animation.json'].join(osfs)
|
||||
if (fs.existsSync(path1)) {
|
||||
Blockbench.read([path1], {}, (files) => {
|
||||
Animator.loadFile(files[0])
|
||||
})
|
||||
} else if (fs.existsSync(path2)) {
|
||||
Blockbench.read([path2], {}, (files) => {
|
||||
Animator.loadFile(files[0])
|
||||
})
|
||||
}
|
||||
}
|
||||
//Clipbench
|
||||
Clipbench.setKeyframes = function() {
|
||||
Object.assign(Clipbench, {
|
||||
setKeyframes() {
|
||||
|
||||
var keyframes = Timeline.selected;
|
||||
|
||||
@ -853,8 +837,8 @@ class EffectAnimator extends GeneralAnimator {
|
||||
if (isApp) {
|
||||
clipboard.writeHTML(JSON.stringify({type: 'keyframes', content: Clipbench.keyframes}))
|
||||
}
|
||||
}
|
||||
Clipbench.pasteKeyframes = function() {
|
||||
},
|
||||
pasteKeyframes() {
|
||||
if (isApp) {
|
||||
var raw = clipboard.readHTML()
|
||||
try {
|
||||
@ -897,6 +881,7 @@ class EffectAnimator extends GeneralAnimator {
|
||||
Undo.finishEdit('paste keyframes');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Animator = {
|
||||
possible_channels: {rotation: true, position: true, scale: true, sound: true, particle: true, timeline: true},
|
||||
@ -933,10 +918,6 @@ const Animator = {
|
||||
if (!Animator.selected && Animator.animations.length) {
|
||||
Animator.animations[0].select()
|
||||
}
|
||||
if (isApp && !ModelMeta.animation_path && !Animator.animations.length && ModelMeta.export_path) {
|
||||
//Load
|
||||
findBedrockAnimation()
|
||||
}
|
||||
Animator.preview()
|
||||
},
|
||||
leave() {
|
||||
@ -986,11 +967,12 @@ const Animator = {
|
||||
}
|
||||
Blockbench.dispatchEvent('display_animation_frame')
|
||||
},
|
||||
loadFile(file) {
|
||||
loadFile(file, animation_filter) {
|
||||
var json = file.json || autoParseJSON(file.content);
|
||||
let path = file.path;
|
||||
if (json && typeof json.animations === 'object') {
|
||||
for (var ani_name in json.animations) {
|
||||
if (animation_filter && !animation_filter.includes(ani_name)) continue;
|
||||
//Animation
|
||||
var a = json.animations[ani_name]
|
||||
var animation = new Animation({
|
||||
|
@ -65,6 +65,7 @@ window.BedrockEntityManager = {
|
||||
BedrockEntityManager.client_entity = BedrockEntityManager.getEntityFile();
|
||||
if (BedrockEntityManager.client_entity && BedrockEntityManager.client_entity.description) {
|
||||
|
||||
// Textures
|
||||
var tex_list = BedrockEntityManager.client_entity.description.textures
|
||||
if (tex_list instanceof Object) {
|
||||
var valid_textures_list = [];
|
||||
@ -129,6 +130,41 @@ window.BedrockEntityManager = {
|
||||
}
|
||||
}
|
||||
|
||||
// Animations
|
||||
var anim_list = BedrockEntityManager.client_entity.description.animations
|
||||
if (anim_list instanceof Object) {
|
||||
let animation_names = [];
|
||||
for (var key in anim_list) {
|
||||
if (anim_list[key].match && anim_list[key].match(/^animation\./)) {
|
||||
animation_names.push(anim_list[key]);
|
||||
}
|
||||
}
|
||||
// get all paths in folder
|
||||
let anim_files = [];
|
||||
function searchFolder(path) {
|
||||
try {
|
||||
var files = fs.readdirSync(path);
|
||||
for (var name of files) {
|
||||
var new_path = path + osfs + name;
|
||||
if (name.match(/\.json$/)) {
|
||||
anim_files.push(new_path);
|
||||
} else if (!name.includes('.')) {
|
||||
searchFolder(new_path);
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
searchFolder(PathModule.join(BedrockEntityManager.root_path, 'animations'));
|
||||
|
||||
anim_files.forEach(path => {
|
||||
try {
|
||||
let content = fs.readFileSync(path, 'utf8');
|
||||
Animator.loadFile({path, content}, animation_names);
|
||||
} catch (err) {}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
BedrockEntityManager.findEntityTexture(Project.geometry_name)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user