2016-01-01 15:15:48 +00:00
|
|
|
package net.minecraftforge.client.model.b3d;
|
|
|
|
|
|
|
|
import net.minecraftforge.client.model.b3d.B3DLoader.NodeJoint;
|
|
|
|
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
|
|
|
import net.minecraftforge.client.model.b3d.B3DModel.Node;
|
2016-03-21 07:01:30 +00:00
|
|
|
import net.minecraftforge.common.animation.Event;
|
|
|
|
import net.minecraftforge.common.model.TRSRTransformation;
|
|
|
|
import net.minecraftforge.common.model.animation.IClip;
|
|
|
|
import net.minecraftforge.common.model.animation.IJoint;
|
|
|
|
import net.minecraftforge.common.model.animation.IJointClip;
|
|
|
|
import net.minecraftforge.common.model.animation.JointClips;
|
2016-01-01 15:15:48 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
|
|
|
|
// FIXME: is this fast enough?
|
|
|
|
public enum B3DClip implements IClip
|
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
INSTANCE;
|
2016-01-01 15:15:48 +00:00
|
|
|
|
|
|
|
public IJointClip apply(final IJoint joint)
|
|
|
|
{
|
|
|
|
if(!(joint instanceof NodeJoint))
|
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return JointClips.IdentityJointClip.INSTANCE;
|
2016-01-01 15:15:48 +00:00
|
|
|
}
|
|
|
|
return new NodeClip(((NodeJoint)joint).getNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Iterable<Event> pastEvents(float lastPollTime, float time)
|
|
|
|
{
|
|
|
|
return ImmutableSet.<Event>of();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static class NodeClip implements IJointClip
|
|
|
|
{
|
|
|
|
private final Node<?> node;
|
|
|
|
|
|
|
|
public NodeClip(Node<?> node)
|
|
|
|
{
|
|
|
|
this.node = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TRSRTransformation apply(float time)
|
|
|
|
{
|
|
|
|
TRSRTransformation ret = TRSRTransformation.identity();
|
|
|
|
if(node.getAnimation() == null)
|
|
|
|
{
|
|
|
|
return ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
|
|
|
}
|
|
|
|
int start = Math.max(1, (int)Math.round(Math.floor(time)));
|
|
|
|
int end = Math.min(start + 1, (int)Math.round(Math.ceil(time)));
|
|
|
|
float progress = time - (float)Math.floor(time);
|
|
|
|
Key keyStart = node.getAnimation().getKeys().get(start, node);
|
|
|
|
Key keyEnd = node.getAnimation().getKeys().get(end, node);
|
|
|
|
TRSRTransformation startTr = keyStart == null ? null : new TRSRTransformation(keyStart.getPos(), keyStart.getRot(),keyStart.getScale(), null);
|
|
|
|
TRSRTransformation endTr = keyEnd == null ? null : new TRSRTransformation(keyEnd.getPos(), keyEnd.getRot(),keyEnd.getScale(), null);
|
|
|
|
if(keyStart == null)
|
|
|
|
{
|
|
|
|
if(keyEnd == null)
|
|
|
|
{
|
|
|
|
ret = ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
|
|
|
}
|
2016-03-23 14:34:48 +00:00
|
|
|
// TODO animated TRSRTransformation for speed?
|
2016-01-01 15:15:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = ret.compose(endTr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(progress < 1e-5 || keyEnd == null)
|
|
|
|
{
|
|
|
|
ret = ret.compose(startTr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = ret.compose(startTr.slerp(endTr, progress));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|