# 关于我
Vanilla Viewmodels 是一个数据包库,它为游戏中使用 OBJMC 渲染的视角模型添加了“动画控制器”。要使用该数据包,你需要具备:
- 一个动画(在 Blockbench 中为通用类型)模型。
- 本地安装了 [objmc](https://github.com/Godlander/objmc)。
- 对资源包和数据包的工作原理有基本了解。
使用 Viewmodel?
优点
- 无缝的物品动画,可以按函数运行。
- 得益于 OBJMC,模型可以达到极高的分辨率。
缺点
- OBJMC 光影与 Iris 光影无法同时启用。
- 由于 objmc 导出的高分辨率纹理,资源包体积可能会膨胀。
实用指南:
-
工作原理
由于 objmc 仅导出模型+纹理,需要注意该数据包采用了一些约定以确保其按预期工作。OBJMC 默认不会像 AnimatedJava 等插件那样“为你准备好数据包/资源包”。因此,创建一个正确遵循此数据包约定的资源包至关重要。
资源包中的模型
“play-animation”工具命令接受的可选 'id' 参数需要有效的 item_model 组件值。由于每个 objmc 动画都导出为独立的模型+纹理,你必须:
- 创建一个与模型相似的物品模型 JSON。
例如:'first_person:weapons/glock' 位于 assets/first_person/items/weapons/glock.json
- 模型的动画必须包含在此 item_model 文件夹中,其中“带动画的模型”是在 字符串自定义模型数据值 === 动画名称 时切换的模型。
因此,每个动画都是 item_model JSON 文件中的一个 CustomModelData 字符串。显然,这意味着添加多个动画意味着你必须将每个动画导出为 OBJ 序列 => 通过 OBJMC.py 处理 => 获取压缩后的模型并在 item_model 组件中提及它。
在数据包中注册模型
要在数据包中注册 OBJMC 动画模型,请打开函数文件 vm:global/load 并在数据修改行中添加注册表!

以下是注册表条目的结构示例:
{
id: "first_person:weapons/glock", // item_model 组件
animations: [
{
"name":"equip",
"start": 0,
"end": 27, // 动画的总刻数
"duration": 30, // 包含空白时间的动画刻数
keyframe_functions: [
{ at: 0, function_file: 'test:equip' }, // 在第 0 个关键帧运行函数文件。
{ at: 30, function_file: 'test:end_animation' },
{ at: 25, function_file: 'test:gun_sfx' }
]
},
{
"name": "shoot1",
"start": 0,
"end": 8,
"duration": 6,
"keyframe_functions": [
{ at: 0, function_file: 'gun:shoot' }
]
}
]
}
若要注册无限循环的动画,请将 "end" 值设置为 -1
要播放动画,请运行命令:
function vm:animations/play {args:{}}
args:{} 字段用于调整参数,包括:
id: 存储/应用 *item_model* 组件值
animation: 存储动画的名称。
frame: 动画应开始的帧。
示例命令:
function vm:animations/play {args:{id:"first_person:weapons/glock", animation: "equip", frame: 10}}
此命令将,
- 将药水物品的模型更改为 first_person_weapons/glock
- 设置待播放的动画为 "equip"(这是通过将动画名称设置为等于更改模型的不同动画纹理数据的 custom_model_data 字符串来处理的)
- 将起始帧设置为 0(药水颜色设置为 8388608+10)
要停止动画,只需运行命令:
function vm:animations/stop
鸣谢
- Godlander [& objmc GitHub 仓库上的贡献者] —— 让在 Minecraft 中使用 OBJMC(从而使用 viewmodels)成为可能!
- GhostScoutW (@ghostscout on discord) —— 制作了如何设置使用 OBJMC 的工作视角模型项目的指南!
- pinkiuses (ATMOS: Minecraft Edition 的创作者) —— 提出了使用 OBJMC 作为视角模型的想法!
- 以及你!
About Me
Vanilla Viewmodels is a Datapack Library which adds an "animation controller" for your OBJMC rendered viewmodels ingame. To work with the datapack, you must have:
- An Animated (Generic in Blockbench) Model.
- objmc installed locally.
- A Basic Understanding of How Resourcepacks and Datapacks work.
Using Viewmodel?
Pros
- Seamless Item Animations that can be ran per function.
- Thanks to OBJMC, the models can be extremely High-Resolution.
Cons
- The OBJMC shader doesn't work with an IRIS shader on.
- The Resourcepack Size may bloat due to high res textures exported by objmc
Utility:
-
How it works.
Since objmc only exports model+texture, it should be noted that the datapack adopts certain conventions to make sure that it works as intended. OBJMC, by default, will not "prepare you a datapack/resourcepack" like how plugins like AnimatedJava does. Hence, creating a resourcepack that correctly follows this datapack's convention is CRUCIAL.
Model in Resourcepack
The optional 'id' parameter accepted in the "play-animation" utils command requires a valid item_model component value. Since every objmc animation exports into its own model+texture, you must:
- Create an Item Model JSON that resembles the model.
e.g. 'first_person:weapons/glock' at assets/first_person/items/weapons/glock.json
- Animations for the Model MUST be included in this item_model folder, where the "model with animation" is a model toggled when STRING CUSTOM-MODEL-DATA value === ANIMATION-NAME.
Hence, every animation is a CustomModelData string in the item_model JSON file. Obviously, this implies that adding multiple animations would mean that you'll have to export every animation into its OBJ sequences => put them through OBJMC.py => take the condensed model and mention it in the item_model component.
Registering Models in Datapack.
To Register an OBJMC Animated Model in the datapack, open the function file vm:global/load and add a registry in the data modify line!

Here's how a registry entry's structure looks like:
{
id: "first_person:weapons/glock", // item_model component
animations: [
{
"name":"equip",
"start": 0,
"end": 27, // The Total Ticks of the Animation
"duration": 30, // Ticks of Animation with Dead Space
keyframe_functions: [
{ at: 0, function_file: 'test:equip' }, // Run a function file @ 0th keyframe.
{ at: 30, function_file: 'test:end_animation' },
{ at: 25, function_file: 'test:gun_sfx' }
]
},
{
"name": "shoot1",
"start": 0,
"end": 8,
"duration": 6,
"keyframe_functions": [
{ at: 0, function_file: 'gun:shoot' }
]
}
]
}
To register an animation that loops infinitely, set the "end" value to -1
to play an Animation, run the command:
function vm:animations/play {args:{}}
the args:{} field is used to tweak parameters, namely:
id: it stores/applies the *item_model* component value
animation: it stores the name of the animation.
frame: the frame at which the animation should start.
an example command:
function vm:animations/play {args:{id:"first_person:weapons/glock", animation: "equip", frame: 10}}
This command will,
- change the item model of the potion item to first_person_weapons/glock
- set the animation-to-be-played to "equip" (this is handled by setting animation name equal to custom_model_data string that changes the model into one with different animation texture data)
- set the starting frame to 0 (potion color is set to 8388608+10)
to stop an animation, simply run the command:
function vm:animations/stop
Credits
- Godlander [& the contributors on objmc github repository.] —— For Making OBJMC (and thus, viewmodels) in Minecraft possible!
- GhostScoutW (@ghostscout on discord) —— For making a Guide on how to setup a working viewmodel project with OBJMC!
- pinkiuses (creator of ATMOS: Minecraft Edition) —— For coming up with the idea of using OBJMC as viewmodels!
- And you!
评论 0
登录后参与评分
还没有评论,来抢沙发吧