Skip to content

Commit

Permalink
AnimationData + OpenGLSelectionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Nov 5, 2024
1 parent b4a079a commit 0de88ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/paneedah/weaponlib/WeaponRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ public Builder setupModernAnimations(String animationFile, ItemAttachment<Weapon
SingleAnimation compound = set.getSingleAnimation(BBLoader.KEY_COMPOUND_RELOAD);
if (compound != null) {
if (compound.hasBone(BBLoader.KEY_MAGIC_MAGAZINE)) {
if (compound.getBone(BBLoader.KEY_MAGIC_MAGAZINE).bbTransition.size() > 1) {
if (compound.getBone(BBLoader.KEY_MAGIC_MAGAZINE).getBbTransition().size() > 1) {
compoundReloadUsesTactical = true;
}
}
Expand All @@ -1181,7 +1181,7 @@ public Builder setupModernAnimations(String animationFile, ItemAttachment<Weapon
SingleAnimation compoundEmpty = set.getSingleAnimation(BBLoader.KEY_COMPOUND_RELOAD_EMPTY);
if (compoundEmpty != null) {
if (compoundEmpty.hasBone(BBLoader.KEY_MAGIC_MAGAZINE)) {
if (compoundEmpty.getBone(BBLoader.KEY_MAGIC_MAGAZINE).bbTransition.size() > 1) {
if (compoundEmpty.getBone(BBLoader.KEY_MAGIC_MAGAZINE).getBbTransition().size() > 1) {
compoundReloadEmptyUsesTactical = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@ public class OpenGLSelectionHelper {

public static Framebuffer ballBuf;

public static boolean mouseClick = false;

/**
* Allows you to select obj behind
*
* @return
* @return true
*/
public static boolean shouldRender(int id) {
return true;
}

public static void setupSelectionBuffer() {

return true; //TODO This always returns true
}

public static void bindBallBuf() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.paneedah.weaponlib.animation.Transition;
import com.paneedah.weaponlib.render.bgl.math.AngleKit.EulerAngle;
import com.paneedah.weaponlib.render.bgl.math.AngleKit.Format;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.Vec3d;
Expand All @@ -22,11 +24,11 @@

public class AnimationData {

public TreeMap<Float, BlockbenchTransition> bbTransition = new TreeMap<>();
@Getter @Setter private TreeMap<Float, BlockbenchTransition> bbTransition = new TreeMap<>();

public static final float PACE = 833f;

public ArrayList<Float> timestamps = new ArrayList<>();
@Setter @Getter private ArrayList<Float> timestamps = new ArrayList<>();

public TreeMap<Float, Vec3d> rotationKeyframes = new TreeMap<>();
public TreeMap<Float, Vec3d> translateKeyframes = new TreeMap<>();
Expand All @@ -37,7 +39,7 @@ public class AnimationData {


// The **ACTUAL** duration of the animation as designated in the BlockBench file
private float appointedDuration;
@Setter @Getter private float appointedDuration;


protected AnimationData(ArrayList<Float> arrayList) {
Expand All @@ -46,14 +48,6 @@ protected AnimationData(ArrayList<Float> arrayList) {
this.fTLength = (long) (arrayList.get(arrayList.size() - 1) / arrayList.size());

Check warning on line 48 in src/main/java/com/paneedah/weaponlib/animation/jim/AnimationData.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Auto-unboxing

Auto-unboxing `arrayList.get(arrayList.size() - 1)`
}

public void setAppointedDuration(float f) {
this.appointedDuration = f;
}

public float getAppointedDuration() {
return this.appointedDuration;
}

public AnimationData(JsonObject obj) {

// initialize a timestamp array and the key arrays
Expand Down Expand Up @@ -205,7 +199,7 @@ public void setSounds(HashMap<Float, String> map, ArrayList<Float> overflowList)
for (Entry<Float, BlockbenchTransition> set : this.bbTransition.entrySet()) {
if (map.containsKey(set.getKey())) {
overflowList.remove(set.getKey());
set.getValue().setSound(UniversalSoundLookup.lookupSound(map.get(set.getKey())));
set.getValue().setSoundEvent(UniversalSoundLookup.lookupSound(map.get(set.getKey())));
}
}
}
Expand Down Expand Up @@ -464,21 +458,17 @@ public List<Transition<RenderContext<RenderableState>>> getTransitionList(Transf

public static class BlockbenchTransition {

private float timestamp;
private Vec3d rotation;
private Vec3d translation;
private SoundEvent sound;
@Getter @Setter private float timestamp;
@Getter @Setter private Vec3d rotation;
@Getter @Setter private Vec3d translation;
@Getter @Setter private SoundEvent soundEvent;

public BlockbenchTransition(float timestamp, Vec3d rotation, Vec3d translation) {
this.timestamp = timestamp;
this.rotation = rotation;
this.translation = translation;
}

public void setSound(SoundEvent sound) {
this.sound = sound;
}

public void directTransform() {
GL11.glTranslated(translation.x / 25f, translation.y / 25f, translation.z / 25f);

Expand Down Expand Up @@ -521,9 +511,6 @@ public Transition<?> createVMWTransitionWithADS(Transform normal, Transform ads,
*/


Transform t = normal;


double rotXMult = 1.0;
double rotYMult = 1.0;
double rotZMult = 1.0;
Expand All @@ -548,31 +535,31 @@ public Transition<?> createVMWTransitionWithADS(Transform normal, Transform ads,
double mul = 1 / tesla;

// Original object positioning
GlStateManager.translate(t.getPositionX(), t.getPositionY(), t.getPositionZ());
GlStateManager.translate(normal.getPositionX(), normal.getPositionY(), normal.getPositionZ());

// Animation translation
GL11.glTranslated(translation.x * mul, -translation.y * mul, translation.z * mul);

// Offset rotation point
GlStateManager.translate(t.getRotationPointX(), t.getRotationPointY(), t.getRotationPointZ());
GlStateManager.translate(normal.getRotationPointX(), normal.getRotationPointY(), normal.getRotationPointZ());

// Original object rotation (+Z, -Y, -X)
GL11.glRotated(t.getRotationZ(), 0, 0, 1);
GL11.glRotated(normal.getRotationZ(), 0, 0, 1);
GL11.glRotated(rotation.z * rotZMult, 0, 0, 1);

GL11.glRotated(t.getRotationY(), 0, 1, 0);
GL11.glRotated(normal.getRotationY(), 0, 1, 0);
GL11.glRotated(rotation.y * rotYMult, 0, 1, 0);

GL11.glRotated(t.getRotationX(), 1, 0, 0);
GL11.glRotated(normal.getRotationX(), 1, 0, 0);
GL11.glRotated(rotation.x * rotXMult, 1, 0, 0);

GlStateManager.translate(-t.getRotationPointX(), -t.getRotationPointY(), -t.getRotationPointZ());
GlStateManager.scale(t.getScaleX(), t.getScaleY(), t.getScaleZ());
GlStateManager.translate(-normal.getRotationPointX(), -normal.getRotationPointY(), -normal.getRotationPointZ());
GlStateManager.scale(normal.getScaleX(), normal.getScaleY(), normal.getScaleZ());


}, (int) timestamp);
// System.out.println("Hello?! Brother! " + sound);
trans.setSoundEvent(sound);
// System.out.println("Hello?! Brother! " + soundEvent);
trans.setSoundEvent(soundEvent);

return trans;

Expand Down Expand Up @@ -660,8 +647,8 @@ public Transition<?> createVMWTransition(Transform t, double divisor) {
}, Math.round(timestamp));


//System.out.println("Hello?! Brother! " + sound);
trans.setSoundEvent(sound);
//System.out.println("Hello?! Brother! " + soundEvent);
trans.setSoundEvent(soundEvent);
return trans;

}
Expand All @@ -680,46 +667,6 @@ public String toString() {
return "[(" + this.timestamp + ") " + this.rotation + " > " + this.translation + "]";
}

public float getTimestamp() {
return timestamp;
}

public void setTimestamp(float timestamp) {
this.timestamp = timestamp;
}

public Vec3d getRotation() {
return rotation;
}

public void setRotation(Vec3d rotation) {
this.rotation = rotation;
}

public Vec3d getTranslation() {
return translation;
}

public void setTranslation(Vec3d translation) {
this.translation = translation;
}

}

public TreeMap<Float, BlockbenchTransition> getBbTransition() {
return bbTransition;
}

public void setBbTransition(TreeMap<Float, BlockbenchTransition> bbTransition) {
this.bbTransition = bbTransition;
}

public ArrayList<Float> getTimestamps() {
return timestamps;
}

public void setTimestamps(ArrayList<Float> timestamps) {
this.timestamps = timestamps;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public KeyedAnimation(float max) {

public KeyedAnimation(AnimationData data) {
// Copy keys
for (Entry<Float, BlockbenchTransition> entry : data.bbTransition.entrySet()) {
for (Entry<Float, BlockbenchTransition> entry : data.getBbTransition().entrySet()) {
bbMap.put(entry.getKey(), entry.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public void bake() {

for (int t = 0; t < getTimestamps().size(); ++t) {
if (t == 0) {
data.bbTransition.get(getTimestamps().get(t)).setTimestamp(1.0f);
data.getBbTransition().get(getTimestamps().get(t)).setTimestamp(1.0f);
} else {
float trueDelta = AnimationData.PACE * (getTimestamps().get(t) - getTimestamps().get(t - 1));

Check warning on line 91 in src/main/java/com/paneedah/weaponlib/animation/jim/SingleAnimation.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Auto-unboxing

Auto-unboxing `getTimestamps().get(t - 1)`

Check warning on line 91 in src/main/java/com/paneedah/weaponlib/animation/jim/SingleAnimation.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Auto-unboxing

Auto-unboxing `getTimestamps().get(t)`

//System.out.println("(" + getTimestamps().get(t-1) + ") -> (" + getTimestamps().get(t) + ") " + trueDelta);
data.bbTransition.get(getTimestamps().get(t)).setTimestamp(trueDelta);
data.getBbTransition().get(getTimestamps().get(t)).setTimestamp(trueDelta);
}
}

Expand Down

0 comments on commit 0de88ed

Please sign in to comment.