implement character limb swing animation
(cherry picked from commit 19c59e38feff562ccbaade8e38fdd303bba784a5)
This commit is contained in:
@@ -104,8 +104,8 @@ window.WorldRenderer = class {
|
||||
orientCamera(partialTicks) {
|
||||
let player = this.minecraft.player;
|
||||
|
||||
let rotationY = -MathHelper.toRadians(player.yaw + 180);
|
||||
let rotationX = -MathHelper.toRadians(player.pitch);
|
||||
let rotationY = -MathHelper.toRadians(player.rotationYaw + 180);
|
||||
let rotationX = -MathHelper.toRadians(player.rotationPitch);
|
||||
|
||||
// Position
|
||||
let x = player.prevX + (player.x - player.prevX) * partialTicks;
|
||||
@@ -116,8 +116,10 @@ window.WorldRenderer = class {
|
||||
let mode = this.minecraft.settings.thirdPersonView;
|
||||
if (mode !== 0) {
|
||||
// Flip for front view
|
||||
if (mode === 2) {
|
||||
let frontView = mode === 2;
|
||||
if (frontView) {
|
||||
rotationY += Math.PI;
|
||||
rotationX *= -1;
|
||||
}
|
||||
|
||||
// Shift camera
|
||||
|
||||
@@ -11,9 +11,15 @@ window.EntityRenderer = class {
|
||||
render(entity, partialTicks) {
|
||||
let group = entity.group;
|
||||
|
||||
let rotationOffset = this.interpolateRotation(entity.prevRenderYawOffset, entity.renderYawOffset, partialTicks);
|
||||
let rotationBody = this.interpolateRotation(entity.prevRenderYawOffset, entity.renderYawOffset, partialTicks);
|
||||
let rotationHead = this.interpolateRotation(entity.prevRotationYawHead, entity.rotationYawHead, partialTicks);
|
||||
|
||||
let limbSwing = entity.prevLimbSwingAmount + (entity.limbSwingAmount - entity.prevLimbSwingAmount) * partialTicks;
|
||||
let limbSwingAmount = entity.limbSwing - entity.limbSwingAmount * (1.0 - partialTicks);
|
||||
|
||||
let yaw = rotationHead - rotationBody;
|
||||
let pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
|
||||
|
||||
// Interpolate entity position
|
||||
let interpolatedX = entity.prevX + (entity.x - entity.prevX) * partialTicks;
|
||||
let interpolatedY = entity.prevY + (entity.y - entity.prevY) * partialTicks;
|
||||
@@ -29,11 +35,11 @@ window.EntityRenderer = class {
|
||||
group.scale.set(scale, -scale, scale);
|
||||
|
||||
// Rotate entity model
|
||||
group.rotation.y = MathHelper.toRadians(-entity.yaw + 180);
|
||||
group.rotation.y = MathHelper.toRadians(-rotationBody + 180);
|
||||
|
||||
// Render entity model
|
||||
let time = Date.now() / 100;
|
||||
this.model.render(group, time);
|
||||
let timeAlive = entity.ticksExisted + partialTicks;
|
||||
this.model.render(entity, limbSwingAmount, limbSwing, timeAlive, yaw, pitch);
|
||||
}
|
||||
|
||||
interpolateRotation(prevValue, value, partialTicks) {
|
||||
|
||||
@@ -10,14 +10,8 @@ window.ModelBase = class {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the model
|
||||
*
|
||||
* @param group Group to render
|
||||
* @param time Animation offset
|
||||
*/
|
||||
render(group, time) {
|
||||
group.updateMatrix();
|
||||
render(entity, limbSwingAmount, limbSwing, timeAlive, yaw, pitch) {
|
||||
entity.group.updateMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,25 +22,25 @@ window.ModelPlayer = class extends ModelBase {
|
||||
// Right arm ModelRenderer
|
||||
this.rightArm = new ModelRenderer(width, height)
|
||||
.setTextureOffset(40, 16)
|
||||
.setPosition(-5.0, 2.0, 0.0)
|
||||
.setRotationPoint(-5.0, 2.0, 0.0)
|
||||
.setBox(-3.0, -2.0, -2.0, 4, 12, 4);
|
||||
|
||||
// Left arm ModelRenderer
|
||||
this.leftArm = new ModelRenderer(width, height)
|
||||
.setTextureOffset(40, 16)
|
||||
.setPosition(5.0, 2.0, 0.0)
|
||||
.setRotationPoint(5.0, 2.0, 0.0)
|
||||
.setBox(-1.0, -2.0, -2.0, 4, 12, 4);
|
||||
|
||||
// Right Legs ModelRenderer
|
||||
this.rightLeg = new ModelRenderer(width, height)
|
||||
.setTextureOffset(0, 16)
|
||||
.setPosition(-2.0, 12.0, 0.0)
|
||||
.setRotationPoint(-2.0, 12.0, 0.0)
|
||||
.setBox(-2.0, 0.0, -2.0, 4, 12, 4);
|
||||
|
||||
// Left leg ModelRenderer
|
||||
this.leftLeg = new ModelRenderer(width, height)
|
||||
.setTextureOffset(0, 16)
|
||||
.setPosition(2.0, 12.0, 0.0)
|
||||
.setRotationPoint(2.0, 12.0, 0.0)
|
||||
.setBox(-2.0, 0.0, -2.0, 4, 12, 4);
|
||||
}
|
||||
|
||||
@@ -55,22 +55,47 @@ window.ModelPlayer = class extends ModelBase {
|
||||
this.rightLeg.rebuild(tessellator, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the model
|
||||
*
|
||||
* @param group Group to update position and rotation of
|
||||
* @param time Animation offset
|
||||
*/
|
||||
render(group, time) {
|
||||
// Set rotation of cubes
|
||||
this.head.yRotation = Math.sin(time * 0.83);
|
||||
this.head.xRotation = Math.sin(time) * 0.8;
|
||||
this.rightArm.xRotation = Math.sin(time * 0.6662 + Math.PI) * 2.0;
|
||||
this.rightArm.zRotation = (Math.sin(time * 0.2312) + 1.0);
|
||||
this.leftArm.xRotation = Math.sin(time * 0.6662) * 2.0;
|
||||
this.leftArm.zRotation = (Math.sin(time * 0.2812) - 1.0);
|
||||
this.rightLeg.xRotation = Math.sin(time * 0.6662) * 1.4;
|
||||
this.leftLeg.xRotation = Math.sin(time * 0.6662 + Math.PI) * 1.4;
|
||||
render(entity, limbSwingAmount, limbSwing, timeAlive, yaw, pitch) {
|
||||
let group = entity.group;
|
||||
|
||||
this.head.rotateAngleY = MathHelper.toRadians(yaw);
|
||||
this.head.rotateAngleX = MathHelper.toRadians(pitch);
|
||||
this.rightArm.rotateAngleX = Math.cos(limbSwingAmount * 0.6662 + Math.PI) * 2.0 * limbSwing * 0.5;
|
||||
this.leftArm.rotateAngleX = Math.cos(limbSwingAmount * 0.6662) * 2.0 * limbSwing * 0.5;
|
||||
this.rightArm.rotateAngleZ = 0.0;
|
||||
this.leftArm.rotateAngleZ = 0.0;
|
||||
this.rightLeg.rotateAngleX = Math.cos(limbSwingAmount * 0.6662) * 1.4 * limbSwing;
|
||||
this.leftLeg.rotateAngleX = Math.cos(limbSwingAmount * 0.6662 + Math.PI) * 1.4 * limbSwing;
|
||||
this.rightLeg.rotateAngleY = 0.0;
|
||||
this.leftLeg.rotateAngleY = 0.0;
|
||||
|
||||
this.rightArm.rotateAngleY = 0.0;
|
||||
this.rightArm.rotateAngleZ = 0.0;
|
||||
|
||||
if (entity.sneaking) {
|
||||
this.body.rotateAngleX = 0.5;
|
||||
this.rightArm.rotateAngleX += 0.4;
|
||||
this.leftArm.rotateAngleX += 0.4;
|
||||
this.rightLeg.rotationPointZ = 4.0;
|
||||
this.leftLeg.rotationPointZ = 4.0;
|
||||
this.rightLeg.rotationPointY = 9.0;
|
||||
this.leftLeg.rotationPointY = 9.0;
|
||||
this.head.rotationPointY = 1.0;
|
||||
|
||||
group.translateY(-0.2);
|
||||
} else {
|
||||
this.body.rotateAngleX = 0.0;
|
||||
this.rightLeg.rotationPointZ = 0.1;
|
||||
this.leftLeg.rotationPointZ = 0.1;
|
||||
this.rightLeg.rotationPointY = 12.0;
|
||||
this.leftLeg.rotationPointY = 12.0;
|
||||
this.head.rotationPointY = 0.0;
|
||||
}
|
||||
|
||||
this.rightArm.rotateAngleZ += Math.cos(timeAlive * 0.09) * 0.05 + 0.05;
|
||||
this.leftArm.rotateAngleZ -= Math.cos(timeAlive * 0.09) * 0.05 + 0.05;
|
||||
this.rightArm.rotateAngleX += Math.sin(timeAlive * 0.067) * 0.05;
|
||||
this.leftArm.rotateAngleX -= Math.sin(timeAlive * 0.067) * 0.05;
|
||||
|
||||
// Render cubes
|
||||
this.head.render(group);
|
||||
@@ -80,7 +105,7 @@ window.ModelPlayer = class extends ModelBase {
|
||||
this.rightLeg.render(group);
|
||||
this.leftLeg.render(group);
|
||||
|
||||
super.render(group, time);
|
||||
super.render(entity, limbSwingAmount, limbSwing, timeAlive, yaw, pitch);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,13 +10,13 @@ window.ModelRenderer = class {
|
||||
this.textureOffsetX = 0;
|
||||
this.textureOffsetY = 0;
|
||||
|
||||
this.xRotation = 0;
|
||||
this.yRotation = 0;
|
||||
this.zRotation = 0;
|
||||
this.rotateAngleX = 0;
|
||||
this.rotateAngleY = 0;
|
||||
this.rotateAngleZ = 0;
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
this.rotationPointX = 0;
|
||||
this.rotationPointY = 0;
|
||||
this.rotationPointZ = 0;
|
||||
|
||||
this.bone = new THREE.Object3D();
|
||||
}
|
||||
@@ -128,10 +128,10 @@ window.ModelRenderer = class {
|
||||
* @param y Absolute y position of cube
|
||||
* @param z Absolute z position of cube
|
||||
*/
|
||||
setPosition(x, y, z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
setRotationPoint(x, y, z) {
|
||||
this.rotationPointX = x;
|
||||
this.rotationPointY = y;
|
||||
this.rotationPointZ = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -151,14 +151,14 @@ window.ModelRenderer = class {
|
||||
}
|
||||
|
||||
render(group) {
|
||||
this.bone.position.setX(this.x);
|
||||
this.bone.position.setY(this.y);
|
||||
this.bone.position.setZ(this.z);
|
||||
this.bone.position.setX(this.rotationPointX);
|
||||
this.bone.position.setY(this.rotationPointY);
|
||||
this.bone.position.setZ(this.rotationPointZ);
|
||||
|
||||
this.bone.rotation.order = 'ZYX';
|
||||
this.bone.rotation.x = this.xRotation;
|
||||
this.bone.rotation.y = this.yRotation;
|
||||
this.bone.rotation.z = this.zRotation;
|
||||
this.bone.rotation.x = this.rotateAngleX;
|
||||
this.bone.rotation.y = -this.rotateAngleY;
|
||||
this.bone.rotation.z = this.rotateAngleZ;
|
||||
|
||||
this.bone.updateMatrix();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user