Skip to content

MCModderAnchor/SimpleBedrockModel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SimpleBedrockModel

License Modrinth

A simple library for loading and rendering Minecraft Bedrock Edition entity models and animations in Java Edition

🎯 Supported Features

  • βœ… Bedrock Model: Full support Bedrock Model loading and rendering
  • βœ… Bedrock Animation: Complex bone structures and transformations
  • βŒ› Molang Support: In progress...
  • βœ… Animation Running: A full-featured animation player.
  • βœ… Animation Blending: Support for blendspace, layered, kinematic interpolation blending
  • βœ… Resource Pack Support: Load models and animations from resource packs

πŸš€ Quick Start

For Mod Developers

Add SimpleBedrockModel to your mod's dependencies:

Minecraft 1.20.1 (Forge)

repositories {
    maven {
        url = "https://api.modrinth.com/maven"
        content {
            includeGroup "maven.modrinth"
        }
    }
}

dependencies {
    jarJar(implementation(fg.deobf("maven.modrinth:simplebedrockmodel:1.5.0-forge+1.20.1"))) {
        jarJar.ranged(it, "[1.5.0,)")
    }
    // The animation library is already included in jar (jar in jar), 
    // but since modrinth maven cannot handle transitive dependencies,
    // you need to include it to pass the compilation.
    compileOnly("com.maydaymemory:mae:1.0.2")
}

Minecraft 1.21.1 (NeoForge)

repositories {
    maven {
        url = "https://api.modrinth.com/maven"
        content {
            includeGroup "maven.modrinth"
        }
    }
}

dependencies {
    implementation jarJar("maven.modrinth:simplebedrockmodel:1.5.0-neoforge+mc1.21.1") {
        version {
            prefer '1.5.0-neoforge+1.21.1'
        }
    }
    // The animation library is already included in jar (jar in jar), 
    // but since modrinth maven cannot handle transitive dependencies,
    // you need to include it to pass the compilation.
    compileOnly("com.maydaymemory:mae:1.0.2")
}

πŸ“– Usage Examples

Loading a Bedrock Model

There is a utility class "GsonUtil" to help you create pojo from json:

InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
Gson gson = GsonUtil.GSON;
BedrockModelPOJO pojo = gson.fromJson(reader, BedrockModelPOJO.class);
BedrockModel model = new BedrockModel(pojo);

Loading a Bedrock Animations

There is a utility class "GsonUtil" to help you create pojo from json:

BedrockModel model = ...;
BoneIndexProvider indexProvider = new BedrockModelBoneIndexProvider(model);
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
Gson gson = GsonUtil.GSON;
BedrockAnimationFile pojo = gson.fromJson(reader, BedrockAnimationFile.class);

Animation Instance Construct: A utility class "Animations" could help construct animation instance as long as you got the pojo.

BedrockAnimationFile animationFilePojo = ...;
BedrockAnimationPOJO animationPojo = ...;
BedrockModel model = ...;
BoneIndexProvider indexProvider = new BedrockModelBoneIndexProvider(model);
// BedrockAnimationFile represents a complete Bedrock Edition animation file, 
// which containing multiple animations.
List<BedrockAnimation> animations = Animations.createAnimation(animationFilePojo, indexProvider);
// BedrockAnimationPOJO represents a single animation.
BedrockAnimation animation = Animations.createAnimation("animation_name", animationPojo, indexProvider);

Create Animation Runner

Animation Runner can control the progress of animation according to time, and estimate Pose, Animation Events and Curves according to the progress.

BedrockAnimation animation = ...;
// use getSpecifiedEndTimeS because bedrock animation has its own end time.
AnimationContext animationContext = new AnimationContext(animation.getSpecifiedEndTimeS()); 
animationContext.setState(new LoopingState(System::nanoTime));
AnimationRunner animationRunner = new AnimationRunner(animation, animationContext);

// somewhere else
Pose pose = animationRunner.evaluate();

Apply animations to model

// According to the Bedrock Edition animation standard,
// this type of blender must be used and ZYX BoneTransform must be used.
AdditiveBlender blender = new SimpleAdditiveBlender(new ZYXBoneTransformFactory(), ArrayPoseBuilder::new);

// Before rendering
Pose bindPose = model.getBindPose(); // The initial pose of the model
Pose animationPose = ...; // For example, animationRunner.evaluate()
Pose blended = blender.blend(bindPose, animationPose);
// Apply animation to model
model.applyPose(blended);
// Rendering
model.renderToBuffer(poseStack, buffer, packedLight, packedOverlay);
// After Rendering, You can choose whether to restore to binding pose according to your usage.
// model.applyPose(bindPose);

How to use animation blending

See the documentation of Mayday Animation Engine

πŸ—οΈ Project Structure

src/main/java/com/github/mcmodderanchor/simplebedrockmodel/
β”œβ”€β”€ v1/client/bedrock/
β”‚   β”œβ”€β”€ model/           # Core model classes
β”‚   β”œβ”€β”€ animation/       # Animation system
β”‚   β”œβ”€β”€ pojo/           # Data transfer objects
β”‚   └── compat/         # Compatibility layers
└── example/            # Usage examples, not included in builds

πŸ“ License

This project is licensed under the LGPL-3.0 License - see the LICENSE file for details.

Specifically, assets under the example namespace are provided solely as tutorial examples and for reference. Their respective owners retain ALL RIGHTS.
Please do not reuse or redistribute them without permission.

πŸ‘₯ Contributors

  • TartaricAcid - Lead Developer
  • MaydayMemory - Core Developer
  • MoePus - Developer
  • Hidomatn - Developer
  • xjqsh - Developer

🀝 Contributing

We welcome contributions! Please feel free to submit issues and pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ž Support

πŸ”— Related Projects


Made with ❀️ by the SimpleBedrockModel Team

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages